Skip to content

Commit 3131916

Browse files
authored
feat(WebrtcCamerastreamer): adds ping/pong support (#1693)
Signed-off-by: Pedro Lamas <[email protected]>
1 parent d011124 commit 3131916

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/components/widgets/camera/services/WebrtcCamerastreamerCamera.vue

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default class WebrtcCamerastreamerCamera extends Mixins(CameraMixin) {
3131
playbackAbortController: AbortController | null = null
3232
sleepAbortController: AbortController | null = null
3333
34-
// adapted from https://github.com/ayufan/camera-streamer/blob/4203f89df1596cc349b0260f26bf24a3c446a56b/html/webrtc.html
34+
// adapted from https://github.com/ayufan/camera-streamer/blob/2d3a4884378f384346680a55196bf9244b99b6b6/html/webrtc.html
3535
3636
async loadStream () {
3737
this.pc?.close()
@@ -58,7 +58,8 @@ export default class WebrtcCamerastreamerCamera extends Mixins(CameraMixin) {
5858
'stun:stun.l.google.com:19302'
5959
]
6060
}
61-
]
61+
],
62+
keepAlive: true
6263
}),
6364
headers: {
6465
'Content-Type': 'application/json'
@@ -83,6 +84,16 @@ export default class WebrtcCamerastreamerCamera extends Mixins(CameraMixin) {
8384
8485
const pc = this.pc = new RTCPeerConnection(config)
8586
87+
pc.ondatachannel = (event: RTCDataChannelEvent) => {
88+
const dc = event.channel
89+
90+
if (dc.label === 'keepalive') {
91+
dc.onmessage = () => {
92+
dc.send('pong')
93+
}
94+
}
95+
}
96+
8697
pc.addTransceiver('video', {
8798
direction: 'recvonly'
8899
})

0 commit comments

Comments
 (0)