2022-03-02 11:00:58 +01:00
|
|
|
import { Component, HostListener, OnDestroy, OnInit, Output, EventEmitter } from '@angular/core';
|
2022-03-31 12:25:02 +02:00
|
|
|
import { PublisherProperties } from 'openvidu-browser';
|
2022-03-02 11:00:58 +01:00
|
|
|
import { Subscription } from 'rxjs';
|
|
|
|
import { CustomDevice } from '../../models/device.model';
|
|
|
|
import { ILogger } from '../../models/logger.model';
|
2022-03-31 12:25:02 +02:00
|
|
|
import { ParticipantAbstractModel } from '../../models/participant.model';
|
2022-03-02 11:00:58 +01:00
|
|
|
import { DeviceService } from '../../services/device/device.service';
|
|
|
|
import { LayoutService } from '../../services/layout/layout.service';
|
|
|
|
import { LoggerService } from '../../services/logger/logger.service';
|
|
|
|
import { OpenViduService } from '../../services/openvidu/openvidu.service';
|
|
|
|
import { ParticipantService } from '../../services/participant/participant.service';
|
|
|
|
import { StorageService } from '../../services/storage/storage.service';
|
|
|
|
|
2022-03-23 13:48:17 +01:00
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*/
|
2022-03-02 11:00:58 +01:00
|
|
|
@Component({
|
|
|
|
selector: 'ov-pre-join',
|
|
|
|
templateUrl: './pre-join.component.html',
|
|
|
|
styleUrls: ['./pre-join.component.css']
|
|
|
|
})
|
|
|
|
export class PreJoinComponent implements OnInit, OnDestroy {
|
2022-03-09 15:31:21 +01:00
|
|
|
@Output() onJoinButtonClicked = new EventEmitter<any>();
|
2022-03-02 11:00:58 +01:00
|
|
|
cameras: CustomDevice[];
|
|
|
|
microphones: CustomDevice[];
|
|
|
|
cameraSelected: CustomDevice;
|
|
|
|
microphoneSelected: CustomDevice;
|
|
|
|
isVideoMuted: boolean;
|
|
|
|
isAudioMuted: boolean;
|
|
|
|
localParticipant: ParticipantAbstractModel;
|
|
|
|
windowSize: number;
|
|
|
|
hasVideoDevices: boolean;
|
|
|
|
hasAudioDevices: boolean;
|
|
|
|
isLoading = true;
|
|
|
|
nickname: string;
|
|
|
|
private log: ILogger;
|
|
|
|
private localParticipantSubscription: Subscription;
|
|
|
|
private screenShareStateSubscription: Subscription;
|
|
|
|
|
|
|
|
@HostListener('window:resize')
|
|
|
|
sizeChange() {
|
|
|
|
this.windowSize = window.innerWidth;
|
|
|
|
this.layoutService.update();
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
private layoutService: LayoutService,
|
|
|
|
private deviceSrv: DeviceService,
|
|
|
|
private loggerSrv: LoggerService,
|
|
|
|
private openviduService: OpenViduService,
|
|
|
|
private participantService: ParticipantService,
|
|
|
|
private storageSrv: StorageService
|
|
|
|
) {
|
|
|
|
this.log = this.loggerSrv.get('PreJoinComponent');
|
|
|
|
}
|
|
|
|
|
2022-03-10 14:12:43 +01:00
|
|
|
ngOnInit() {
|
2022-03-02 11:00:58 +01:00
|
|
|
this.subscribeToLocalParticipantEvents();
|
2022-03-10 14:12:43 +01:00
|
|
|
|
2022-03-02 11:00:58 +01:00
|
|
|
this.windowSize = window.innerWidth;
|
2022-03-10 14:12:43 +01:00
|
|
|
this.hasVideoDevices = this.deviceSrv.hasVideoDeviceAvailable();
|
|
|
|
this.hasAudioDevices = this.deviceSrv.hasAudioDeviceAvailable();
|
|
|
|
this.microphones = this.deviceSrv.getMicrophones();
|
|
|
|
this.cameras = this.deviceSrv.getCameras();
|
|
|
|
this.cameraSelected = this.deviceSrv.getCameraSelected();
|
|
|
|
this.microphoneSelected = this.deviceSrv.getMicrophoneSelected();
|
|
|
|
|
|
|
|
this.isVideoMuted = this.deviceSrv.isVideoMuted();
|
|
|
|
this.isAudioMuted = this.deviceSrv.isAudioMuted();
|
|
|
|
|
2022-03-02 11:00:58 +01:00
|
|
|
this.isLoading = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
|
|
|
if (this.localParticipantSubscription) {
|
|
|
|
this.localParticipantSubscription.unsubscribe();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.screenShareStateSubscription) {
|
|
|
|
this.screenShareStateSubscription.unsubscribe();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async onCameraSelected(event: any) {
|
|
|
|
const videoSource = event?.value;
|
|
|
|
// Is New deviceId different from the old one?
|
|
|
|
if (this.deviceSrv.needUpdateVideoTrack(videoSource)) {
|
|
|
|
const mirror = this.deviceSrv.cameraNeedsMirror(videoSource);
|
|
|
|
//TODO: Uncomment this when replaceTrack issue is fixed
|
|
|
|
// const pp: PublisherProperties = { videoSource, audioSource: false, mirror };
|
|
|
|
// await this.openviduService.replaceTrack(VideoType.CAMERA, pp);
|
|
|
|
// TODO: Remove this when replaceTrack issue is fixed
|
|
|
|
const pp: PublisherProperties = { videoSource, audioSource: this.microphoneSelected.device, mirror };
|
|
|
|
await this.openviduService.republishTrack(pp);
|
|
|
|
|
2022-03-31 12:25:02 +02:00
|
|
|
this.deviceSrv.setCameraSelected(videoSource);
|
|
|
|
this.cameraSelected = this.deviceSrv.getCameraSelected();
|
2022-03-02 11:00:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async onMicrophoneSelected(event: any) {
|
|
|
|
const audioSource = event?.value;
|
|
|
|
if (this.deviceSrv.needUpdateAudioTrack(audioSource)) {
|
|
|
|
//TODO: Uncomment this when replaceTrack issue is fixed
|
|
|
|
// const pp: PublisherProperties = { audioSource, videoSource: false };
|
|
|
|
// await this.openviduService.replaceTrack(VideoType.CAMERA, pp);
|
|
|
|
// TODO: Remove this when replaceTrack issue is fixed
|
|
|
|
const mirror = this.deviceSrv.cameraNeedsMirror(this.cameraSelected.device);
|
|
|
|
const pp: PublisherProperties = { videoSource: this.cameraSelected.device, audioSource, mirror };
|
|
|
|
await this.openviduService.republishTrack(pp);
|
|
|
|
|
2022-03-31 12:25:02 +02:00
|
|
|
this.deviceSrv.setMicSelected(audioSource);
|
|
|
|
this.microphoneSelected = this.deviceSrv.getMicrophoneSelected();
|
2022-03-02 11:00:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-31 12:25:02 +02:00
|
|
|
async toggleCam() {
|
2022-03-02 11:00:58 +01:00
|
|
|
const publish = this.isVideoMuted;
|
2022-04-01 13:24:56 +02:00
|
|
|
await this.openviduService.publishVideo(publish);
|
2022-03-02 11:00:58 +01:00
|
|
|
this.isVideoMuted = !this.isVideoMuted;
|
|
|
|
this.storageSrv.setVideoMuted(this.isVideoMuted);
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleMic() {
|
|
|
|
const publish = this.isAudioMuted;
|
2022-04-01 13:24:56 +02:00
|
|
|
this.openviduService.publishAudio(publish);
|
2022-03-02 11:00:58 +01:00
|
|
|
this.isAudioMuted = !this.isAudioMuted;
|
|
|
|
this.storageSrv.setAudioMuted(this.isAudioMuted);
|
|
|
|
}
|
|
|
|
|
|
|
|
updateNickname() {
|
2022-03-10 14:12:43 +01:00
|
|
|
this.nickname = this.nickname === '' ? this.participantService.getMyNickname() : this.nickname;
|
2022-03-02 11:00:58 +01:00
|
|
|
this.participantService.setMyNickname(this.nickname);
|
|
|
|
this.storageSrv.setNickname(this.nickname);
|
|
|
|
}
|
|
|
|
|
|
|
|
joinSession() {
|
2022-03-09 15:31:21 +01:00
|
|
|
this.onJoinButtonClicked.emit();
|
2022-03-02 11:00:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private subscribeToLocalParticipantEvents() {
|
|
|
|
this.localParticipantSubscription = this.participantService.localParticipantObs.subscribe((p) => {
|
|
|
|
this.localParticipant = p;
|
2022-03-16 14:21:58 +01:00
|
|
|
this.nickname = this.localParticipant.getNickname();
|
2022-03-02 11:00:58 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
//? After test in Chrome and Firefox, the devices always have labels.
|
|
|
|
//? It's not longer needed
|
|
|
|
// private handlePublisherSuccess(publisher: Publisher) {
|
|
|
|
// publisher.once('accessAllowed', async () => {
|
|
|
|
// if (this.deviceSrv.areEmptyLabels()) {
|
|
|
|
// await this.deviceSrv.forceUpdate();
|
|
|
|
// if (this.hasAudioDevices) {
|
|
|
|
// const audioLabel = publisher?.stream?.getMediaStream()?.getAudioTracks()[0]?.label;
|
|
|
|
// this.deviceSrv.setMicSelected(audioLabel);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (this.hasVideoDevices) {
|
|
|
|
// const videoLabel = publisher?.stream?.getMediaStream()?.getVideoTracks()[0]?.label;
|
|
|
|
// this.deviceSrv.setCameraSelected(videoLabel);
|
|
|
|
// }
|
|
|
|
// this.setDevicesInfo();
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
}
|