All files / src/lib/components/participant participant.component.ts

42.25% Statements 30/71
22.8% Branches 13/57
35% Functions 7/20
38.46% Lines 25/65

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 1661x 1x 1x 1x 1x                                       1x   1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x                                                 1x 1x       1x     1x                                                                                                                     1x                 1x                   1x                                  
import { Component, ElementRef, HostListener, Input, OnInit, ViewChild, ViewContainerRef } from '@angular/core';
import { FormControl, Validators } from '@angular/forms';
impoIrt { MatMenuPanel, MatMenuTrigger } from '@angular/material/menu';
import { NicknameMatcher } from '../../matchers/nickname.matcher';
import { VideoFullscreenIcon, VideoSizeIcon } from '../../models/icon.model';
import { UserModel } from '../../models/user.model';
import { VideoType } from '../../models/video-type.model';
import { Storage } from '../../models/storage.model';
import { DocumentService } from '../../services/document/document.service';
import { CdkOverlayService } from '../../services/cdk-overlay/cdk-overlay.service';
import { WebrtcService } from '../../services/webrtc/webrtc.service';
import { LayoutService } from '../../services/layout/layout.service';
import { LocalUserService } from '../../services/local-user/local-user.service';
import { RemoteUserService } from '../../services/remote-user/remote-user.service';
import { StorageService } from '../../services/storage/storage.service';
import { Signal } from '../../models/signal.model';
import { LayoutClass } from '../../models/layout.model';
 
@Component({
	selector: 'ov-participant',
	templateUrl: './participant.component.html',
	styleUrls: ['./participant.component.css']
})
export class ParticipantComponent implements OnInit {
	videoSizeIconEnum = VideoSizeIcon;
	videoFullscreenIconEnum = VideoFullscreenIcon;
	videoTypeEnum = VideoType;
	videoSizeIcon: VideoSizeIcon = VideoSizeIcon.BIG;
	fullscreenIcon: VideoFullscreenIcon = VideoFullscreenIcon.BIG;
	mutedSound: boolean;
	toggleNickname: boolean;
	isFullscreen: boolean;
 
	nicknameFormControl: FormControl;
	matcher: NicknameMatcher;
 
	_user: UserModel;
 
	@ViewChild('streamComponent', { read: ViewContainerRef }) streamComponent: ViewContainerRef;
	@ViewChild(MatMenuTrigger) public menuTrigger: MatMenuTrigger;
	@ViewChild('menu') menu: MatMenuPanel;

	constructor(
		private documentService: DocumentService,
		private openViduWebRTCService: WebrtcService,
		private layoutService: LayoutService,
		private localUserService: LocalUserService,
		private remoteUserService: RemoteUserService,
		private storageService: StorageService,
		private cdkSrv: CdkOverlayService
	) {}
 
	@HostListener('window:resize', ['$event'])
	sizeChange(event) {
		const maxHeight = window.screen.height;
		const maxWidth = window.screen.width;
		const curHeight = window.innerHeight;
		const curWidth = window.innerWidth;
		if (maxWidth !== curWidth && maxHeight !== curHeight) {
			this.isFullscreen = false;
			this.videoSizeIcon = VideoSizeIcon.BIG;
		}
	}

	@HostListener('document:fullscreenchange', ['$event'])
	@HostListener('document:webkitfullscreenchange', ['$event'])
	@HostListener('document:mozfullscreenchange', ['$event'])
	@HostListener('document:MSFullscreenChange', ['$event'])
	onFullscreenHandler(event) {
		this.toggleFullscreenIcon();
	}
 
	// Has been mandatory fullscreen Input because of Input user did not fire changing
	// the fullscreen user property in publisherStartSpeaking event in VideoRoom Component
	@Input()
	set videoSizeBig(videoSizeBig: boolean) {
		this.checkVideoSizeBigIcon(videoSizeBig);
	}
 
	@Input()
	set user(user: UserModel) {
		this._user = user;
		this.nicknameFormControl = new FormControl(this._user.getNickname(), [Validators.maxLength(25), Validators.required]);
	}
 
	@ViewChild('nicknameInput')
	set nicknameInputElement(element: ElementRef) {
		setTimeout(() => {
			element?.nativeElement.focus();
		});
	}

	ngOnInit() {
		this.matcher = new NicknameMatcher();
	}

	ngOnDestroy() {
		this.cdkSrv.setSelector('body');
	}

	toggleVideoSize(resetAll?) {
		const element = this.documentService.getHTMLElementByClassName(this.streamComponent.element.nativeElement, LayoutClass.ROOT_ELEMENT);
		if (!!resetAll) {
			this.documentService.removeAllBigElementClass();
			this.remoteUserService.resetUsersZoom();
			this.localUserService.resetUsersZoom();
		}

		this.documentService.toggleBigElementClass(element);
 
		if (!!this._user.getConnectionId()) {
			if (this.openViduWebRTCService.isMyOwnConnection(this._user.getConnectionId())) {
				this.localUserService.toggleZoom(this._user.getConnectionId());
			} else {
				this.remoteUserService.toggleUserZoom(this._user.getConnectionId());
			}
		}
		this.layoutService.update();
	}

	toggleFullscreen() {
		this.documentService.toggleFullscreen('container-' + this._user.getStreamManager().stream.streamId);
	}

	toggleVideoMenu(event) {
		if (this.menuTrigger.menuOpen) {
			this.menuTrigger.closeMenu();
			return;
		}
		this.cdkSrv.setSelector('#container-' + this._user.streamManager?.stream?.streamId);
		this.menuTrigger.openMenu();
	}
 
	toggleSound() {
		this.mutedSound = !this.mutedSound;
	}
 
	toggleNicknameForm() {
		if (this._user.isLocal()) {
			this.toggleNickname = !this.toggleNickname;
		}
	}
 
	eventKeyPress(event) {
		if (event && event.keyCode === 13 && this.nicknameFormControl.valid) {
			const nickname = this.nicknameFormControl.value;
			this.localUserService.updateUsersNickname(nickname);
			this.storageService.set(Storage.USER_NICKNAME, nickname);
			this.openViduWebRTCService.sendSignal(Signal.NICKNAME_CHANGED, undefined, {clientData: nickname});
			this.toggleNicknameForm();
		}
	}
 
	replaceScreenTrack() {
		this.openViduWebRTCService.replaceScreenTrack();
	}
 
	private checkVideoSizeBigIcon(videoSizeBig: boolean) {
		this.videoSizeIcon = videoSizeBig ? VideoSizeIcon.NORMAL : VideoSizeIcon.BIG;
	}
 
	private toggleFullscreenIcon() {
		this.fullscreenIcon = this.fullscreenIcon === VideoFullscreenIcon.BIG ? VideoFullscreenIcon.NORMAL : VideoFullscreenIcon.BIG;
	}
}