From 85a178efd9b1930e752707e8333a1db8db7b7f16 Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Sat, 13 Apr 2024 14:47:52 +0200 Subject: [PATCH] fix: fix WebRTC(MediaMTX) webcam client (#1843) --- .../webcams/streamers/WebrtcMediaMTX.vue | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/components/webcams/streamers/WebrtcMediaMTX.vue b/src/components/webcams/streamers/WebrtcMediaMTX.vue index 257a93808..f26194cda 100644 --- a/src/components/webcams/streamers/WebrtcMediaMTX.vue +++ b/src/components/webcams/streamers/WebrtcMediaMTX.vue @@ -39,6 +39,7 @@ export default class WebrtcMediaMTX extends Mixins(BaseMixin, WebcamMixin) { private restartTimeout: any = null private status: string = 'connecting' private eTag: string | null = null + private sessionUuid: string | null = null private queuedCandidates: RTCIceCandidate[] = [] private offerData: OfferData = { iceUfrag: '', @@ -206,6 +207,9 @@ export default class WebrtcMediaMTX extends Mixins(BaseMixin, WebcamMixin) { this.pc = new RTCPeerConnection({ iceServers, + // https://webrtc.org/getting-started/unified-plan-transition-guide + // @ts-ignore + sdpSemantics: 'unified-plan', }) const direction = 'sendrecv' @@ -238,6 +242,7 @@ export default class WebrtcMediaMTX extends Mixins(BaseMixin, WebcamMixin) { .then((res) => { if (res.status !== 201) throw new Error('bad status code') this.eTag = res.headers.get('ETag') + this.sessionUuid = res.headers.get('location') // fallback for MediaMTX v1.0.x with broken ETag header if (res.headers.has('E-Tag')) this.eTag = res.headers.get('E-Tag') @@ -296,7 +301,8 @@ export default class WebrtcMediaMTX extends Mixins(BaseMixin, WebcamMixin) { } sendLocalCandidates(candidates: RTCIceCandidate[]) { - fetch(this.url, { + const url = new URL(this.sessionUuid ?? '', this.url).toString() + fetch(url, { method: 'PATCH', headers: { 'Content-Type': 'application/trickle-ice-sdpfrag', @@ -306,7 +312,14 @@ export default class WebrtcMediaMTX extends Mixins(BaseMixin, WebcamMixin) { body: this.generateSdpFragment(this.offerData, candidates), }) .then((res) => { - if (res.status !== 204) throw new Error('bad status code') + switch (res.status) { + case 204: + break + case 404: + throw new Error('stream not found') + default: + throw new Error(`bad status code ${res.status}`) + } }) .catch((err) => { this.log(err)