cleanup cameraThread/dataPortConnection
parent
993636746c
commit
440939483b
|
@ -1,24 +1,10 @@
|
|||
module.exports = function(jsonData,onConnected){
|
||||
module.exports = function(jsonData,onConnected,onError,onClose){
|
||||
const config = jsonData.globalInfo.config;
|
||||
const dataPortToken = jsonData.dataPortToken;
|
||||
const CWS = require('cws');
|
||||
const client = new CWS(`ws://localhost:${config.port}/dataPort`);
|
||||
console.log('readyState:', client.readyState);
|
||||
client.on('error', e => {
|
||||
console.error(e);
|
||||
});
|
||||
client.on('close', e => {
|
||||
console.log('The websocket was closed');
|
||||
});
|
||||
//
|
||||
// // Listen for messages & log them
|
||||
// client.on('message', message => {
|
||||
// if ('string' !== typeof message) throw Error("Message could not be decoded");
|
||||
// const received = JSON.parse(message);
|
||||
// console.log('Message received:', received);
|
||||
// });
|
||||
client.on('open', () => {
|
||||
onConnected()
|
||||
});
|
||||
if(onError)client.on('error',onError);
|
||||
if(onClose)client.on('close',onClose);
|
||||
client.on('open',onConnected);
|
||||
return client;
|
||||
}
|
||||
|
|
|
@ -14,8 +14,24 @@ const stdioPipes = jsonData.pipes || []
|
|||
var newPipes = []
|
||||
var stdioWriters = [];
|
||||
|
||||
const dataPort = require('./libs/dataPortConnection.js')(jsonData,() => {
|
||||
const dataPort = require('./libs/dataPortConnection.js')(jsonData,
|
||||
// onConnected
|
||||
() => {
|
||||
dataPort.send(jsonData.dataPortToken)
|
||||
},
|
||||
// onError
|
||||
(err) => {
|
||||
writeToStderr([
|
||||
'dataPort:Connection:Error',
|
||||
err
|
||||
])
|
||||
},
|
||||
// onClose
|
||||
(e) => {
|
||||
writeToStderr([
|
||||
'dataPort:Connection:Closed',
|
||||
e
|
||||
])
|
||||
})
|
||||
|
||||
var writeToStderr = function(argsAsArray){
|
||||
|
|
Loading…
Reference in New Issue