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