import { AfterViewInit, Component, ContentChild, EventEmitter, Input, OnInit, Output, TemplateRef, ViewChild } from '@angular/core'; import { ChatPanelDirective, LayoutDirective, PanelDirective, ParticipantPanelItemDirective, ParticipantsPanelDirective, StreamDirective, ToolbarDirective } from '../../directives/template/openvidu-angular.directive'; import { ILogger } from '../../models/logger.model'; import { LoggerService } from '../../services/logger/logger.service'; @Component({ selector: 'ov-videoconference', templateUrl: './videoconference.component.html', styleUrls: ['./videoconference.component.css'] }) export class VideoconferenceComponent implements OnInit, AfterViewInit { // *** Toolbar *** @ContentChild(ToolbarDirective) externalToolbar: ToolbarDirective; // *** Panels *** @ContentChild(PanelDirective) externalPanel: PanelDirective; @ContentChild(ChatPanelDirective) externalChatPanel: ChatPanelDirective; @ContentChild(ParticipantsPanelDirective) externalParticipantsPanel: ParticipantsPanelDirective; @ContentChild(ParticipantPanelItemDirective) externalParticipantPanelItem: ParticipantPanelItemDirective; // *** Layout *** @ContentChild(LayoutDirective) externalLayout: LayoutDirective; @ContentChild(StreamDirective) externalStream: StreamDirective; @ViewChild('defaultToolbar', { static: false, read: TemplateRef }) defaultToolbarTemplate: TemplateRef; @ViewChild('defaultPanel', { static: false, read: TemplateRef }) defaultPanelTemplate: TemplateRef; @ViewChild('defaultChatPanel', { static: false, read: TemplateRef }) defaultChatPanelTemplate: TemplateRef; @ViewChild('defaultParticipantsPanel', { static: false, read: TemplateRef }) defaultParticipantsPanelTemplate: TemplateRef; @ViewChild('defaultParticipantPanelItem', { static: false, read: TemplateRef }) defaultParticipantPanelItemTemplate: TemplateRef; @ViewChild('defaultLayout', { static: false, read: TemplateRef }) defaultLayoutTemplate: TemplateRef; @ViewChild('defaultStream', { static: false, read: TemplateRef }) defaultStreamTemplate: TemplateRef; openviduAngularToolbarTemplate: TemplateRef; openviduAngularPanelTemplate: TemplateRef; openviduAngularChatPanelTemplate: TemplateRef; openviduAngularParticipantsPanelTemplate: TemplateRef; openviduAngularParticipantPanelItemTemplate: TemplateRef; openviduAngularLayoutTemplate: TemplateRef; openviduAngularStreamTemplate: TemplateRef; // *** Parameters *** @Input() sessionName: string; @Input() participantName: string; @Input() set tokens(tokens: { webcam: string; screen: string }) { if (!tokens || (!tokens.webcam && !tokens.screen)) { //No tokens received // throw new Error('No tokens received'); this.log.w('No tokens received'); } else { if (tokens.webcam || tokens.screen) { this._tokens = { webcam: tokens.webcam, screen: tokens.screen }; this.isSessionAlive = true; } } } // *** Events *** // Event sent when user click on the join button in pre-join page @Output() onJoinButtonClicked = new EventEmitter(); // Event sent when user click on the join button in pre-join page @Output() onToolbarLeaveButtonClicked = new EventEmitter(); @Output() onToolbarCameraButtonClicked = new EventEmitter(); @Output() onToolbarMicrophoneButtonClicked = new EventEmitter(); @Output() onToolbarScreenshareButtonClicked = new EventEmitter(); @Output() onToolbarFullscreenButtonClicked = new EventEmitter(); @Output() onToolbarParticipantsPanelButtonClicked = new EventEmitter(); @Output() onToolbarChatPanelButtonClicked = new EventEmitter(); // Event sent when participant has joined the session @Output() onParticipantJoined = new EventEmitter(); // Event sent when participant has left the session // @Output() onParticipantLeft = new EventEmitter(); // Event sent when session has been created @Output() onSessionCreated = new EventEmitter(); joinSessionClicked: boolean = false; isSessionAlive: boolean = false; _tokens: { webcam: string; screen: string }; error: boolean = false; errorMessage: string = ''; private log: ILogger; constructor(private loggerSrv: LoggerService) { this.log = this.loggerSrv.get('VideoconferenceComponent'); } ngAfterViewInit() { if (this.externalToolbar) { this.openviduAngularToolbarTemplate = this.externalToolbar.template; this.log.d('Setting EXTERNAL TOOLBAR'); } else { this.openviduAngularToolbarTemplate = this.defaultToolbarTemplate; this.log.d('Setting DEFAULT TOOLBAR'); } if (this.externalPanel) { this.openviduAngularPanelTemplate = this.externalPanel.template; this.log.d('Setting EXTERNAL PANEL'); } else { this.log.d('Setting DEFAULT PANEL'); if (this.externalParticipantsPanel) { this.openviduAngularParticipantsPanelTemplate = this.externalParticipantsPanel.template; this.log.d('Setting EXTERNAL PARTICIPANTS PANEL'); } else { this.log.d('Setting DEFAULT PARTICIPANTS PANEL'); if (this.externalParticipantPanelItem) { this.openviduAngularParticipantPanelItemTemplate = this.externalParticipantPanelItem.template; this.log.d('Setting EXTERNAL P ITEM'); } else { this.openviduAngularParticipantPanelItemTemplate = this.defaultParticipantPanelItemTemplate; this.log.d('Setting DEFAULT P ITEM'); } this.openviduAngularParticipantsPanelTemplate = this.defaultParticipantsPanelTemplate; } if (this.externalChatPanel) { this.openviduAngularChatPanelTemplate = this.externalChatPanel.template; this.log.d('Setting EXTERNAL CHAT PANEL'); } else { this.openviduAngularChatPanelTemplate = this.defaultChatPanelTemplate; this.log.d('Setting DEFAULT CHAT PANEL'); } this.openviduAngularPanelTemplate = this.defaultPanelTemplate; } if (this.externalLayout) { this.openviduAngularLayoutTemplate = this.externalLayout.template; this.log.d('Setting EXTERNAL LAYOUT'); } else { this.log.d('Setting DEAFULT LAYOUT'); if (this.externalStream) { this.openviduAngularStreamTemplate = this.externalStream.template; this.log.d('Setting EXTERNAL STREAM'); } else { this.openviduAngularStreamTemplate = this.defaultStreamTemplate; this.log.d('Setting DEFAULT STREAM'); } this.openviduAngularLayoutTemplate = this.defaultLayoutTemplate; } } ngOnInit() {} _onJoinButtonClicked() { this.joinSessionClicked = true; this.onJoinButtonClicked.emit(); } onLeaveButtonClicked() { this.joinSessionClicked = false; this.isSessionAlive = false; this.onToolbarLeaveButtonClicked.emit(); } onCameraButtonClicked() { this.onToolbarCameraButtonClicked.emit(); } onMicrophoneButtonClicked() { this.onToolbarMicrophoneButtonClicked.emit(); } onScreenshareButtonClicked() { this.onToolbarScreenshareButtonClicked.emit(); } onFullscreenButtonClicked() { this.onToolbarFullscreenButtonClicked.emit(); } onParticipantsPanelButtonClicked() { this.onToolbarParticipantsPanelButtonClicked.emit(); } onChatPanelButtonClicked() { this.onToolbarChatPanelButtonClicked.emit(); } }