openvidu-browser: Fixed video data timeouts errors

Fixex and cleaned timeout and intervals in sendVideoData method when session is left or when loops are finished
pull/574/head
csantosm 2020-12-01 13:26:41 +01:00
parent 2e5797e348
commit 293899de8a
1 changed files with 19 additions and 4 deletions

View File

@ -143,6 +143,14 @@ export class Session extends EventDispatcher {
* @hidden
*/
stopSpeakingEventsEnabledOnce = false;
/**
* @hidden
*/
private videoDataInterval: NodeJS.Timeout;
/**
* @hidden
*/
private videoDataTimeout: NodeJS.Timeout;
/**
* @hidden
@ -1122,6 +1130,7 @@ export class Session extends EventDispatcher {
forced = !!forced;
logger.info('Leaving Session (forced=' + forced + ')');
this.stopVideoDataIntervals();
if (!!this.connection) {
if (!this.connection.disposed && !forced) {
@ -1193,15 +1202,16 @@ export class Session extends EventDispatcher {
}
if (doInterval) {
let loops = 1;
let timer = setTimeout(async function myTimer() {
await obtainAndSendVideo();
this.videoDataInterval = setInterval(() => {
if (loops < maxLoops) {
loops++;
timer = setTimeout(myTimer, intervalSeconds * 1000);
obtainAndSendVideo();
}else {
clearInterval(this.videoDataInterval);
}
}, intervalSeconds * 1000);
} else {
setTimeout(obtainAndSendVideo, intervalSeconds * 1000);
this.videoDataTimeout = setTimeout(obtainAndSendVideo, intervalSeconds * 1000);
}
} else if (platform.isFirefoxBrowser() || platform.isFirefoxMobileBrowser() || platform.isIonicIos() || platform.isReactNative()) {
// Basic version for Firefox and Ionic iOS. They do not support stats
@ -1289,6 +1299,11 @@ export class Session extends EventDispatcher {
}
}
private stopVideoDataIntervals(): void {
clearInterval(this.videoDataInterval);
clearTimeout(this.videoDataTimeout);
}
private stringClientMetadata(metadata: any): string {
if (typeof metadata !== 'string') {
return JSON.stringify(metadata);