openvidu-browser: fix unexpected undefined exception on reconnected callback

pull/546/head
pabloFuente 2020-09-29 11:59:30 +02:00
parent a852a826fa
commit 12f215ddd9
2 changed files with 23 additions and 19 deletions

View File

@ -337,10 +337,10 @@ export class OpenVidu {
const family = platform.os!!.family; const family = platform.os!!.family;
const userAgent = !!platform.ua ? platform.ua : navigator.userAgent; const userAgent = !!platform.ua ? platform.ua : navigator.userAgent;
if(this.isIPhoneOrIPad(userAgent)) { if (this.isIPhoneOrIPad(userAgent)) {
if(this.isIOSWithSafari(userAgent) || platform['isIonicIos']){ if (this.isIOSWithSafari(userAgent) || platform['isIonicIos']) {
return 1; return 1;
} }
return 0; return 0;
} }
@ -377,7 +377,7 @@ export class OpenVidu {
} }
if ((browser !== 'Chrome') && (browser !== 'Firefox') && (browser !== 'Opera') && (browser !== 'Electron') && if ((browser !== 'Chrome') && (browser !== 'Firefox') && (browser !== 'Opera') && (browser !== 'Electron') &&
(browser === 'Safari' && version < 13)) { (browser === 'Safari' && version < 13)) {
return 0; return 0;
} else { } else {
return 1; return 1;
@ -1025,17 +1025,21 @@ export class OpenVidu {
private reconnectedCallback(): void { private reconnectedCallback(): void {
logger.warn('Websocket reconnected'); logger.warn('Websocket reconnected');
if (this.isRoomAvailable()) { if (this.isRoomAvailable()) {
this.sendRequest('connect', { sessionId: this.session.connection.rpcSessionId }, (error, response) => { if (!!this.session.connection) {
if (!!error) { this.sendRequest('connect', { sessionId: this.session.connection.rpcSessionId }, (error, response) => {
logger.error(error); if (!!error) {
logger.warn('Websocket was able to reconnect to OpenVidu Server, but your Connection was already destroyed due to timeout. You are no longer a participant of the Session and your media streams have been destroyed'); logger.error(error);
this.session.onLostConnection("networkDisconnect"); logger.warn('Websocket was able to reconnect to OpenVidu Server, but your Connection was already destroyed due to timeout. You are no longer a participant of the Session and your media streams have been destroyed');
this.jsonRpcClient.close(4101, "Reconnection fault"); this.session.onLostConnection("networkDisconnect");
} else { this.jsonRpcClient.close(4101, "Reconnection fault");
this.jsonRpcClient.resetPing(); } else {
this.session.onRecoveredConnection(); this.jsonRpcClient.resetPing();
} this.session.onRecoveredConnection();
}); }
});
} else {
logger.warn('There was no previous connection when running reconnection callback');
}
} else { } else {
alert('Connection error. Please reload page.'); alert('Connection error. Please reload page.');
} }
@ -1064,9 +1068,9 @@ export class OpenVidu {
return isIPad || isIPhone; return isIPad || isIPhone;
} }
private isIOSWithSafari(userAgent): boolean{ private isIOSWithSafari(userAgent): boolean {
return /\b(\w*Apple\w*)\b/.test(navigator.vendor) && /\b(\w*Safari\w*)\b/.test(userAgent) return /\b(\w*Apple\w*)\b/.test(navigator.vendor) && /\b(\w*Safari\w*)\b/.test(userAgent)
&& !/\b(\w*CriOS\w*)\b/.test(userAgent) && !/\b(\w*FxiOS\w*)\b/.test(userAgent); && !/\b(\w*CriOS\w*)\b/.test(userAgent) && !/\b(\w*FxiOS\w*)\b/.test(userAgent);
} }

View File

@ -987,7 +987,7 @@ export class Session extends EventDispatcher {
*/ */
onLostConnection(reason: string): void { onLostConnection(reason: string): void {
logger.warn('Lost connection in Session ' + this.sessionId); logger.warn('Lost connection in Session ' + this.sessionId);
if (!!this.sessionId && !this.connection.disposed) { if (!!this.sessionId && !!this.connection && !this.connection.disposed) {
this.leave(true, reason); this.leave(true, reason);
} }
} }