From ae015d7cbc9da2d3dbfedf42660ce29bf235acad Mon Sep 17 00:00:00 2001 From: Sebastian Reimers Date: Wed, 28 Feb 2024 14:33:11 +0100 Subject: [PATCH] webrtc: try catch audio/video srcObject and play --- webui/src/webrtc.ts | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/webui/src/webrtc.ts b/webui/src/webrtc.ts index 5f07051..8029f0a 100644 --- a/webui/src/webrtc.ts +++ b/webui/src/webrtc.ts @@ -173,6 +173,7 @@ function pc_setup() { pc.ontrack = function (event) { const track = event.track console.log('got remote track: kind=%s', track.kind) + const stream = event.streams[0] if (track.kind == 'audio') { const audio: HTMLAudioElement | null = document.querySelector('audio#live') @@ -181,10 +182,18 @@ function pc_setup() { return } - if (audio.srcObject !== event.streams[0]) { - audio.srcObject = event.streams[0] - console.log('received remote audio stream') + console.log('received remote audio stream') + + try { + audio.srcObject = stream + } catch (e) { + console.log("Error attaching audio stream to element", e) + } + + try { audio.play() + } catch (e) { + console.log("Error audio play", e) } } @@ -195,10 +204,18 @@ function pc_setup() { return } - if (video.srcObject !== event.streams[0]) { - video.srcObject = event.streams[0] - console.log('received remote video stream') + console.log('received remote video stream') + + try { + video.srcObject = stream + } catch (e) { + console.log("Error attaching video stream to element", e) + } + + try { video.play() + } catch (e) { + console.log("Error video play", e) } } }