mirror of https://github.com/OpenVidu/openvidu.git
openvidu-browser: OpenVidu.life logic
parent
91d24ccd42
commit
8eae2e0eab
|
@ -109,6 +109,10 @@ export class OpenVidu {
|
||||||
* @hidden
|
* @hidden
|
||||||
*/
|
*/
|
||||||
mediaServer: string;
|
mediaServer: string;
|
||||||
|
/**
|
||||||
|
* @hidden
|
||||||
|
*/
|
||||||
|
life: number = -1;
|
||||||
/**
|
/**
|
||||||
* @hidden
|
* @hidden
|
||||||
*/
|
*/
|
||||||
|
@ -1029,15 +1033,43 @@ export class OpenVidu {
|
||||||
logger.warn('Websocket reconnected');
|
logger.warn('Websocket reconnected');
|
||||||
if (this.isRoomAvailable()) {
|
if (this.isRoomAvailable()) {
|
||||||
if (!!this.session.connection) {
|
if (!!this.session.connection) {
|
||||||
|
// This RPC method allows checking if the WebSocket reconnected to a session where
|
||||||
|
// the user is still a participant, or the session evicted the user
|
||||||
this.sendRequest('connect', { sessionId: this.session.connection.rpcSessionId }, (error, response) => {
|
this.sendRequest('connect', { sessionId: this.session.connection.rpcSessionId }, (error, response) => {
|
||||||
if (!!error) {
|
if (!!error) {
|
||||||
|
|
||||||
if (this.isMasterNodeCrashed()) {
|
if (this.isMasterNodeCrashed()) {
|
||||||
|
|
||||||
logger.warn('Master Node has crashed!');
|
logger.warn('Master Node has crashed!');
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
logger.error(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");
|
const notifyNetworkDisconnection = (error) => {
|
||||||
this.jsonRpcClient.close(4101, "Reconnection fault");
|
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.life === -1) {
|
||||||
|
notifyNetworkDisconnection(error);
|
||||||
|
} else {
|
||||||
|
// This RPC method is only required to find out the reason of the disconnection:
|
||||||
|
// whether the client lost its network connection or a Master Node crashed
|
||||||
|
this.sendRequest('sessionStatus', { sessionId: this.session.sessionId }, (error, response) => {
|
||||||
|
if (this.life === response.life) {
|
||||||
|
// If the life stored in the client matches the life stored in the server, it means that the client lost its network connection
|
||||||
|
notifyNetworkDisconnection(error);
|
||||||
|
} else {
|
||||||
|
// If the life stored in the client is below the life stored in the server, it means that the Master Node has crashed
|
||||||
|
logger.warn('Websocket was able to reconnect to OpenVidu Server, but your Master Node crashed.');
|
||||||
|
this.session.onLostConnection("nodeCrashed");
|
||||||
|
this.jsonRpcClient.close(4101, "Reconnection fault");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.jsonRpcClient.resetPing();
|
this.jsonRpcClient.resetPing();
|
||||||
|
|
|
@ -1544,6 +1544,9 @@ export class Session extends EventDispatcher {
|
||||||
forceDisconnect: this.openvidu.role === 'MODERATOR'
|
forceDisconnect: this.openvidu.role === 'MODERATOR'
|
||||||
};
|
};
|
||||||
logger.info("openvidu-server version: " + opts.version);
|
logger.info("openvidu-server version: " + opts.version);
|
||||||
|
if (opts.life != null) {
|
||||||
|
this.openvidu.life = opts.life;
|
||||||
|
}
|
||||||
if (opts.version !== this.openvidu.libraryVersion) {
|
if (opts.version !== this.openvidu.libraryVersion) {
|
||||||
logger.warn('OpenVidu Server (' + opts.version +
|
logger.warn('OpenVidu Server (' + opts.version +
|
||||||
') and OpenVidu Browser (' + this.openvidu.libraryVersion +
|
') and OpenVidu Browser (' + this.openvidu.libraryVersion +
|
||||||
|
|
|
@ -32,4 +32,5 @@ export interface LocalConnectionOptions {
|
||||||
turnCredential: string;
|
turnCredential: string;
|
||||||
version: string;
|
version: string;
|
||||||
mediaServer: string;
|
mediaServer: string;
|
||||||
|
life: number;
|
||||||
}
|
}
|
|
@ -136,6 +136,10 @@ function WebSocketWithReconnection(config) {
|
||||||
ws.close();
|
ws.close();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.forceClose = () => {
|
||||||
|
ws.close();
|
||||||
|
};
|
||||||
|
|
||||||
this.reconnectWs = () => {
|
this.reconnectWs = () => {
|
||||||
Logger.debug("reconnectWs");
|
Logger.debug("reconnectWs");
|
||||||
reconnect(MAX_RETRIES, 1);
|
reconnect(MAX_RETRIES, 1);
|
||||||
|
|
Loading…
Reference in New Issue