Skip to content

Commit

Permalink
Activate speaker after camera connects
Browse files Browse the repository at this point in the history
  • Loading branch information
dgreif committed Aug 19, 2023
1 parent 52b7706 commit d54168d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/cuddly-eggs-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'ring-client-api': patch
---

Wait to activate camera speaker until camera is connected to call. This prevents race conditions in two-way audio. Thanks to @tsightler for tracking this down!
11 changes: 7 additions & 4 deletions packages/ring-client-api/streaming/webrtc-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class WebrtcConnection extends Subscribed {
private readonly onSessionId = new ReplaySubject<string>(1)
private readonly onOfferSent = new ReplaySubject<void>(1)
private readonly dialogId = generateUuid()
readonly onCameraConnected = new ReplaySubject<void>(1)
readonly onCallAnswered = new ReplaySubject<string>(1)
readonly onCallEnded = new ReplaySubject<void>(1)
readonly onError = new ReplaySubject<void>(1)
Expand Down Expand Up @@ -203,10 +204,12 @@ export class WebrtcConnection extends Subscribed {
return
case 'notification':
const { text } = message.body
if (
if (text === 'camera_connected') {
this.onCameraConnected.next()
return
} else if (
text === 'PeerConnectionState::kConnecting' ||
text === 'PeerConnectionState::kConnected' ||
text === 'camera_connected'
text === 'PeerConnectionState::kConnected'
) {
return
}
Expand Down Expand Up @@ -282,7 +285,7 @@ export class WebrtcConnection extends Subscribed {
activateCameraSpeaker() {
// Fire and forget this call so that callers don't get hung up waiting for answer (which might not happen)
this.addSubscriptions(
this.onCallAnswered.pipe(take(1)).subscribe(() => {
this.onCameraConnected.pipe(take(1)).subscribe(() => {
this.sendSessionMessage('camera_options', {
stealth_mode: false,
})
Expand Down

0 comments on commit d54168d

Please sign in to comment.