From a135ea0aec51d0ee72247a4f6bb176f89e28c8e9 Mon Sep 17 00:00:00 2001 From: pabloFuente Date: Mon, 24 May 2021 14:55:47 +0200 Subject: [PATCH] openvidu-browser: support Master Node crash --- openvidu-browser/src/OpenVidu/OpenVidu.ts | 33 ++++++++++++++++++----- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/openvidu-browser/src/OpenVidu/OpenVidu.ts b/openvidu-browser/src/OpenVidu/OpenVidu.ts index e4f0fa49..67b02967 100644 --- a/openvidu-browser/src/OpenVidu/OpenVidu.ts +++ b/openvidu-browser/src/OpenVidu/OpenVidu.ts @@ -67,6 +67,7 @@ let platform: PlatformUtils; export class OpenVidu { private jsonRpcClient: any; + private masterNodeHasCrashed = false; /** * @hidden @@ -744,7 +745,8 @@ export class OpenVidu { onconnected: onConnectSucces, ondisconnect: this.disconnectCallback.bind(this), onreconnecting: this.reconnectingCallback.bind(this), - onreconnected: this.reconnectedCallback.bind(this) + onreconnected: this.reconnectedCallback.bind(this), + ismasternodecrashed: this.isMasterNodeCrashed.bind(this) }, rpc: { requestTimeout: 10000, @@ -761,12 +763,23 @@ export class OpenVidu { networkQualityLevelChanged: this.session.onNetworkQualityLevelChangedChanged.bind(this.session), filterEventDispatched: this.session.onFilterEventDispatched.bind(this.session), iceCandidate: this.session.recvIceCandidate.bind(this.session), - mediaError: this.session.onMediaError.bind(this.session) + mediaError: this.session.onMediaError.bind(this.session), + masterNodeCrashedNotification: this.onMasterNodeCrashedNotification.bind(this) } }; this.jsonRpcClient = new RpcBuilder.clients.JsonRpcClient(config); } + /** + * @hidden + */ + onMasterNodeCrashedNotification(response): void { + console.error('Master Node has crashed'); + this.masterNodeHasCrashed = true; + this.session.onLostConnection("nodeCrashed"); + this.jsonRpcClient.close(4103, "Master Node has crashed"); + } + /** * @hidden */ @@ -1009,10 +1022,14 @@ export class OpenVidu { if (!!this.session.connection) { this.sendRequest('connect', { sessionId: this.session.connection.rpcSessionId }, (error, response) => { if (!!error) { - logger.error(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'); - this.session.onLostConnection("networkDisconnect"); - this.jsonRpcClient.close(4101, "Reconnection fault"); + if (this.isMasterNodeCrashed()) { + logger.warn('Master Node has crashed!'); + } else { + logger.error(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'); + this.session.onLostConnection("networkDisconnect"); + this.jsonRpcClient.close(4101, "Reconnection fault"); + } } else { this.jsonRpcClient.resetPing(); this.session.onRecoveredConnection(); @@ -1030,6 +1047,10 @@ export class OpenVidu { } } + private isMasterNodeCrashed() { + return this.masterNodeHasCrashed; + } + private isRoomAvailable(): boolean { if (this.session !== undefined && this.session instanceof Session) { return true;