@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.
Files changed (55) hide show
  1. package/lib/CallSummary.d.ts +2 -9
  2. package/lib/CallSummary.d.ts.map +1 -1
  3. package/lib/ObservedCall.d.ts.map +1 -1
  4. package/lib/ObservedCall.js +4 -0
  5. package/lib/ObservedClient.d.ts +3 -0
  6. package/lib/ObservedClient.d.ts.map +1 -1
  7. package/lib/ObservedClient.js +6 -0
  8. package/lib/ObservedDataChannel.d.ts +1 -0
  9. package/lib/ObservedDataChannel.d.ts.map +1 -1
  10. package/lib/ObservedDataChannel.js +1 -1
  11. package/lib/ObservedICE.d.ts +1 -0
  12. package/lib/ObservedICE.d.ts.map +1 -1
  13. package/lib/ObservedICE.js +1 -1
  14. package/lib/ObservedInboundTrack.d.ts +1 -0
  15. package/lib/ObservedInboundTrack.d.ts.map +1 -1
  16. package/lib/ObservedInboundTrack.js +1 -1
  17. package/lib/ObservedOutboundTrack.d.ts +1 -0
  18. package/lib/ObservedOutboundTrack.d.ts.map +1 -1
  19. package/lib/ObservedOutboundTrack.js +1 -1
  20. package/lib/ObservedPeerConnection.d.ts +4 -0
  21. package/lib/ObservedPeerConnection.d.ts.map +1 -1
  22. package/lib/ObservedPeerConnection.js +14 -1
  23. package/lib/ObservedSfu.d.ts +15 -2
  24. package/lib/ObservedSfu.d.ts.map +1 -1
  25. package/lib/ObservedSfu.js +76 -0
  26. package/lib/ObservedSfuInboundRtpPad.d.ts +38 -0
  27. package/lib/ObservedSfuInboundRtpPad.d.ts.map +1 -0
  28. package/lib/ObservedSfuInboundRtpPad.js +67 -0
  29. package/lib/ObservedSfuOutboundRtpPad.d.ts +38 -0
  30. package/lib/ObservedSfuOutboundRtpPad.d.ts.map +1 -0
  31. package/lib/ObservedSfuOutboundRtpPad.js +68 -0
  32. package/lib/ObservedSfuSctpChannel.d.ts +38 -0
  33. package/lib/ObservedSfuSctpChannel.d.ts.map +1 -0
  34. package/lib/ObservedSfuSctpChannel.js +53 -0
  35. package/lib/ObservedSfuTransport.d.ts +54 -0
  36. package/lib/ObservedSfuTransport.d.ts.map +1 -0
  37. package/lib/ObservedSfuTransport.js +116 -0
  38. package/lib/Observer.d.ts +5 -0
  39. package/lib/Observer.d.ts.map +1 -1
  40. package/lib/Observer.js +21 -0
  41. package/package.json +1 -1
  42. package/src/CallSummary.ts +2 -10
  43. package/src/ObservedCall.ts +5 -0
  44. package/src/ObservedClient.ts +10 -1
  45. package/src/ObservedDataChannel.ts +2 -0
  46. package/src/ObservedICE.ts +3 -0
  47. package/src/ObservedInboundTrack.ts +2 -0
  48. package/src/ObservedOutboundTrack.ts +2 -0
  49. package/src/ObservedPeerConnection.ts +19 -0
  50. package/src/ObservedSfu.ts +123 -4
  51. package/src/ObservedSfuInboundRtpPad.ts +100 -0
  52. package/src/ObservedSfuOutboundRtpPad.ts +101 -0
  53. package/src/ObservedSfuSctpChannel.ts +97 -0
  54. package/src/ObservedSfuTransport.ts +179 -0
  55. package/src/Observer.ts +31 -1
@@ -27,6 +27,8 @@ export class ObservedICE extends EventEmitter {
27
27
  return new ObservedICE(peerConnection);
28
28
  }
29
29
 
30
+ public marker?: string;
31
+
30
32
  private readonly _localCandidates = new Map<string, IceLocalCandidate>();
31
33
  private readonly _remoteCandidates = new Map<string, IceLocalCandidate>();
32
34
 
@@ -141,6 +143,7 @@ export class ObservedICE extends EventEmitter {
141
143
  timestamp,
142
144
  ...candidatePair,
143
145
  sampleSeq: -1, // deprecated
146
+ marker: this.marker,
144
147
  };
145
148
 
146
149
  this.reports.addIceCandidatePairReport(report);
@@ -58,6 +58,7 @@ export class ObservedInboundTrack<Kind extends MediaKind> extends EventEmitter {
58
58
  public bitrate = 0;
59
59
  public rttInMs?: number;
60
60
  public fractionLoss = 0;
61
+ public marker?: string;
61
62
 
62
63
  public totalLostPackets = 0;
63
64
  public totalReceivedPackets = 0;
@@ -197,6 +198,7 @@ export class ObservedInboundTrack<Kind extends MediaKind> extends EventEmitter {
197
198
  remoteUserId: this.remoteOutboundTrack?.peerConnection.client.userId,
198
199
  remoteTrackId: this.remoteOutboundTrack?.trackId,
199
200
  remotePeerConnectionId: this.remoteOutboundTrack?.peerConnection.peerConnectionId,
201
+ marker: this.marker,
200
202
  };
201
203
 
202
204
  if (this.kind === 'audio') this.reports.addInboundAudioTrackReport(report);
@@ -47,6 +47,7 @@ export class ObservedOutboundTrack<Kind extends MediaKind> extends EventEmitter
47
47
 
48
48
  public bitrate = 0;
49
49
  public rttInMs?: number;
50
+ public marker?: string;
50
51
 
51
52
  public totalLostPackets = 0;
52
53
  public totalSentPackets = 0;
@@ -162,6 +163,7 @@ export class ObservedOutboundTrack<Kind extends MediaKind> extends EventEmitter
162
163
  ...sample,
163
164
  timestamp,
164
165
  sampleSeq: -1,
166
+ marker: this.marker,
165
167
  };
166
168
 
167
169
  if (this.kind === 'audio') this.reports.addOutboundAudioTrackReport(report);
@@ -14,6 +14,7 @@ export type ObservedPeerConnectionEvents = {
14
14
  newinboudvideotrack: [ObservedInboundTrack<'video'>],
15
15
  newoutboundaudiotrack: [ObservedOutboundTrack<'audio'>],
16
16
  newoutboundvideotrack: [ObservedOutboundTrack<'video'>],
17
+ newdatachannel: [ObservedDataChannel],
17
18
  };
18
19
 
19
20
  export type ObservedPeerConnectionModel = {
@@ -72,6 +73,7 @@ export class ObservedPeerConnection extends EventEmitter {
72
73
  private _closed = false;
73
74
  private _updated = Date.now();
74
75
  private _sample?: ObservedPeerConnectionStats;
76
+ private _marker?: string;
75
77
 
76
78
  public readonly ICE = ObservedICE.create(this);
77
79
  private readonly _inboundAudioTracks = new Map<string, ObservedInboundTrack<'audio'>>();
@@ -169,6 +171,20 @@ export class ObservedPeerConnection extends EventEmitter {
169
171
  return this._updated - this.created;
170
172
  }
171
173
 
174
+ public get marker() {
175
+ return this._marker;
176
+ }
177
+
178
+ public set marker(value: string | undefined) {
179
+ this._marker = value;
180
+ this._inboundAudioTracks.forEach((track) => (track.marker = value));
181
+ this._inboundVideoTracks.forEach((track) => (track.marker = value));
182
+ this._outboundAudioTracks.forEach((track) => (track.marker = value));
183
+ this._outboundVideoTracks.forEach((track) => (track.marker = value));
184
+ this._dataChannels.forEach((channel) => (channel.marker = value));
185
+ this.ICE.marker = value;
186
+ }
187
+
172
188
  public get closed() {
173
189
  return this._closed;
174
190
  }
@@ -329,6 +345,7 @@ export class ObservedPeerConnection extends EventEmitter {
329
345
  ...sample,
330
346
  timestamp,
331
347
  sampleSeq: -1, // deprecated
348
+ marker: this.marker,
332
349
  };
333
350
 
334
351
  this.reports.addPeerConnectionTransportReports(report);
@@ -421,6 +438,8 @@ export class ObservedPeerConnection extends EventEmitter {
421
438
  });
422
439
  this._dataChannels.set(result.channelId, result);
423
440
 
441
+ this.emit('newdatachannel', result);
442
+
424
443
  return result;
425
444
  }
426
445
  }
@@ -1,9 +1,12 @@
1
1
  import { EventEmitter } from 'events';
2
2
  import { Observer } from './Observer';
3
3
  import { SfuSample } from '@observertc/sample-schemas-js';
4
+ import { ObservedSfuTransport, ObservedSfuTransportModel } from './ObservedSfuTransport';
5
+ import { SfuEventReport, SfuExtensionReport } from '@observertc/report-schemas-js';
4
6
 
5
7
  export type ObservedSfuModel= {
6
8
  serviceId: string;
9
+ mediaUnitId: string;
7
10
  sfuId: string;
8
11
  joined?: number;
9
12
  };
@@ -11,13 +14,17 @@ export type ObservedSfuModel= {
11
14
  export type ObservedSfuEvents = {
12
15
  update: [],
13
16
  close: [],
17
+ newtransport: [ObservedSfuTransport],
14
18
  };
15
19
 
16
- export declare interface ObservedSfu {
20
+ export declare interface ObservedSfu<AppData extends Record<string, unknown> = Record<string, unknown>> {
17
21
  on<U extends keyof ObservedSfuEvents>(event: U, listener: (...args: ObservedSfuEvents[U]) => void): this;
18
22
  off<U extends keyof ObservedSfuEvents>(event: U, listener: (...args: ObservedSfuEvents[U]) => void): this;
19
23
  once<U extends keyof ObservedSfuEvents>(event: U, listener: (...args: ObservedSfuEvents[U]) => void): this;
20
24
  emit<U extends keyof ObservedSfuEvents>(event: U, ...args: ObservedSfuEvents[U]): boolean;
25
+
26
+ readonly appData: AppData;
27
+ update(sample: SfuSample): void;
21
28
  }
22
29
 
23
30
  export class ObservedSfu<AppData extends Record<string, unknown> = Record<string, unknown>> extends EventEmitter {
@@ -25,7 +32,12 @@ export class ObservedSfu<AppData extends Record<string, unknown> = Record<string
25
32
 
26
33
  private _updated = Date.now();
27
34
  private _closed = false;
28
-
35
+ private _marker?: string;
36
+ private _timeZoneOffsetInHours?: number;
37
+ private _left?: number;
38
+
39
+ private readonly _transports = new Map<string, ObservedSfuTransport>();
40
+
29
41
  public constructor(
30
42
  private readonly _model: ObservedSfuModel,
31
43
  public readonly observer: Observer,
@@ -35,11 +47,23 @@ export class ObservedSfu<AppData extends Record<string, unknown> = Record<string
35
47
  this.setMaxListeners(Infinity);
36
48
  }
37
49
 
50
+ public get marker() {
51
+ return this._marker;
52
+ }
53
+
54
+ public get reports() {
55
+ return this.observer.reports;
56
+ }
57
+
38
58
  public get serviceId() {
39
59
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
40
60
  return this._model.serviceId!;
41
61
  }
42
62
 
63
+ public get mediaUnitId() {
64
+ return this._model.mediaUnitId;
65
+ }
66
+
43
67
  public get sfuId() {
44
68
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
45
69
  return this._model.sfuId!;
@@ -50,6 +74,10 @@ export class ObservedSfu<AppData extends Record<string, unknown> = Record<string
50
74
  return Number(this._model.joined!);
51
75
  }
52
76
 
77
+ public get transports(): ReadonlyMap<string, ObservedSfuTransport> {
78
+ return this._transports;
79
+ }
80
+
53
81
  public get updated() {
54
82
  return this._updated;
55
83
  }
@@ -61,14 +89,105 @@ export class ObservedSfu<AppData extends Record<string, unknown> = Record<string
61
89
  public close() {
62
90
  if (this._closed) return;
63
91
  this._closed = true;
92
+
93
+ [ ...this._transports.values() ].forEach((transport) => transport.close());
94
+
64
95
  this.emit('close');
65
96
  }
66
97
 
67
98
  public update(sample: SfuSample) {
68
99
  if (this._closed) throw new Error(`Sfu ${this.sfuId} is closed`);
69
100
  if (sample.sfuId !== this.sfuId) throw new Error(`Sfu ${this.sfuId} is not the same as sample.sfuId`);
70
-
101
+
102
+ if (!this._timeZoneOffsetInHours && sample.timeZoneOffsetInHours) {
103
+ this._timeZoneOffsetInHours = sample.timeZoneOffsetInHours;
104
+ }
105
+
106
+ for (const customSfuEvents of sample.customSfuEvents ?? []) {
107
+ const report: SfuEventReport = {
108
+ serviceId: this.serviceId,
109
+ mediaUnitId: this.mediaUnitId,
110
+ sfuId: this.sfuId,
111
+ ...customSfuEvents,
112
+ timestamp: sample.timestamp,
113
+ marker: this._marker,
114
+ };
115
+
116
+ this.reports.addSfuEventReport(report);
117
+ }
118
+
119
+ for (const extensionStats of sample.extensionStats ?? []) {
120
+
121
+ const report: SfuExtensionReport = {
122
+ serviceId: this.serviceId,
123
+ mediaUnitId: this.mediaUnitId,
124
+ sfuId: this.sfuId,
125
+ extensionType: extensionStats.type,
126
+ payload: extensionStats.payload,
127
+ timestamp: sample.timestamp,
128
+ };
129
+
130
+ this.reports.addSfuExtensionReport(report);
131
+ }
132
+
133
+ for (const transport of sample.transports ?? []) {
134
+ const observedSfuTransport = this._transports.get(transport.transportId) ?? this._createTransport({
135
+ sfuTransportId: transport.transportId,
136
+ });
137
+
138
+ observedSfuTransport.update(transport, sample.timestamp);
139
+ }
140
+
141
+ for (const inboundRtpPad of sample.inboundRtpPads ?? []) {
142
+ const transport = this._transports.get(inboundRtpPad.transportId) ?? this._createTransport({
143
+ sfuTransportId: inboundRtpPad.transportId,
144
+ });
145
+
146
+ const observedSfuInboundRtpPad = transport.inboundRtpPads.get(inboundRtpPad.padId) ?? transport.createSfuInboundRtpPad({
147
+ sfuInboundRtpPadId: inboundRtpPad.padId,
148
+ });
149
+
150
+ observedSfuInboundRtpPad.update(inboundRtpPad, sample.timestamp);
151
+ }
152
+
153
+ for (const outboundRtpPad of sample.outboundRtpPads ?? []) {
154
+ const transport = this._transports.get(outboundRtpPad.transportId) ?? this._createTransport({
155
+ sfuTransportId: outboundRtpPad.transportId,
156
+ });
157
+
158
+ const observedSfuOutboundRtpPad = transport.outboundRtpPads.get(outboundRtpPad.padId) ?? transport.createSfuOutboundRtpPad({
159
+ sfuOutboundRtpPadId: outboundRtpPad.padId,
160
+ });
161
+
162
+ observedSfuOutboundRtpPad.update(outboundRtpPad, sample.timestamp);
163
+ }
164
+
165
+ for (const sctpChannel of sample.sctpChannels ?? []) {
166
+ const transport = this._transports.get(sctpChannel.transportId) ?? this._createTransport({
167
+ sfuTransportId: sctpChannel.transportId,
168
+ });
169
+
170
+ const observedSfuSctpChannel = transport.sctpChannels.get(sctpChannel.channelId) ?? transport.createSfuSctpChannel({
171
+ sfuSctpChannelId: sctpChannel.channelId,
172
+ });
173
+
174
+ observedSfuSctpChannel.update(sctpChannel, sample.timestamp);
175
+ }
176
+
71
177
  this._updated = Date.now();
72
178
  this.emit('update');
73
179
  }
74
- }
180
+
181
+ private _createTransport(model: ObservedSfuTransportModel) {
182
+ const result = new ObservedSfuTransport(model, this);
183
+
184
+ result.once('close', () => {
185
+ this._transports.delete(model.sfuTransportId);
186
+ });
187
+ this._transports.set(model.sfuTransportId, result);
188
+
189
+ this.emit('newtransport', result);
190
+
191
+ return result;
192
+ }
193
+ }
@@ -0,0 +1,100 @@
1
+ import { EventEmitter } from 'events';
2
+ import { SfuInboundRtpPad } from '@observertc/sample-schemas-js';
3
+ import { ObservedSfuTransport } from './ObservedSfuTransport';
4
+ import { SfuInboundRtpPadReport } from '@observertc/report-schemas-js';
5
+
6
+ export type ObservedSfuInboundRtpPadModel= {
7
+ sfuInboundRtpPadId: string;
8
+ };
9
+
10
+ export type ObservedSfuInboundRtpPadEvents = {
11
+ update: [],
12
+ close: [],
13
+ };
14
+
15
+ export declare interface ObservedSfuInboundRtpPad {
16
+ on<U extends keyof ObservedSfuInboundRtpPadEvents>(event: U, listener: (...args: ObservedSfuInboundRtpPadEvents[U]) => void): this;
17
+ off<U extends keyof ObservedSfuInboundRtpPadEvents>(event: U, listener: (...args: ObservedSfuInboundRtpPadEvents[U]) => void): this;
18
+ once<U extends keyof ObservedSfuInboundRtpPadEvents>(event: U, listener: (...args: ObservedSfuInboundRtpPadEvents[U]) => void): this;
19
+ emit<U extends keyof ObservedSfuInboundRtpPadEvents>(event: U, ...args: ObservedSfuInboundRtpPadEvents[U]): boolean;
20
+
21
+ update(sample: SfuInboundRtpPad, timestamp: number): void;
22
+ }
23
+
24
+ export class ObservedSfuInboundRtpPad extends EventEmitter {
25
+ public readonly created = Date.now();
26
+
27
+ public stats?: SfuInboundRtpPad;
28
+ public marker?: string;
29
+ private _updated = Date.now();
30
+ private _closed = false;
31
+
32
+ public constructor(
33
+ private readonly _model: ObservedSfuInboundRtpPadModel,
34
+ public readonly transport: ObservedSfuTransport,
35
+ ) {
36
+ super();
37
+ this.setMaxListeners(Infinity);
38
+ }
39
+
40
+ public get reports() {
41
+ return this.transport.reports;
42
+ }
43
+
44
+ public get serviceId() {
45
+ return this.transport.serviceId;
46
+ }
47
+
48
+ public get mediaUnitId() {
49
+ return this.transport.mediaUnitId;
50
+ }
51
+
52
+ public get sfuId() {
53
+ return this.transport.sfuId;
54
+ }
55
+
56
+ public get sfuTransportId() {
57
+ return this.transport.sfuTransportId;
58
+ }
59
+
60
+ public get sfuRtpPadId() {
61
+ return this._model.sfuInboundRtpPadId;
62
+ }
63
+
64
+ public get updated() {
65
+ return this._updated;
66
+ }
67
+
68
+ public get closed() {
69
+ return this._closed;
70
+ }
71
+
72
+ public close() {
73
+ if (this._closed) return;
74
+ this._closed = true;
75
+ this.emit('close');
76
+ }
77
+
78
+ public update(sample: SfuInboundRtpPad, timestamp: number) {
79
+
80
+ const { streamId: sfuStreamId, padId: rtpPadId, ...reportData } = sample;
81
+
82
+ const report: SfuInboundRtpPadReport = {
83
+ serviceId: this.serviceId,
84
+ mediaUnitId: this.mediaUnitId,
85
+ sfuId: this.sfuId,
86
+ callId: undefined, // TODO: where to get this from?
87
+ sfuStreamId,
88
+ rtpPadId,
89
+ ...reportData,
90
+ timestamp,
91
+ marker: this.marker,
92
+ };
93
+
94
+ this.reports.addSfuInboundRtpPadReport(report);
95
+ this.stats = sample;
96
+
97
+ this._updated = Date.now();
98
+ this.emit('update');
99
+ }
100
+ }
@@ -0,0 +1,101 @@
1
+ import { EventEmitter } from 'events';
2
+ import { SfuOutboundRtpPad } from '@observertc/sample-schemas-js';
3
+ import { SfuOutboundRtpPadReport } from '@observertc/report-schemas-js';
4
+ import { ObservedSfuTransport } from './ObservedSfuTransport';
5
+
6
+ export type ObservedSfuOutboundRtpPadModel= {
7
+ sfuOutboundRtpPadId: string;
8
+ };
9
+
10
+ export type ObservedSfuOutboundRtpPadEvents = {
11
+ update: [],
12
+ close: [],
13
+ };
14
+
15
+ export declare interface ObservedSfuOutboundRtpPad {
16
+ on<U extends keyof ObservedSfuOutboundRtpPadEvents>(event: U, listener: (...args: ObservedSfuOutboundRtpPadEvents[U]) => void): this;
17
+ off<U extends keyof ObservedSfuOutboundRtpPadEvents>(event: U, listener: (...args: ObservedSfuOutboundRtpPadEvents[U]) => void): this;
18
+ once<U extends keyof ObservedSfuOutboundRtpPadEvents>(event: U, listener: (...args: ObservedSfuOutboundRtpPadEvents[U]) => void): this;
19
+ emit<U extends keyof ObservedSfuOutboundRtpPadEvents>(event: U, ...args: ObservedSfuOutboundRtpPadEvents[U]): boolean;
20
+
21
+ update(sample: SfuOutboundRtpPad, timestamp: number): void;
22
+ }
23
+
24
+ export class ObservedSfuOutboundRtpPad extends EventEmitter {
25
+ public readonly created = Date.now();
26
+
27
+ public stats?: SfuOutboundRtpPad;
28
+ public marker?: string;
29
+ private _updated = Date.now();
30
+ private _closed = false;
31
+
32
+ public constructor(
33
+ private readonly _model: ObservedSfuOutboundRtpPadModel,
34
+ public readonly transport: ObservedSfuTransport,
35
+ ) {
36
+ super();
37
+ this.setMaxListeners(Infinity);
38
+ }
39
+
40
+ public get reports() {
41
+ return this.transport.reports;
42
+ }
43
+
44
+ public get serviceId() {
45
+ return this.transport.serviceId;
46
+ }
47
+
48
+ public get mediaUnitId() {
49
+ return this.transport.mediaUnitId;
50
+ }
51
+
52
+ public get sfuId() {
53
+ return this.transport.sfuId;
54
+ }
55
+
56
+ public get sfuTransportId() {
57
+ return this.transport.sfuTransportId;
58
+ }
59
+
60
+ public get sfuRtpPadId() {
61
+ return this._model.sfuOutboundRtpPadId;
62
+ }
63
+
64
+ public get updated() {
65
+ return this._updated;
66
+ }
67
+
68
+ public get closed() {
69
+ return this._closed;
70
+ }
71
+
72
+ public close() {
73
+ if (this._closed) return;
74
+ this._closed = true;
75
+ this.emit('close');
76
+ }
77
+
78
+ public update(sample: SfuOutboundRtpPad, timestamp: number) {
79
+
80
+ const { streamId: sfuStreamId, padId: rtpPadId, sinkId: sfuSinkId, ...reportData } = sample;
81
+
82
+ const report: SfuOutboundRtpPadReport = {
83
+ serviceId: this.serviceId,
84
+ mediaUnitId: this.mediaUnitId,
85
+ sfuId: this.sfuId,
86
+ callId: undefined, // TODO: where to get this from?
87
+ sfuStreamId,
88
+ sfuSinkId,
89
+ rtpPadId,
90
+ ...reportData,
91
+ timestamp,
92
+ marker: this.marker,
93
+ };
94
+
95
+ this.reports.addSfuOutboundRtpPadReport(report);
96
+ this.stats = sample;
97
+
98
+ this._updated = Date.now();
99
+ this.emit('update');
100
+ }
101
+ }
@@ -0,0 +1,97 @@
1
+ import { EventEmitter } from 'events';
2
+ import { SfuSctpChannel } from '@observertc/sample-schemas-js';
3
+ import { ObservedSfuTransport } from './ObservedSfuTransport';
4
+ import { SfuSctpStreamReport } from '@observertc/report-schemas-js';
5
+
6
+ export type ObservedSfuSctpChannelModel= {
7
+ sfuSctpChannelId: string;
8
+ };
9
+
10
+ export type ObservedSfuSctpChannelEvents = {
11
+ update: [],
12
+ close: [],
13
+ };
14
+
15
+ export declare interface ObservedSfuSctpChannel {
16
+ on<U extends keyof ObservedSfuSctpChannelEvents>(event: U, listener: (...args: ObservedSfuSctpChannelEvents[U]) => void): this;
17
+ off<U extends keyof ObservedSfuSctpChannelEvents>(event: U, listener: (...args: ObservedSfuSctpChannelEvents[U]) => void): this;
18
+ once<U extends keyof ObservedSfuSctpChannelEvents>(event: U, listener: (...args: ObservedSfuSctpChannelEvents[U]) => void): this;
19
+ emit<U extends keyof ObservedSfuSctpChannelEvents>(event: U, ...args: ObservedSfuSctpChannelEvents[U]): boolean;
20
+
21
+ update(sample: SfuSctpChannel, timestamp: number): void;
22
+ }
23
+
24
+ export class ObservedSfuSctpChannel extends EventEmitter {
25
+ public readonly created = Date.now();
26
+
27
+ public stats?: SfuSctpChannel;
28
+ public marker?: string;
29
+ private _updated = Date.now();
30
+ private _closed = false;
31
+
32
+ public constructor(
33
+ private readonly _model: ObservedSfuSctpChannelModel,
34
+ public readonly transport: ObservedSfuTransport,
35
+ ) {
36
+ super();
37
+ this.setMaxListeners(Infinity);
38
+ }
39
+
40
+ public get serviceId() {
41
+ return this.transport.serviceId;
42
+ }
43
+
44
+ public get sfuId() {
45
+ return this.transport.sfuId;
46
+ }
47
+
48
+ public get mediaUnitId() {
49
+ return this.transport.mediaUnitId;
50
+ }
51
+
52
+ public get sfuTransportId() {
53
+ return this.transport.sfuTransportId;
54
+ }
55
+
56
+ public get sfuSctpChannelId() {
57
+ return this._model.sfuSctpChannelId;
58
+ }
59
+
60
+ public get reports() {
61
+ return this.transport.reports;
62
+ }
63
+
64
+ public get updated() {
65
+ return this._updated;
66
+ }
67
+
68
+ public get closed() {
69
+ return this._closed;
70
+ }
71
+
72
+ public close() {
73
+ if (this._closed) return;
74
+ this._closed = true;
75
+ this.emit('close');
76
+ }
77
+
78
+ public update(sample: SfuSctpChannel, timestamp: number) {
79
+
80
+ const report: SfuSctpStreamReport = {
81
+ serviceId: this.serviceId,
82
+ mediaUnitId: this.mediaUnitId,
83
+ sfuId: this.sfuId,
84
+ callId: undefined, // TODO: where to get this from?
85
+ roomId: undefined, // TODO: where to get this from?
86
+ ...sample,
87
+ timestamp,
88
+ marker: this.marker,
89
+ };
90
+
91
+ this.reports.addSfuTransportReport(report);
92
+ this.stats = sample;
93
+
94
+ this._updated = Date.now();
95
+ this.emit('update');
96
+ }
97
+ }