2024-07-02 19:19:05 +02:00
|
|
|
import { Component, HostListener, Input } from '@angular/core';
|
|
|
|
|
|
|
|
|
|
import { RoomConf } from '../test-sessions/test-sessions.component';
|
|
|
|
|
import { LivekitParamsService } from 'src/app/services/livekit-params.service';
|
2018-03-01 11:25:25 +01:00
|
|
|
|
2018-04-27 11:08:03 +02:00
|
|
|
import {
|
2024-07-02 19:19:05 +02:00
|
|
|
ConnectionQuality,
|
|
|
|
|
ConnectionState,
|
2024-09-17 01:32:41 +02:00
|
|
|
CreateLocalTracksOptions,
|
2024-07-02 19:19:05 +02:00
|
|
|
DataPacket_Kind,
|
|
|
|
|
DataPublishOptions,
|
|
|
|
|
DisconnectReason,
|
|
|
|
|
LocalAudioTrack,
|
|
|
|
|
LocalParticipant,
|
2024-09-17 01:32:41 +02:00
|
|
|
LocalTrack,
|
2024-07-02 19:19:05 +02:00
|
|
|
LocalTrackPublication,
|
|
|
|
|
LocalVideoTrack,
|
|
|
|
|
MediaDeviceFailure,
|
|
|
|
|
Participant,
|
|
|
|
|
RemoteAudioTrack,
|
|
|
|
|
RemoteParticipant,
|
|
|
|
|
RemoteTrack,
|
|
|
|
|
RemoteTrackPublication,
|
|
|
|
|
RemoteVideoTrack,
|
|
|
|
|
Room,
|
|
|
|
|
RoomConnectOptions,
|
|
|
|
|
RoomEvent,
|
|
|
|
|
RoomOptions,
|
2024-09-17 01:32:41 +02:00
|
|
|
ScreenShareCaptureOptions,
|
2024-07-02 19:19:05 +02:00
|
|
|
SubscriptionError,
|
|
|
|
|
Track,
|
|
|
|
|
TrackPublication,
|
2024-09-17 01:32:41 +02:00
|
|
|
TrackPublishOptions,
|
2024-07-02 19:19:05 +02:00
|
|
|
} from 'livekit-client';
|
|
|
|
|
import { ParticipantPermission } from 'livekit-server-sdk';
|
|
|
|
|
import {
|
|
|
|
|
TestAppEvent,
|
|
|
|
|
TestFeedService,
|
|
|
|
|
} from 'src/app/services/test-feed.service';
|
|
|
|
|
import { RoomEventCallbacks } from 'livekit-client/dist/src/room/Room';
|
|
|
|
|
import { MatDialog } from '@angular/material/dialog';
|
|
|
|
|
import { RoomApiDialogComponent } from '../dialogs/room-api-dialog/room-api-dialog.component';
|
|
|
|
|
import { RoomApiService } from 'src/app/services/room-api.service';
|
2018-06-15 14:45:47 +02:00
|
|
|
import { EventsDialogComponent } from '../dialogs/events-dialog/events-dialog.component';
|
2024-09-17 01:32:41 +02:00
|
|
|
import { OptionsDialogComponent } from '../dialogs/options-dialog/options-dialog.component';
|
2024-10-02 01:14:42 +02:00
|
|
|
import PCTransport from 'livekit-client/dist/src/room/PCTransport';
|
|
|
|
|
import { InfoDialogComponent } from '../dialogs/info-dialog/info-dialog.component';
|
2017-10-02 15:18:28 +02:00
|
|
|
|
2017-09-28 19:13:29 +02:00
|
|
|
@Component({
|
2025-02-19 12:03:43 +01:00
|
|
|
selector: 'app-openvidu-instance',
|
|
|
|
|
templateUrl: './openvidu-instance.component.html',
|
|
|
|
|
styleUrls: ['./openvidu-instance.component.css'],
|
|
|
|
|
standalone: false
|
2017-09-28 19:13:29 +02:00
|
|
|
})
|
2024-07-02 19:19:05 +02:00
|
|
|
export class OpenviduInstanceComponent {
|
2017-09-28 19:13:29 +02:00
|
|
|
@Input()
|
2024-07-02 19:19:05 +02:00
|
|
|
roomConf: RoomConf;
|
2021-06-25 12:38:32 +02:00
|
|
|
|
2018-05-29 18:32:49 +02:00
|
|
|
@Input()
|
|
|
|
|
index: number;
|
|
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
room?: Room;
|
|
|
|
|
roomEvents: Map<RoomEvent, Boolean> = new Map<RoomEvent, boolean>();
|
2024-09-17 01:32:41 +02:00
|
|
|
|
|
|
|
|
roomName: string = 'TestRoom';
|
|
|
|
|
participantName: string = 'TestParticipant';
|
|
|
|
|
|
|
|
|
|
// Options
|
2024-07-02 19:19:05 +02:00
|
|
|
roomOptions: RoomOptions = {
|
|
|
|
|
adaptiveStream: true,
|
|
|
|
|
dynacast: true,
|
|
|
|
|
videoCaptureDefaults: {
|
|
|
|
|
resolution: {
|
|
|
|
|
width: 640,
|
|
|
|
|
height: 480,
|
|
|
|
|
frameRate: 30,
|
|
|
|
|
},
|
2021-04-05 20:50:29 +02:00
|
|
|
},
|
2018-05-18 12:46:41 +02:00
|
|
|
};
|
2024-07-02 19:19:05 +02:00
|
|
|
roomConnectOptions: RoomConnectOptions = {
|
|
|
|
|
autoSubscribe: false,
|
2018-05-29 18:32:49 +02:00
|
|
|
};
|
2024-09-17 01:32:41 +02:00
|
|
|
createLocalTracksOptions: CreateLocalTracksOptions = {
|
2024-12-02 17:26:21 +01:00
|
|
|
audio: true,
|
2024-09-17 01:32:41 +02:00
|
|
|
video: {
|
|
|
|
|
resolution: {
|
2024-11-21 14:54:49 +01:00
|
|
|
width: 1920,
|
|
|
|
|
height: 1080,
|
2024-09-17 01:32:41 +02:00
|
|
|
frameRate: 30,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
screenShareCaptureOptions: ScreenShareCaptureOptions;
|
|
|
|
|
trackPublishOptions: TrackPublishOptions = {};
|
2024-07-02 19:19:05 +02:00
|
|
|
|
|
|
|
|
localTracks: {
|
|
|
|
|
audioTrack: LocalAudioTrack | undefined;
|
|
|
|
|
videoTrack: LocalVideoTrack | undefined;
|
|
|
|
|
} = { audioTrack: undefined, videoTrack: undefined };
|
|
|
|
|
remoteTracks: Map<
|
|
|
|
|
string,
|
|
|
|
|
{
|
|
|
|
|
audioTrack: RemoteAudioTrack | undefined;
|
|
|
|
|
videoTrack: RemoteVideoTrack | undefined;
|
2018-08-01 15:12:34 +02:00
|
|
|
}
|
2024-07-02 19:19:05 +02:00
|
|
|
> = new Map();
|
2018-06-08 11:07:38 +02:00
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
events: TestAppEvent[] = [];
|
2017-09-30 13:48:40 +02:00
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
private decoder = new TextDecoder();
|
2017-10-04 10:30:15 +02:00
|
|
|
|
2018-01-11 11:13:50 +01:00
|
|
|
constructor(
|
2024-07-02 19:19:05 +02:00
|
|
|
private livekitParamsService: LivekitParamsService,
|
|
|
|
|
private testFeedService: TestFeedService,
|
|
|
|
|
private roomApiService: RoomApiService,
|
|
|
|
|
private dialog: MatDialog
|
2024-09-17 01:32:41 +02:00
|
|
|
) {
|
|
|
|
|
const roomForDefaults = new Room(this.roomOptions);
|
|
|
|
|
this.roomOptions = roomForDefaults.options;
|
|
|
|
|
this.trackPublishOptions = roomForDefaults.options.publishDefaults!;
|
|
|
|
|
}
|
2024-07-02 19:19:05 +02:00
|
|
|
|
|
|
|
|
async ngOnInit() {
|
|
|
|
|
for (let event of Object.keys(RoomEvent)) {
|
|
|
|
|
this.roomEvents.set(RoomEvent[event as keyof typeof RoomEvent], true);
|
|
|
|
|
this.roomEvents.set(RoomEvent.ActiveSpeakersChanged, false);
|
2017-10-02 15:18:28 +02:00
|
|
|
}
|
2024-07-02 19:19:05 +02:00
|
|
|
this.participantName += this.index;
|
|
|
|
|
if (this.roomConf.startSession) {
|
|
|
|
|
const token = await this.roomApiService.createToken(
|
|
|
|
|
{ roomJoin: true },
|
|
|
|
|
this.participantName,
|
|
|
|
|
this.roomName
|
|
|
|
|
);
|
|
|
|
|
this.connectRoom(token);
|
2017-09-30 13:48:40 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-28 19:13:29 +02:00
|
|
|
ngOnDestroy() {
|
2024-07-02 19:19:05 +02:00
|
|
|
this.disconnectRoom();
|
2017-09-28 19:13:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@HostListener('window:beforeunload')
|
|
|
|
|
beforeunloadHandler() {
|
2024-07-02 19:19:05 +02:00
|
|
|
this.disconnectRoom();
|
2017-09-28 19:13:29 +02:00
|
|
|
}
|
|
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
async createTokenAndConnectRoom() {
|
|
|
|
|
this.connectRoom(
|
|
|
|
|
await this.roomApiService.createToken(
|
|
|
|
|
{ roomJoin: true },
|
|
|
|
|
this.participantName,
|
|
|
|
|
this.roomName
|
|
|
|
|
)
|
|
|
|
|
);
|
2017-10-16 15:49:23 +02:00
|
|
|
}
|
|
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
async connectRoom(token: string): Promise<void> {
|
|
|
|
|
// creates a new room with options
|
|
|
|
|
this.room = new Room(this.roomOptions);
|
2017-09-28 19:13:29 +02:00
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
this.setupRoomEventListeners(new Map(), true);
|
2017-09-28 19:13:29 +02:00
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
// connect to room
|
|
|
|
|
await this.room.connect(
|
|
|
|
|
this.livekitParamsService.getParams().livekitUrl,
|
|
|
|
|
token,
|
|
|
|
|
this.roomConnectOptions
|
|
|
|
|
);
|
2023-02-08 09:49:11 +01:00
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
if (this.roomConf.publisher) {
|
2024-09-17 14:46:21 +02:00
|
|
|
const tracks: LocalTrack[] = [];
|
|
|
|
|
if (
|
|
|
|
|
this.createLocalTracksOptions.audio ||
|
|
|
|
|
this.createLocalTracksOptions.video
|
|
|
|
|
) {
|
|
|
|
|
tracks.push(
|
|
|
|
|
...(await this.room.localParticipant.createTracks(
|
|
|
|
|
this.createLocalTracksOptions
|
|
|
|
|
))
|
2024-09-17 01:32:41 +02:00
|
|
|
);
|
2024-09-17 14:46:21 +02:00
|
|
|
}
|
2024-09-17 01:32:41 +02:00
|
|
|
if (this.screenShareCaptureOptions) {
|
|
|
|
|
const screenTracks: LocalTrack[] =
|
|
|
|
|
await this.room.localParticipant.createScreenTracks(
|
|
|
|
|
this.screenShareCaptureOptions
|
|
|
|
|
);
|
|
|
|
|
tracks.push(...screenTracks);
|
|
|
|
|
}
|
|
|
|
|
await Promise.all(
|
|
|
|
|
tracks.map((track) =>
|
|
|
|
|
this.room!.localParticipant.publishTrack(
|
|
|
|
|
track,
|
|
|
|
|
this.trackPublishOptions
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
);
|
2024-07-02 19:19:05 +02:00
|
|
|
}
|
2017-09-30 13:48:40 +02:00
|
|
|
}
|
|
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
setupRoomEventListeners(oldValues: Map<string, boolean>, firstTime: boolean) {
|
|
|
|
|
// This is a link to the complete list of Room events
|
|
|
|
|
let callbacks: RoomEventCallbacks;
|
|
|
|
|
let events: RoomEvent;
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
firstTime ||
|
|
|
|
|
this.roomEvents.get(RoomEvent.Connected) !==
|
|
|
|
|
oldValues.get(RoomEvent.Connected)
|
|
|
|
|
) {
|
|
|
|
|
this.room?.removeAllListeners(RoomEvent.Connected);
|
|
|
|
|
if (this.roomEvents.get(RoomEvent.Connected)) {
|
|
|
|
|
this.room!.on(RoomEvent.Connected, () => {
|
|
|
|
|
this.updateEventList(RoomEvent.Connected, {}, '');
|
|
|
|
|
this.room!.remoteParticipants.forEach(
|
|
|
|
|
(remoteParticipant: RemoteParticipant) => {
|
|
|
|
|
if (this.roomConf.subscriber) {
|
|
|
|
|
// Subscribe to already existing tracks
|
|
|
|
|
remoteParticipant.trackPublications.forEach(
|
|
|
|
|
(publication: RemoteTrackPublication) => {
|
|
|
|
|
publication.setSubscribed(true);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-29 16:19:23 +02:00
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
if (
|
|
|
|
|
firstTime ||
|
|
|
|
|
this.roomEvents.get(RoomEvent.Reconnecting) !==
|
|
|
|
|
oldValues.get(RoomEvent.Reconnecting)
|
|
|
|
|
) {
|
|
|
|
|
this.room?.removeAllListeners(RoomEvent.Reconnecting);
|
|
|
|
|
if (this.roomEvents.get(RoomEvent.Reconnecting)) {
|
|
|
|
|
this.room!.on(RoomEvent.Reconnecting, () => {
|
|
|
|
|
this.updateEventList(RoomEvent.Reconnecting, {}, '');
|
|
|
|
|
});
|
|
|
|
|
}
|
2018-05-31 13:08:34 +02:00
|
|
|
}
|
2017-09-29 16:19:23 +02:00
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
if (
|
|
|
|
|
firstTime ||
|
|
|
|
|
this.roomEvents.get(RoomEvent.Reconnected) !==
|
|
|
|
|
oldValues.get(RoomEvent.Reconnected)
|
|
|
|
|
) {
|
|
|
|
|
this.room?.removeAllListeners(RoomEvent.Reconnected);
|
|
|
|
|
if (this.roomEvents.get(RoomEvent.Reconnected)) {
|
|
|
|
|
this.room!.on(RoomEvent.Reconnected, () => {
|
|
|
|
|
this.updateEventList(RoomEvent.Reconnected, {}, '');
|
|
|
|
|
});
|
|
|
|
|
}
|
2017-09-29 13:54:22 +02:00
|
|
|
}
|
2017-09-29 16:19:23 +02:00
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
if (
|
|
|
|
|
firstTime ||
|
|
|
|
|
this.roomEvents.get(RoomEvent.Disconnected) !==
|
|
|
|
|
oldValues.get(RoomEvent.Disconnected)
|
|
|
|
|
) {
|
|
|
|
|
this.room?.removeAllListeners(RoomEvent.Disconnected);
|
|
|
|
|
if (this.roomEvents.get(RoomEvent.Disconnected)) {
|
|
|
|
|
this.room!.on(RoomEvent.Disconnected, (reason?: DisconnectReason) => {
|
2024-12-05 11:35:16 +01:00
|
|
|
this.updateEventList(RoomEvent.Disconnected, {}, `Reason: ${reason ? DisconnectReason[reason] : reason}`);
|
2024-07-02 19:19:05 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-29 16:19:23 +02:00
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
if (
|
|
|
|
|
firstTime ||
|
|
|
|
|
this.roomEvents.get(RoomEvent.ConnectionStateChanged) !==
|
|
|
|
|
oldValues.get(RoomEvent.ConnectionStateChanged)
|
|
|
|
|
) {
|
|
|
|
|
this.room?.removeAllListeners(RoomEvent.ConnectionStateChanged);
|
|
|
|
|
if (this.roomEvents.get(RoomEvent.ConnectionStateChanged)) {
|
|
|
|
|
this.room!.on(
|
|
|
|
|
RoomEvent.ConnectionStateChanged,
|
|
|
|
|
(state: ConnectionState) => {
|
|
|
|
|
this.updateEventList(
|
|
|
|
|
RoomEvent.ConnectionStateChanged,
|
|
|
|
|
{ state },
|
|
|
|
|
state
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
2017-09-29 16:19:23 +02:00
|
|
|
}
|
|
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
if (
|
|
|
|
|
firstTime ||
|
|
|
|
|
this.roomEvents.get(RoomEvent.MediaDevicesChanged) !==
|
|
|
|
|
oldValues.get(RoomEvent.MediaDevicesChanged)
|
|
|
|
|
) {
|
|
|
|
|
this.room?.removeAllListeners(RoomEvent.MediaDevicesChanged);
|
|
|
|
|
if (this.roomEvents.get(RoomEvent.MediaDevicesChanged)) {
|
|
|
|
|
this.room!.on(RoomEvent.MediaDevicesChanged, () => {
|
|
|
|
|
this.updateEventList(RoomEvent.MediaDevicesChanged, {}, '');
|
|
|
|
|
});
|
|
|
|
|
}
|
2017-09-29 16:19:23 +02:00
|
|
|
}
|
|
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
if (
|
|
|
|
|
firstTime ||
|
|
|
|
|
this.roomEvents.get(RoomEvent.ParticipantConnected) !==
|
|
|
|
|
oldValues.get(RoomEvent.ParticipantConnected)
|
|
|
|
|
) {
|
|
|
|
|
this.room?.removeAllListeners(RoomEvent.ParticipantConnected);
|
|
|
|
|
if (this.roomEvents.get(RoomEvent.ParticipantConnected)) {
|
|
|
|
|
this.room!.on(
|
|
|
|
|
RoomEvent.ParticipantConnected,
|
|
|
|
|
(participant: RemoteParticipant) => {
|
|
|
|
|
this.updateEventList(
|
|
|
|
|
RoomEvent.ParticipantConnected,
|
|
|
|
|
{ participant },
|
|
|
|
|
participant.identity
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-29 16:19:23 +02:00
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
if (
|
|
|
|
|
firstTime ||
|
|
|
|
|
this.roomEvents.get(RoomEvent.ParticipantDisconnected) !==
|
|
|
|
|
oldValues.get(RoomEvent.ParticipantDisconnected)
|
|
|
|
|
) {
|
|
|
|
|
this.room?.removeAllListeners(RoomEvent.ParticipantDisconnected);
|
|
|
|
|
if (this.roomEvents.get(RoomEvent.ParticipantDisconnected)) {
|
|
|
|
|
this.room!.on(
|
|
|
|
|
RoomEvent.ParticipantDisconnected,
|
|
|
|
|
(participant: RemoteParticipant) => {
|
|
|
|
|
this.updateEventList(
|
|
|
|
|
RoomEvent.ParticipantDisconnected,
|
|
|
|
|
{ participant },
|
|
|
|
|
participant.identity
|
|
|
|
|
);
|
|
|
|
|
this.remoteTracks.delete(participant.identity);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-28 19:13:29 +02:00
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
if (
|
|
|
|
|
firstTime ||
|
|
|
|
|
this.roomEvents.get(RoomEvent.TrackPublished) !==
|
|
|
|
|
oldValues.get(RoomEvent.TrackPublished)
|
|
|
|
|
) {
|
|
|
|
|
this.room?.removeAllListeners(RoomEvent.TrackPublished);
|
|
|
|
|
if (this.roomEvents.get(RoomEvent.TrackPublished)) {
|
|
|
|
|
this.room!.on(
|
|
|
|
|
RoomEvent.TrackPublished,
|
|
|
|
|
(
|
|
|
|
|
publication: RemoteTrackPublication,
|
|
|
|
|
participant: RemoteParticipant
|
|
|
|
|
) => {
|
|
|
|
|
this.updateEventList(
|
|
|
|
|
RoomEvent.TrackPublished,
|
|
|
|
|
{ publication, participant },
|
|
|
|
|
`${participant.identity} (${publication.source})`
|
|
|
|
|
);
|
|
|
|
|
if (this.roomConf.subscriber) {
|
|
|
|
|
publication.setSubscribed(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-12-11 17:09:57 +01:00
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
if (
|
|
|
|
|
firstTime ||
|
|
|
|
|
this.roomEvents.get(RoomEvent.TrackSubscribed) !==
|
|
|
|
|
oldValues.get(RoomEvent.TrackSubscribed)
|
|
|
|
|
) {
|
|
|
|
|
this.room?.removeAllListeners(RoomEvent.TrackSubscribed);
|
|
|
|
|
if (this.roomEvents.get(RoomEvent.TrackSubscribed)) {
|
|
|
|
|
this.room!.on(
|
|
|
|
|
RoomEvent.TrackSubscribed,
|
|
|
|
|
(
|
|
|
|
|
track: RemoteTrack,
|
|
|
|
|
publication: RemoteTrackPublication,
|
|
|
|
|
participant: RemoteParticipant
|
|
|
|
|
) => {
|
|
|
|
|
this.updateEventList(
|
|
|
|
|
RoomEvent.TrackSubscribed,
|
|
|
|
|
{ track, publication, participant },
|
|
|
|
|
`${participant.identity} (${publication.source})`
|
|
|
|
|
);
|
|
|
|
|
if (!this.remoteTracks.has(participant.identity)) {
|
|
|
|
|
this.remoteTracks.set(participant.identity, {
|
|
|
|
|
audioTrack: undefined,
|
|
|
|
|
videoTrack: undefined,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (publication.kind === Track.Kind.Video) {
|
|
|
|
|
this.remoteTracks.get(participant.identity)!.videoTrack =
|
|
|
|
|
track as RemoteVideoTrack;
|
|
|
|
|
} else if (publication.kind === Track.Kind.Audio) {
|
|
|
|
|
this.remoteTracks.get(participant.identity)!.audioTrack =
|
|
|
|
|
track as RemoteAudioTrack;
|
|
|
|
|
} else {
|
|
|
|
|
console.warn('Unknown track kind');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-03-01 11:25:25 +01:00
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
if (
|
|
|
|
|
firstTime ||
|
|
|
|
|
this.roomEvents.get(RoomEvent.TrackSubscriptionFailed) !==
|
|
|
|
|
oldValues.get(RoomEvent.TrackSubscriptionFailed)
|
|
|
|
|
) {
|
|
|
|
|
this.room?.removeAllListeners(RoomEvent.TrackSubscriptionFailed);
|
|
|
|
|
if (this.roomEvents.get(RoomEvent.TrackSubscriptionFailed)) {
|
|
|
|
|
this.room!.on(
|
|
|
|
|
RoomEvent.TrackSubscriptionFailed,
|
|
|
|
|
(
|
|
|
|
|
trackSid: string,
|
|
|
|
|
participant: RemoteParticipant,
|
|
|
|
|
reason?: SubscriptionError
|
|
|
|
|
) => {
|
|
|
|
|
this.updateEventList(
|
|
|
|
|
RoomEvent.TrackSubscriptionFailed,
|
|
|
|
|
{ trackSid, participant },
|
2024-12-05 11:35:16 +01:00
|
|
|
`${participant.identity} (${trackSid}). Reason: ${reason ? SubscriptionError[reason] : reason}`
|
2024-07-02 19:19:05 +02:00
|
|
|
);
|
2018-05-29 18:32:49 +02:00
|
|
|
}
|
2024-07-02 19:19:05 +02:00
|
|
|
);
|
2018-05-29 18:32:49 +02:00
|
|
|
}
|
2018-03-01 11:25:25 +01:00
|
|
|
}
|
|
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
if (
|
|
|
|
|
firstTime ||
|
|
|
|
|
this.roomEvents.get(RoomEvent.TrackUnpublished) !==
|
|
|
|
|
oldValues.get(RoomEvent.TrackUnpublished)
|
|
|
|
|
) {
|
|
|
|
|
this.room?.removeAllListeners(RoomEvent.TrackUnpublished);
|
|
|
|
|
if (this.roomEvents.get(RoomEvent.TrackUnpublished)) {
|
|
|
|
|
this.room!.on(
|
|
|
|
|
RoomEvent.TrackUnpublished,
|
|
|
|
|
(
|
|
|
|
|
publication: RemoteTrackPublication,
|
|
|
|
|
participant: RemoteParticipant
|
|
|
|
|
) => {
|
|
|
|
|
this.updateEventList(
|
|
|
|
|
RoomEvent.TrackUnpublished,
|
|
|
|
|
{ publication, participant },
|
|
|
|
|
`${participant.identity} (${publication.source})`
|
|
|
|
|
);
|
2018-05-29 18:32:49 +02:00
|
|
|
}
|
2024-07-02 19:19:05 +02:00
|
|
|
);
|
2018-05-29 18:32:49 +02:00
|
|
|
}
|
2018-03-01 11:25:25 +01:00
|
|
|
}
|
|
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
if (
|
|
|
|
|
firstTime ||
|
|
|
|
|
this.roomEvents.get(RoomEvent.TrackUnsubscribed) !==
|
|
|
|
|
oldValues.get(RoomEvent.TrackUnsubscribed)
|
|
|
|
|
) {
|
|
|
|
|
this.room?.removeAllListeners(RoomEvent.TrackUnsubscribed);
|
|
|
|
|
if (this.roomEvents.get(RoomEvent.TrackUnsubscribed)) {
|
|
|
|
|
this.room!.on(
|
|
|
|
|
RoomEvent.TrackUnsubscribed,
|
|
|
|
|
(
|
|
|
|
|
track: Track,
|
|
|
|
|
publication: RemoteTrackPublication,
|
|
|
|
|
participant: RemoteParticipant
|
|
|
|
|
) => {
|
|
|
|
|
this.updateEventList(
|
|
|
|
|
RoomEvent.TrackUnsubscribed,
|
|
|
|
|
{ track, publication, participant },
|
|
|
|
|
`${participant.identity} (${publication.source})`
|
|
|
|
|
);
|
|
|
|
|
let remoteTracks = this.remoteTracks.get(participant.identity);
|
|
|
|
|
if (remoteTracks) {
|
|
|
|
|
if (publication.kind === Track.Kind.Video) {
|
|
|
|
|
delete remoteTracks.videoTrack;
|
|
|
|
|
} else if (publication.kind === Track.Kind.Audio) {
|
|
|
|
|
delete remoteTracks.audioTrack;
|
|
|
|
|
} else {
|
|
|
|
|
console.warn('Unknown track kind');
|
|
|
|
|
}
|
|
|
|
|
if (
|
|
|
|
|
remoteTracks.audioTrack === undefined &&
|
|
|
|
|
remoteTracks.videoTrack === undefined
|
|
|
|
|
) {
|
|
|
|
|
this.remoteTracks.delete(participant.identity);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
track.detach();
|
2018-08-01 15:12:34 +02:00
|
|
|
}
|
2024-07-02 19:19:05 +02:00
|
|
|
);
|
2018-07-03 15:48:21 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
if (
|
|
|
|
|
firstTime ||
|
|
|
|
|
this.roomEvents.get(RoomEvent.TrackMuted) !==
|
|
|
|
|
oldValues.get(RoomEvent.TrackMuted)
|
|
|
|
|
) {
|
|
|
|
|
this.room?.removeAllListeners(RoomEvent.TrackMuted);
|
|
|
|
|
if (this.roomEvents.get(RoomEvent.TrackMuted)) {
|
|
|
|
|
this.room!.on(
|
|
|
|
|
RoomEvent.TrackMuted,
|
|
|
|
|
(publication: TrackPublication, participant: Participant) => {
|
|
|
|
|
this.updateEventList(
|
|
|
|
|
RoomEvent.TrackMuted,
|
|
|
|
|
{ publication, participant },
|
|
|
|
|
`${participant.identity} (${publication.source})`
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
);
|
2020-10-22 20:42:54 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
if (
|
|
|
|
|
firstTime ||
|
|
|
|
|
this.roomEvents.get(RoomEvent.TrackUnmuted) !==
|
|
|
|
|
oldValues.get(RoomEvent.TrackUnmuted)
|
|
|
|
|
) {
|
|
|
|
|
this.room?.removeAllListeners(RoomEvent.TrackUnmuted);
|
|
|
|
|
if (this.roomEvents.get(RoomEvent.TrackUnmuted)) {
|
|
|
|
|
this.room!.on(
|
|
|
|
|
RoomEvent.TrackUnmuted,
|
|
|
|
|
(publication: TrackPublication, participant: Participant) => {
|
|
|
|
|
this.updateEventList(
|
|
|
|
|
RoomEvent.TrackUnmuted,
|
|
|
|
|
{ publication, participant },
|
|
|
|
|
`${participant.identity} (${publication.source})`
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
);
|
2020-11-05 17:33:25 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
if (
|
|
|
|
|
firstTime ||
|
|
|
|
|
this.roomEvents.get(RoomEvent.LocalTrackPublished) !==
|
|
|
|
|
oldValues.get(RoomEvent.LocalTrackPublished)
|
|
|
|
|
) {
|
|
|
|
|
this.room?.removeAllListeners(RoomEvent.LocalTrackPublished);
|
|
|
|
|
if (this.roomEvents.get(RoomEvent.LocalTrackPublished)) {
|
|
|
|
|
this.room!.on(
|
|
|
|
|
RoomEvent.LocalTrackPublished,
|
|
|
|
|
(
|
|
|
|
|
publication: LocalTrackPublication,
|
|
|
|
|
participant: LocalParticipant
|
|
|
|
|
) => {
|
|
|
|
|
this.updateEventList(
|
|
|
|
|
RoomEvent.LocalTrackPublished,
|
|
|
|
|
{ publication, participant },
|
|
|
|
|
publication.source
|
|
|
|
|
);
|
|
|
|
|
if (publication.kind === Track.Kind.Video) {
|
|
|
|
|
this.localTracks.videoTrack = publication.videoTrack;
|
|
|
|
|
} else if (publication.kind === Track.Kind.Audio) {
|
|
|
|
|
this.localTracks.audioTrack = publication.audioTrack;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
2018-05-29 18:32:49 +02:00
|
|
|
}
|
2018-01-11 11:13:50 +01:00
|
|
|
}
|
|
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
if (
|
|
|
|
|
firstTime ||
|
|
|
|
|
this.roomEvents.get(RoomEvent.LocalTrackUnpublished) !==
|
|
|
|
|
oldValues.get(RoomEvent.LocalTrackUnpublished)
|
|
|
|
|
) {
|
|
|
|
|
this.room?.removeAllListeners(RoomEvent.LocalTrackUnpublished);
|
|
|
|
|
if (this.roomEvents.get(RoomEvent.LocalTrackUnpublished)) {
|
|
|
|
|
this.room!.on(
|
|
|
|
|
RoomEvent.LocalTrackUnpublished,
|
|
|
|
|
(
|
|
|
|
|
publication: LocalTrackPublication,
|
|
|
|
|
participant: LocalParticipant
|
|
|
|
|
) => {
|
|
|
|
|
this.updateEventList(
|
|
|
|
|
RoomEvent.LocalTrackUnpublished,
|
|
|
|
|
{ publication, participant },
|
|
|
|
|
publication.source
|
|
|
|
|
);
|
|
|
|
|
publication.track!.detach();
|
|
|
|
|
}
|
|
|
|
|
);
|
2018-01-18 16:09:39 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
if (
|
|
|
|
|
firstTime ||
|
|
|
|
|
this.roomEvents.get(RoomEvent.LocalAudioSilenceDetected) !==
|
|
|
|
|
oldValues.get(RoomEvent.LocalAudioSilenceDetected)
|
|
|
|
|
) {
|
|
|
|
|
this.room?.removeAllListeners(RoomEvent.LocalAudioSilenceDetected);
|
|
|
|
|
if (this.roomEvents.get(RoomEvent.LocalAudioSilenceDetected)) {
|
|
|
|
|
this.room!.on(
|
|
|
|
|
RoomEvent.LocalAudioSilenceDetected,
|
|
|
|
|
(publication: LocalTrackPublication) => {
|
|
|
|
|
this.updateEventList(
|
|
|
|
|
RoomEvent.LocalAudioSilenceDetected,
|
|
|
|
|
{ publication },
|
|
|
|
|
publication.source
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-10-19 18:03:58 +02:00
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
if (
|
|
|
|
|
firstTime ||
|
|
|
|
|
this.roomEvents.get(RoomEvent.ParticipantMetadataChanged) !==
|
|
|
|
|
oldValues.get(RoomEvent.ParticipantMetadataChanged)
|
|
|
|
|
) {
|
|
|
|
|
this.room?.removeAllListeners(RoomEvent.ParticipantMetadataChanged);
|
|
|
|
|
if (this.roomEvents.get(RoomEvent.ParticipantMetadataChanged)) {
|
|
|
|
|
this.room!.on(
|
|
|
|
|
RoomEvent.ParticipantMetadataChanged,
|
|
|
|
|
(metadata: string | undefined, participant: Participant) => {
|
|
|
|
|
this.updateEventList(
|
|
|
|
|
RoomEvent.ParticipantMetadataChanged,
|
|
|
|
|
{ metadata, participant },
|
|
|
|
|
`previous: ${metadata}, new: ${participant.metadata}`
|
|
|
|
|
);
|
2021-10-19 18:03:58 +02:00
|
|
|
}
|
2024-07-02 19:19:05 +02:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-10-19 18:03:58 +02:00
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
if (
|
|
|
|
|
firstTime ||
|
|
|
|
|
this.roomEvents.get(RoomEvent.ParticipantNameChanged) !==
|
|
|
|
|
oldValues.get(RoomEvent.ParticipantNameChanged)
|
|
|
|
|
) {
|
|
|
|
|
this.room?.removeAllListeners(RoomEvent.ParticipantNameChanged);
|
|
|
|
|
if (this.roomEvents.get(RoomEvent.ParticipantNameChanged)) {
|
|
|
|
|
this.room!.on(
|
|
|
|
|
RoomEvent.ParticipantNameChanged,
|
|
|
|
|
(name: string, participant: Participant) => {
|
|
|
|
|
this.updateEventList(
|
|
|
|
|
RoomEvent.ParticipantNameChanged,
|
|
|
|
|
{ name, participant },
|
|
|
|
|
`${participant.identity} (${name})`
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
);
|
2018-01-18 16:09:39 +01:00
|
|
|
}
|
2018-05-29 18:32:49 +02:00
|
|
|
}
|
2018-01-18 16:09:39 +01:00
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
if (
|
|
|
|
|
firstTime ||
|
|
|
|
|
this.roomEvents.get(RoomEvent.ParticipantPermissionsChanged) !==
|
|
|
|
|
oldValues.get(RoomEvent.ParticipantPermissionsChanged)
|
|
|
|
|
) {
|
|
|
|
|
this.room?.removeAllListeners(RoomEvent.ParticipantPermissionsChanged);
|
|
|
|
|
if (this.roomEvents.get(RoomEvent.ParticipantPermissionsChanged)) {
|
|
|
|
|
this.room!.on(
|
|
|
|
|
RoomEvent.ParticipantPermissionsChanged,
|
|
|
|
|
(
|
|
|
|
|
prevPermissions: ParticipantPermission | undefined,
|
|
|
|
|
participant: RemoteParticipant | LocalParticipant
|
|
|
|
|
) => {
|
|
|
|
|
this.updateEventList(
|
|
|
|
|
RoomEvent.ParticipantPermissionsChanged,
|
|
|
|
|
{ prevPermissions, participant },
|
|
|
|
|
`${
|
|
|
|
|
participant.identity
|
|
|
|
|
} (previous: ${prevPermissions}, new: ${JSON.stringify(
|
|
|
|
|
participant.permissions
|
|
|
|
|
)}`
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
);
|
2018-04-17 15:08:02 +02:00
|
|
|
}
|
2018-05-29 18:32:49 +02:00
|
|
|
}
|
2018-01-18 16:09:39 +01:00
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
if (
|
|
|
|
|
firstTime ||
|
|
|
|
|
this.roomEvents.get(RoomEvent.ActiveSpeakersChanged) !==
|
|
|
|
|
oldValues.get(RoomEvent.ActiveSpeakersChanged)
|
|
|
|
|
) {
|
|
|
|
|
this.room?.removeAllListeners(RoomEvent.ActiveSpeakersChanged);
|
|
|
|
|
if (this.roomEvents.get(RoomEvent.ActiveSpeakersChanged)) {
|
|
|
|
|
this.room!.on(
|
|
|
|
|
RoomEvent.ActiveSpeakersChanged,
|
|
|
|
|
(speakers: Participant[]) => {
|
|
|
|
|
this.updateEventList(
|
|
|
|
|
RoomEvent.ActiveSpeakersChanged,
|
|
|
|
|
{ speakers },
|
|
|
|
|
JSON.stringify(
|
|
|
|
|
speakers.map(
|
|
|
|
|
(speaker) => `${speaker.identity}: ${speaker.audioLevel}`
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
);
|
2018-01-18 16:09:39 +01:00
|
|
|
}
|
2018-03-02 11:36:12 +01:00
|
|
|
}
|
2018-03-01 11:25:25 +01:00
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
if (
|
|
|
|
|
firstTime ||
|
|
|
|
|
this.roomEvents.get(RoomEvent.RoomMetadataChanged) !==
|
|
|
|
|
oldValues.get(RoomEvent.RoomMetadataChanged)
|
|
|
|
|
) {
|
|
|
|
|
this.room?.removeAllListeners(RoomEvent.RoomMetadataChanged);
|
|
|
|
|
if (this.roomEvents.get(RoomEvent.RoomMetadataChanged)) {
|
|
|
|
|
this.room!.on(RoomEvent.RoomMetadataChanged, (metadata: string) => {
|
|
|
|
|
this.updateEventList(
|
|
|
|
|
RoomEvent.RoomMetadataChanged,
|
|
|
|
|
{ metadata },
|
|
|
|
|
metadata
|
|
|
|
|
);
|
2018-05-29 18:32:49 +02:00
|
|
|
});
|
2018-03-02 11:36:12 +01:00
|
|
|
}
|
2018-03-01 11:25:25 +01:00
|
|
|
}
|
|
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
if (
|
|
|
|
|
firstTime ||
|
|
|
|
|
this.roomEvents.get(RoomEvent.DataReceived) !==
|
|
|
|
|
oldValues.get(RoomEvent.DataReceived)
|
|
|
|
|
) {
|
|
|
|
|
this.room?.removeAllListeners(RoomEvent.DataReceived);
|
|
|
|
|
if (this.roomEvents.get(RoomEvent.DataReceived)) {
|
|
|
|
|
this.room!.on(
|
|
|
|
|
RoomEvent.DataReceived,
|
|
|
|
|
(
|
|
|
|
|
payload: Uint8Array,
|
|
|
|
|
participant?: RemoteParticipant,
|
|
|
|
|
kind?: DataPacket_Kind,
|
|
|
|
|
topic?: string
|
|
|
|
|
) => {
|
|
|
|
|
const decodedPayload = this.decoder.decode(payload);
|
|
|
|
|
this.updateEventList(
|
|
|
|
|
RoomEvent.DataReceived,
|
|
|
|
|
{ payload: decodedPayload, participant, kind, topic },
|
|
|
|
|
decodedPayload
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
);
|
2023-02-06 12:45:17 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
if (
|
|
|
|
|
firstTime ||
|
|
|
|
|
this.roomEvents.get(RoomEvent.ConnectionQualityChanged) !==
|
|
|
|
|
oldValues.get(RoomEvent.ConnectionQualityChanged)
|
|
|
|
|
) {
|
|
|
|
|
this.room?.removeAllListeners(RoomEvent.ConnectionQualityChanged);
|
|
|
|
|
if (this.roomEvents.get(RoomEvent.ConnectionQualityChanged)) {
|
|
|
|
|
this.room!.on(
|
|
|
|
|
RoomEvent.ConnectionQualityChanged,
|
|
|
|
|
(quality: ConnectionQuality, participant: Participant) => {
|
|
|
|
|
this.updateEventList(
|
|
|
|
|
RoomEvent.ConnectionQualityChanged,
|
|
|
|
|
{ quality, participant },
|
|
|
|
|
`${participant.identity} (${quality})`
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
);
|
2023-02-06 12:45:17 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
if (
|
|
|
|
|
firstTime ||
|
|
|
|
|
this.roomEvents.get(RoomEvent.MediaDevicesError) !==
|
|
|
|
|
oldValues.get(RoomEvent.MediaDevicesError)
|
|
|
|
|
) {
|
|
|
|
|
this.room?.removeAllListeners(RoomEvent.MediaDevicesError);
|
|
|
|
|
if (this.roomEvents.get(RoomEvent.MediaDevicesError)) {
|
|
|
|
|
this.room!.on(RoomEvent.MediaDevicesError, (error: Error) => {
|
|
|
|
|
this.updateEventList(
|
|
|
|
|
RoomEvent.MediaDevicesError,
|
|
|
|
|
{
|
|
|
|
|
error: error.message,
|
|
|
|
|
failure: MediaDeviceFailure.getFailure(error),
|
|
|
|
|
},
|
|
|
|
|
`${error.message} (${MediaDeviceFailure.getFailure(error)})`
|
|
|
|
|
);
|
2018-05-29 18:32:49 +02:00
|
|
|
});
|
2018-03-02 11:36:12 +01:00
|
|
|
}
|
2018-03-01 11:25:25 +01:00
|
|
|
}
|
2018-03-02 11:36:12 +01:00
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
if (
|
|
|
|
|
firstTime ||
|
|
|
|
|
this.roomEvents.get(RoomEvent.TrackStreamStateChanged) !==
|
|
|
|
|
oldValues.get(RoomEvent.TrackStreamStateChanged)
|
|
|
|
|
) {
|
|
|
|
|
this.room?.removeAllListeners(RoomEvent.TrackStreamStateChanged);
|
|
|
|
|
if (this.roomEvents.get(RoomEvent.TrackStreamStateChanged)) {
|
|
|
|
|
this.room!.on(
|
|
|
|
|
RoomEvent.TrackStreamStateChanged,
|
|
|
|
|
(
|
|
|
|
|
publication: RemoteTrackPublication,
|
|
|
|
|
streamState: Track.StreamState,
|
|
|
|
|
participant: RemoteParticipant
|
|
|
|
|
) => {
|
|
|
|
|
this.updateEventList(
|
|
|
|
|
RoomEvent.TrackStreamStateChanged,
|
|
|
|
|
{ publication, streamState, participant },
|
|
|
|
|
`${participant.identity} (${publication.source}: ${streamState})`
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
);
|
2018-07-22 22:54:36 +02:00
|
|
|
}
|
2024-07-02 19:19:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
firstTime ||
|
|
|
|
|
this.roomEvents.get(RoomEvent.TrackSubscriptionPermissionChanged) !==
|
|
|
|
|
oldValues.get(RoomEvent.TrackSubscriptionPermissionChanged)
|
|
|
|
|
) {
|
|
|
|
|
this.room?.removeAllListeners(
|
|
|
|
|
RoomEvent.TrackSubscriptionPermissionChanged
|
|
|
|
|
);
|
|
|
|
|
if (this.roomEvents.get(RoomEvent.TrackSubscriptionPermissionChanged)) {
|
|
|
|
|
this.room!.on(
|
|
|
|
|
RoomEvent.TrackSubscriptionPermissionChanged,
|
|
|
|
|
(
|
|
|
|
|
publication: RemoteTrackPublication,
|
|
|
|
|
status: TrackPublication.PermissionStatus,
|
|
|
|
|
participant: RemoteParticipant
|
|
|
|
|
) => {
|
|
|
|
|
this.updateEventList(
|
|
|
|
|
RoomEvent.TrackSubscriptionPermissionChanged,
|
|
|
|
|
{ publication, status, participant },
|
|
|
|
|
`${participant.identity} (${publication.source}: ${status})`
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
);
|
2018-05-29 18:32:49 +02:00
|
|
|
}
|
2018-03-02 11:36:12 +01:00
|
|
|
}
|
2020-02-17 22:00:51 +01:00
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
if (
|
|
|
|
|
firstTime ||
|
|
|
|
|
this.roomEvents.get(RoomEvent.TrackSubscriptionStatusChanged) !==
|
|
|
|
|
oldValues.get(RoomEvent.TrackSubscriptionStatusChanged)
|
|
|
|
|
) {
|
|
|
|
|
this.room?.removeAllListeners(RoomEvent.TrackSubscriptionStatusChanged);
|
|
|
|
|
if (this.roomEvents.get(RoomEvent.TrackSubscriptionStatusChanged)) {
|
|
|
|
|
this.room!.on(
|
|
|
|
|
RoomEvent.TrackSubscriptionStatusChanged,
|
|
|
|
|
(
|
|
|
|
|
publication: RemoteTrackPublication,
|
|
|
|
|
status: TrackPublication.SubscriptionStatus,
|
|
|
|
|
participant: RemoteParticipant
|
|
|
|
|
) => {
|
|
|
|
|
this.updateEventList(
|
|
|
|
|
RoomEvent.TrackSubscriptionStatusChanged,
|
|
|
|
|
{ publication, status, participant },
|
|
|
|
|
`${participant.identity} (${publication.source} to ${status})`
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
);
|
2022-10-10 12:04:17 +02:00
|
|
|
}
|
2024-07-02 19:19:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
firstTime ||
|
|
|
|
|
this.roomEvents.get(RoomEvent.AudioPlaybackStatusChanged) !==
|
|
|
|
|
oldValues.get(RoomEvent.AudioPlaybackStatusChanged)
|
|
|
|
|
) {
|
|
|
|
|
this.room?.removeAllListeners(RoomEvent.AudioPlaybackStatusChanged);
|
|
|
|
|
if (this.roomEvents.get(RoomEvent.AudioPlaybackStatusChanged)) {
|
|
|
|
|
this.room!.on(
|
|
|
|
|
RoomEvent.AudioPlaybackStatusChanged,
|
|
|
|
|
(playing: boolean) => {
|
|
|
|
|
this.updateEventList(
|
|
|
|
|
RoomEvent.AudioPlaybackStatusChanged,
|
|
|
|
|
{ playing },
|
|
|
|
|
`canPlaybackAudio: ${this.room!.canPlaybackAudio}`
|
|
|
|
|
);
|
2022-11-08 14:20:42 +01:00
|
|
|
}
|
2024-07-02 19:19:05 +02:00
|
|
|
);
|
2022-10-10 12:04:17 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
if (
|
|
|
|
|
firstTime ||
|
|
|
|
|
this.roomEvents.get(RoomEvent.SignalConnected) !==
|
|
|
|
|
oldValues.get(RoomEvent.SignalConnected)
|
|
|
|
|
) {
|
|
|
|
|
this.room?.removeAllListeners(RoomEvent.SignalConnected);
|
|
|
|
|
if (this.roomEvents.get(RoomEvent.SignalConnected)) {
|
|
|
|
|
this.room!.on(RoomEvent.SignalConnected, () => {
|
|
|
|
|
this.updateEventList(RoomEvent.SignalConnected, {}, '');
|
2020-02-17 22:00:51 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
if (
|
|
|
|
|
firstTime ||
|
|
|
|
|
this.roomEvents.get(RoomEvent.RecordingStatusChanged) !==
|
|
|
|
|
oldValues.get(RoomEvent.RecordingStatusChanged)
|
|
|
|
|
) {
|
|
|
|
|
this.room?.removeAllListeners(RoomEvent.RecordingStatusChanged);
|
|
|
|
|
if (this.roomEvents.get(RoomEvent.RecordingStatusChanged)) {
|
|
|
|
|
this.room!.on(
|
|
|
|
|
RoomEvent.RecordingStatusChanged,
|
|
|
|
|
(recording: boolean) => {
|
|
|
|
|
this.updateEventList(
|
|
|
|
|
RoomEvent.RecordingStatusChanged,
|
|
|
|
|
{ recording },
|
|
|
|
|
`recording: ${recording}`
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
);
|
2020-02-17 22:00:51 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
if (
|
|
|
|
|
firstTime ||
|
|
|
|
|
this.roomEvents.get(RoomEvent.ParticipantEncryptionStatusChanged) !==
|
|
|
|
|
oldValues.get(RoomEvent.ParticipantEncryptionStatusChanged)
|
|
|
|
|
) {
|
|
|
|
|
this.room?.removeAllListeners(
|
|
|
|
|
RoomEvent.ParticipantEncryptionStatusChanged
|
|
|
|
|
);
|
|
|
|
|
if (this.roomEvents.get(RoomEvent.ParticipantEncryptionStatusChanged)) {
|
|
|
|
|
this.room!.on(
|
|
|
|
|
RoomEvent.ParticipantEncryptionStatusChanged,
|
|
|
|
|
(encrypted: boolean, participant?: Participant) => {
|
|
|
|
|
this.updateEventList(
|
|
|
|
|
RoomEvent.ParticipantEncryptionStatusChanged,
|
|
|
|
|
{ encrypted, participant },
|
|
|
|
|
`${participant?.identity} (encrypted: ${encrypted})`
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
);
|
2021-05-26 17:31:47 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
if (
|
|
|
|
|
firstTime ||
|
|
|
|
|
this.roomEvents.get(RoomEvent.EncryptionError) !==
|
|
|
|
|
oldValues.get(RoomEvent.EncryptionError)
|
|
|
|
|
) {
|
|
|
|
|
this.room?.removeAllListeners(RoomEvent.EncryptionError);
|
|
|
|
|
if (this.roomEvents.get(RoomEvent.EncryptionError)) {
|
|
|
|
|
this.room!.on(RoomEvent.EncryptionError, (error: Error) => {
|
|
|
|
|
this.updateEventList(
|
|
|
|
|
RoomEvent.EncryptionError,
|
|
|
|
|
{ error: error.message },
|
|
|
|
|
`${error.message}`
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-03-01 11:25:25 +01:00
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
if (
|
|
|
|
|
firstTime ||
|
|
|
|
|
this.roomEvents.get(RoomEvent.DCBufferStatusChanged) !==
|
|
|
|
|
oldValues.get(RoomEvent.DCBufferStatusChanged)
|
|
|
|
|
) {
|
|
|
|
|
this.room?.removeAllListeners(RoomEvent.DCBufferStatusChanged);
|
|
|
|
|
if (this.roomEvents.get(RoomEvent.DCBufferStatusChanged)) {
|
|
|
|
|
this.room!.on(
|
|
|
|
|
RoomEvent.DCBufferStatusChanged,
|
|
|
|
|
(isLow: boolean, kind: DataPacket_Kind) => {
|
|
|
|
|
this.updateEventList(
|
|
|
|
|
RoomEvent.DCBufferStatusChanged,
|
|
|
|
|
{ isLow, kind },
|
|
|
|
|
`isLow: ${isLow} (${kind})`
|
|
|
|
|
);
|
2018-04-17 15:08:02 +02:00
|
|
|
}
|
2024-07-02 19:19:05 +02:00
|
|
|
);
|
|
|
|
|
}
|
2018-04-17 15:08:02 +02:00
|
|
|
}
|
|
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
if (
|
|
|
|
|
firstTime ||
|
|
|
|
|
this.roomEvents.get(RoomEvent.ActiveDeviceChanged) !==
|
|
|
|
|
oldValues.get(RoomEvent.ActiveDeviceChanged)
|
|
|
|
|
) {
|
|
|
|
|
this.room?.removeAllListeners(RoomEvent.ActiveDeviceChanged);
|
|
|
|
|
if (this.roomEvents.get(RoomEvent.ActiveDeviceChanged)) {
|
|
|
|
|
this.room!.on(
|
|
|
|
|
RoomEvent.ActiveDeviceChanged,
|
|
|
|
|
(kind: MediaDeviceKind, deviceId: string) => {
|
|
|
|
|
this.updateEventList(
|
|
|
|
|
RoomEvent.DCBufferStatusChanged,
|
|
|
|
|
{ kind, deviceId },
|
|
|
|
|
`${kind} (${deviceId})`
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
);
|
2020-11-19 17:06:50 +01:00
|
|
|
}
|
2024-07-02 19:19:05 +02:00
|
|
|
}
|
2024-09-30 15:19:33 +02:00
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
firstTime ||
|
|
|
|
|
this.roomEvents.get(RoomEvent.LocalTrackSubscribed) !==
|
|
|
|
|
oldValues.get(RoomEvent.LocalTrackSubscribed)
|
|
|
|
|
) {
|
|
|
|
|
this.room?.removeAllListeners(RoomEvent.LocalTrackSubscribed);
|
|
|
|
|
if (this.roomEvents.get(RoomEvent.LocalTrackSubscribed)) {
|
|
|
|
|
this.room!.on(
|
|
|
|
|
RoomEvent.LocalTrackSubscribed,
|
|
|
|
|
(
|
|
|
|
|
publication: LocalTrackPublication,
|
|
|
|
|
participant: LocalParticipant
|
|
|
|
|
) => {
|
|
|
|
|
this.updateEventList(
|
|
|
|
|
RoomEvent.LocalTrackSubscribed,
|
|
|
|
|
{ publication, participant },
|
|
|
|
|
`${publication.source}`
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-07-02 19:19:05 +02:00
|
|
|
}
|
2020-11-19 17:06:50 +01:00
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
updateEventList(
|
|
|
|
|
eventType: RoomEvent,
|
|
|
|
|
eventContent: any,
|
|
|
|
|
eventDescription: string
|
|
|
|
|
) {
|
|
|
|
|
const event: TestAppEvent = {
|
|
|
|
|
eventType,
|
|
|
|
|
eventCategory: 'RoomEvent',
|
|
|
|
|
eventContent,
|
|
|
|
|
eventDescription,
|
|
|
|
|
};
|
|
|
|
|
this.events.push(event);
|
|
|
|
|
this.testFeedService.pushNewEvent({ user: this.index, event });
|
2018-04-17 15:08:02 +02:00
|
|
|
}
|
|
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
async disconnectRoom() {
|
|
|
|
|
if (this.room) {
|
|
|
|
|
await this.room.disconnect();
|
|
|
|
|
delete this.room;
|
|
|
|
|
delete this.localTracks.audioTrack;
|
|
|
|
|
delete this.localTracks.videoTrack;
|
|
|
|
|
this.remoteTracks.clear();
|
|
|
|
|
}
|
2018-04-17 15:08:02 +02:00
|
|
|
}
|
|
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
async setCameraEnabled() {
|
|
|
|
|
this.room!.localParticipant.setCameraEnabled(true);
|
|
|
|
|
}
|
2018-05-18 12:46:41 +02:00
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
async setMicrophoneEnabled() {
|
|
|
|
|
this.room!.localParticipant.setMicrophoneEnabled(true);
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-17 01:32:41 +02:00
|
|
|
openOptionsDialog() {
|
|
|
|
|
const dialogRef = this.dialog.open(OptionsDialogComponent, {
|
|
|
|
|
data: {
|
|
|
|
|
roomOptions: this.roomOptions,
|
|
|
|
|
createLocalTracksOptions: this.createLocalTracksOptions,
|
|
|
|
|
shareScreen: true,
|
|
|
|
|
screenShareCaptureOptions: this.screenShareCaptureOptions,
|
|
|
|
|
trackPublishOptions: this.trackPublishOptions,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
dialogRef.afterClosed().subscribe((result) => {
|
|
|
|
|
if (!!result) {
|
2024-10-02 01:14:42 +02:00
|
|
|
this.roomOptions = result.roomOptions;
|
2024-09-17 01:32:41 +02:00
|
|
|
this.createLocalTracksOptions = result.createLocalTracksOptions;
|
|
|
|
|
this.screenShareCaptureOptions = result.screenShareCaptureOptions;
|
|
|
|
|
this.trackPublishOptions = result.trackPublishOptions;
|
2024-09-17 14:46:21 +02:00
|
|
|
if (
|
|
|
|
|
this.createLocalTracksOptions.audio != undefined &&
|
|
|
|
|
typeof this.createLocalTracksOptions.audio !== 'boolean'
|
|
|
|
|
) {
|
|
|
|
|
this.roomOptions.audioCaptureDefaults =
|
|
|
|
|
this.createLocalTracksOptions.audio;
|
|
|
|
|
}
|
|
|
|
|
if (
|
|
|
|
|
this.createLocalTracksOptions.video != undefined &&
|
|
|
|
|
typeof this.createLocalTracksOptions.video !== 'boolean'
|
|
|
|
|
) {
|
|
|
|
|
this.roomOptions.videoCaptureDefaults =
|
|
|
|
|
this.createLocalTracksOptions.video;
|
|
|
|
|
}
|
|
|
|
|
if (this.trackPublishOptions != undefined) {
|
|
|
|
|
this.roomOptions.publishDefaults = this.trackPublishOptions;
|
|
|
|
|
}
|
2024-09-17 01:32:41 +02:00
|
|
|
}
|
|
|
|
|
});
|
2018-05-18 12:46:41 +02:00
|
|
|
}
|
|
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
openRoomApiDialog() {
|
|
|
|
|
const dialogRef = this.dialog.open(RoomApiDialogComponent, {
|
2018-05-18 12:46:41 +02:00
|
|
|
data: {
|
2024-07-02 19:19:05 +02:00
|
|
|
room: this.room,
|
|
|
|
|
localParticipant: this.room?.localParticipant,
|
2018-05-18 12:46:41 +02:00
|
|
|
},
|
2024-07-02 19:19:05 +02:00
|
|
|
disableClose: true,
|
2018-05-18 12:46:41 +02:00
|
|
|
});
|
2024-07-02 19:19:05 +02:00
|
|
|
dialogRef.afterClosed().subscribe((result) => {
|
|
|
|
|
document
|
|
|
|
|
.getElementById('room-api-btn-' + this.index)
|
|
|
|
|
?.classList.remove('cdk-program-focused');
|
2018-05-29 18:32:49 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
openRoomEventsDialog() {
|
|
|
|
|
const oldValues: Map<string, boolean> = new Map(
|
|
|
|
|
JSON.parse(JSON.stringify([...this.roomEvents]))
|
|
|
|
|
);
|
2018-05-29 18:32:49 +02:00
|
|
|
|
|
|
|
|
const dialogRef = this.dialog.open(EventsDialogComponent, {
|
|
|
|
|
data: {
|
2024-07-02 19:19:05 +02:00
|
|
|
eventCollection: this.roomEvents,
|
|
|
|
|
target: 'Session',
|
2018-05-29 18:32:49 +02:00
|
|
|
},
|
2024-07-02 19:19:05 +02:00
|
|
|
width: '800px',
|
2018-05-29 18:32:49 +02:00
|
|
|
autoFocus: false,
|
2024-07-02 19:19:05 +02:00
|
|
|
disableClose: true,
|
2018-05-18 12:46:41 +02:00
|
|
|
});
|
|
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
dialogRef.afterClosed().subscribe((result) => {
|
|
|
|
|
if (
|
|
|
|
|
!!this.room &&
|
|
|
|
|
JSON.stringify(Array.from(this.roomEvents.entries())) !==
|
|
|
|
|
JSON.stringify(Array.from(oldValues.entries()))
|
|
|
|
|
) {
|
|
|
|
|
this.setupRoomEventListeners(oldValues, false);
|
2018-05-31 13:08:34 +02:00
|
|
|
}
|
2020-11-19 23:58:26 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
sendData(destinationIdentity?: string) {
|
|
|
|
|
let strData = `Message from ${this.room?.localParticipant.identity}`;
|
2024-09-17 01:32:41 +02:00
|
|
|
strData += destinationIdentity
|
|
|
|
|
? ` to ${destinationIdentity}`
|
|
|
|
|
: ' to all room';
|
2024-07-02 19:19:05 +02:00
|
|
|
const data = new TextEncoder().encode(strData);
|
|
|
|
|
let options: DataPublishOptions = {
|
|
|
|
|
reliable: true,
|
|
|
|
|
};
|
|
|
|
|
if (destinationIdentity) {
|
|
|
|
|
options.destinationIdentities = [destinationIdentity];
|
2018-05-31 13:08:34 +02:00
|
|
|
}
|
2024-07-02 19:19:05 +02:00
|
|
|
this.room?.localParticipant.publishData(data, options);
|
2018-05-31 13:08:34 +02:00
|
|
|
}
|
2024-10-02 01:14:42 +02:00
|
|
|
|
|
|
|
|
openInfoDialog() {
|
|
|
|
|
const updateFunction = async (): Promise<string> => {
|
|
|
|
|
const pub: PCTransport = this.getPublisherPC()!;
|
|
|
|
|
const sub: PCTransport = this.getSubscriberPC()!;
|
|
|
|
|
return JSON.stringify(
|
|
|
|
|
{
|
|
|
|
|
publisher: {
|
|
|
|
|
connectedAddress: await pub.getConnectedAddress(),
|
|
|
|
|
connectionState: pub.getConnectionState(),
|
|
|
|
|
iceConnectionState: pub.getICEConnectionState(),
|
|
|
|
|
signallingState: pub.getSignallingState(),
|
|
|
|
|
},
|
|
|
|
|
subscriber: {
|
|
|
|
|
connectedAddress: await sub.getConnectedAddress(),
|
|
|
|
|
connectionState: sub.getConnectionState(),
|
|
|
|
|
iceConnectionState: sub.getICEConnectionState(),
|
|
|
|
|
signallingState: sub.getSignallingState(),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
null,
|
|
|
|
|
2
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
this.dialog.open(InfoDialogComponent, {
|
|
|
|
|
data: {
|
|
|
|
|
title: 'PCTransports info',
|
|
|
|
|
updateFunction,
|
|
|
|
|
},
|
|
|
|
|
minWidth: '50vh'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getPublisherPC(): PCTransport | undefined {
|
|
|
|
|
return this.room?.localParticipant.engine.pcManager?.publisher;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getSubscriberPC(): PCTransport | undefined {
|
|
|
|
|
return this.room?.localParticipant.engine.pcManager?.subscriber;
|
|
|
|
|
}
|
2017-09-28 19:13:29 +02:00
|
|
|
}
|