diff --git a/package.json b/package.json index a9525ac..17485cd 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,6 @@ "inferno-bootstrap": "^5.0.0", "inferno-dev-utils": "^5.3.0", "inferno-router": "^5.0.1", - "isomorphic-ws": "^4.0.0", "lodash": "^4.17.5", "ws": "^5.1.1" }, @@ -63,8 +62,8 @@ }, "scripts": { "build": "node scripts/build.js", - "dist": "yarn run build && build", - "electron-start": "node src/electron/wait-inferno", + "dist": "yarn run build && build", + "electron-start": "node src/electron/wait-inferno", "electron": "electron .", "fix": "eslint --fix src/**/*.js", "lint": "eslint src/**/*.js", diff --git a/src/App.js b/src/App.js index e78ea4d..c25808a 100644 --- a/src/App.js +++ b/src/App.js @@ -1,7 +1,6 @@ import * as _ from 'lodash'; import { Component } from 'inferno'; import { BrowserRouter, Link, NavLink } from 'inferno-router'; -import WS from 'isomorphic-ws'; import { Loader } from './components'; import { Container, @@ -27,7 +26,7 @@ export class App extends Component { } componentDidMount () { - window.clientWS = new WS('ws://localhost:65432/'); + window.clientWS = new WebSocket('ws://localhost:65432/'); window.clientWS.addEventListener('open', this.onWebSocketOpen); window.clientWS.addEventListener('message', console); diff --git a/src/electron/starter.js b/src/electron/starter.js index bca6e09..b539951 100644 --- a/src/electron/starter.js +++ b/src/electron/starter.js @@ -6,7 +6,9 @@ log.transports.console.level = 'info'; const path = require('path'); const url = require('url'); -const WS = require('isomorphic-ws'); + +// eslint-disable-next-line +const WebSocket = require('ws'); // eslint-disable-next-line global.eval = () => {}; @@ -71,9 +73,17 @@ app.on('activate', () => { } }); -const wss = new WS.Server({ +const wss = new WebSocket.Server({ + perMessageDeflate: false, port: 65432, }); +wss.broadcast = (data) => { + wss.clients.forEach(client => { + if (client.readyState === WebSocket.OPEN) { + client.send(data); + } + }); +}; // In this file you can include the rest of your app's specific main process // code. You can also put them in separate files and require them here. require('./websocket-events')(wss); diff --git a/src/electron/websocket-events.js b/src/electron/websocket-events.js index 16a4893..1329a9d 100644 --- a/src/electron/websocket-events.js +++ b/src/electron/websocket-events.js @@ -9,18 +9,16 @@ const exiftool = new ExifTool(); module.exports = (wss) => { wss.on('connection', ws => { ws.send(JSONMessage('server-log', 'Connected to client!')); - ws.on('message', (...args) => { const [type, message] = JSON.parse(args); switch (type) { case 'dropped-files': - const filemap = []; - message.forEach(async file => { + const filemap = message.map(async file => { const tags = await getExifTags(file); - console.info(tags); - filemap[file] = tags; + // console.info('Parsed tags', JSON.stringify(tags)); + return JSON.parse(JSON.stringify(tags)); }); - ws.send(JSONMessage('parsed-exif-tags', filemap)); + wss.broadcast(JSONMessage('parsed-exif-tags', filemap)); break; default: @@ -30,6 +28,6 @@ module.exports = (wss) => { }); }; -function getExifTags (imgPath) { - return exiftool.read(imgPath); +async function getExifTags (imgPath) { + await exiftool.read(imgPath); } diff --git a/yarn.lock b/yarn.lock index f6e7eb1..c6d7878 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4657,10 +4657,6 @@ isomorphic-fetch@^2.1.1: node-fetch "^1.0.1" whatwg-fetch ">=0.10.0" -isomorphic-ws@^4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/isomorphic-ws/-/isomorphic-ws-4.0.0.tgz#7b528b238c920eeb3f5fe429ac416df669ea4cba" - isstream@~0.1.2: version "0.1.2" resolved "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a"