'sessionDisconnected' event emitted by Session (preventDefault() defined)

pull/20/head
pabloFuente 2017-05-22 23:02:28 +02:00
parent 3422b0f474
commit 850dab186b
3 changed files with 43 additions and 20 deletions

File diff suppressed because one or more lines are too long

View File

@ -3,7 +3,7 @@ import { Stream } from '../OpenViduInternal/Stream';
import { Connection } from "../OpenViduInternal/Connection";
import { OpenVidu } from './OpenVidu';
import { Publisher} from './Publisher';
import { Publisher } from './Publisher';
import { Subscriber } from './Subscriber';
import EventEmitter = require('wolfy87-eventemitter');
@ -24,6 +24,17 @@ export class Session {
event.stream.removeVideo();
});
// Listens to the deactivation of the default behaviour upon the disconnection of a Session
this.session.addEventListener('session-disconnected-default', () => {
let s: Stream;
for (s of this.openVidu.openVidu.getRemoteStreams()) {
s.removeVideo();
}
for (let streamId in this.connection.getStreams()) {
this.connection.getStreams()[streamId].removeVideo();
}
});
// Sets or updates the value of 'connection' property. Triggered by SessionInternal when succesful connection
this.session.addEventListener('update-connection-object', event => {
this.connection = event.connection;
@ -31,8 +42,8 @@ export class Session {
}
connect(token: string, callback: any);
connect(token:string, metadata: string, callback: any);
connect(token: string, metadata: string, callback: any);
connect(param1, param2, param3?) {
// Early configuration to deactivate automatic subscription to streams
if (typeof param2 == "string") {
@ -56,13 +67,10 @@ export class Session {
disconnect() {
this.openVidu.openVidu.close(false);
let s: Stream;
for (s of this.openVidu.openVidu.getRemoteStreams()){
s.removeVideo();
}
for (let streamId in this.connection.getStreams()) {
this.connection.getStreams()[streamId].removeVideo();
}
this.session.emitEvent('sessionDisconnected', [{
preventDefault: () => { this.session.removeEvent('session-disconnected-default'); }
}]);
this.session.emitEvent('session-disconnected-default', [{}]);
}
publish(publisher: Publisher) {
@ -135,7 +143,7 @@ export class Session {
subscribe(stream: Stream, htmlId: string, videoOptions: any): Subscriber;
subscribe(stream: Stream, htmlId: string): Subscriber;
subscribe(param1, param2, param3?): Subscriber {
// Subscription
this.session.subscribe(param1);

View File

@ -177,6 +177,10 @@ export class SessionInternal {
this.ee.off(eventName, listener);
}
removeEvent(eventName){
this.ee.removeEvent(eventName);
}
emitEvent(eventName, eventsArray) {
this.ee.emitEvent(eventName, eventsArray);
}