2022-02-04 11:26:27 +01:00
|
|
|
import { AfterViewInit, Component, ContentChild, OnDestroy, OnInit, TemplateRef } from '@angular/core';
|
2022-01-26 16:01:12 +01:00
|
|
|
import { Subscription } from 'rxjs';
|
2022-01-19 17:24:11 +01:00
|
|
|
import { ParticipantService } from '../../services/participant/participant.service';
|
|
|
|
import { ParticipantAbstractModel } from '../../models/participant.model';
|
2022-01-26 16:01:12 +01:00
|
|
|
import { LayoutService } from '../../services/layout/layout.service';
|
2022-02-17 17:26:30 +01:00
|
|
|
import { StreamDirective } from '../../directives/openvidu-angular.directive';
|
2022-01-19 17:24:11 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'ov-layout',
|
|
|
|
templateUrl: './layout.component.html',
|
|
|
|
styleUrls: ['./layout.component.css']
|
|
|
|
})
|
|
|
|
export class LayoutComponent implements OnInit, OnDestroy, AfterViewInit {
|
2022-02-03 17:08:23 +01:00
|
|
|
@ContentChild('stream', { read: TemplateRef }) streamTemplate: TemplateRef<any>;
|
|
|
|
|
2022-02-17 17:26:30 +01:00
|
|
|
@ContentChild(StreamDirective)
|
|
|
|
set externalStream (externalStream: StreamDirective) {
|
|
|
|
// This directive will has value only when STREAM component tagget with '*ovStream' directive
|
|
|
|
// is inside of the layout component tagged with '*ovLayout' directive
|
|
|
|
if(externalStream) {
|
|
|
|
this.streamTemplate = externalStream.template;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-19 17:24:11 +01:00
|
|
|
localParticipant: ParticipantAbstractModel;
|
|
|
|
remoteParticipants: ParticipantAbstractModel[] = [];
|
|
|
|
protected localParticipantSubs: Subscription;
|
|
|
|
protected remoteParticipantsSubs: Subscription;
|
|
|
|
|
2022-01-26 16:01:12 +01:00
|
|
|
constructor(protected layoutService: LayoutService, protected participantService: ParticipantService) {}
|
2022-01-19 17:24:11 +01:00
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
this.subscribeToUsers();
|
|
|
|
}
|
|
|
|
|
|
|
|
ngAfterViewInit() {}
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
|
|
|
this.localParticipant = null;
|
|
|
|
this.remoteParticipants = [];
|
|
|
|
if (this.localParticipantSubs) this.localParticipantSubs.unsubscribe();
|
|
|
|
if (this.remoteParticipantsSubs) this.remoteParticipantsSubs.unsubscribe();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected subscribeToUsers() {
|
|
|
|
this.localParticipantSubs = this.participantService.localParticipantObs.subscribe((p) => {
|
|
|
|
this.localParticipant = p;
|
|
|
|
this.layoutService.update();
|
|
|
|
});
|
|
|
|
|
|
|
|
this.remoteParticipantsSubs = this.participantService.remoteParticipantsObs.subscribe((participants) => {
|
|
|
|
this.remoteParticipants = [...participants];
|
|
|
|
this.layoutService.update();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|