/
signal.model.ts
34 lines (29 loc) · 997 Bytes
/
signal.model.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Opentok signaling https://tokbox.com/developer/guides/signaling/js/#send_signal_to_client
import {isNullOrUndefined} from "util";
export class OTSignal {
private data: string;
private to: any; //Opentok Connection
private type: string;
private event: string
constructor(type?: string, data?: string, to?: any) {
if(type) this.type = type;
this.event = this.getSignalEvent();
if (to) this.to = to;
if (data) this.data = data;
}
getSignalEvent(): string {
return isNullOrUndefined(this.type) ? 'signal' : ('signal:' + this.type);
}
getSignal(): Object {
let signalAsHash: Object = {
data: this.data,
type: this.type,
to: this.to
};
Object.keys(signalAsHash).forEach((signalProperty) => {
if (isNullOrUndefined(signalAsHash[signalProperty]))
delete signalAsHash[signalProperty];
});
return signalAsHash;
}
}