2022-02-15 15:52:59 +01:00
|
|
|
import { Component, ElementRef, Input, OnInit, ViewChild } from '@angular/core';
|
2022-01-19 17:24:11 +01:00
|
|
|
import { FormControl, Validators } from '@angular/forms';
|
|
|
|
import { MatMenuPanel, MatMenuTrigger } from '@angular/material/menu';
|
|
|
|
import { NicknameMatcher } from '../../matchers/nickname.matcher';
|
|
|
|
import { VideoSizeIcon } from '../../models/icon.model';
|
|
|
|
import { ScreenType, VideoType } from '../../models/video-type.model';
|
|
|
|
import { DocumentService } from '../../services/document/document.service';
|
|
|
|
import { CdkOverlayService } from '../../services/cdk-overlay/cdk-overlay.service';
|
2022-02-15 15:52:59 +01:00
|
|
|
import { OpenViduService } from '../../services/openvidu/openvidu.service';
|
2022-01-19 17:24:11 +01:00
|
|
|
import { LayoutService } from '../../services/layout/layout.service';
|
|
|
|
import { StorageService } from '../../services/storage/storage.service';
|
|
|
|
import { Signal } from '../../models/signal.model';
|
|
|
|
import { PublisherProperties } from 'openvidu-browser';
|
2022-01-26 11:30:30 +01:00
|
|
|
import { StreamModel } from '../../models/participant.model';
|
2022-01-19 17:24:11 +01:00
|
|
|
import { ParticipantService } from '../../services/participant/participant.service';
|
|
|
|
|
|
|
|
@Component({
|
2022-01-26 11:30:30 +01:00
|
|
|
selector: 'ov-stream',
|
|
|
|
templateUrl: './stream.component.html',
|
|
|
|
styleUrls: ['./stream.component.css']
|
2022-01-19 17:24:11 +01:00
|
|
|
})
|
2022-01-26 11:30:30 +01:00
|
|
|
export class StreamComponent implements OnInit {
|
2022-01-19 17:24:11 +01:00
|
|
|
videoSizeIconEnum = VideoSizeIcon;
|
|
|
|
videoTypeEnum = VideoType;
|
|
|
|
videoSizeIcon: VideoSizeIcon = VideoSizeIcon.BIG;
|
|
|
|
mutedSound: boolean;
|
|
|
|
toggleNickname: boolean;
|
|
|
|
nicknameFormControl: FormControl;
|
|
|
|
matcher: NicknameMatcher;
|
2022-02-07 10:43:21 +01:00
|
|
|
_stream: StreamModel;
|
2022-02-07 15:40:05 +01:00
|
|
|
private _streamContainer: ElementRef;
|
2022-01-19 17:24:11 +01:00
|
|
|
@ViewChild(MatMenuTrigger) public menuTrigger: MatMenuTrigger;
|
|
|
|
@ViewChild('menu') menu: MatMenuPanel;
|
|
|
|
|
2022-02-21 17:33:23 +01:00
|
|
|
@Input() showNickname: boolean = true;
|
|
|
|
@Input() showAudioDetection: boolean = true;
|
|
|
|
@Input() showSettings: boolean = true;
|
|
|
|
|
2022-01-19 17:24:11 +01:00
|
|
|
constructor(
|
|
|
|
protected documentService: DocumentService,
|
2022-02-15 15:52:59 +01:00
|
|
|
protected openviduService: OpenViduService,
|
2022-01-19 17:24:11 +01:00
|
|
|
protected layoutService: LayoutService,
|
|
|
|
protected participantService: ParticipantService,
|
|
|
|
protected storageService: StorageService,
|
|
|
|
protected cdkSrv: CdkOverlayService
|
|
|
|
) {}
|
|
|
|
|
2022-02-07 15:40:05 +01:00
|
|
|
@ViewChild('streamContainer', { static: false, read: ElementRef })
|
|
|
|
set streamContainer(streamContainer: ElementRef) {
|
|
|
|
setTimeout(() => {
|
|
|
|
if (streamContainer) {
|
|
|
|
this._streamContainer = streamContainer;
|
2022-02-24 13:02:00 +01:00
|
|
|
// Remove 'no-size' css class for showing the element in the view.
|
|
|
|
// This is a workaround for fixing a layout bug which provide a bad UX with each new elements created.
|
|
|
|
this.documentService.removeNoSizeElementClass(this._streamContainer.nativeElement);
|
2022-02-07 15:40:05 +01:00
|
|
|
}
|
|
|
|
}, 0);
|
|
|
|
}
|
2022-01-19 17:24:11 +01:00
|
|
|
|
|
|
|
@Input()
|
2022-02-07 10:43:21 +01:00
|
|
|
set stream(stream: StreamModel) {
|
|
|
|
this._stream = stream;
|
2022-02-07 15:40:05 +01:00
|
|
|
this.checkVideoEnlarged();
|
2022-02-07 10:43:21 +01:00
|
|
|
this.nicknameFormControl = new FormControl(this._stream.nickname, [Validators.maxLength(25), Validators.required]);
|
2022-01-19 17:24:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@ViewChild('nicknameInput')
|
|
|
|
set nicknameInputElement(element: ElementRef) {
|
|
|
|
setTimeout(() => {
|
|
|
|
element?.nativeElement.focus();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.matcher = new NicknameMatcher();
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
|
|
|
this.cdkSrv.setSelector('body');
|
|
|
|
}
|
|
|
|
|
2022-02-25 13:53:49 +01:00
|
|
|
toggleVideoEnlarged() {
|
2022-02-07 10:43:21 +01:00
|
|
|
if (!!this._stream.streamManager?.stream?.connection?.connectionId) {
|
2022-02-15 15:52:59 +01:00
|
|
|
if (this.openviduService.isMyOwnConnection(this._stream.streamManager?.stream?.connection?.connectionId)) {
|
2022-02-07 15:40:05 +01:00
|
|
|
this.participantService.toggleMyVideoEnlarged(this._stream.streamManager?.stream?.connection?.connectionId);
|
2022-01-19 17:24:11 +01:00
|
|
|
} else {
|
2022-02-07 15:40:05 +01:00
|
|
|
this.participantService.toggleRemoteVideoEnlarged(this._stream.streamManager?.stream?.connection?.connectionId);
|
2022-01-19 17:24:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
this.layoutService.update();
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleVideoMenu(event) {
|
|
|
|
if (this.menuTrigger.menuOpen) {
|
|
|
|
this.menuTrigger.closeMenu();
|
|
|
|
return;
|
|
|
|
}
|
2022-02-07 10:43:21 +01:00
|
|
|
this.cdkSrv.setSelector('#container-' + this._stream.streamManager?.stream?.streamId);
|
2022-01-19 17:24:11 +01:00
|
|
|
this.menuTrigger.openMenu();
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleSound() {
|
|
|
|
this.mutedSound = !this.mutedSound;
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleNicknameForm() {
|
2022-02-07 10:43:21 +01:00
|
|
|
if (this._stream.local) {
|
2022-01-19 17:24:11 +01:00
|
|
|
this.toggleNickname = !this.toggleNickname;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
eventKeyPress(event) {
|
|
|
|
if (event && event.keyCode === 13 && this.nicknameFormControl.valid) {
|
|
|
|
const nickname = this.nicknameFormControl.value;
|
2022-02-07 10:43:21 +01:00
|
|
|
this.participantService.setNickname(this._stream.connectionId, nickname);
|
2022-02-21 17:33:23 +01:00
|
|
|
this.storageService.setNickname(nickname);
|
2022-02-15 15:52:59 +01:00
|
|
|
this.openviduService.sendSignal(Signal.NICKNAME_CHANGED, undefined, { clientData: nickname });
|
2022-01-19 17:24:11 +01:00
|
|
|
this.toggleNicknameForm();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async replaceScreenTrack() {
|
|
|
|
const properties: PublisherProperties = {
|
|
|
|
videoSource: ScreenType.SCREEN,
|
|
|
|
publishVideo: true,
|
2022-02-25 11:19:21 +01:00
|
|
|
publishAudio: !this.participantService.isMyCameraActive(),
|
2022-01-19 17:24:11 +01:00
|
|
|
mirror: false
|
|
|
|
};
|
2022-02-21 17:33:23 +01:00
|
|
|
await this.openviduService.replaceTrack(VideoType.SCREEN, properties);
|
2022-01-19 17:24:11 +01:00
|
|
|
}
|
|
|
|
|
2022-02-07 15:40:05 +01:00
|
|
|
protected checkVideoEnlarged() {
|
|
|
|
this.videoSizeIcon = this._stream.videoEnlarged ? VideoSizeIcon.NORMAL : VideoSizeIcon.BIG;
|
2022-01-19 17:24:11 +01:00
|
|
|
}
|
|
|
|
}
|