openvidu/openvidu-testapp/src/app/components/test-sessions/test-sessions.component.ts

117 lines
2.9 KiB
TypeScript
Raw Normal View History

import { Component, OnInit, OnDestroy } from '@angular/core';
2018-06-04 14:27:37 +02:00
import { Subscription } from 'rxjs';
import { OpenviduParamsService } from '../../services/openvidu-params.service';
import { TestFeedService } from '../../services/test-feed.service';
import { SessionConf } from '../openvidu-instance/openvidu-instance.component';
var stringify = require('json-stringify-safe');
@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;
eventsInfoSubscription: Subscription;
// OpenViduInstance collection
users: SessionConf[] = [];
numberSubs = 3;
autoJoin = false;
constructor(private openviduParamsService: OpenviduParamsService, private testFeedService: TestFeedService) { }
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;
});
this.eventsInfoSubscription = this.testFeedService.newLastEvent$.subscribe(
newEvent => {
(window as any).myEvents += ('<br>' + this.stringifyEventNoCircularDependencies(newEvent));
});
}
ngOnDestroy() {
this.paramsSubscription.unsubscribe();
2018-06-15 14:45:47 +02:00
this.eventsInfoSubscription.unsubscribe();
}
2018-06-04 14:27:37 +02:00
addUser(): void {
this.users.push({
subscribeTo: true,
publishTo: true,
startSession: false
});
}
2018-06-04 14:27:37 +02:00
removeUser(): void {
this.users.pop();
}
2018-06-04 14:27:37 +02:00
removeAllUsers(): void {
this.users = [];
}
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
});
}
}
2018-06-15 14:45:47 +02:00
loadScenario(subsPubs: number, pubs: number, subs: number): void {
this.users = [];
this.loadSubsPubs(subsPubs);
this.loadPubs(pubs);
this.loadSubs(subs);
}
stringifyEventNoCircularDependencies(event: Event): string {
return stringify(event, (key, value) => {
// Remove unnecessary properties
if (key == 'ee' || key == 'openvidu' || key == 'userHandlerArrowHandler' || key == 'handlers') {
return
} else {
return value;
}
});
}
}