mirror of https://github.com/OpenVidu/openvidu.git
openvidu-browser: SignalEvent update to support signal REST API
parent
80cd9dacea
commit
2ed986053c
|
@ -780,18 +780,29 @@ export class Session implements EventDispatcher {
|
||||||
|
|
||||||
console.info('New signal: ' + JSON.stringify(msg));
|
console.info('New signal: ' + JSON.stringify(msg));
|
||||||
|
|
||||||
this.getConnection(msg.from, "Connection '" + msg.from + "' unknow when 'onNewMessage'. Existing remote connections: "
|
const strippedType: string = !!msg.type ? msg.type.replace(/^(signal:)/, '') : undefined;
|
||||||
+ JSON.stringify(Object.keys(this.remoteConnections)) + '. Existing local connection: ' + this.connection.connectionId)
|
|
||||||
|
|
||||||
.then(connection => {
|
if (!!msg.from) {
|
||||||
this.ee.emitEvent('signal', [new SignalEvent(this, msg.type, msg.data, connection)]);
|
// Signal sent by other client
|
||||||
if (msg.type !== 'signal') {
|
this.getConnection(msg.from, "Connection '" + msg.from + "' unknow when 'onNewMessage'. Existing remote connections: "
|
||||||
this.ee.emitEvent(msg.type, [new SignalEvent(this, msg.type, msg.data, connection)]);
|
+ JSON.stringify(Object.keys(this.remoteConnections)) + '. Existing local connection: ' + this.connection.connectionId)
|
||||||
}
|
|
||||||
})
|
.then(connection => {
|
||||||
.catch(openViduError => {
|
this.ee.emitEvent('signal', [new SignalEvent(this, strippedType, msg.data, connection)]);
|
||||||
console.error(openViduError);
|
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)]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
import { Filter } from '../../OpenVidu/Filter';
|
import { Filter } from '../../OpenVidu/Filter';
|
||||||
import { StreamManager } from '../../OpenVidu/StreamManager';
|
import { StreamManager } from '../../OpenVidu/StreamManager';
|
||||||
import { Session } from '../../OpenVidu/Session';
|
import { Session } from '../../OpenVidu/Session';
|
||||||
import { Stream } from '../../OpenVidu/Stream';
|
|
||||||
|
|
||||||
export abstract class Event {
|
export abstract class Event {
|
||||||
|
|
||||||
|
|
|
@ -28,30 +28,34 @@ import { Session } from '../../OpenVidu/Session';
|
||||||
export class SignalEvent extends Event {
|
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;
|
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
|
* @hidden
|
||||||
*/
|
*/
|
||||||
constructor(target: Session, type: string, data: string, from: Connection) {
|
constructor(target: Session, type: string, data?: string, from?: Connection) {
|
||||||
super(false, target, type);
|
super(false, target, 'signal');
|
||||||
this.type = type;
|
if (!!type) {
|
||||||
|
this.type = 'signal:' + type;
|
||||||
|
}
|
||||||
this.data = data;
|
this.data = data;
|
||||||
this.from = from;
|
this.from = from;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue