homebridge-nest-accfactory 0.0.4-a → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/streamer.js CHANGED
@@ -13,7 +13,7 @@
13
13
  // streamer.talkingAudio(talkingData)
14
14
  // streamer.update(deviceData) <- call super after
15
15
  //
16
- // Code version 6/9/2024
16
+ // Code version 11/9/2024
17
17
  // Mark Hulskamp
18
18
  'use strict';
19
19
 
@@ -35,17 +35,18 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url)); // Make a define
35
35
 
36
36
  // Streamer object
37
37
  export default class Streamer {
38
- cameraOfflineFrame = undefined;
39
- cameraVideoOffFrame = undefined;
40
- videoEnabled = undefined;
41
- audioEnabled = undefined;
42
- online = undefined;
38
+ videoEnabled = undefined; // Video stream on camera enabled or not
39
+ audioEnabled = undefined; // Audio from camera enabled or not
40
+ online = undefined; // Camera online or not
43
41
  host = ''; // Host to connect to or connected too
44
- socket = null; // TCP socket object
42
+ uuid = undefined; // UUID of the device connecting
43
+ connected = false; // Streamer connected to endpoint
45
44
 
46
45
  // Internal data only for this class
47
46
  #outputTimer = undefined; // Timer for non-blocking loop to stream output data
48
47
  #outputs = {}; // Output streams ie: buffer, live, record
48
+ #cameraOfflineFrame = undefined; // Camera offline video frame
49
+ #cameraVideoOffFrame = undefined; // Video turned off on camera video frame
49
50
 
50
51
  constructor(deviceData, options) {
51
52
  // Setup logger object if passed as option
@@ -63,6 +64,7 @@ export default class Streamer {
63
64
  this.online = deviceData?.online === true;
64
65
  this.videoEnabled = deviceData?.streaming_enabled === true;
65
66
  this.audioEnabled = deviceData?.audio_enabled === true;
67
+ this.uuid = deviceData?.uuid;
66
68
 
67
69
  // Setup location for *.h264 frame files. This can be overriden by a passed in option
68
70
  let resourcePath = path.resolve(__dirname + '/res'); // Default location for *.h264 files
@@ -76,19 +78,19 @@ export default class Streamer {
76
78
 
77
79
  // load buffer for camera offline image in .h264 frame
78
80
  if (fs.existsSync(path.resolve(resourcePath + '/' + CAMERAOFFLINEH264FILE)) === true) {
79
- this.cameraOfflineFrame = fs.readFileSync(path.resolve(resourcePath + '/' + CAMERAOFFLINEH264FILE));
81
+ this.#cameraOfflineFrame = fs.readFileSync(path.resolve(resourcePath + '/' + CAMERAOFFLINEH264FILE));
80
82
  // remove any H264 NALU from beginning of any video data. We do this as they are added later when output by our ffmpeg router
81
- if (this.cameraOfflineFrame.indexOf(H264NALStartcode) === 0) {
82
- this.cameraOfflineFrame = this.cameraOfflineFrame.subarray(H264NALStartcode.length);
83
+ if (this.#cameraOfflineFrame.indexOf(H264NALStartcode) === 0) {
84
+ this.#cameraOfflineFrame = this.#cameraOfflineFrame.subarray(H264NALStartcode.length);
83
85
  }
84
86
  }
85
87
 
86
88
  // load buffer for camera stream off image in .h264 frame
87
89
  if (fs.existsSync(path.resolve(resourcePath + '/' + CAMERAOFFH264FILE)) === true) {
88
- this.cameraVideoOffFrame = fs.readFileSync(path.resolve(resourcePath + '/' + CAMERAOFFH264FILE));
90
+ this.#cameraVideoOffFrame = fs.readFileSync(path.resolve(resourcePath + '/' + CAMERAOFFH264FILE));
89
91
  // remove any H264 NALU from beginning of any video data. We do this as they are added later when output by our ffmpeg router
90
- if (this.cameraVideoOffFrame.indexOf(H264NALStartcode) === 0) {
91
- this.cameraVideoOffFrame = this.cameraVideoOffFrame.subarray(H264NALStartcode.length);
92
+ if (this.#cameraVideoOffFrame.indexOf(H264NALStartcode) === 0) {
93
+ this.#cameraVideoOffFrame = this.#cameraVideoOffFrame.subarray(H264NALStartcode.length);
92
94
  }
93
95
  }
94
96
 
@@ -103,15 +105,15 @@ export default class Streamer {
103
105
  Object.values(this.#outputs).forEach((output) => {
104
106
  // Monitor for camera going offline and/or video enabled/disabled
105
107
  // We'll insert the appropriate video frame into the stream
106
- if (this.online === false && this.cameraOfflineFrame !== undefined && outputVideoFrame === true) {
108
+ if (this.online === false && this.#cameraOfflineFrame !== undefined && outputVideoFrame === true) {
107
109
  // Camera is offline so feed in our custom h264 frame and AAC silence
108
- output.buffer.push({ type: 'video', time: dateNow, data: this.cameraOfflineFrame });
110
+ output.buffer.push({ type: 'video', time: dateNow, data: this.#cameraOfflineFrame });
109
111
  output.buffer.push({ type: 'audio', time: dateNow, data: AACAudioSilence });
110
112
  lastTimeVideo = dateNow;
111
113
  }
112
- if (this.online === true && this.videoEnabled === false && this.cameraVideoOffFrame !== undefined && outputVideoFrame === true) {
114
+ if (this.online === true && this.videoEnabled === false && this.#cameraVideoOffFrame !== undefined && outputVideoFrame === true) {
113
115
  // Camera video is turned off so feed in our custom h264 frame and AAC silence
114
- output.buffer.push({ type: 'video', time: dateNow, data: this.cameraVideoOffFrame });
116
+ output.buffer.push({ type: 'video', time: dateNow, data: this.#cameraVideoOffFrame });
115
117
  output.buffer.push({ type: 'audio', time: dateNow, data: AACAudioSilence });
116
118
  lastTimeVideo = dateNow;
117
119
  }
@@ -150,10 +152,10 @@ export default class Streamer {
150
152
  startBuffering() {
151
153
  if (this.#outputs?.buffer === undefined) {
152
154
  // No active buffer session, start connection to streamer
153
- if (this.socket === null && typeof this.host === 'string' && this.host !== '') {
155
+ if (this.connected === false && typeof this.host === 'string' && this.host !== '') {
154
156
  if (typeof this.connect === 'function') {
155
- this.connect(this.host);
156
157
  this?.log?.debug && this.log.debug('Started buffering from "%s"', this.host);
158
+ this.connect(this.host);
157
159
  }
158
160
  }
159
161
 
@@ -199,7 +201,7 @@ export default class Streamer {
199
201
  });
200
202
  }
201
203
 
202
- if (this.socket === null && typeof this.host === 'string' && this.host !== '') {
204
+ if (this.connected === false && typeof this.host === 'string' && this.host !== '') {
203
205
  // We do not have an active socket connection, so startup connection to host
204
206
  if (typeof this.connect === 'function') {
205
207
  this.connect(this.host);
@@ -218,9 +220,9 @@ export default class Streamer {
218
220
  // finally, we've started live stream
219
221
  this?.log?.debug &&
220
222
  this.log.debug(
221
- 'Started live stream from "%s" %s and sesssion id of "%s"',
223
+ 'Started live stream from "%s" %s "%s"',
222
224
  this.host,
223
- talkbackStream !== null && typeof talkbackStream === 'object' ? 'with two-way audio' : '',
225
+ talkbackStream !== null && typeof talkbackStream === 'object' ? 'with two-way audio and sesssion id of' : 'and sesssion id of',
224
226
  sessionID,
225
227
  );
226
228
  }
@@ -239,7 +241,7 @@ export default class Streamer {
239
241
  });
240
242
  }
241
243
 
242
- if (this.socket === null && typeof this.host === 'string' && this.host !== '') {
244
+ if (this.connected === false && typeof this.host === 'string' && this.host !== '') {
243
245
  // We do not have an active socket connection, so startup connection to host
244
246
  if (typeof this.connect === 'function') {
245
247
  this.connect(this.host);
@@ -302,20 +304,21 @@ export default class Streamer {
302
304
  return;
303
305
  }
304
306
 
305
- this.online = deviceData?.online === true;
306
- this.videoEnabled = deviceData?.streaming_enabled === true;
307
- this.audioEnabled = deviceData?.audio_enabled === true;
308
-
309
307
  if (this.host !== deviceData.streaming_host) {
310
308
  this.host = deviceData.streaming_host;
311
- this?.log?.debug && this.log.debug('New streaming host has requested a new host "%s" for connection', this.host);
309
+ this?.log?.debug && this.log.debug('New streaming host has been requested for connection. Host requested is "%s"', this.host);
312
310
  }
313
311
 
314
- if (this.online !== deviceData.online || this.videoEnabled !== deviceData.streaming_enabled) {
312
+ if (
313
+ this.online !== deviceData.online ||
314
+ this.videoEnabled !== deviceData.streaming_enabled ||
315
+ this.audioEnabled !== deviceData?.audio_enabled
316
+ ) {
315
317
  // Online status or streaming status has changed has changed
316
318
  this.online = deviceData?.online === true;
317
319
  this.videoEnabled = deviceData?.streaming_enabled === true;
318
- if ((this.online === false || this.videoEnabled === false) && typeof this.close === 'function') {
320
+ this.audioEnabled = deviceData?.audio_enabled === true;
321
+ if ((this.online === false || this.videoEnabled === false || this.audioEnabled === false) && typeof this.close === 'function') {
319
322
  this.close(true); // as offline or streaming not enabled, close socket
320
323
  }
321
324
  if (this.online === true && this.videoEnabled === true && typeof this.connect === 'function') {