2018-04-26 15:33:47 +02:00
|
|
|
/*
|
2022-01-13 11:18:47 +01:00
|
|
|
* (C) Copyright 2017-2022 OpenVidu (https://openvidu.io)
|
2018-04-26 15:33:47 +02:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
import { Event } from './Event';
|
2018-05-08 13:01:34 +02:00
|
|
|
import { Session } from '../../OpenVidu/Session';
|
2020-05-04 20:01:56 +02:00
|
|
|
import { OpenViduLogger } from '../Logger/OpenViduLogger';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @hidden
|
|
|
|
*/
|
|
|
|
const logger: OpenViduLogger = OpenViduLogger.getInstance();
|
2018-05-08 13:01:34 +02:00
|
|
|
|
2018-04-26 15:33:47 +02:00
|
|
|
|
|
|
|
/**
|
2022-01-13 13:54:34 +01:00
|
|
|
* Triggered by [[sessionDisconnected]]
|
2018-04-26 15:33:47 +02:00
|
|
|
*/
|
|
|
|
export class SessionDisconnectedEvent extends Event {
|
|
|
|
|
|
|
|
/**
|
2018-05-07 16:54:19 +02:00
|
|
|
* - "disconnect": you have called `Session.disconnect()`
|
2018-07-09 15:45:20 +02:00
|
|
|
* - "forceDisconnectByUser": you have been evicted from the Session by other user calling `Session.forceDisconnect()`
|
|
|
|
* - "forceDisconnectByServer": you have been evicted from the Session by the application
|
|
|
|
* - "sessionClosedByServer": the Session has been closed by the application
|
2020-02-14 20:51:52 +01:00
|
|
|
* - "networkDisconnect": your network connection has dropped. Before a SessionDisconnectedEvent with this reason is triggered,
|
|
|
|
* Session object will always have previously dispatched a `reconnecting` event. If the reconnection process succeeds,
|
|
|
|
* Session object will dispatch a `reconnected` event. If it fails, Session object will dispatch a SessionDisconnectedEvent
|
|
|
|
* with reason "networkDisconnect"
|
2021-06-01 15:01:40 +02:00
|
|
|
* - "nodeCrashed": a node has crashed in the server side. You can use this reason to ask your application's backend to reconnect
|
|
|
|
* to a new session to replace the crashed one
|
2018-04-26 15:33:47 +02:00
|
|
|
*/
|
|
|
|
reason: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @hidden
|
|
|
|
*/
|
|
|
|
constructor(target: Session, reason: string) {
|
|
|
|
super(true, target, 'sessionDisconnected');
|
|
|
|
this.reason = reason;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @hidden
|
|
|
|
*/
|
2018-07-03 15:35:08 +02:00
|
|
|
callDefaultBehavior() {
|
2018-04-26 15:33:47 +02:00
|
|
|
|
2020-05-04 20:01:56 +02:00
|
|
|
logger.info("Calling default behavior upon '" + this.type + "' event dispatched by 'Session'");
|
2018-04-26 15:33:47 +02:00
|
|
|
|
|
|
|
const session = <Session>this.target;
|
|
|
|
|
|
|
|
// Dispose and delete all remote Connections
|
2021-02-18 16:00:07 +01:00
|
|
|
session.remoteConnections.forEach(remoteConnection => {
|
|
|
|
const connectionId = remoteConnection.connectionId;
|
2021-02-03 17:32:23 +01:00
|
|
|
if (!!session.remoteConnections.get(connectionId)?.stream) {
|
|
|
|
session.remoteConnections.get(connectionId)?.stream!.disposeWebRtcPeer();
|
|
|
|
session.remoteConnections.get(connectionId)?.stream!.disposeMediaStream();
|
|
|
|
if (session.remoteConnections.get(connectionId)?.stream!.streamManager) {
|
|
|
|
session.remoteConnections.get(connectionId)?.stream!.streamManager.removeAllVideos();
|
2018-05-29 18:28:58 +02:00
|
|
|
}
|
2021-02-03 17:32:23 +01:00
|
|
|
const streamId = session.remoteConnections.get(connectionId)?.stream?.streamId;
|
2021-02-18 16:00:07 +01:00
|
|
|
if (!!streamId) {
|
2021-02-03 17:32:23 +01:00
|
|
|
session.remoteStreamsCreated.delete(streamId);
|
|
|
|
}
|
|
|
|
session.remoteConnections.get(connectionId)?.dispose();
|
2018-04-26 15:33:47 +02:00
|
|
|
}
|
2021-02-03 17:32:23 +01:00
|
|
|
session.remoteConnections.delete(connectionId);
|
2021-02-18 16:00:07 +01:00
|
|
|
});
|
2018-04-26 15:33:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|