diff --git a/openvidu-browser/src/OpenVidu/Session.ts b/openvidu-browser/src/OpenVidu/Session.ts index 1f7507a7..4a79f35f 100644 --- a/openvidu-browser/src/OpenVidu/Session.ts +++ b/openvidu-browser/src/OpenVidu/Session.ts @@ -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)]); + } + } } /** diff --git a/openvidu-browser/src/OpenViduInternal/Events/Event.ts b/openvidu-browser/src/OpenViduInternal/Events/Event.ts index 70c344d4..10d47713 100644 --- a/openvidu-browser/src/OpenViduInternal/Events/Event.ts +++ b/openvidu-browser/src/OpenViduInternal/Events/Event.ts @@ -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 { diff --git a/openvidu-browser/src/OpenViduInternal/Events/SignalEvent.ts b/openvidu-browser/src/OpenViduInternal/Events/SignalEvent.ts index de8f469d..5e2080b6 100644 --- a/openvidu-browser/src/OpenViduInternal/Events/SignalEvent.ts +++ b/openvidu-browser/src/OpenViduInternal/Events/SignalEvent.ts @@ -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; }