2017-09-30 13:48:40 +02:00
|
|
|
import { Component, OnInit, OnDestroy } from '@angular/core';
|
|
|
|
import { Subscription } from 'rxjs/Subscription';
|
|
|
|
import { OpenviduParamsService } from '../../services/openvidu-params.service';
|
2017-10-09 18:48:05 +02:00
|
|
|
import { TestFeedService } from '../../services/test-feed.service';
|
2017-10-02 15:18:28 +02:00
|
|
|
import { SessionConf } from '../openvidu-instance/openvidu-instance.component';
|
2017-09-30 13:48:40 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-test-sessions',
|
|
|
|
templateUrl: './test-sessions.component.html',
|
|
|
|
styleUrls: ['./test-sessions.component.css']
|
|
|
|
})
|
|
|
|
export class TestSessionsComponent implements OnInit, OnDestroy {
|
|
|
|
|
|
|
|
openviduUrl: string;
|
|
|
|
openviduSecret: string;
|
|
|
|
|
|
|
|
paramsSubscription: Subscription;
|
2017-10-09 18:48:05 +02:00
|
|
|
eventsInfoSubscription: Subscription;
|
2017-09-30 13:48:40 +02:00
|
|
|
|
|
|
|
// OpenViduInstance collection
|
2017-10-02 15:18:28 +02:00
|
|
|
users: SessionConf[] = [];
|
|
|
|
|
|
|
|
numberSubs = 3;
|
|
|
|
autoJoin = false;
|
2017-09-30 13:48:40 +02:00
|
|
|
|
2017-10-09 18:48:05 +02:00
|
|
|
constructor(private openviduParamsService: OpenviduParamsService, private testFeedService: TestFeedService) { }
|
2017-09-30 13:48:40 +02:00
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
const openviduParams = this.openviduParamsService.getParams();
|
|
|
|
this.openviduUrl = openviduParams.openviduUrl;
|
|
|
|
this.openviduSecret = openviduParams.openviduSecret;
|
|
|
|
|
|
|
|
this.paramsSubscription = this.openviduParamsService.newParams$.subscribe(
|
|
|
|
params => {
|
|
|
|
this.openviduUrl = params.openviduUrl;
|
|
|
|
this.openviduSecret = params.openviduSecret;
|
|
|
|
});
|
2017-10-09 18:48:05 +02:00
|
|
|
|
|
|
|
this.eventsInfoSubscription = this.testFeedService.newLastEvent$.subscribe(
|
|
|
|
newEvent => {
|
|
|
|
(window as any).myEvents += ('<br>' + JSON.stringify(newEvent));
|
|
|
|
});
|
2017-09-30 13:48:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
|
|
|
this.paramsSubscription.unsubscribe();
|
|
|
|
}
|
|
|
|
|
2017-10-02 15:18:28 +02:00
|
|
|
private addUser(): void {
|
|
|
|
this.users.push({
|
|
|
|
subscribeTo: true,
|
|
|
|
publishTo: true,
|
|
|
|
startSession: false
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-10-09 18:48:05 +02:00
|
|
|
private removeUser(): void {
|
|
|
|
this.users.pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
private removeAllUsers(): void {
|
|
|
|
this.users = [];
|
|
|
|
}
|
|
|
|
|
2017-10-02 15:18:28 +02:00
|
|
|
private loadSubsPubs(n: number): void {
|
|
|
|
for (let i = 0; i < n; i++) {
|
|
|
|
this.users.push({
|
|
|
|
subscribeTo: true,
|
|
|
|
publishTo: true,
|
|
|
|
startSession: this.autoJoin
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private loadSubs(n: number): void {
|
|
|
|
for (let i = 0; i < n; i++) {
|
|
|
|
this.users.push({
|
|
|
|
subscribeTo: true,
|
|
|
|
publishTo: false,
|
|
|
|
startSession: this.autoJoin
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private loadPubs(n: number): void {
|
|
|
|
for (let i = 0; i < n; i++) {
|
|
|
|
this.users.push({
|
|
|
|
subscribeTo: false,
|
|
|
|
publishTo: true,
|
|
|
|
startSession: this.autoJoin
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private loadScenario(subsPubs: number, pubs: number, subs: number, ): void {
|
|
|
|
this.users = [];
|
|
|
|
this.loadSubsPubs(subsPubs);
|
|
|
|
this.loadPubs(pubs);
|
|
|
|
this.loadSubs(subs);
|
2017-09-30 13:48:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|