almost functional dataPort
parent
70b912ce06
commit
8240933437
|
@ -33,6 +33,8 @@ require('./libs/ffmpeg.js')(s,config,lang, async () => {
|
|||
require('./libs/auth.js')(s,config,lang)
|
||||
//express web server with ejs
|
||||
const app = require('./libs/webServer.js')(s,config,lang,io)
|
||||
//data port
|
||||
require('./libs/dataPort.js')(s,config,lang,app,io)
|
||||
//page layout load
|
||||
require('./libs/definitions.js')(s,config,lang,app,io)
|
||||
//web server routes : page handling..
|
||||
|
@ -85,8 +87,6 @@ require('./libs/ffmpeg.js')(s,config,lang, async () => {
|
|||
require('./libs/scheduler.js')(s,config,lang,app,io)
|
||||
//onvif device manager
|
||||
require('./libs/onvifDeviceManager.js')(s,config,lang,app,io)
|
||||
//data port
|
||||
// require('./libs/dataPort.js')(s,config,lang,app,io)
|
||||
//alternate logins
|
||||
require('./libs/auth/logins.js')(s,config,lang,app)
|
||||
//on-start actions, daemon(s) starter
|
||||
|
|
|
@ -1,35 +1,24 @@
|
|||
module.exports = function(jsonData){
|
||||
var WebSocketClient = require('websocket').client;
|
||||
|
||||
var client = new WebSocketClient();
|
||||
|
||||
client.on('connectFailed', function(error) {
|
||||
console.log('Connect Error: ' + error.toString());
|
||||
module.exports = function(jsonData,onConnected){
|
||||
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('connect', function(connection) {
|
||||
console.log('WebSocket Client Connected');
|
||||
connection.on('error', function(error) {
|
||||
console.log("Connection Error: " + error.toString());
|
||||
});
|
||||
connection.on('close', function() {
|
||||
console.log('echo-protocol Connection Closed');
|
||||
});
|
||||
connection.on('message', function(message) {
|
||||
if (message.type === 'utf8') {
|
||||
console.log("Received: '" + message.utf8Data + "'");
|
||||
}
|
||||
});
|
||||
|
||||
function sendNumber() {
|
||||
if (connection.connected) {
|
||||
var number = Math.round(Math.random() * 0xFFFFFF);
|
||||
connection.sendUTF(number.toString());
|
||||
setTimeout(sendNumber, 1000);
|
||||
}
|
||||
}
|
||||
sendNumber();
|
||||
client.on('close', e => {
|
||||
console.log('The websocket was closed');
|
||||
});
|
||||
|
||||
client.connect('ws://localhost:8080/', 'echo-protocol');
|
||||
//
|
||||
// // 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()
|
||||
});
|
||||
return client;
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ module.exports = function(jsonData,pamDiffResponder,alternatePamDiff){
|
|||
}
|
||||
}
|
||||
function logData(...args){
|
||||
process.logData(JSON.stringify(args))
|
||||
process.logData(args)
|
||||
}
|
||||
function getRegionsWithMinimumChange(data){
|
||||
try{
|
||||
|
|
|
@ -14,11 +14,17 @@ const stdioPipes = jsonData.pipes || []
|
|||
var newPipes = []
|
||||
var stdioWriters = [];
|
||||
|
||||
// const dataPort = require('./libs/dataPortConnection.js')(jsonData)
|
||||
const dataPort = require('./libs/dataPortConnection.js')(jsonData,() => {
|
||||
dataPort.send(jsonData.dataPortToken)
|
||||
})
|
||||
|
||||
var writeToStderr = function(text){
|
||||
var writeToStderr = function(argsAsArray){
|
||||
try{
|
||||
process.stderr.write(Buffer.from(`${text}`, 'utf8' ))
|
||||
// process.stderr.write(Buffer.from(`${text}`, 'utf8' ))
|
||||
dataPort.send({
|
||||
f: 'debugLog',
|
||||
data: argsAsArray,
|
||||
})
|
||||
// stdioWriters[2].write(Buffer.from(`${new Error('writeToStderr').stack}`, 'utf8' ))
|
||||
}catch(err){
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
const url = require('url');
|
||||
module.exports = function(s,config,lang,app,io){
|
||||
const {
|
||||
triggerEvent,
|
||||
|
@ -21,8 +22,10 @@ module.exports = function(s,config,lang,app,io){
|
|||
// client.send(someDataToSendAsStringOrBinary)
|
||||
setClientKillTimerIfNotAuthenticatedInTime(client)
|
||||
function onAuthenticate(data){
|
||||
console.log('AUTHING DATA PORT',data)
|
||||
clearKillTimer(client)
|
||||
if(s.dataPortTokens[data]){
|
||||
console.log('AUTH DATA PORT',true)
|
||||
sendData = onAuthenticatedData;
|
||||
delete(s.dataPortTokens[data]);
|
||||
}else{
|
||||
|
@ -30,6 +33,7 @@ module.exports = function(s,config,lang,app,io){
|
|||
}
|
||||
}
|
||||
function onAuthenticatedData(data){
|
||||
console.log('DATA PORT',data)
|
||||
switch(data.f){
|
||||
case'trigger':
|
||||
triggerEvent(data)
|
||||
|
@ -37,18 +41,18 @@ module.exports = function(s,config,lang,app,io){
|
|||
case's.tx':
|
||||
s.tx(data.data,data.to)
|
||||
break;
|
||||
case'log':
|
||||
console.log(data.data)
|
||||
break;
|
||||
case'debugLog':
|
||||
s.debugLog(data.data)
|
||||
break;
|
||||
default:
|
||||
console.log(data)
|
||||
break;
|
||||
}
|
||||
s.onDataPortMessageExtensions.forEach(function(extender){
|
||||
extender(data)
|
||||
})
|
||||
}
|
||||
let sendData = onAuthenticate;
|
||||
var sendData = onAuthenticate;
|
||||
client.on('message', sendData)
|
||||
})
|
||||
theWebSocket.broadcast = function(data) {
|
||||
|
|
|
@ -26,12 +26,12 @@ module.exports = async (s,config,lang,onFinish) => {
|
|||
|
||||
s.ffmpeg = function(e){
|
||||
try{
|
||||
// const dataPortToken = s.gid(10);
|
||||
// s.dataPortTokens[dataPortToken] = {
|
||||
// type: 'cameraThread',
|
||||
// ke: e.ke,
|
||||
// mid: e.mid,
|
||||
// }
|
||||
const dataPortToken = s.gid(10);
|
||||
s.dataPortTokens[dataPortToken] = {
|
||||
type: 'cameraThread',
|
||||
ke: e.ke,
|
||||
mid: e.mid,
|
||||
}
|
||||
const ffmpegCommand = [`-progress pipe:5`];
|
||||
([
|
||||
buildMainInput(e),
|
||||
|
@ -60,7 +60,7 @@ module.exports = async (s,config,lang,onFinish) => {
|
|||
|
||||
}
|
||||
fs.writeFileSync(e.sdir + 'cmd.txt',JSON.stringify({
|
||||
// dataPortToken: dataPortToken,
|
||||
dataPortToken: dataPortToken,
|
||||
cmd: ffmpegCommandParsed,
|
||||
pipes: stdioPipes.length,
|
||||
rawMonitorConfig: s.group[e.ke].rawMonitorConfigurations[e.id],
|
||||
|
|
Loading…
Reference in New Issue