mirror of https://github.com/OpenVidu/openvidu.git
ov-components: update disconnect logic to handle client-initiated events in OpenViduService
parent
3027ab6c5b
commit
3c72bc6c4d
|
@ -104,7 +104,6 @@ export class SessionComponent implements OnInit, OnDestroy {
|
|||
loading: boolean = true;
|
||||
|
||||
private shouldDisconnectRoomWhenComponentIsDestroyed: boolean = true;
|
||||
private shouldListenClientInitiatedDisconnectEvent: boolean = true;
|
||||
private readonly SIDENAV_WIDTH_LIMIT_MODE = 790;
|
||||
private menuSubscription: Subscription;
|
||||
private layoutWidthSubscription: Subscription;
|
||||
|
@ -244,14 +243,13 @@ export class SessionComponent implements OnInit, OnDestroy {
|
|||
async disconnectRoom(reason: ParticipantLeftReason) {
|
||||
// Mark session as disconnected for avoiding to do it again in ngOnDestroy
|
||||
this.shouldDisconnectRoomWhenComponentIsDestroyed = false;
|
||||
this.shouldListenClientInitiatedDisconnectEvent = false;
|
||||
await this.openviduService.disconnectRoom(() => {
|
||||
this.onParticipantLeft.emit({
|
||||
roomName: this.openviduService.getRoomName(),
|
||||
participantName: this.participantService.getLocalParticipant()?.identity || '',
|
||||
reason
|
||||
});
|
||||
});
|
||||
}, false);
|
||||
}
|
||||
|
||||
private subscribeToTogglingMenu() {
|
||||
|
@ -473,7 +471,7 @@ export class SessionComponent implements OnInit, OnDestroy {
|
|||
);
|
||||
}
|
||||
|
||||
subscribeToReconnection() {
|
||||
private subscribeToReconnection() {
|
||||
this.room.on(RoomEvent.Reconnecting, () => {
|
||||
this.log.w('Connection lost: Reconnecting');
|
||||
this.actionService.openConnectionDialog(
|
||||
|
@ -500,7 +498,7 @@ export class SessionComponent implements OnInit, OnDestroy {
|
|||
switch (reason) {
|
||||
case DisconnectReason.CLIENT_INITIATED:
|
||||
// Skip disconnect reason if a default disconnect method has been called
|
||||
if (!this.shouldListenClientInitiatedDisconnectEvent) return;
|
||||
if (!this.openviduService.shouldHandleClientInitiatedDisconnectEvent) return;
|
||||
participantLeftEvent.reason = ParticipantLeftReason.LEAVE;
|
||||
break;
|
||||
case DisconnectReason.DUPLICATE_IDENTITY:
|
||||
|
|
|
@ -518,7 +518,13 @@ export class ToolbarComponent implements OnInit, OnDestroy, AfterViewInit {
|
|||
*/
|
||||
async disconnect() {
|
||||
try {
|
||||
await this.openviduService.disconnectRoom();
|
||||
await this.openviduService.disconnectRoom(() => {
|
||||
this.onParticipantLeft.emit({
|
||||
roomName: this.openviduService.getRoomName(),
|
||||
participantName: this.participantService.getLocalParticipant()?.identity || '',
|
||||
reason: ParticipantLeftReason.LEAVE
|
||||
});
|
||||
}, false);
|
||||
} catch (error) {
|
||||
this.log.e('There was an error disconnecting:', error.code, error.message);
|
||||
this.actionService.openDialog(this.translateService.translate('ERRORS.DISCONNECT'), error?.error || error?.message || error);
|
||||
|
|
|
@ -32,6 +32,13 @@ export class OpenViduService {
|
|||
|
||||
private room: Room;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* Indicates whether the client initiated disconnect event should be handled.
|
||||
* This is used to determine if the disconnect event should be emitted when the 'Disconnect' event is triggered
|
||||
*/
|
||||
shouldHandleClientInitiatedDisconnectEvent = true;
|
||||
|
||||
/*
|
||||
* Tracks used in the prejoin component. They are created when the room is not yet created.
|
||||
*/
|
||||
|
@ -109,7 +116,8 @@ export class OpenViduService {
|
|||
* @param callback - Optional function to be executed after a successful disconnection
|
||||
* @returns A Promise that resolves once the disconnection is complete
|
||||
*/
|
||||
async disconnectRoom(callback?: () => void): Promise<void> {
|
||||
async disconnectRoom(callback?: () => void, shouldHandleClientInitiatedDisconnectEvent: boolean = true): Promise<void> {
|
||||
this.shouldHandleClientInitiatedDisconnectEvent = shouldHandleClientInitiatedDisconnectEvent;
|
||||
if (this.isRoomConnected()) {
|
||||
this.log.d('Disconnecting from room');
|
||||
await this.room.disconnect();
|
||||
|
|
Loading…
Reference in New Issue