openvidu-angular-library: Updated tutorial

This commit is contained in:
csantosm 2020-04-15 12:29:56 +02:00
parent b002f66211
commit 82f0af38e3
2 changed files with 38 additions and 17 deletions

View File

@ -19,7 +19,9 @@
</div>
<div *ngIf="session" id="session">
<opv-session #ovSessionComponent [sessionName]="mySessionId" [user]="myUserName" [tokens]="tokens" (leaveSession)="handlerLeaveSessionEvent($event)"
(joinSession)="handlerJoinSessionEvent($event)" (error)="handlerErrorEvent($event)">
<opv-session #ovSessionComponent [sessionName]="mySessionId" [user]="myUserName" [tokens]="tokens"
(sessionCreated)="handlerSessionCreatedEvent($event)" (participantCreated)="handlerPublisherCreatedEvent($event)" (error)="handlerErrorEvent($event)">
</opv-session>
<!-- <opv-session [sessionName]="mySessionId" [user]="myUserName" [openviduServerUrl]="'https://localhost:4443'" [openviduSecret]="'MY_SECRET'"></opv-session> -->
</div>

View File

@ -2,7 +2,7 @@ import { Component, ViewChild } from '@angular/core';
import { throwError as observableThrowError } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import {OpenviduSessionComponent, StreamEvent, Session, UserModel, OpenViduLayout, OpenViduLayoutOptions} from 'openvidu-angular';
import {OpenviduSessionComponent, StreamEvent, Session, UserModel, OpenViduLayout, OvSettingsModel, OpenViduLayoutOptions, SessionDisconnectedEvent, Publisher} from 'openvidu-angular';
@Component({
selector: 'app-root',
@ -24,6 +24,8 @@ export class AppComponent {
ovLayout: OpenViduLayout;
ovLayoutOptions: OpenViduLayoutOptions;
ovSettings: OvSettingsModel = new OvSettingsModel();
@ViewChild('ovSessionComponent')
public ovSessionComponent: OpenviduSessionComponent;
@ -39,13 +41,40 @@ export class AppComponent {
});
}
handlerJoinSessionEvent(event): void {
handlerSessionCreatedEvent(session: Session): void {
// You can see the session documentation here
// https://docs.openvidu.io/en/stable/api/openvidu-browser/classes/session.html
console.log('SESSION CREATED EVENT', session);
session.on('streamCreated', (event: StreamEvent) => {
// Do something
});
session.on('streamDestroyed', (event: StreamEvent) => {
// Do something
});
session.on('sessionDisconnected', (event: SessionDisconnectedEvent) => {
this.session = false;
this.tokens = [];
});
this.myMethod();
}
handlerLeaveSessionEvent(event): void {
this.session = false;
this.tokens = [];
handlerPublisherCreatedEvent(publisher: Publisher) {
// You can see the publisher documentation here
// https://docs.openvidu.io/en/stable/api/openvidu-browser/classes/publisher.html
publisher.on('streamCreated', (e) => {
console.log('Publisher streamCreated', e);
});
}
handlerErrorEvent(event): void {
@ -53,19 +82,9 @@ export class AppComponent {
}
myMethod() {
this.ovSession = this.ovSessionComponent.getSession();
this.ovLocalUsers = this.ovSessionComponent.getLocalUsers();
this.ovLayout = this.ovSessionComponent.getOpenviduLayout();
this.ovLayoutOptions = this.ovSessionComponent.getOpenviduLayoutOptions();
this.ovSession.on('streamCreated', (event: StreamEvent) => {
// Do something
});
this.ovSession.on('streamDestroyed', (event: StreamEvent) => {
// Do something
});
}
/**