From cc02fa4f7a3801ee61868c6a8e358646b95d9061 Mon Sep 17 00:00:00 2001 From: csantosm <4a.santos@gmail.com> Date: Thu, 25 Feb 2021 15:16:18 +0100 Subject: [PATCH] openvidu-browser: Fixed sendVideoData bug when peerConnection is closed --- openvidu-browser/src/OpenVidu/Session.ts | 35 +++++++++++++----------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/openvidu-browser/src/OpenVidu/Session.ts b/openvidu-browser/src/OpenVidu/Session.ts index 21eedb1d..dc033b20 100644 --- a/openvidu-browser/src/OpenVidu/Session.ts +++ b/openvidu-browser/src/OpenVidu/Session.ts @@ -1170,24 +1170,27 @@ export class Session extends EventDispatcher { platform.isSamsungBrowser() || platform.isIonicAndroid() || (platform.isIPhoneOrIPad() && platform.isIOSWithSafari()) ) { const obtainAndSendVideo = async () => { - const statsMap = await streamManager.stream.getRTCPeerConnection().getStats(); - const arr: any[] = []; - statsMap.forEach(stats => { - if (("frameWidth" in stats) && ("frameHeight" in stats) && (arr.length === 0)) { - arr.push(stats); - } - }); - if (arr.length > 0) { - this.openvidu.sendRequest('videoData', { - height: arr[0].frameHeight, - width: arr[0].frameWidth, - videoActive: streamManager.stream.videoActive != null ? streamManager.stream.videoActive : false, - audioActive: streamManager.stream.audioActive != null ? streamManager.stream.audioActive : false - }, (error, response) => { - if (error) { - logger.error("Error sending 'videoData' event", error); + const pc = streamManager.stream.getRTCPeerConnection(); + if (pc.connectionState === 'connected') { + const statsMap = await pc.getStats(); + const arr: any[] = []; + statsMap.forEach(stats => { + if (("frameWidth" in stats) && ("frameHeight" in stats) && (arr.length === 0)) { + arr.push(stats); } }); + if (arr.length > 0) { + this.openvidu.sendRequest('videoData', { + height: arr[0].frameHeight, + width: arr[0].frameWidth, + videoActive: streamManager.stream.videoActive != null ? streamManager.stream.videoActive : false, + audioActive: streamManager.stream.audioActive != null ? streamManager.stream.audioActive : false + }, (error, response) => { + if (error) { + logger.error("Error sending 'videoData' event", error); + } + }); + } } } if (doInterval) {