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;
|
loading: boolean = true;
|
||||||
|
|
||||||
private shouldDisconnectRoomWhenComponentIsDestroyed: boolean = true;
|
private shouldDisconnectRoomWhenComponentIsDestroyed: boolean = true;
|
||||||
private shouldListenClientInitiatedDisconnectEvent: boolean = true;
|
|
||||||
private readonly SIDENAV_WIDTH_LIMIT_MODE = 790;
|
private readonly SIDENAV_WIDTH_LIMIT_MODE = 790;
|
||||||
private menuSubscription: Subscription;
|
private menuSubscription: Subscription;
|
||||||
private layoutWidthSubscription: Subscription;
|
private layoutWidthSubscription: Subscription;
|
||||||
|
@ -244,14 +243,13 @@ export class SessionComponent implements OnInit, OnDestroy {
|
||||||
async disconnectRoom(reason: ParticipantLeftReason) {
|
async disconnectRoom(reason: ParticipantLeftReason) {
|
||||||
// Mark session as disconnected for avoiding to do it again in ngOnDestroy
|
// Mark session as disconnected for avoiding to do it again in ngOnDestroy
|
||||||
this.shouldDisconnectRoomWhenComponentIsDestroyed = false;
|
this.shouldDisconnectRoomWhenComponentIsDestroyed = false;
|
||||||
this.shouldListenClientInitiatedDisconnectEvent = false;
|
|
||||||
await this.openviduService.disconnectRoom(() => {
|
await this.openviduService.disconnectRoom(() => {
|
||||||
this.onParticipantLeft.emit({
|
this.onParticipantLeft.emit({
|
||||||
roomName: this.openviduService.getRoomName(),
|
roomName: this.openviduService.getRoomName(),
|
||||||
participantName: this.participantService.getLocalParticipant()?.identity || '',
|
participantName: this.participantService.getLocalParticipant()?.identity || '',
|
||||||
reason
|
reason
|
||||||
});
|
});
|
||||||
});
|
}, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private subscribeToTogglingMenu() {
|
private subscribeToTogglingMenu() {
|
||||||
|
@ -473,7 +471,7 @@ export class SessionComponent implements OnInit, OnDestroy {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
subscribeToReconnection() {
|
private subscribeToReconnection() {
|
||||||
this.room.on(RoomEvent.Reconnecting, () => {
|
this.room.on(RoomEvent.Reconnecting, () => {
|
||||||
this.log.w('Connection lost: Reconnecting');
|
this.log.w('Connection lost: Reconnecting');
|
||||||
this.actionService.openConnectionDialog(
|
this.actionService.openConnectionDialog(
|
||||||
|
@ -500,7 +498,7 @@ export class SessionComponent implements OnInit, OnDestroy {
|
||||||
switch (reason) {
|
switch (reason) {
|
||||||
case DisconnectReason.CLIENT_INITIATED:
|
case DisconnectReason.CLIENT_INITIATED:
|
||||||
// Skip disconnect reason if a default disconnect method has been called
|
// Skip disconnect reason if a default disconnect method has been called
|
||||||
if (!this.shouldListenClientInitiatedDisconnectEvent) return;
|
if (!this.openviduService.shouldHandleClientInitiatedDisconnectEvent) return;
|
||||||
participantLeftEvent.reason = ParticipantLeftReason.LEAVE;
|
participantLeftEvent.reason = ParticipantLeftReason.LEAVE;
|
||||||
break;
|
break;
|
||||||
case DisconnectReason.DUPLICATE_IDENTITY:
|
case DisconnectReason.DUPLICATE_IDENTITY:
|
||||||
|
|
|
@ -518,7 +518,13 @@ export class ToolbarComponent implements OnInit, OnDestroy, AfterViewInit {
|
||||||
*/
|
*/
|
||||||
async disconnect() {
|
async disconnect() {
|
||||||
try {
|
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) {
|
} catch (error) {
|
||||||
this.log.e('There was an error disconnecting:', error.code, error.message);
|
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);
|
this.actionService.openDialog(this.translateService.translate('ERRORS.DISCONNECT'), error?.error || error?.message || error);
|
||||||
|
|
|
@ -32,6 +32,13 @@ export class OpenViduService {
|
||||||
|
|
||||||
private room: Room;
|
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.
|
* 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
|
* @param callback - Optional function to be executed after a successful disconnection
|
||||||
* @returns A Promise that resolves once the disconnection is complete
|
* @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()) {
|
if (this.isRoomConnected()) {
|
||||||
this.log.d('Disconnecting from room');
|
this.log.d('Disconnecting from room');
|
||||||
await this.room.disconnect();
|
await this.room.disconnect();
|
||||||
|
|
Loading…
Reference in New Issue