openvidu-browser: SignalEvent update to support signal REST API

pull/375/head
pabloFuente 2019-09-16 10:00:38 +02:00
parent 80cd9dacea
commit 2ed986053c
3 changed files with 36 additions and 22 deletions

View File

@ -780,18 +780,29 @@ export class Session implements EventDispatcher {
console.info('New signal: ' + JSON.stringify(msg));
this.getConnection(msg.from, "Connection '" + msg.from + "' unknow when 'onNewMessage'. Existing remote connections: "
+ JSON.stringify(Object.keys(this.remoteConnections)) + '. Existing local connection: ' + this.connection.connectionId)
const strippedType: string = !!msg.type ? msg.type.replace(/^(signal:)/, '') : undefined;
.then(connection => {
this.ee.emitEvent('signal', [new SignalEvent(this, msg.type, msg.data, connection)]);
if (msg.type !== 'signal') {
this.ee.emitEvent(msg.type, [new SignalEvent(this, msg.type, msg.data, connection)]);
}
})
.catch(openViduError => {
console.error(openViduError);
});
if (!!msg.from) {
// Signal sent by other client
this.getConnection(msg.from, "Connection '" + msg.from + "' unknow when 'onNewMessage'. Existing remote connections: "
+ JSON.stringify(Object.keys(this.remoteConnections)) + '. Existing local connection: ' + this.connection.connectionId)
.then(connection => {
this.ee.emitEvent('signal', [new SignalEvent(this, strippedType, msg.data, connection)]);
if (msg.type !== 'signal') {
this.ee.emitEvent(msg.type, [new SignalEvent(this, strippedType, msg.data, connection)]);
}
})
.catch(openViduError => {
console.error(openViduError);
});
} else {
// Signal sent by server
this.ee.emitEvent('signal', [new SignalEvent(this, strippedType, msg.data, undefined)]);
if (msg.type !== 'signal') {
this.ee.emitEvent(msg.type, [new SignalEvent(this, strippedType, msg.data, undefined)]);
}
}
}
/**

View File

@ -18,7 +18,6 @@
import { Filter } from '../../OpenVidu/Filter';
import { StreamManager } from '../../OpenVidu/StreamManager';
import { Session } from '../../OpenVidu/Session';
import { Stream } from '../../OpenVidu/Stream';
export abstract class Event {

View File

@ -28,30 +28,34 @@ import { Session } from '../../OpenVidu/Session';
export class SignalEvent extends Event {
/**
* The type of signal (can be empty).
* The type of signal. It is string `"signal"` for those signals sent with no [[SignalOptions.type]] property, and `"signal:type"` if was sent with a
* valid [[SignalOptions.type]] property.
*
* The client must be subscribed to `Session.on('signal:type', function(signalEvent) {...})` to receive this object in the callback.
* The client must be specifically subscribed to `Session.on('signal:type', function(signalEvent) {...})` to trigger that type of signal.
*
* Subscribing to `Session.on('signal', function(signalEvent) {...})` will trigger all types of signals.
* Subscribing to `Session.on('signal', function(signalEvent) {...})` will trigger all signals, no matter their type.
*/
type: string;
/**
* The message of the signal (can be emtpy)
* The message of the signal (can be empty)
*/
data: string;
data?: string;
/**
* The client that sent the signal
* The client that sent the signal. This property is undefined if the signal
* was directly generated by the application server (not by other client)
*/
from: Connection;
from?: Connection;
/**
* @hidden
*/
constructor(target: Session, type: string, data: string, from: Connection) {
super(false, target, type);
this.type = type;
constructor(target: Session, type: string, data?: string, from?: Connection) {
super(false, target, 'signal');
if (!!type) {
this.type = 'signal:' + type;
}
this.data = data;
this.from = from;
}