2022-03-10 15:41:51 +01:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
2024-07-02 19:19:05 +02:00
|
|
|
import {
|
|
|
|
BroadcastingStartRequestedEvent,
|
|
|
|
BroadcastingStopRequestedEvent,
|
|
|
|
RecordingDeleteRequestedEvent,
|
|
|
|
RecordingStartRequestedEvent,
|
|
|
|
RecordingStopRequestedEvent,
|
|
|
|
Room,
|
|
|
|
RoomEvent
|
|
|
|
} from 'openvidu-components-angular';
|
2022-01-19 17:24:11 +01:00
|
|
|
import { RestService } from '../services/rest.service';
|
2024-07-02 19:19:05 +02:00
|
|
|
import { CustomDevice } from 'dist/openvidu-components-angular/lib/models/device.model';
|
|
|
|
import { LangOption } from 'dist/openvidu-components-angular/lib/models/lang.model';
|
|
|
|
import { ActivatedRoute, Router } from '@angular/router';
|
2022-04-28 13:09:42 +02:00
|
|
|
|
2022-01-19 17:24:11 +01:00
|
|
|
@Component({
|
|
|
|
selector: 'app-call',
|
|
|
|
templateUrl: './call.component.html',
|
|
|
|
styleUrls: ['./call.component.scss']
|
|
|
|
})
|
|
|
|
export class CallComponent implements OnInit {
|
2024-07-02 19:19:05 +02:00
|
|
|
roomName = 'daily-call';
|
|
|
|
token: string;
|
|
|
|
tokenError: string | undefined;
|
2022-01-19 17:24:11 +01:00
|
|
|
isSessionAlive: boolean = false;
|
2024-07-02 19:19:05 +02:00
|
|
|
|
|
|
|
private staticVideos = [
|
|
|
|
'https://videos.pexels.com/video-files/4089575/4089575-hd_1280_720_50fps.mp4',
|
|
|
|
'https://videos.pexels.com/video-files/8375762/8375762-hd_1080_2048_25fps.mp4',
|
|
|
|
'https://videos.pexels.com/video-files/4994156/4994156-hd_1080_1920_25fps.mp4',
|
|
|
|
'https://videos.pexels.com/video-files/5752499/5752499-hd_1080_1920_25fps.mp4',
|
|
|
|
'https://videos.pexels.com/video-files/6012390/6012390-hd_1080_1920_25fps.mp4',
|
|
|
|
'https://videos.pexels.com/video-files/6388880/6388880-hd_1080_1920_25fps.mp4',
|
|
|
|
'https://videos.pexels.com/video-files/5956873/5956873-hd_1080_1920_25fps.mp4',
|
|
|
|
'https://videos.pexels.com/video-files/5384955/5384955-hd_1080_1920_25fps.mp4',
|
|
|
|
'https://videos.pexels.com/video-files/5199626/5199626-hd_1280_720_25fps.mp4',
|
|
|
|
'https://videos.pexels.com/video-files/5638228/5638228-hd_1080_1920_25fps.mp4',
|
|
|
|
'https://videos.pexels.com/video-files/5647316/5647316-hd_1080_1920_25fps.mp4',
|
|
|
|
'https://videos.pexels.com/video-files/5992459/5992459-hd_1080_1920_25fps.mp4',
|
|
|
|
'https://videos.pexels.com/video-files/5438937/5438937-hd_1080_1920_25fps.mp4',
|
|
|
|
'https://videos.pexels.com/video-files/5586701/5586701-hd_1080_1920_25fps.mp4',
|
|
|
|
'https://videos.pexels.com/video-files/8375616/8375616-hd_1080_2048_25fps.mp4',
|
|
|
|
'https://videos.pexels.com/video-files/5087894/5087894-hd_1080_1920_25fps.mp4',
|
|
|
|
'https://videos.pexels.com/video-files/9569674/9569674-hd_1080_2048_25fps.mp4'
|
|
|
|
];
|
|
|
|
|
|
|
|
private areStaticVideosEnabled = false;
|
2022-01-19 17:24:11 +01:00
|
|
|
|
2023-02-22 13:08:22 +01:00
|
|
|
constructor(
|
|
|
|
private restService: RestService,
|
2024-07-02 19:19:05 +02:00
|
|
|
private router: Router,
|
|
|
|
private activatedRoute: ActivatedRoute
|
2023-02-22 13:08:22 +01:00
|
|
|
) {}
|
2022-01-19 17:24:11 +01:00
|
|
|
|
2022-03-10 15:41:51 +01:00
|
|
|
async ngOnInit() {
|
2024-07-02 19:19:05 +02:00
|
|
|
this.activatedRoute.queryParams.subscribe((params) => {
|
|
|
|
this.areStaticVideosEnabled = params['staticVideos'] === 'true';
|
|
|
|
console.log('Static videos enabled: ', this.areStaticVideosEnabled);
|
|
|
|
});
|
|
|
|
if (this.areStaticVideosEnabled) {
|
|
|
|
setTimeout(() => {
|
|
|
|
const videoElements = document.querySelectorAll('video');
|
|
|
|
this.replaceWithStaticVideos(videoElements);
|
|
|
|
}, 3000);
|
|
|
|
}
|
2022-11-04 16:24:42 +01:00
|
|
|
}
|
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
async onTokenRequested(participantName: string) {
|
|
|
|
await this.requestForTokens(participantName);
|
2022-04-28 13:09:42 +02:00
|
|
|
}
|
2022-01-19 17:24:11 +01:00
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
async onReadyToJoin() {
|
|
|
|
console.warn('VC IS READY TO JOIN');
|
|
|
|
}
|
|
|
|
|
|
|
|
onRoomCreated(room: Room) {
|
2025-03-07 13:04:22 +01:00
|
|
|
console.warn('VC ROOM CREATED', room.name);
|
2024-07-02 19:19:05 +02:00
|
|
|
room.on(RoomEvent.Connected, () => {
|
|
|
|
if (this.areStaticVideosEnabled) {
|
|
|
|
setTimeout(() => {
|
|
|
|
const videoElements = document.querySelectorAll('video');
|
|
|
|
this.replaceWithStaticVideos(videoElements);
|
|
|
|
}, 3000);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
room.on(RoomEvent.TrackPublished, (publication, participant) => {
|
|
|
|
participant.videoTrackPublications.forEach((publication) => {
|
|
|
|
if (this.areStaticVideosEnabled) {
|
|
|
|
setTimeout(() => {
|
|
|
|
if (publication.videoTrack?.attachedElements) {
|
|
|
|
this.replaceWithStaticVideos(publication.videoTrack?.attachedElements);
|
|
|
|
const firstVideo = this.staticVideos.shift();
|
|
|
|
this.staticVideos.push(firstVideo);
|
|
|
|
}
|
|
|
|
}, 2000);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2022-01-19 17:24:11 +01:00
|
|
|
}
|
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
onVideoEnabledChanged(value: boolean) {
|
|
|
|
console.warn('VC video enabled: ', value);
|
2022-03-10 15:41:51 +01:00
|
|
|
}
|
2024-07-02 19:19:05 +02:00
|
|
|
onVideoDeviceChanged(device: CustomDevice) {
|
|
|
|
console.warn('VC video device changed: ', device);
|
2022-03-10 15:41:51 +01:00
|
|
|
}
|
2024-07-02 19:19:05 +02:00
|
|
|
onAudioEnabledChanged(value: boolean) {
|
|
|
|
console.warn('VC audio enabled: ', value);
|
2022-03-10 15:41:51 +01:00
|
|
|
}
|
2024-07-02 19:19:05 +02:00
|
|
|
onAudioDeviceChanged(device: CustomDevice) {
|
|
|
|
console.warn('VC audio device changed: ', device);
|
2022-03-10 15:41:51 +01:00
|
|
|
}
|
2024-07-02 19:19:05 +02:00
|
|
|
onScreenShareEnabledChanged(enabled: boolean) {
|
|
|
|
console.warn('VC screenshare enabled: ', enabled);
|
2022-03-10 15:41:51 +01:00
|
|
|
}
|
2024-07-02 19:19:05 +02:00
|
|
|
onFullscreenEnabledChanged(enabled: boolean) {
|
|
|
|
console.warn('VC fullscreen enabled: ', enabled);
|
|
|
|
}
|
|
|
|
onParticipantsPanelStatusChanged(event) {
|
|
|
|
console.warn('VC participants panel status changed: ', event);
|
|
|
|
}
|
|
|
|
onChatPanelStatusChanged(event) {
|
|
|
|
console.warn('VC chat status changed: ', event);
|
2022-02-03 17:08:23 +01:00
|
|
|
}
|
2022-01-19 17:24:11 +01:00
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
onRoomDisconnected() {
|
2022-03-10 15:41:51 +01:00
|
|
|
this.isSessionAlive = false;
|
|
|
|
console.log('VC LEAVE BUTTON CLICKED');
|
2024-07-02 19:19:05 +02:00
|
|
|
this.router.navigate(['/']);
|
2022-03-10 15:41:51 +01:00
|
|
|
}
|
2022-01-19 17:24:11 +01:00
|
|
|
|
2022-03-10 15:41:51 +01:00
|
|
|
onFullscreenButtonClicked() {
|
|
|
|
console.warn('TOOLBAR fullscreen CLICKED');
|
|
|
|
}
|
|
|
|
onParticipantsPanelButtonClicked() {
|
|
|
|
console.warn('TOOLBAR participants CLICKED');
|
|
|
|
}
|
|
|
|
onChatPanelButtonClicked() {
|
|
|
|
console.warn('TOOLBAR chat CLICKED');
|
|
|
|
}
|
2022-01-19 17:24:11 +01:00
|
|
|
|
2022-03-10 15:41:51 +01:00
|
|
|
onLeaveButtonClicked() {
|
2022-01-19 17:24:11 +01:00
|
|
|
this.isSessionAlive = false;
|
2022-03-10 15:41:51 +01:00
|
|
|
console.log('TOOLBAR LEAVE CLICKED');
|
2022-01-19 17:24:11 +01:00
|
|
|
}
|
2022-06-22 12:42:02 +02:00
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
onLangChanged(event: LangOption) {
|
|
|
|
console.warn('LANG CHANGED', event);
|
2023-06-21 11:10:41 +02:00
|
|
|
}
|
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
async onBroadcastingStartRequested(event: BroadcastingStartRequestedEvent) {
|
|
|
|
console.log('START STREAMING', event);
|
2022-12-23 16:17:04 +01:00
|
|
|
try {
|
2024-07-02 19:19:05 +02:00
|
|
|
const resp = await this.restService.startBroadcasting(event.broadcastUrl);
|
2023-02-17 17:03:15 +01:00
|
|
|
console.log('Broadcasting response ', resp);
|
2022-12-23 16:17:04 +01:00
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
async onBroadcastingStopRequested(event: BroadcastingStopRequestedEvent) {
|
|
|
|
console.log('STOP STREAMING', event);
|
2022-12-23 16:17:04 +01:00
|
|
|
try {
|
2023-02-17 17:03:15 +01:00
|
|
|
const resp = await this.restService.stopBroadcasting();
|
|
|
|
console.log('Broadcasting response ', resp);
|
2022-12-23 16:17:04 +01:00
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
async onRecordingStartRequested(event: RecordingStartRequestedEvent) {
|
|
|
|
console.warn('START RECORDING CLICKED', event);
|
2022-06-22 12:42:02 +02:00
|
|
|
try {
|
2024-07-02 19:19:05 +02:00
|
|
|
await this.restService.startRecording(this.roomName);
|
2022-06-22 12:42:02 +02:00
|
|
|
} catch (error) {
|
2024-07-02 19:19:05 +02:00
|
|
|
console.error(error);
|
2022-06-22 12:42:02 +02:00
|
|
|
}
|
|
|
|
}
|
2024-07-02 19:19:05 +02:00
|
|
|
async onRecordingStopRequested(event: RecordingStopRequestedEvent) {
|
|
|
|
console.warn('STOP RECORDING CLICKED', event);
|
2022-06-22 12:42:02 +02:00
|
|
|
try {
|
2024-07-02 19:19:05 +02:00
|
|
|
await this.restService.stopRecording(event);
|
2022-06-22 12:42:02 +02:00
|
|
|
} catch (error) {
|
2024-07-02 19:19:05 +02:00
|
|
|
console.error(error);
|
2022-06-22 12:42:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
async onRecordingDeleteRequested(event: RecordingDeleteRequestedEvent) {
|
|
|
|
console.warn('DELETE RECORDING requested', event);
|
2022-06-22 12:42:02 +02:00
|
|
|
|
|
|
|
try {
|
2024-07-02 19:19:05 +02:00
|
|
|
await this.restService.deleteRecording(event);
|
2022-06-22 12:42:02 +02:00
|
|
|
} catch (error) {
|
2024-07-02 19:19:05 +02:00
|
|
|
console.error(error);
|
2022-06-22 12:42:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
private async requestForTokens(participantName: string) {
|
|
|
|
try {
|
|
|
|
const { token } = await this.restService.getTokenFromBackend(this.roomName, participantName);
|
|
|
|
this.token = token;
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
|
|
|
this.tokenError = error.error;
|
|
|
|
}
|
2023-04-28 17:50:11 +02:00
|
|
|
}
|
|
|
|
|
2024-07-02 19:19:05 +02:00
|
|
|
private replaceWithStaticVideos(videoElements) {
|
|
|
|
let sourceIndex = 0;
|
|
|
|
for (let i = 0; i < videoElements.length; i++) {
|
|
|
|
const videoElement = videoElements[i];
|
|
|
|
videoElement.srcObject = null;
|
|
|
|
videoElement.src = this.staticVideos[sourceIndex];
|
|
|
|
console.log(`Assigned ${this.staticVideos[sourceIndex]}`);
|
|
|
|
sourceIndex = (sourceIndex + 1) % this.staticVideos.length;
|
|
|
|
videoElement.addEventListener('ended', () => {
|
|
|
|
// Allow loop
|
|
|
|
videoElement.currentTime = 0;
|
|
|
|
videoElement.play();
|
|
|
|
});
|
|
|
|
}
|
2022-11-04 16:24:42 +01:00
|
|
|
}
|
2022-01-19 17:24:11 +01:00
|
|
|
}
|