Skip to content

Commit ac6d06f

Browse files
committed
0.0.6 fix for twoway audio
1 parent 3b39d80 commit ac6d06f

File tree

6 files changed

+63
-64
lines changed

6 files changed

+63
-64
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ All notable changes to `homebridge-nest-accfactory` will be documented in this f
66

77
Currently all releases are considered 'alpha' status, where things may or may not be working. Use at your own risk :-)
88

9-
## v0.0.5 (2024/09/13)
9+
## v0.0.6 (2024-09-14)
10+
11+
- Fix for two/way audio starting on non-enabled HKSV camera/doorbells
12+
13+
## v0.0.5 (2024-09-13)
1014

1115
- General code cleanup and bug fixes
1216
- External dependancy reductions, dropped pbf and axios libraries

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"displayName": "Nest Accfactory",
33
"name": "homebridge-nest-accfactory",
44
"homepage": "https://github.com/n0rt0nthec4t/homebridge-nest-accfactory",
5-
"version": "0.0.5",
5+
"version": "0.0.6",
66
"description": "Homebridge support for Nest/Google devices including HomeKit Secure Video (HKSV) support for doorbells and cameras",
77
"license": "Apache-2.0",
88
"author": "n0rt0nthec4t",

src/camera.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Nest Cameras
22
// Part of homebridge-nest-accfactory
33
//
4-
// Code version 12/9/2024
4+
// Code version 13/9/2024
55
// Mark Hulskamp
66
'use strict';
77

@@ -33,6 +33,7 @@ export default class NestCamera extends HomeKitDevice {
3333
controller = undefined; // HomeKit Camera/Doorbell controller service
3434
streamer = undefined; // Streamer object for live/recording stream
3535
motionServices = undefined; // Object of Camera/Doorbell motion sensor(s)
36+
batteryService = undefined; // If a camera has a battery
3637
operatingModeService = undefined; // Link to camera/doorbell operating mode service
3738
personTimer = undefined; // Cooldown timer for person/face events
3839
motionTimer = undefined; // Cooldown timer for motion events

src/floodlight.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Nest Cam with Floodlight
22
// Part of homebridge-nest-accfactory
33
//
4-
// Code version 12/9/2024
4+
// Code version 13/9/2024
55
// Mark Hulskamp
66
'use strict';
77

@@ -48,7 +48,7 @@ export default class NestFloodlight extends NestCamera {
4848
if (value !== this.deviceData.light_brightness) {
4949
this.set({ light_brightness: value });
5050

51-
this?.log?.info && this.log.info('Floodlight brightness on "%s" was set to "%s %"', this.deviceData.description);
51+
this?.log?.info && this.log.info('Floodlight brightness on "%s" was set to "%s %"', this.deviceData.description, value);
5252
}
5353
});
5454

src/nexustalk.js

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//
66
// Credit to https://github.com/Brandawg93/homebridge-nest-cam for the work on the Nest Camera comms code on which this is based
77
//
8-
// Code version 11/9/2024
8+
// Code version 14/9/2024
99
// Mark Hulskamp
1010
'use strict';
1111

@@ -59,18 +59,19 @@ const PacketType = {
5959
export default class NexusTalk extends Streamer {
6060
token = undefined;
6161
tokenType = undefined;
62-
id = undefined; // Session ID
6362
pingTimer = undefined; // Timer object for ping interval
6463
stalledTimer = undefined; // Timer object for no received data
6564
video = {}; // Video stream details
6665
audio = {}; // Audio stream details
66+
host = ''; // Host to connect to or connected too
6767

6868
// Internal data only for this class
6969
#protobufNexusTalk = undefined; // Protobuf for NexusTalk
7070
#socket = undefined; // TCP socket object
7171
#packets = []; // Incoming packets
7272
#messages = []; // Incoming messages
7373
#authorised = false; // Have we been authorised
74+
#id = undefined; // Session ID
7475

7576
constructor(deviceData, options) {
7677
super(deviceData, options);
@@ -98,7 +99,7 @@ export default class NexusTalk extends Streamer {
9899
this.pingTimer = clearInterval(this.pingTimer);
99100
this.stalledTimer = clearInterval(this.stalledTimer);
100101

101-
this.id = undefined; // No session ID yet
102+
this.#id = undefined; // No session ID yet
102103

103104
if (this.online === true && this.videoEnabled === true) {
104105
if (typeof host === 'undefined' || host === null) {
@@ -134,7 +135,7 @@ export default class NexusTalk extends Streamer {
134135
this.#authorised = false; // Since connection close, we can't be authorised anymore
135136
this.#socket = undefined; // Clear socket object
136137
this.connected = false;
137-
this.id = undefined; // Not an active session anymore
138+
this.#id = undefined; // Not an active session anymore
138139

139140
if (hadError === true && this.haveOutputs() === true) {
140141
// We still have either active buffering occuring or output streams running
@@ -147,7 +148,7 @@ export default class NexusTalk extends Streamer {
147148

148149
close(stopStreamFirst) {
149150
// Close an authenicated socket stream gracefully
150-
if (this.#socket !== null) {
151+
if (this.#socket !== undefined) {
151152
if (stopStreamFirst === true) {
152153
// Send a notifcation to nexus we're finished playback
153154
this.#stopNexusData();
@@ -157,7 +158,7 @@ export default class NexusTalk extends Streamer {
157158

158159
this.connected = false;
159160
this.#socket = undefined;
160-
this.id = undefined; // Not an active session anymore
161+
this.#id = undefined; // Not an active session anymore
161162
this.#packets = [];
162163
this.#messages = [];
163164
}
@@ -171,24 +172,29 @@ export default class NexusTalk extends Streamer {
171172
// access token has changed so re-authorise
172173
this.token = deviceData.apiAccess.token;
173174

174-
if (this.#socket !== null) {
175+
if (this.#socket !== undefined) {
175176
this.#Authenticate(true); // Update authorisation only if connected
176177
}
177178
}
178179

180+
if (this.host !== deviceData.streaming_host) {
181+
this.host = deviceData.streaming_host;
182+
this?.log?.debug && this.log.debug('New host has been requested for connection. Host requested is "%s"', this.host);
183+
}
184+
179185
// Let our parent handle the remaining updates
180186
super.update(deviceData);
181187
}
182188

183189
talkingAudio(talkingData) {
184190
// Encode audio packet for sending to camera
185191
if (typeof talkingData === 'object' && this.#protobufNexusTalk !== undefined) {
186-
let TraitMap = this.#protobufNexusTalk.lookup('nest.nexustalk.v1.StartPlayback');
192+
let TraitMap = this.#protobufNexusTalk.lookup('nest.nexustalk.v1.AudioPayload');
187193
if (TraitMap !== null) {
188194
let encodedData = TraitMap.encode(
189195
TraitMap.fromObject({
190196
payload: talkingData,
191-
sessionId: this.id,
197+
sessionId: this.#id,
192198
codec: 'SPEEX',
193199
sampleRate: 16000,
194200
}),
@@ -227,12 +233,12 @@ export default class NexusTalk extends Streamer {
227233
}
228234

229235
#stopNexusData() {
230-
if (this.id !== undefined && this.#protobufNexusTalk !== undefined) {
236+
if (this.#id !== undefined && this.#protobufNexusTalk !== undefined) {
231237
let TraitMap = this.#protobufNexusTalk.lookup('nest.nexustalk.v1.StopPlayback');
232238
if (TraitMap !== null) {
233239
let encodedData = TraitMap.encode(
234240
TraitMap.fromObject({
235-
sessionId: this.id,
241+
sessionId: this.#id,
236242
}),
237243
).finish();
238244
this.#sendMessage(PacketType.STOP_PLAYBACK, encodedData);
@@ -241,7 +247,7 @@ export default class NexusTalk extends Streamer {
241247
}
242248

243249
#sendMessage(type, data) {
244-
if (this.#socket === null || this.#socket.readyState !== 'open' || (type !== PacketType.HELLO && this.#authorised === false)) {
250+
if (this.#socket?.readyState !== 'open' || (type !== PacketType.HELLO && this.#authorised === false)) {
245251
// We're not connect and/or authorised yet, so 'cache' message for processing once this occurs
246252
this.#messages.push({ type: type, data: data });
247253
return;
@@ -358,11 +364,11 @@ export default class NexusTalk extends Streamer {
358364
});
359365

360366
// Since this is the beginning of playback, clear any active buffers contents
361-
this.id = decodedMessage.sessionId;
367+
this.#id = decodedMessage.sessionId;
362368
this.#packets = [];
363369
this.#messages = [];
364370

365-
this?.log?.debug && this.log.debug('Playback started from "%s" with session ID "%s"', this.host, this.id);
371+
this?.log?.debug && this.log.debug('Playback started from "%s" with session ID "%s"', this.host, this.#id);
366372
}
367373
}
368374

@@ -381,7 +387,7 @@ export default class NexusTalk extends Streamer {
381387
// Setup listener for socket close event. Once socket is closed, we'll perform the re-connection
382388
this.#socket &&
383389
this.#socket.on('close', () => {
384-
this.connect(this.host); // try reconnection
390+
this.connect(); // try reconnection
385391
});
386392
this.close(false); // Close existing socket
387393
}, 8000);
@@ -405,7 +411,7 @@ export default class NexusTalk extends Streamer {
405411
if (typeof payload === 'object' && this.#protobufNexusTalk !== undefined) {
406412
let decodedMessage = this.#protobufNexusTalk.lookup('nest.nexustalk.v1.PlaybackEnd').decode(payload).toJSON();
407413

408-
if (this.id !== null && decodedMessage.reason === 'USER_ENDED_SESSION') {
414+
if (this.#id !== undefined && decodedMessage.reason === 'USER_ENDED_SESSION') {
409415
// Normal playback ended ie: when we stopped playback
410416
this?.log?.debug && this.log.debug('Playback ended on "%s"', this.host);
411417
}
@@ -418,7 +424,7 @@ export default class NexusTalk extends Streamer {
418424
// Setup listener for socket close event. Once socket is closed, we'll perform the re-connection
419425
this.#socket &&
420426
this.#socket.on('close', () => {
421-
this.connect(this.host); // try reconnection to existing host
427+
this.connect(); // try reconnection to existing host
422428
});
423429
this.close(false); // Close existing socket
424430
}
@@ -443,15 +449,15 @@ export default class NexusTalk extends Streamer {
443449
// Decode talk begin packet
444450
if (typeof payload === 'object' && this.#protobufNexusTalk !== undefined) {
445451
let decodedMessage = this.#protobufNexusTalk.lookup('nest.nexustalk.v1.TalkbackBegin').decode(payload).toJSON();
446-
this?.log?.debug && this.log.debug('Talkback started on "%s"', decodedMessage.deviceId);
452+
this?.log?.debug && this.log.debug('Talkback started to uuid "%s" with id of "%s"', this.uuid, decodedMessage.deviceId);
447453
}
448454
}
449455

450456
#handleTalkbackEnd(payload) {
451457
// Decode talk end packet
452458
if (typeof payload === 'object' && this.#protobufNexusTalk !== undefined) {
453459
let decodedMessage = this.#protobufNexusTalk.lookup('nest.nexustalk.v1.TalkbackEnd').decode(payload).toJSON();
454-
this?.log?.debug && this.log.debug('Talkback ended on "%s"', decodedMessage.device_id);
460+
this?.log?.debug && this.log.debug('Talkback ended from uuid "%s" with id of "%s"', this.uuid, decodedMessage.deviceId);
455461
}
456462
}
457463

0 commit comments

Comments
 (0)