mirror of https://github.com/OpenVidu/openvidu.git
ov-components: add onParticipantLeft event and disconnect callback to notify when local participant leaves
parent
d965e72822
commit
7315360fbc
|
@ -46,7 +46,7 @@ import {
|
||||||
RoomEvent,
|
RoomEvent,
|
||||||
Track
|
Track
|
||||||
} from 'livekit-client';
|
} from 'livekit-client';
|
||||||
import { ParticipantModel } from '../../models/participant.model';
|
import { ParticipantLeftEvent, ParticipantModel } from '../../models/participant.model';
|
||||||
import { ServiceConfigService } from '../../services/config/service-config.service';
|
import { ServiceConfigService } from '../../services/config/service-config.service';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -89,6 +89,11 @@ export class SessionComponent implements OnInit, OnDestroy {
|
||||||
*/
|
*/
|
||||||
@Output() onParticipantConnected: EventEmitter<ParticipantModel> = new EventEmitter<ParticipantModel>();
|
@Output() onParticipantConnected: EventEmitter<ParticipantModel> = new EventEmitter<ParticipantModel>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This event is emitted when the local participant leaves the room.
|
||||||
|
*/
|
||||||
|
@Output() onParticipantLeft: EventEmitter<ParticipantLeftEvent> = new EventEmitter<ParticipantLeftEvent>();
|
||||||
|
|
||||||
room: Room;
|
room: Room;
|
||||||
sideMenu: MatSidenav;
|
sideMenu: MatSidenav;
|
||||||
sidenavMode: SidenavMode = SidenavMode.SIDE;
|
sidenavMode: SidenavMode = SidenavMode.SIDE;
|
||||||
|
@ -206,6 +211,13 @@ export class SessionComponent implements OnInit, OnDestroy {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await this.participantService.connect();
|
await this.participantService.connect();
|
||||||
|
this.openviduService.setDisconnectCallback(() => {
|
||||||
|
const event: ParticipantLeftEvent = {
|
||||||
|
roomName: this.openviduService.getRoomName(),
|
||||||
|
participantName: this.participantService.getLocalParticipant()?.identity || ''
|
||||||
|
};
|
||||||
|
this.onParticipantLeft.emit(event);
|
||||||
|
});
|
||||||
// Send room created after participant connect for avoiding to send incomplete room payload
|
// Send room created after participant connect for avoiding to send incomplete room payload
|
||||||
this.onRoomCreated.emit(this.room);
|
this.onRoomCreated.emit(this.room);
|
||||||
this.cd.markForCheck();
|
this.cd.markForCheck();
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
(onRoomReconnected)="onRoomReconnected.emit()"
|
(onRoomReconnected)="onRoomReconnected.emit()"
|
||||||
(onParticipantConnected)="onParticipantCreated.emit($event)"
|
(onParticipantConnected)="onParticipantCreated.emit($event)"
|
||||||
(onParticipantConnected)="onParticipantConnected.emit($event)"
|
(onParticipantConnected)="onParticipantConnected.emit($event)"
|
||||||
|
(onParticipantLeft)="_onParticipantLeft($event)"
|
||||||
>
|
>
|
||||||
<ng-template #toolbar>
|
<ng-template #toolbar>
|
||||||
<ng-container *ngIf="openviduAngularToolbarTemplate">
|
<ng-container *ngIf="openviduAngularToolbarTemplate">
|
||||||
|
|
|
@ -38,6 +38,7 @@ export class OpenViduService {
|
||||||
private localTracks: LocalTrack[] = [];
|
private localTracks: LocalTrack[] = [];
|
||||||
private livekitToken = '';
|
private livekitToken = '';
|
||||||
private livekitUrl = '';
|
private livekitUrl = '';
|
||||||
|
private disconnectCallback: () => void;
|
||||||
private log: ILogger;
|
private log: ILogger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -107,9 +108,27 @@ export class OpenViduService {
|
||||||
if (this.isRoomConnected()) {
|
if (this.isRoomConnected()) {
|
||||||
this.log.d('Disconnecting room');
|
this.log.d('Disconnecting room');
|
||||||
await this.room.disconnect();
|
await this.room.disconnect();
|
||||||
|
if (this.disconnectCallback) {
|
||||||
|
this.disconnectCallback();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a callback function that triggers when a participant is disconnected
|
||||||
|
* from the session using the OpenViduService.disconnectRoom() method.
|
||||||
|
*
|
||||||
|
* This is particularly useful in cases where the disconnection occurs externally,
|
||||||
|
* outside of this component, ensuring that the parent component is notified
|
||||||
|
* even when the service is used directly.
|
||||||
|
*
|
||||||
|
* @param callback - The function to be executed upon disconnection.
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
setDisconnectCallback(callback: () => void): void {
|
||||||
|
this.disconnectCallback = callback;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns Room instance
|
* @returns Room instance
|
||||||
*/
|
*/
|
||||||
|
@ -128,7 +147,6 @@ export class OpenViduService {
|
||||||
return this.room?.name;
|
return this.room?.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns if local participant is connected to the room
|
* Returns if local participant is connected to the room
|
||||||
* @returns
|
* @returns
|
||||||
|
|
Loading…
Reference in New Issue