Skip to content

Commit 7b786f3

Browse files
committed
fix: update werift and ring edge connection strategy
1 parent 6f9d3df commit 7b786f3

File tree

4 files changed

+233
-279
lines changed

4 files changed

+233
-279
lines changed

Diff for: api/streaming/peer-connection.ts

+17-21
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,19 @@ import {
99
RtpPacket,
1010
} from 'werift'
1111
import { interval, merge, Observable, ReplaySubject, Subject } from 'rxjs'
12-
import { logError, logInfo } from '../util'
12+
import { logDebug, logError, logInfo } from '../util'
1313
import { Subscribed } from '../subscribed'
1414

15-
const debug = false,
16-
ringIceServers = [
17-
'stun:stun.kinesisvideo.us-east-1.amazonaws.com:443',
18-
'stun:stun.kinesisvideo.us-east-2.amazonaws.com:443',
19-
'stun:stun.kinesisvideo.us-west-2.amazonaws.com:443',
20-
'stun:stun.l.google.com:19302',
21-
'stun:stun1.l.google.com:19302',
22-
'stun:stun2.l.google.com:19302',
23-
'stun:stun3.l.google.com:19302',
24-
'stun:stun4.l.google.com:19302',
25-
]
15+
const ringIceServers = [
16+
'stun:stun.kinesisvideo.us-east-1.amazonaws.com:443',
17+
'stun:stun.kinesisvideo.us-east-2.amazonaws.com:443',
18+
'stun:stun.kinesisvideo.us-west-2.amazonaws.com:443',
19+
'stun:stun.l.google.com:19302',
20+
'stun:stun1.l.google.com:19302',
21+
'stun:stun2.l.google.com:19302',
22+
'stun:stun3.l.google.com:19302',
23+
'stun:stun4.l.google.com:19302',
24+
]
2625

2726
export interface BasicPeerConnection {
2827
createOffer(): Promise<{ sdp: string }>
@@ -31,7 +30,7 @@ export interface BasicPeerConnection {
3130
sdp: string
3231
}): Promise<RTCSessionDescriptionInit>
3332
acceptAnswer(answer: { type: 'answer'; sdp: string }): Promise<void>
34-
addIceCandidate(candidate: RTCIceCandidate): Promise<void>
33+
addIceCandidate(candidate: Partial<RTCIceCandidate>): Promise<void>
3534
onIceCandidate: Observable<RTCIceCandidate>
3635
onConnectionState: Observable<ConnectionState>
3736
close(): void
@@ -87,6 +86,7 @@ export class WeriftPeerConnection
8786
},
8887
iceServers: ringIceServers.map((server) => ({ urls: server })),
8988
iceTransportPolicy: 'all',
89+
bundlePolicy: 'disable',
9090
})),
9191
audioTransceiver = pc.addTransceiver(this.returnAudioTrack, {
9292
direction: 'sendrecv',
@@ -104,11 +104,9 @@ export class WeriftPeerConnection
104104
this.onAudioRtcp.next(rtcp)
105105
})
106106

107-
if (debug) {
108-
track.onReceiveRtp.once(() => {
109-
logInfo('received first audio packet')
110-
})
111-
}
107+
track.onReceiveRtp.once(() => {
108+
logDebug('received first audio packet')
109+
})
112110
})
113111

114112
videoTransceiver.onTrack.subscribe((track) => {
@@ -121,9 +119,7 @@ export class WeriftPeerConnection
121119
})
122120

123121
track.onReceiveRtp.once(() => {
124-
if (debug) {
125-
logInfo('received first video packet')
126-
}
122+
logDebug('received first video packet')
127123

128124
this.addSubscriptions(
129125
merge(this.onRequestKeyFrame, interval(4000)).subscribe(() => {

Diff for: api/streaming/ring-edge-connection.ts

+2-12
Original file line numberDiff line numberDiff line change
@@ -125,17 +125,7 @@ export class RingEdgeConnection extends StreamingConnectionBase {
125125
body: {
126126
doorbot_id: camera.id,
127127
ice: iceCandidate.candidate,
128-
mlineindex: 0,
129-
},
130-
})
131-
// HACK: send ice candidate with both mline indexes to convince ring edge to connect both audio and video
132-
// Without this, only audio will connect unless you connect from the network of the Ring Edge router
133-
this.sendMessage({
134-
method: 'ice',
135-
body: {
136-
doorbot_id: camera.id,
137-
ice: iceCandidate.candidate,
138-
mlineindex: 1,
128+
mlineindex: iceCandidate.sdpMLineIndex,
139129
},
140130
})
141131
})
@@ -150,7 +140,7 @@ export class RingEdgeConnection extends StreamingConnectionBase {
150140
body: {
151141
doorbot_id: this.camera.id,
152142
stream_options: { audio_enabled: true, video_enabled: true },
153-
sdp: sdp.replace('\na=group:BUNDLE 0 1', ''),
143+
sdp,
154144
},
155145
})
156146

0 commit comments

Comments
 (0)