Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix WebRTC(MediaMTX) webcam client #1843

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/components/webcams/streamers/WebrtcMediaMTX.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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: '',
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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',
Expand All @@ -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)
Expand Down
Loading