film-exif/src/electron/websocket-events.js

34 lines
874 B
JavaScript
Raw Normal View History

2018-04-12 21:57:16 -04:00
/**
* Websocket event handlers
*/
2018-04-16 16:37:00 -04:00
const {ExifTool} = require('exiftool-vendored');
2018-04-13 23:28:55 -04:00
const {JSONMessage} = require('../helpers/web-socket');
2018-04-12 21:57:16 -04:00
2018-04-16 16:37:00 -04:00
const exiftool = new ExifTool();
2018-04-12 21:57:16 -04:00
module.exports = (wss) => {
2018-04-13 23:28:55 -04:00
wss.on('connection', ws => {
ws.send(JSONMessage('server-log', 'Connected to client!'));
ws.on('message', (...args) => {
2018-04-16 16:37:00 -04:00
const [type, message] = JSON.parse(args);
switch (type) {
case 'dropped-files':
2018-04-17 14:12:55 -04:00
const filemap = message.map(async file => {
2018-04-16 16:37:00 -04:00
const tags = await getExifTags(file);
2018-04-17 14:12:55 -04:00
// console.info('Parsed tags', JSON.stringify(tags));
return JSON.parse(JSON.stringify(tags));
2018-04-16 16:37:00 -04:00
});
2018-04-17 14:12:55 -04:00
wss.broadcast(JSONMessage('parsed-exif-tags', filemap));
2018-04-16 16:37:00 -04:00
break;
2018-04-13 23:28:55 -04:00
2018-04-16 16:37:00 -04:00
default:
return ws.send(JSONMessage('server-log', [type, message]));
}
2018-04-12 21:57:16 -04:00
});
});
};
2018-04-16 16:37:00 -04:00
2018-04-17 14:12:55 -04:00
async function getExifTags (imgPath) {
await exiftool.read(imgPath);
2018-04-16 16:37:00 -04:00
}