2022-03-09 12:34:10 +01:00
|
|
|
import {
|
|
|
|
AfterViewInit,
|
|
|
|
ChangeDetectionStrategy,
|
|
|
|
ChangeDetectorRef,
|
|
|
|
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-03-07 15:50:27 +01:00
|
|
|
import { StreamDirective } from '../../directives/template/openvidu-angular.directive';
|
2022-01-19 17:24:11 +01:00
|
|
|
|
2022-03-23 13:48:17 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* The **LayoutComponent** is hosted inside of the {@link VideoconferenceComponent}.
|
|
|
|
* It is in charge of displaying the participants streams layout.
|
|
|
|
*
|
|
|
|
* <div class="custom-table-container">
|
|
|
|
*
|
|
|
|
* <div>
|
|
|
|
* <h3>OpenVidu Angular Directives</h3>
|
|
|
|
*
|
|
|
|
* The LayoutComponent can be replaced with a custom component. It provides us the following {@link https://angular.io/guide/structural-directives Angular structural directives}
|
|
|
|
* for doing this.
|
|
|
|
*
|
|
|
|
* | **Directive** | **Reference** |
|
|
|
|
* |:----------------------------------:|:---------------------------------------------:|
|
|
|
|
* | ***ovLayout** | {@link LayoutDirective} |
|
|
|
|
*
|
|
|
|
* </br>
|
|
|
|
*
|
|
|
|
* It is also providing us a way to **replace the {@link StreamComponent Stream Component}** (<span class="italic">which is hosted inside of it</span>) with a custom one.
|
|
|
|
* It will recognise the following directive in a child element.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* | **Directive** | **Reference** |
|
|
|
|
* |:----------------------------------:|:---------------------------------------------:|
|
|
|
|
* | ***ovStream** | {@link StreamDirective} |
|
|
|
|
*
|
|
|
|
* <p class="component-link-text">
|
|
|
|
* <span class="italic">See all {@link OpenViduAngularDirectiveModule OpenVidu Angular Directives}</span>
|
|
|
|
* </p>
|
|
|
|
* </div>
|
|
|
|
* </div>
|
|
|
|
*/
|
2022-01-19 17:24:11 +01:00
|
|
|
@Component({
|
|
|
|
selector: 'ov-layout',
|
|
|
|
templateUrl: './layout.component.html',
|
2022-02-23 12:13:28 +01:00
|
|
|
styleUrls: ['./layout.component.css'],
|
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush
|
2022-01-19 17:24:11 +01:00
|
|
|
})
|
|
|
|
export class LayoutComponent implements OnInit, OnDestroy, AfterViewInit {
|
2022-03-23 13:48:17 +01:00
|
|
|
/**
|
|
|
|
* @ignore
|
|
|
|
*/
|
2022-02-03 17:08:23 +01:00
|
|
|
@ContentChild('stream', { read: TemplateRef }) streamTemplate: TemplateRef<any>;
|
|
|
|
|
2022-03-23 13:48:17 +01:00
|
|
|
/**
|
|
|
|
* @ignore
|
|
|
|
*/
|
2022-02-17 17:26:30 +01:00
|
|
|
@ContentChild(StreamDirective)
|
2022-03-09 12:34:10 +01:00
|
|
|
set externalStream(externalStream: StreamDirective) {
|
2022-02-17 17:26:30 +01:00
|
|
|
// This directive will has value only when STREAM component tagget with '*ovStream' directive
|
|
|
|
// is inside of the layout component tagged with '*ovLayout' directive
|
2022-03-09 12:34:10 +01:00
|
|
|
if (externalStream) {
|
2022-02-17 17:26:30 +01:00
|
|
|
this.streamTemplate = externalStream.template;
|
|
|
|
}
|
|
|
|
}
|
2022-01-19 17:24:11 +01:00
|
|
|
|
|
|
|
localParticipant: ParticipantAbstractModel;
|
|
|
|
remoteParticipants: ParticipantAbstractModel[] = [];
|
|
|
|
protected localParticipantSubs: Subscription;
|
|
|
|
protected remoteParticipantsSubs: Subscription;
|
|
|
|
|
2022-03-23 13:48:17 +01:00
|
|
|
/**
|
|
|
|
* @ignore
|
|
|
|
*/
|
|
|
|
constructor(protected layoutService: LayoutService, protected participantService: ParticipantService, private cd: ChangeDetectorRef) {}
|
2022-01-28 15:16:09 +01:00
|
|
|
|
2022-01-19 17:24:11 +01:00
|
|
|
ngOnInit(): void {
|
2022-01-28 15:16:09 +01:00
|
|
|
this.subscribeToParticipants();
|
2022-01-19 17:24:11 +01:00
|
|
|
}
|
|
|
|
|
2022-03-02 11:00:58 +01:00
|
|
|
ngAfterViewInit() {
|
2022-03-10 14:12:43 +01:00
|
|
|
let timeout: number = 0;
|
2022-03-09 12:34:10 +01:00
|
|
|
this.layoutService.initialize(timeout);
|
|
|
|
this.layoutService.update(timeout);
|
2022-01-19 17:24:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
|
|
|
this.localParticipant = null;
|
|
|
|
this.remoteParticipants = [];
|
|
|
|
if (this.localParticipantSubs) this.localParticipantSubs.unsubscribe();
|
|
|
|
if (this.remoteParticipantsSubs) this.remoteParticipantsSubs.unsubscribe();
|
2022-02-23 12:13:28 +01:00
|
|
|
this.layoutService.clear();
|
2022-01-19 17:24:11 +01:00
|
|
|
}
|
|
|
|
|
2022-03-23 13:48:17 +01:00
|
|
|
private subscribeToParticipants() {
|
2022-01-19 17:24:11 +01:00
|
|
|
this.localParticipantSubs = this.participantService.localParticipantObs.subscribe((p) => {
|
|
|
|
this.localParticipant = p;
|
|
|
|
this.layoutService.update();
|
2022-02-23 12:13:28 +01:00
|
|
|
this.cd.markForCheck();
|
2022-01-19 17:24:11 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
this.remoteParticipantsSubs = this.participantService.remoteParticipantsObs.subscribe((participants) => {
|
2022-03-03 10:21:33 +01:00
|
|
|
this.remoteParticipants = participants;
|
2022-01-19 17:24:11 +01:00
|
|
|
this.layoutService.update();
|
2022-02-23 12:13:28 +01:00
|
|
|
this.cd.markForCheck();
|
2022-01-19 17:24:11 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|