From 1feeba92b06dfa6a106640f31bb3ea26b64c54b5 Mon Sep 17 00:00:00 2001 From: Alessandro Ros Date: Tue, 26 Dec 2023 12:53:33 +0100 Subject: [PATCH] webrtc: prevent NotReadableError when publishing with Android (#2698) (#2842) --- internal/servers/webrtc/publish_index.html | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/internal/servers/webrtc/publish_index.html b/internal/servers/webrtc/publish_index.html index 77e0bbc05f3..5537cb102c3 100644 --- a/internal/servers/webrtc/publish_index.html +++ b/internal/servers/webrtc/publish_index.html @@ -717,13 +717,19 @@ } navigator.mediaDevices.getUserMedia({ video: true, audio: true }) - .then(() => Promise.all([ - populateDevices(), - populateCodecs(), - ])) - .then(() => { - state = DEVICE; - render(); + .then((stream) => { + return Promise.all([ + populateDevices(), + populateCodecs(), + ]) + .then(() => { + // free the webcam to prevent 'NotReadableError' on Android + stream.getTracks() + .forEach(track => track.stop()); + + state = DEVICE; + render(); + }); }) .catch((err) => { state = ERROR;