@observertc/observer-js 0.40.2-beta → 0.40.4-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/CallSummary.d.ts +2 -9
- package/lib/CallSummary.d.ts.map +1 -1
- package/lib/ObservedCall.d.ts.map +1 -1
- package/lib/ObservedCall.js +4 -0
- package/lib/ObservedClient.d.ts +3 -0
- package/lib/ObservedClient.d.ts.map +1 -1
- package/lib/ObservedClient.js +6 -0
- package/lib/ObservedDataChannel.d.ts +1 -0
- package/lib/ObservedDataChannel.d.ts.map +1 -1
- package/lib/ObservedDataChannel.js +1 -1
- package/lib/ObservedICE.d.ts +1 -0
- package/lib/ObservedICE.d.ts.map +1 -1
- package/lib/ObservedICE.js +1 -1
- package/lib/ObservedInboundTrack.d.ts +1 -0
- package/lib/ObservedInboundTrack.d.ts.map +1 -1
- package/lib/ObservedInboundTrack.js +1 -1
- package/lib/ObservedOutboundTrack.d.ts +1 -0
- package/lib/ObservedOutboundTrack.d.ts.map +1 -1
- package/lib/ObservedOutboundTrack.js +1 -1
- package/lib/ObservedPeerConnection.d.ts +4 -0
- package/lib/ObservedPeerConnection.d.ts.map +1 -1
- package/lib/ObservedPeerConnection.js +14 -1
- package/lib/ObservedSfu.d.ts +15 -2
- package/lib/ObservedSfu.d.ts.map +1 -1
- package/lib/ObservedSfu.js +76 -0
- package/lib/ObservedSfuInboundRtpPad.d.ts +38 -0
- package/lib/ObservedSfuInboundRtpPad.d.ts.map +1 -0
- package/lib/ObservedSfuInboundRtpPad.js +67 -0
- package/lib/ObservedSfuOutboundRtpPad.d.ts +38 -0
- package/lib/ObservedSfuOutboundRtpPad.d.ts.map +1 -0
- package/lib/ObservedSfuOutboundRtpPad.js +68 -0
- package/lib/ObservedSfuSctpChannel.d.ts +38 -0
- package/lib/ObservedSfuSctpChannel.d.ts.map +1 -0
- package/lib/ObservedSfuSctpChannel.js +53 -0
- package/lib/ObservedSfuTransport.d.ts +54 -0
- package/lib/ObservedSfuTransport.d.ts.map +1 -0
- package/lib/ObservedSfuTransport.js +116 -0
- package/lib/Observer.d.ts +5 -0
- package/lib/Observer.d.ts.map +1 -1
- package/lib/Observer.js +21 -0
- package/package.json +1 -1
- package/src/CallSummary.ts +2 -10
- package/src/ObservedCall.ts +5 -0
- package/src/ObservedClient.ts +10 -1
- package/src/ObservedDataChannel.ts +2 -0
- package/src/ObservedICE.ts +3 -0
- package/src/ObservedInboundTrack.ts +2 -0
- package/src/ObservedOutboundTrack.ts +2 -0
- package/src/ObservedPeerConnection.ts +19 -0
- package/src/ObservedSfu.ts +123 -4
- package/src/ObservedSfuInboundRtpPad.ts +100 -0
- package/src/ObservedSfuOutboundRtpPad.ts +101 -0
- package/src/ObservedSfuSctpChannel.ts +97 -0
- package/src/ObservedSfuTransport.ts +179 -0
- package/src/Observer.ts +31 -1
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
import { SfuTransport } from '@observertc/sample-schemas-js';
|
|
3
|
+
import { ObservedSfu } from './ObservedSfu';
|
|
4
|
+
import { SFUTransportReport } from '@observertc/report-schemas-js';
|
|
5
|
+
import { ObservedSfuInboundRtpPad, ObservedSfuInboundRtpPadModel } from './ObservedSfuInboundRtpPad';
|
|
6
|
+
import { ObservedSfuOutboundRtpPad, ObservedSfuOutboundRtpPadModel } from './ObservedSfuOutboundRtpPad';
|
|
7
|
+
import { ObservedSfuSctpChannel, ObservedSfuSctpChannelModel } from './ObservedSfuSctpChannel';
|
|
8
|
+
|
|
9
|
+
export type ObservedSfuTransportModel= {
|
|
10
|
+
sfuTransportId: string;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type ObservedSfuTransportEvents = {
|
|
14
|
+
update: [],
|
|
15
|
+
close: [],
|
|
16
|
+
newsfuoutboundrtppad: [ObservedSfuOutboundRtpPad],
|
|
17
|
+
newsfuinboundrtppad: [ObservedSfuInboundRtpPad],
|
|
18
|
+
newsfusctpchannel: [ObservedSfuSctpChannel],
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export declare interface ObservedSfuTransport {
|
|
22
|
+
on<U extends keyof ObservedSfuTransportEvents>(event: U, listener: (...args: ObservedSfuTransportEvents[U]) => void): this;
|
|
23
|
+
off<U extends keyof ObservedSfuTransportEvents>(event: U, listener: (...args: ObservedSfuTransportEvents[U]) => void): this;
|
|
24
|
+
once<U extends keyof ObservedSfuTransportEvents>(event: U, listener: (...args: ObservedSfuTransportEvents[U]) => void): this;
|
|
25
|
+
emit<U extends keyof ObservedSfuTransportEvents>(event: U, ...args: ObservedSfuTransportEvents[U]): boolean;
|
|
26
|
+
|
|
27
|
+
update(sample: SfuTransport, timestamp: number): void;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export class ObservedSfuTransport extends EventEmitter {
|
|
31
|
+
public readonly created = Date.now();
|
|
32
|
+
|
|
33
|
+
public stats?: SfuTransport;
|
|
34
|
+
private _updated = Date.now();
|
|
35
|
+
private _closed = false;
|
|
36
|
+
private _marker?: string;
|
|
37
|
+
|
|
38
|
+
private readonly _inboundRtpPads = new Map<string, ObservedSfuInboundRtpPad>();
|
|
39
|
+
private readonly _outboundRtpPads = new Map<string, ObservedSfuOutboundRtpPad>();
|
|
40
|
+
private readonly _sctpChannels = new Map<string, ObservedSfuSctpChannel>();
|
|
41
|
+
|
|
42
|
+
public constructor(
|
|
43
|
+
private readonly _model: ObservedSfuTransportModel,
|
|
44
|
+
public readonly sfu: ObservedSfu,
|
|
45
|
+
) {
|
|
46
|
+
super();
|
|
47
|
+
this.setMaxListeners(Infinity);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public get inboundRtpPads(): ReadonlyMap<string, ObservedSfuInboundRtpPad> {
|
|
51
|
+
return this._inboundRtpPads;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public get outboundRtpPads(): ReadonlyMap<string, ObservedSfuOutboundRtpPad> {
|
|
55
|
+
return this._outboundRtpPads;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public get sctpChannels(): ReadonlyMap<string, ObservedSfuSctpChannel> {
|
|
59
|
+
return this._sctpChannels;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
public get serviceId() {
|
|
63
|
+
return this.sfu.serviceId;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
public get mediaUnitId() {
|
|
67
|
+
return this.sfu.mediaUnitId;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
public get sfuId() {
|
|
71
|
+
return this.sfu.sfuId;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
public get sfuTransportId() {
|
|
75
|
+
return this._model.sfuTransportId;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
public get reports() {
|
|
79
|
+
return this.sfu.reports;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
public get updated() {
|
|
83
|
+
return this._updated;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
public get marker() {
|
|
87
|
+
return this._marker;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
public set marker(value: string | undefined) {
|
|
91
|
+
this._marker = value;
|
|
92
|
+
this._inboundRtpPads.forEach((pad) => (pad.marker = value));
|
|
93
|
+
this._outboundRtpPads.forEach((pad) => (pad.marker = value));
|
|
94
|
+
this._sctpChannels.forEach((channel) => (channel.marker = value));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
public get closed() {
|
|
98
|
+
return this._closed;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
public close() {
|
|
102
|
+
if (this._closed) return;
|
|
103
|
+
this._closed = true;
|
|
104
|
+
|
|
105
|
+
[ ...this._inboundRtpPads.values() ].forEach((pad) => pad.close());
|
|
106
|
+
[ ...this._outboundRtpPads.values() ].forEach((pad) => pad.close());
|
|
107
|
+
[ ...this._sctpChannels.values() ].forEach((channel) => channel.close());
|
|
108
|
+
|
|
109
|
+
this.emit('close');
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
public update(sample: SfuTransport, timestamp: number) {
|
|
113
|
+
|
|
114
|
+
const report: SFUTransportReport = {
|
|
115
|
+
serviceId: this.serviceId,
|
|
116
|
+
mediaUnitId: this.mediaUnitId,
|
|
117
|
+
sfuId: this.sfuId,
|
|
118
|
+
callId: undefined, // TODO: where to get this from?
|
|
119
|
+
roomId: undefined, // TODO: where to get this from?
|
|
120
|
+
...sample,
|
|
121
|
+
timestamp,
|
|
122
|
+
marker: this.marker,
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
this.reports.addSfuTransportReport(report);
|
|
126
|
+
this.stats = sample;
|
|
127
|
+
|
|
128
|
+
this._updated = Date.now();
|
|
129
|
+
this.emit('update');
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
public createSfuOutboundRtpPad(model: ObservedSfuOutboundRtpPadModel) {
|
|
133
|
+
if (this._closed) throw new Error('Cannot create SfuOutboundRtpPad on closed SfuTransport');
|
|
134
|
+
if (this._inboundRtpPads.has(model.sfuOutboundRtpPadId)) throw new Error(`SfuOutboundRtpPad with id ${model.sfuOutboundRtpPadId} already exists`);
|
|
135
|
+
|
|
136
|
+
const result = new ObservedSfuOutboundRtpPad(model, this);
|
|
137
|
+
|
|
138
|
+
result.once('close', () => {
|
|
139
|
+
this._outboundRtpPads.delete(model.sfuOutboundRtpPadId);
|
|
140
|
+
});
|
|
141
|
+
this._outboundRtpPads.set(model.sfuOutboundRtpPadId, result);
|
|
142
|
+
|
|
143
|
+
this.emit('newsfuoutboundrtppad', result);
|
|
144
|
+
|
|
145
|
+
return result;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
public createSfuInboundRtpPad(model: ObservedSfuInboundRtpPadModel) {
|
|
149
|
+
if (this._closed) throw new Error('Cannot create SfuInboundRtpPad on closed SfuTransport');
|
|
150
|
+
if (this._inboundRtpPads.has(model.sfuInboundRtpPadId)) throw new Error(`SfuInboundRtpPad with id ${model.sfuInboundRtpPadId} already exists`);
|
|
151
|
+
|
|
152
|
+
const result = new ObservedSfuInboundRtpPad(model, this);
|
|
153
|
+
|
|
154
|
+
result.once('close', () => {
|
|
155
|
+
this._inboundRtpPads.delete(model.sfuInboundRtpPadId);
|
|
156
|
+
});
|
|
157
|
+
this._inboundRtpPads.set(model.sfuInboundRtpPadId, result);
|
|
158
|
+
|
|
159
|
+
this.emit('newsfuinboundrtppad', result);
|
|
160
|
+
|
|
161
|
+
return result;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
public createSfuSctpChannel(model: ObservedSfuSctpChannelModel) {
|
|
165
|
+
if (this._closed) throw new Error('Cannot create SfuSctpChannel on closed SfuTransport');
|
|
166
|
+
if (this._sctpChannels.has(model.sfuSctpChannelId)) throw new Error(`SfuSctpChannel with id ${model.sfuSctpChannelId} already exists`);
|
|
167
|
+
|
|
168
|
+
const result = new ObservedSfuSctpChannel(model, this);
|
|
169
|
+
|
|
170
|
+
result.once('close', () => {
|
|
171
|
+
this._sctpChannels.delete(model.sfuSctpChannelId);
|
|
172
|
+
});
|
|
173
|
+
this._sctpChannels.set(model.sfuSctpChannelId, result);
|
|
174
|
+
|
|
175
|
+
this.emit('newsfusctpchannel', result);
|
|
176
|
+
|
|
177
|
+
return result;
|
|
178
|
+
}
|
|
179
|
+
}
|
package/src/Observer.ts
CHANGED
|
@@ -5,12 +5,13 @@ import { EventEmitter } from 'events';
|
|
|
5
5
|
import { PartialBy } from './common/utils';
|
|
6
6
|
import { createCallEndedEventReport, createCallStartedEventReport } from './common/callEventReports';
|
|
7
7
|
import { ObserverSinkContext } from './common/types';
|
|
8
|
+
import { ObservedSfu, ObservedSfuModel } from './ObservedSfu';
|
|
8
9
|
|
|
9
10
|
const logger = createLogger('Observer');
|
|
10
11
|
|
|
11
12
|
export type ObserverEvents = {
|
|
12
13
|
'newcall': [ObservedCall],
|
|
13
|
-
|
|
14
|
+
'newsfu': [ObservedSfu],
|
|
14
15
|
'reports': [ObserverSinkContext],
|
|
15
16
|
'close': [],
|
|
16
17
|
}
|
|
@@ -67,6 +68,8 @@ export class Observer extends EventEmitter {
|
|
|
67
68
|
|
|
68
69
|
public readonly reports = new ReportsCollector();
|
|
69
70
|
private readonly _observedCalls = new Map<string, ObservedCall>();
|
|
71
|
+
private readonly _observedSfus = new Map<string, ObservedSfu>();
|
|
72
|
+
|
|
70
73
|
private _reportTimer?: ReturnType<typeof setTimeout>;
|
|
71
74
|
private _closed = false;
|
|
72
75
|
public constructor(
|
|
@@ -135,10 +138,37 @@ export class Observer extends EventEmitter {
|
|
|
135
138
|
return call;
|
|
136
139
|
}
|
|
137
140
|
|
|
141
|
+
public createObservedSfu<AppData extends Record<string, unknown> = Record<string, unknown>>(
|
|
142
|
+
model: ObservedSfuModel,
|
|
143
|
+
appData: AppData,
|
|
144
|
+
): ObservedSfu<AppData> {
|
|
145
|
+
if (this._closed) {
|
|
146
|
+
throw new Error('Attempted to create an sfu source on a closed observer');
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const sfu = new ObservedSfu<AppData>(model, this, appData);
|
|
150
|
+
|
|
151
|
+
if (this._closed) throw new Error('Cannot create an observed sfu on a closed observer');
|
|
152
|
+
if (this._observedSfus.has(sfu.sfuId)) throw new Error(`Observed SFU with id ${sfu.sfuId} already exists`);
|
|
153
|
+
|
|
154
|
+
sfu.once('close', () => {
|
|
155
|
+
this._observedSfus.delete(sfu.sfuId);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
this._observedSfus.set(sfu.sfuId, sfu);
|
|
159
|
+
this.emit('newsfu', sfu);
|
|
160
|
+
|
|
161
|
+
return sfu;
|
|
162
|
+
}
|
|
163
|
+
|
|
138
164
|
public get observedCalls(): ReadonlyMap<string, ObservedCall> {
|
|
139
165
|
return this._observedCalls;
|
|
140
166
|
}
|
|
141
167
|
|
|
168
|
+
public get observedSfus(): ReadonlyMap<string, ObservedSfu> {
|
|
169
|
+
return this._observedSfus;
|
|
170
|
+
}
|
|
171
|
+
|
|
142
172
|
public get closed() {
|
|
143
173
|
return this._closed;
|
|
144
174
|
}
|