Skip to content

Commit

Permalink
Merge pull request #98 from ckhmer1/camera
Browse files Browse the repository at this point in the history
Added AppIds to the camera node
  • Loading branch information
Caprico85 authored Jan 28, 2021
2 parents 78aca23 + e3fd5bc commit 170d34e
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 20 deletions.
32 changes: 32 additions & 0 deletions devices/camera.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,41 @@
<input type="text" id="node-input-hls" data-i18n="[placeholder]camera.placeholder.hls">
</div>

<div class="form-row">
<label for="node-input-hls_app_id"><i class="fa fa-tasks"></i> <span data-i18n="camera.label.hls_app_id"></span></label>
<input type="text" id="node-input-hls_app_id" data-i18n="[placeholder]camera.placeholder.hls_app_id">
</div>

<div class="form-row">
<label for="node-input-dash"><i class="fa fa-tasks"></i> <span data-i18n="camera.label.dash"></span></label>
<input type="text" id="node-input-dash" data-i18n="[placeholder]camera.placeholder.dash">
</div>

<div class="form-row">
<label for="node-input-dash_app_id"><i class="fa fa-tasks"></i> <span data-i18n="camera.label.dash_app_id"></span></label>
<input type="text" id="node-input-dash_app_id" data-i18n="[placeholder]camera.placeholder.dash_app_id">
</div>

<div class="form-row">
<label for="node-input-smooth_stream"><i class="fa fa-tasks"></i> <span data-i18n="camera.label.smooth_stream"></span></label>
<input type="text" id="node-input-smooth_stream" data-i18n="[placeholder]camera.placeholder.smooth_stream">
</div>

<div class="form-row">
<label for="node-input-smooth_stream_app_id"><i class="fa fa-tasks"></i> <span data-i18n="camera.label.smooth_stream_app_id"></span></label>
<input type="text" id="node-input-smooth_stream_app_id" data-i18n="[placeholder]camera.placeholder.smooth_stream_app_id">
</div>

<div class="form-row">
<label for="node-input-progressive_mp4"><i class="fa fa-tasks"></i> <span data-i18n="camera.label.progressive_mp4"></span></label>
<input type="text" id="node-input-progressive_mp4" data-i18n="[placeholder]camera.placeholder.progressive_mp4">
</div>

<div class="form-row">
<label for="node-input-progressive_mp4_app_id"><i class="fa fa-tasks"></i> <span data-i18n="camera.label.progressive_mp4_app_id"></span></label>
<input type="text" id="node-input-progressive_mp4_app_id" data-i18n="[placeholder]camera.placeholder.progressive_mp4_app_id">
</div>

<div class="form-row">
<label for="node-input-auth_token"><i class="fa fa-tasks"></i> <span data-i18n="camera.label.auth_token"></span></label>
<input type="text" id="node-input-auth_token" data-i18n="[placeholder]camera.placeholder.auth_token">
Expand Down Expand Up @@ -162,15 +182,27 @@ <h3>References</h3>
hls: {
value: "", required:false
},
hls_app_id: {
value: "", required:false
},
dash: {
value: "", required:false
},
dash_app_id: {
value: "", required:false
},
smooth_stream: {
value: "", required:false
},
smooth_stream_app_id: {
value: "", required:false
},
progressive_mp4: {
value: "", required:false
},
progressive_mp4_app_id: {
value: "", required:false
},
auth_token: {
value: "", required:false
},
Expand Down
59 changes: 41 additions & 18 deletions devices/camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,18 @@ module.exports = function(RED) {
constructor(config) {
RED.nodes.createNode(this, config);

this.client = config.client;
this.clientConn = RED.nodes.getNode(this.client);
this.topicOut = config.topic;
this.hlsUrl = config.hls.trim();
this.dashUrl = config.dash.trim();
this.smoothStreamUrl = config.smooth_stream.trim();
this.progressiveMp4Url = config.progressive_mp4.trim();
this.authToken = config.auth_token.trim();
this.client = config.client;
this.clientConn = RED.nodes.getNode(this.client);
this.topicOut = config.topic;
this.hlsUrl = config.hls.trim();
this.hlsAppId = config.hls_app_id.trim();
this.dashUrl = config.dash.trim();
this.dashAppId = config.dash_app_id.trim();
this.smoothStreamUrl = config.smooth_stream.trim();
this.smoothStreamAppId = config.smooth_stream_app_id.trim();
this.progressiveMp4Url = config.progressive_mp4.trim();
this.progressiveMp4AppId = config.progressive_mp4_app_id.trim();
this.authToken = config.auth_token.trim();

if (!this.clientConn) {
this.error(RED._("camera.errors.missing-config"));
Expand All @@ -48,21 +52,21 @@ module.exports = function(RED) {
return;
}

let protocols = [];
this.protocols = [];
if (this.hlsUrl) {
protocols.push('hls');
this.protocols.push('hls');
}
if (this.dashUrl) {
protocols.push('dash');
this.protocols.push('dash');
}
if (this.smoothStreamUrl) {
protocols.push('smooth_stream');
this.protocols.push('smooth_stream');
}
if (this.progressiveMp4Url) {
protocols.push('progressive_mp4');
this.protocols.push('progressive_mp4');
}

this.states = this.clientConn.register(this, 'camera', config.name, protocols, this.authToken.length > 0);
this.states = this.clientConn.register(this, 'camera', config.name, this);

this.status({fill: "yellow", shape: "dot", text: "Ready"});

Expand All @@ -74,7 +78,8 @@ module.exports = function(RED) {
* called to register device
*
*/
registerDevice(client, name, protocols, needAuthToken) {
registerDevice(client, name, me) {
const needAuthToken = me.authToken.length > 0;
let states = {
online: true
};
Expand All @@ -90,7 +95,7 @@ module.exports = function(RED) {
},
willReportState: true,
attributes: {
cameraStreamSupportedProtocols: protocols,
cameraStreamSupportedProtocols: me.protocols,
cameraStreamNeedAuthToken: needAuthToken
},
deviceInfo: {
Expand Down Expand Up @@ -232,6 +237,20 @@ module.exports = function(RED) {
return '';
}

getAppId(protocol_type) {
switch(protocol_type) {
case 'hls':
return this.hlsAppId;
case 'dash':
return this.dashAppId;
case 'smooth_stream':
return this.smoothStreamAppId;
case 'progressive_mp4':
return this.progressiveMp4AppId;
}
return '';
}

execCommand(device, command) {
let me = this;

Expand All @@ -251,16 +270,20 @@ module.exports = function(RED) {
}
});
if (protocol.length > 0) {
let executionStates = ['online', 'cameraStreamAccessUrl', 'cameraStreamReceiverAppId', 'cameraStreamProtocol'];
let executionStates = ['online', 'cameraStreamAccessUrl', 'cameraStreamProtocol'];
if (me.authToken.length > 0) {
executionStates.push('cameraStreamAuthToken');
}
const appId = this.getAppId(protocol);
if (appId.length > 0) {
executionStates.push('cameraStreamReceiverAppId');
}
return {
status: 'SUCCESS',
states: {
online: true,
cameraStreamAccessUrl: stramUrl,
cameraStreamReceiverAppId: device.id, // App ID ??
cameraStreamReceiverAppId: appId,
cameraStreamAuthToken: me.authToken,
cameraStreamProtocol: protocol
},
Expand Down
8 changes: 8 additions & 0 deletions devices/locales/en-US/camera.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,26 @@
"name": "Name",
"topic": "Out topic",
"hls": "Hls url",
"hls_app_id": "Hls App Id",
"dash": "Dash url",
"dash_app_id": "Dash App Id",
"smooth_stream": "Smooth stream url",
"smooth_stream_app_id": "Smooth stream App Id",
"progressive_mp4": "Progressive mp4 url",
"progressive_mp4_app_id": "Progressive mp4 App Id",
"auth_token": "Authorization token"
},
"placeholder": {
"name": "Name",
"topic": "Outgoing topic",
"hls": "Hls url",
"hls_app_id": "Hls App Id",
"dash": "Dash url",
"dash_app_id": "Dash App Id",
"smooth_stream": "Smooth stream url",
"smooth_stream_app_id": "Smooth stream App Id",
"progressive_mp4": "Progressive mp4 url",
"progressive_mp4_app_id": "Progressive mp4 App Id",
"auth_token": "Authorization token"
},
"errors": {
Expand Down
12 changes: 10 additions & 2 deletions devices/locales/it_IT/camera.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,26 @@
"name": "Nome",
"topic": "Oggetto in uscita",
"hls": "Hls url",
"hls_app_id": "Hls App Id",
"dash": "Dash url",
"dasmooth_streamsh": "Smooth stream url",
"dash_app_id": "Dash App Id",
"smooth_stream": "Smooth stream url",
"smooth_stream_app_id": "Smooth stream App Id",
"progressive_mp4": "Progressive mp4 url",
"progressive_mp4_app_id": "Progressive mp4 App Id",
"auth_token": "Token di autorizzazione"
},
"placeholder": {
"name": "Nome",
"topic": "Oggetto corrente",
"hls": "Hls url",
"hls_app_id": "Hls App Id",
"dash": "Dash url",
"dasmooth_streamsh": "Smooth stream url",
"dash_app_id": "Dash App Id",
"smooth_stream": "Smooth stream url",
"smooth_stream_app_id": "Smooth stream App Id",
"progressive_mp4": "Progressive mp4 url",
"progressive_mp4_app_id": "Progressive mp4 App Id",
"auth_token": "Token di autorizzazione"
},
"errors": {
Expand Down

0 comments on commit 170d34e

Please sign in to comment.