openvidu-browser: RPC listeners updated to support forced operations

pull/88/merge
pabloFuente 2018-07-05 17:50:49 +02:00
parent d011c5b88b
commit cb59dbcc4d
2 changed files with 32 additions and 23 deletions

View File

@ -76,7 +76,7 @@ export class Publisher extends StreamManager {
this.properties = properties;
this.openvidu = openvidu;
this.stream.ee.on('local-stream-destroyed-by-disconnect', (reason: string) => {
this.stream.ee.on('local-stream-destroyed', (reason: string) => {
const streamEvent = new StreamEvent(true, this, 'streamDestroyed', this.stream, reason);
this.emitEvent('streamDestroyed', [streamEvent]);
streamEvent.callDefaultBehavior();

View File

@ -630,6 +630,10 @@ export class Session implements EventDispatcher {
* @hidden
*/
onParticipantUnpublished(msg): void {
if (msg.connectionId === this.connection.connectionId) {
// Your stream has been forcedly unpublished from the session
this.stopPublisherStream(msg.reason);
} else {
this.getRemoteConnection(msg.connectionId, "Remote connection '" + msg.connectionId + "' unknown when 'onParticipantUnpublished'. " +
'Existing remote connections: ' + JSON.stringify(Object.keys(this.remoteConnections)))
@ -648,6 +652,7 @@ export class Session implements EventDispatcher {
console.error(openViduError);
});
}
}
/**
* @hidden
@ -860,14 +865,7 @@ export class Session implements EventDispatcher {
this.openvidu.closeWs();
}
if (!!this.connection.stream) {
// Dispose Publisher's local stream
this.connection.stream.disposeWebRtcPeer();
if (this.connection.stream.isLocalStreamPublished) {
// Make Publisher object dispatch 'streamDestroyed' event if the Stream was published
this.connection.stream.ee.emitEvent('local-stream-destroyed-by-disconnect', [reason]);
}
}
this.stopPublisherStream(reason);
if (!this.connection.disposed) {
// Make Session object dispatch 'sessionDisconnected' event (if it is not already disposed)
@ -951,6 +949,17 @@ export class Session implements EventDispatcher {
});
}
private stopPublisherStream(reason: string) {
if (!!this.connection.stream) {
// Dispose Publisher's local stream
this.connection.stream.disposeWebRtcPeer();
if (this.connection.stream.isLocalStreamPublished) {
// Make Publisher object dispatch 'streamDestroyed' event if the Stream was published
this.connection.stream.ee.emitEvent('local-stream-destroyed', [reason]);
}
}
}
private stringClientMetadata(metadata: any): string {
if (typeof metadata !== 'string') {
return JSON.stringify(metadata);