smartfacecloud-emulator-dispatcher
Advanced tools
Comparing version
{ | ||
"name": "smartfacecloud-emulator-dispatcher", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "Handles Emulator Dispatcher Part of SmartfaceCloud", | ||
@@ -38,3 +38,3 @@ "main": "src/index.js", | ||
"node-uuid": "1.4.7", | ||
"smartfacecloud-emulator-control": "0.0.2", | ||
"smartfacecloud-emulator-control": "0.0.3", | ||
"smartfacecloud-emulator-file": "0.0.4", | ||
@@ -57,8 +57,3 @@ "unique-random-array": "1.0.0", | ||
"path": "node_modules/cz-conventional-changelog" | ||
}, | ||
"config": { | ||
"ghooks": { | ||
"pre-commit": "npm run test:single && npm run check-coverage" | ||
} | ||
} | ||
} |
@@ -39,3 +39,3 @@ var CLIENTS = {}; | ||
} | ||
var ws; | ||
var ws, json_str; | ||
/* istanbul ignore next */ | ||
@@ -49,5 +49,7 @@ if (message.meta.to === 'device') { | ||
if (message.meta.to === 'device') { | ||
ws.send(JSON.stringify(message.data)); | ||
json_str = JSON.stringify(message.data); | ||
ws.send(json_str, ackErrorGenerator("An error occured while sending message to device: " + json_str)); | ||
} else if (message.meta.to === 'UI') { | ||
ws.send(JSON.stringify(message)); | ||
json_str = JSON.stringify(message); | ||
ws.send(json_str, ackErrorGenerator("An error occured while sending message to UI: " + json_str)); | ||
} | ||
@@ -63,6 +65,2 @@ } else { | ||
const service = ws.upgradeReq.url.replace('/', ''); | ||
allWebsockets[service] = ws; | ||
if (service === 'UI') { | ||
ws.send('hello UI'); | ||
} | ||
var id = 0; | ||
@@ -78,2 +76,6 @@ const shouldLogToConsole = true || opts.meta.logToConsole; | ||
} | ||
if (allWebsockets[service]) { | ||
allWebsockets[service].terminate(); | ||
} | ||
allWebsockets[service] = ws; | ||
/* istanbul ignore next */ | ||
@@ -102,3 +104,3 @@ shouldLogToConsole && console.log('\n[connecting]', service); | ||
} | ||
eventEmitter.emit('message', { | ||
eventEmitter.emit('message', { | ||
meta: { | ||
@@ -112,3 +114,2 @@ id: uuid.v4(), | ||
}); | ||
// eventEmitter.emit('message', message); | ||
}); | ||
@@ -123,3 +124,3 @@ }); | ||
wss.clients.forEach(function (client) { | ||
client.send(data); | ||
client.send(data, ackErrorGenerator(data)); | ||
}); | ||
@@ -178,4 +179,12 @@ }; | ||
function ackErrorGenerator(str) { | ||
return function ack(error) { | ||
if (error) { | ||
console.log(str); | ||
} | ||
} | ||
} | ||
module.exports = { | ||
init: init | ||
}; |
@@ -21,2 +21,6 @@ function capitalizeFirstLetter(string) { | ||
function log(message) { | ||
console.log("[DISPATCHER] ", message); | ||
} | ||
module.exports = { | ||
@@ -23,0 +27,0 @@ capitalizeFirstLetter: capitalizeFirstLetter, |
@@ -8,3 +8,3 @@ const WebSocket = require('ws'); | ||
describe('Websocket', function() { | ||
describe.skip('Websocket', function() { | ||
before(function(done) { | ||
@@ -11,0 +11,0 @@ dispatcher = init({ |
140710
580.22%31
106.67%1003
62.3%+ Added
- Removed