@observertc/observer-js 0.30.6-beta → 0.40.0-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/ObservedCall.d.ts +6 -13
- package/lib/ObservedCall.d.ts.map +1 -1
- package/lib/ObservedCall.js +24 -104
- package/lib/ObservedClient.d.ts +16 -27
- package/lib/ObservedClient.d.ts.map +1 -1
- package/lib/ObservedClient.js +360 -523
- package/lib/ObservedInboundTrack.d.ts +3 -8
- package/lib/ObservedInboundTrack.d.ts.map +1 -1
- package/lib/ObservedInboundTrack.js +74 -154
- package/lib/ObservedOutboundTrack.d.ts +9 -8
- package/lib/ObservedOutboundTrack.d.ts.map +1 -1
- package/lib/ObservedOutboundTrack.js +76 -130
- package/lib/ObservedPeerConnection.d.ts +17 -15
- package/lib/ObservedPeerConnection.d.ts.map +1 -1
- package/lib/ObservedPeerConnection.js +64 -173
- package/lib/ObservedSfu.d.ts +5 -7
- package/lib/ObservedSfu.d.ts.map +1 -1
- package/lib/ObservedSfu.js +10 -74
- package/lib/Observer.d.ts +5 -6
- package/lib/Observer.d.ts.map +1 -1
- package/lib/Observer.js +28 -31
- package/lib/common/types.d.ts +0 -55
- package/lib/common/types.d.ts.map +1 -1
- package/lib/index.d.ts +5 -7
- package/lib/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/ObservedCall.ts +27 -87
- package/src/ObservedClient.ts +425 -582
- package/src/ObservedInboundTrack.ts +14 -65
- package/src/ObservedOutboundTrack.ts +32 -53
- package/src/ObservedPeerConnection.ts +55 -117
- package/src/ObservedSfu.ts +11 -46
- package/src/Observer.ts +11 -16
- package/src/common/types.ts +0 -69
- package/src/index.ts +5 -7
- package/lib/models/Models.d.ts +0 -642
- package/lib/models/Models.d.ts.map +0 -1
- package/lib/models/Models.js +0 -481
- package/lib/models/samples_pb.d.ts +0 -2452
- package/lib/models/samples_pb.d.ts.map +0 -1
- package/lib/models/samples_pb.js +0 -1495
- package/lib/storages/ObserverStorage.d.ts +0 -87
- package/lib/storages/ObserverStorage.d.ts.map +0 -1
- package/lib/storages/ObserverStorage.js +0 -2
- package/lib/storages/SimpleStorage.d.ts +0 -19
- package/lib/storages/SimpleStorage.d.ts.map +0 -1
- package/lib/storages/SimpleStorage.js +0 -106
- package/lib/storages/StorageProvider.d.ts +0 -16
- package/lib/storages/StorageProvider.d.ts.map +0 -1
- package/lib/storages/StorageProvider.js +0 -29
- package/src/models/Models.ts +0 -1103
- package/src/models/samples_pb.ts +0 -4061
- package/src/storages/ObserverStorage.ts +0 -99
- package/src/storages/SimpleStorage.ts +0 -120
- package/src/storages/StorageProvider.ts +0 -42
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
|
-
import { StorageProvider } from './storages/StorageProvider';
|
|
3
|
-
import * as Models from './models/Models';
|
|
4
2
|
import { ObservedPeerConnection } from './ObservedPeerConnection';
|
|
5
3
|
import { InboundAudioTrack, InboundVideoTrack } from '@observertc/sample-schemas-js';
|
|
6
4
|
import { ObservedOutboundTrack } from './ObservedOutboundTrack';
|
|
7
5
|
import { InboundAudioTrackReport, InboundVideoTrackReport } from '@observertc/report-schemas-js';
|
|
8
6
|
import { MediaKind } from './common/types';
|
|
9
|
-
import { createSingleExecutor } from './common/SingleExecutor';
|
|
10
7
|
|
|
11
|
-
export type
|
|
8
|
+
export type ObservedInboundTrackModel<K extends MediaKind> = {
|
|
12
9
|
trackId: string;
|
|
13
10
|
kind: K;
|
|
14
11
|
sfuStreamId?: string;
|
|
@@ -51,35 +48,9 @@ export declare interface ObservedInboundTrack<Kind extends MediaKind> {
|
|
|
51
48
|
}
|
|
52
49
|
|
|
53
50
|
export class ObservedInboundTrack<Kind extends MediaKind> extends EventEmitter {
|
|
54
|
-
public
|
|
55
|
-
config: ObservedInboundTrackConfig<K>,
|
|
56
|
-
peerConnection: ObservedPeerConnection,
|
|
57
|
-
storageProvider: StorageProvider,
|
|
58
|
-
) {
|
|
59
|
-
const model = new Models.InboundTrack({
|
|
60
|
-
serviceId: peerConnection.client.serviceId,
|
|
61
|
-
roomId: peerConnection.client.roomId,
|
|
62
|
-
callId: peerConnection.client.callId,
|
|
63
|
-
clientId: peerConnection.client.clientId,
|
|
64
|
-
mediaUnitId: peerConnection.client.mediaUnitId,
|
|
65
|
-
peerConnectionId: peerConnection.peerConnectionId,
|
|
66
|
-
trackId: config.trackId,
|
|
67
|
-
kind: config.kind,
|
|
68
|
-
sfuStreamId: config.sfuStreamId,
|
|
69
|
-
sfuSinkId: config.sfuSinkId,
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
const alreadyInserted = await storageProvider.inboundTrackStorage.insert(config.trackId, model);
|
|
73
|
-
|
|
74
|
-
if (alreadyInserted) throw new Error(`InboundAudioTrack with id ${config.trackId} already exists`);
|
|
75
|
-
|
|
76
|
-
return new ObservedInboundTrack<K>(model, peerConnection, storageProvider);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
public created = Date.now();
|
|
51
|
+
public readonly created = Date.now();
|
|
80
52
|
|
|
81
53
|
private readonly _stats = new Map<number, ObservedInboundTrackStats<Kind>>();
|
|
82
|
-
private readonly _execute = createSingleExecutor();
|
|
83
54
|
|
|
84
55
|
private _closed = false;
|
|
85
56
|
private _updated = Date.now();
|
|
@@ -106,52 +77,43 @@ export class ObservedInboundTrack<Kind extends MediaKind> extends EventEmitter {
|
|
|
106
77
|
public deltaReceivedSamples = 0;
|
|
107
78
|
public deltaSilentConcealedSamples = 0;
|
|
108
79
|
|
|
109
|
-
|
|
110
|
-
private readonly _model:
|
|
80
|
+
public constructor(
|
|
81
|
+
private readonly _model: ObservedInboundTrackModel<Kind>,
|
|
111
82
|
public readonly peerConnection: ObservedPeerConnection,
|
|
112
|
-
private readonly _storageProvider: StorageProvider,
|
|
113
83
|
) {
|
|
114
84
|
super();
|
|
115
85
|
}
|
|
116
86
|
|
|
117
87
|
public get serviceId() {
|
|
118
|
-
|
|
119
|
-
return this._model.serviceId!;
|
|
88
|
+
return this.peerConnection.serviceId;
|
|
120
89
|
}
|
|
121
90
|
|
|
122
91
|
public get roomId() {
|
|
123
|
-
|
|
124
|
-
return this._model.roomId!;
|
|
92
|
+
return this.peerConnection.roomId;
|
|
125
93
|
}
|
|
126
94
|
|
|
127
95
|
public get callId() {
|
|
128
|
-
|
|
129
|
-
return this._model.callId!;
|
|
96
|
+
return this.peerConnection.callId;
|
|
130
97
|
}
|
|
131
98
|
|
|
132
99
|
public get clientId() {
|
|
133
|
-
|
|
134
|
-
return this._model.clientId!;
|
|
100
|
+
return this.peerConnection.clientId;
|
|
135
101
|
}
|
|
136
102
|
|
|
137
103
|
public get mediaUnitId() {
|
|
138
|
-
|
|
139
|
-
return this._model.mediaUnitId!;
|
|
104
|
+
return this.peerConnection.mediaUnitId;
|
|
140
105
|
}
|
|
141
106
|
|
|
142
107
|
public get peerConnectionId() {
|
|
143
|
-
|
|
144
|
-
return this._model.peerConnectionId!;
|
|
108
|
+
return this.peerConnection.peerConnectionId;
|
|
145
109
|
}
|
|
146
110
|
|
|
147
111
|
public get trackId() {
|
|
148
|
-
|
|
149
|
-
return this._model.trackId!;
|
|
112
|
+
return this._model.trackId;
|
|
150
113
|
}
|
|
151
114
|
|
|
152
115
|
public get kind(): Kind {
|
|
153
|
-
|
|
154
|
-
return this._model.kind! as Kind;
|
|
116
|
+
return this._model.kind as Kind;
|
|
155
117
|
}
|
|
156
118
|
|
|
157
119
|
public get sfuStreamId() {
|
|
@@ -202,9 +164,7 @@ export class ObservedInboundTrack<Kind extends MediaKind> extends EventEmitter {
|
|
|
202
164
|
|
|
203
165
|
this._closed = true;
|
|
204
166
|
|
|
205
|
-
this.
|
|
206
|
-
.catch(() => void 0)
|
|
207
|
-
.finally(() => this.emit('close'));
|
|
167
|
+
this.emit('close');
|
|
208
168
|
}
|
|
209
169
|
|
|
210
170
|
public resetMetrics() {
|
|
@@ -220,9 +180,8 @@ export class ObservedInboundTrack<Kind extends MediaKind> extends EventEmitter {
|
|
|
220
180
|
this.fractionLoss = 0;
|
|
221
181
|
}
|
|
222
182
|
|
|
223
|
-
public
|
|
183
|
+
public update(sample: ObservedInboundTrackStatsUpdate<Kind>, timestamp: number) {
|
|
224
184
|
if (this._closed) return;
|
|
225
|
-
let executeSave = false;
|
|
226
185
|
|
|
227
186
|
const report: InboundAudioTrackReport | InboundVideoTrackReport = {
|
|
228
187
|
serviceId: this.peerConnection.client.call.serviceId,
|
|
@@ -247,12 +206,10 @@ export class ObservedInboundTrack<Kind extends MediaKind> extends EventEmitter {
|
|
|
247
206
|
|
|
248
207
|
if (!this._model.sfuStreamId && sample.sfuStreamId) {
|
|
249
208
|
this._model.sfuStreamId = sample.sfuStreamId;
|
|
250
|
-
executeSave = true;
|
|
251
209
|
}
|
|
252
210
|
|
|
253
211
|
if (!this._model.sfuSinkId && sample.sfuSinkId) {
|
|
254
212
|
this._model.sfuSinkId = sample.sfuSinkId;
|
|
255
|
-
executeSave = true;
|
|
256
213
|
}
|
|
257
214
|
|
|
258
215
|
const elapsedTimeInMs = Math.max(1, timestamp - this._updated);
|
|
@@ -318,15 +275,7 @@ export class ObservedInboundTrack<Kind extends MediaKind> extends EventEmitter {
|
|
|
318
275
|
this.deltaSilentConcealedSamples = [ ...this._stats.values() ].reduce((acc, stat) => acc + (stat.silentConcealedSamples ?? 0), 0);
|
|
319
276
|
this.fractionLoss = 0 < this.deltaReceivedPackets && 0 < this.deltaLostPackets ? (this.deltaLostPackets / (this.deltaReceivedPackets + this.deltaLostPackets)) : 0;
|
|
320
277
|
|
|
321
|
-
if (executeSave) await this._save();
|
|
322
|
-
|
|
323
278
|
this._updated = timestamp;
|
|
324
279
|
this.emit('update');
|
|
325
280
|
}
|
|
326
|
-
|
|
327
|
-
private async _save() {
|
|
328
|
-
if (this._closed) throw new Error(`OutboundTrack ${this.trackId} is closed`);
|
|
329
|
-
|
|
330
|
-
return this._storageProvider.inboundTrackStorage.set(this.trackId, this._model);
|
|
331
|
-
}
|
|
332
281
|
}
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
|
-
import { StorageProvider } from './storages/StorageProvider';
|
|
3
|
-
import * as Models from './models/Models';
|
|
4
2
|
import { ObservedPeerConnection } from './ObservedPeerConnection';
|
|
5
3
|
import { OutboundAudioTrack, OutboundVideoTrack } from '@observertc/sample-schemas-js';
|
|
6
4
|
import { ObservedInboundTrack } from './ObservedInboundTrack';
|
|
7
5
|
import { OutboundAudioTrackReport, OutboundVideoTrackReport } from '@observertc/report-schemas-js';
|
|
8
6
|
import { MediaKind } from './common/types';
|
|
9
|
-
import { createSingleExecutor } from './common/SingleExecutor';
|
|
10
7
|
|
|
11
|
-
export type
|
|
8
|
+
export type ObservedOutboundTrackModel<K extends MediaKind> = {
|
|
12
9
|
trackId: string;
|
|
13
10
|
kind: K;
|
|
14
11
|
sfuStreamId?: string;
|
|
@@ -46,29 +43,7 @@ export declare interface ObservedOutboundTrack<Kind extends MediaKind> {
|
|
|
46
43
|
}
|
|
47
44
|
|
|
48
45
|
export class ObservedOutboundTrack<Kind extends MediaKind> extends EventEmitter {
|
|
49
|
-
public
|
|
50
|
-
config: ObservedOutboundTrackConfig<K>,
|
|
51
|
-
peerConnection: ObservedPeerConnection,
|
|
52
|
-
storageProvider: StorageProvider,
|
|
53
|
-
) {
|
|
54
|
-
const model = new Models.OutboundTrack({
|
|
55
|
-
serviceId: peerConnection.client.serviceId,
|
|
56
|
-
roomId: peerConnection.client.roomId,
|
|
57
|
-
callId: peerConnection.client.callId,
|
|
58
|
-
clientId: peerConnection.client.clientId,
|
|
59
|
-
mediaUnitId: peerConnection.client.mediaUnitId,
|
|
60
|
-
peerConnectionId: peerConnection.peerConnectionId,
|
|
61
|
-
trackId: config.trackId,
|
|
62
|
-
kind: config.kind,
|
|
63
|
-
sfuStreamId: config.sfuStreamId,
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
const alreadyInserted = await storageProvider.outboundTrackStorage.insert(config.trackId, model);
|
|
67
|
-
|
|
68
|
-
if (alreadyInserted) throw new Error(`OutboundAudioTrack with id ${config.trackId} already exists`);
|
|
69
|
-
|
|
70
|
-
return new ObservedOutboundTrack<K>(model, peerConnection, storageProvider);
|
|
71
|
-
}
|
|
46
|
+
public readonly created = Date.now();
|
|
72
47
|
|
|
73
48
|
public bitrate = 0;
|
|
74
49
|
public rttInMs?: number;
|
|
@@ -84,31 +59,49 @@ export class ObservedOutboundTrack<Kind extends MediaKind> extends EventEmitter
|
|
|
84
59
|
public deltaSentFrames = 0;
|
|
85
60
|
public deltaEncodedFrames = 0;
|
|
86
61
|
|
|
87
|
-
public created = Date.now();
|
|
88
|
-
|
|
89
62
|
private readonly _stats = new Map<number, ObservedOutboundTrackStats<Kind>>();
|
|
90
|
-
private readonly _execute = createSingleExecutor();
|
|
91
63
|
|
|
92
64
|
private _closed = false;
|
|
93
65
|
private _updated = Date.now();
|
|
94
66
|
private _remoteInboundTracks = new Map<string, ObservedInboundTrack<Kind>>();
|
|
95
67
|
|
|
96
|
-
|
|
97
|
-
private readonly _model:
|
|
68
|
+
public constructor(
|
|
69
|
+
private readonly _model: ObservedOutboundTrackModel<Kind>,
|
|
98
70
|
public readonly peerConnection: ObservedPeerConnection,
|
|
99
|
-
private readonly _storageProvider: StorageProvider,
|
|
100
71
|
) {
|
|
101
72
|
super();
|
|
102
73
|
}
|
|
103
74
|
|
|
75
|
+
public get serviceId() {
|
|
76
|
+
return this.peerConnection.serviceId;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
public get roomId() {
|
|
80
|
+
return this.peerConnection.roomId;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
public get callId() {
|
|
84
|
+
return this.peerConnection.callId;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
public get clientId() {
|
|
88
|
+
return this.peerConnection.clientId;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
public get mediaUnitId() {
|
|
92
|
+
return this.peerConnection.mediaUnitId;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
public get peerConnectionId() {
|
|
96
|
+
return this.peerConnection.peerConnectionId;
|
|
97
|
+
}
|
|
98
|
+
|
|
104
99
|
public get kind(): Kind {
|
|
105
|
-
|
|
106
|
-
return this._model.kind! as Kind;
|
|
100
|
+
return this._model.kind as Kind;
|
|
107
101
|
}
|
|
108
102
|
|
|
109
103
|
public get trackId() {
|
|
110
|
-
|
|
111
|
-
return this._model.trackId!;
|
|
104
|
+
return this._model.trackId;
|
|
112
105
|
}
|
|
113
106
|
|
|
114
107
|
public get sfuStreamId() {
|
|
@@ -141,12 +134,9 @@ export class ObservedOutboundTrack<Kind extends MediaKind> extends EventEmitter
|
|
|
141
134
|
|
|
142
135
|
public close() {
|
|
143
136
|
if (this._closed) return;
|
|
144
|
-
|
|
145
137
|
this._closed = true;
|
|
146
138
|
|
|
147
|
-
this.
|
|
148
|
-
.catch(() => void 0)
|
|
149
|
-
.finally(() => this.emit('close'));
|
|
139
|
+
this.emit('close');
|
|
150
140
|
}
|
|
151
141
|
|
|
152
142
|
public resetMetrics() {
|
|
@@ -160,9 +150,8 @@ export class ObservedOutboundTrack<Kind extends MediaKind> extends EventEmitter
|
|
|
160
150
|
this.deltaEncodedFrames = 0;
|
|
161
151
|
}
|
|
162
152
|
|
|
163
|
-
public
|
|
153
|
+
public update(sample: ObservedOutboundTrackStatsUpdate<Kind>, timestamp: number): void {
|
|
164
154
|
if (this._closed) return;
|
|
165
|
-
let executeSave = false;
|
|
166
155
|
|
|
167
156
|
const report: OutboundAudioTrackReport | OutboundVideoTrackReport = {
|
|
168
157
|
serviceId: this.peerConnection.client.serviceId,
|
|
@@ -237,12 +226,8 @@ export class ObservedOutboundTrack<Kind extends MediaKind> extends EventEmitter
|
|
|
237
226
|
|
|
238
227
|
if (this.kind === 'audio') this.peerConnection.client.call.sfuStreamIdToOutboundAudioTrack.set(this._model.sfuStreamId, this as ObservedOutboundTrack<'audio'>);
|
|
239
228
|
else if (this.kind === 'video') this.peerConnection.client.call.sfuStreamIdToOutboundVideoTrack.set(this._model.sfuStreamId, this as ObservedOutboundTrack<'video'>);
|
|
240
|
-
|
|
241
|
-
executeSave = true;
|
|
242
229
|
}
|
|
243
230
|
|
|
244
|
-
if (executeSave) await this._save();
|
|
245
|
-
|
|
246
231
|
this._updated = timestamp;
|
|
247
232
|
this.emit('update');
|
|
248
233
|
}
|
|
@@ -257,10 +242,4 @@ export class ObservedOutboundTrack<Kind extends MediaKind> extends EventEmitter
|
|
|
257
242
|
|
|
258
243
|
this._remoteInboundTracks.set(track.trackId, track);
|
|
259
244
|
}
|
|
260
|
-
|
|
261
|
-
private async _save() {
|
|
262
|
-
if (this._closed) throw new Error(`OutboundTrack ${this.trackId} is closed`);
|
|
263
|
-
|
|
264
|
-
return this._storageProvider.outboundTrackStorage.set(this.trackId, this._model);
|
|
265
|
-
}
|
|
266
245
|
}
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
|
-
import * as Models from './models/Models';
|
|
3
|
-
import { StorageProvider } from './storages/StorageProvider';
|
|
4
2
|
import { PeerConnectionTransport } from '@observertc/sample-schemas-js';
|
|
5
3
|
import { ObservedClient } from './ObservedClient';
|
|
6
|
-
import { ObservedInboundTrack,
|
|
7
|
-
import { ObservedOutboundTrack,
|
|
4
|
+
import { ObservedInboundTrack, ObservedInboundTrackModel } from './ObservedInboundTrack';
|
|
5
|
+
import { ObservedOutboundTrack, ObservedOutboundTrackModel } from './ObservedOutboundTrack';
|
|
8
6
|
import { PeerConnectionTransportReport } from '@observertc/report-schemas-js';
|
|
9
|
-
import { createSingleExecutor } from './common/SingleExecutor';
|
|
10
7
|
import { ObservedICE } from './ObservedICE';
|
|
11
8
|
|
|
12
9
|
export type ObservedPeerConnectionEvents = {
|
|
@@ -18,8 +15,9 @@ export type ObservedPeerConnectionEvents = {
|
|
|
18
15
|
newoutboundvideotrack: [ObservedOutboundTrack<'video'>],
|
|
19
16
|
};
|
|
20
17
|
|
|
21
|
-
export type
|
|
18
|
+
export type ObservedPeerConnectionModel = {
|
|
22
19
|
peerConnectionId: string;
|
|
20
|
+
label?: string;
|
|
23
21
|
};
|
|
24
22
|
|
|
25
23
|
export type ObservedPeerConnectionStats = Omit<PeerConnectionTransport, 'transportId' | 'label'>;
|
|
@@ -32,27 +30,7 @@ export declare interface ObservedPeerConnection {
|
|
|
32
30
|
}
|
|
33
31
|
|
|
34
32
|
export class ObservedPeerConnection extends EventEmitter {
|
|
35
|
-
public
|
|
36
|
-
config: ObservedPeerConnectionConfig,
|
|
37
|
-
client: ObservedClient,
|
|
38
|
-
storageProvider: StorageProvider,
|
|
39
|
-
): Promise<ObservedPeerConnection> {
|
|
40
|
-
const model = new Models.PeerConnection({
|
|
41
|
-
roomId: client.roomId,
|
|
42
|
-
serviceId: client.serviceId,
|
|
43
|
-
callId: client.callId,
|
|
44
|
-
clientId: client.clientId,
|
|
45
|
-
peerConnectionId: config.peerConnectionId,
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
const alreadyInserted = await storageProvider.peerConnectionStorage.insert(config.peerConnectionId, model);
|
|
49
|
-
|
|
50
|
-
if (alreadyInserted) throw new Error(`PeerConnection with id ${config.peerConnectionId} already exists`);
|
|
51
|
-
|
|
52
|
-
return new ObservedPeerConnection(model, client, storageProvider);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
public created = Date.now();
|
|
33
|
+
public readonly created = Date.now();
|
|
56
34
|
|
|
57
35
|
public totalInboundPacketsLost = 0;
|
|
58
36
|
public totalInboundPacketsReceived = 0;
|
|
@@ -99,20 +77,42 @@ export class ObservedPeerConnection extends EventEmitter {
|
|
|
99
77
|
private readonly _inboundVideoTracks = new Map<string, ObservedInboundTrack<'video'>>();
|
|
100
78
|
private readonly _outboundAudioTracks = new Map<string, ObservedOutboundTrack<'audio'>>();
|
|
101
79
|
private readonly _outboundVideoTracks = new Map<string, ObservedOutboundTrack<'video'>>();
|
|
102
|
-
private readonly _execute = createSingleExecutor();
|
|
103
80
|
|
|
104
|
-
|
|
105
|
-
private readonly _model:
|
|
81
|
+
public constructor(
|
|
82
|
+
private readonly _model: ObservedPeerConnectionModel,
|
|
106
83
|
public readonly client: ObservedClient,
|
|
107
|
-
private readonly _storageProvider: StorageProvider,
|
|
108
84
|
) {
|
|
109
85
|
super();
|
|
110
86
|
}
|
|
111
87
|
|
|
88
|
+
public get serviceId() {
|
|
89
|
+
return this.client.serviceId;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
public get roomId() {
|
|
93
|
+
return this.client.roomId;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
public get callId() {
|
|
97
|
+
return this.client.callId;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
public get clientId() {
|
|
101
|
+
return this.client.clientId;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
public get mediaUnitId() {
|
|
105
|
+
return this.client.mediaUnitId;
|
|
106
|
+
}
|
|
107
|
+
|
|
112
108
|
public get label() {
|
|
113
109
|
return this._model.label;
|
|
114
110
|
}
|
|
115
111
|
|
|
112
|
+
public set label(value: string | undefined) {
|
|
113
|
+
this._model.label = value;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
116
|
public get usingTURN() {
|
|
117
117
|
return this.ICE.selectedRemoteCandidate?.candidateType?.toLowerCase() === 'relay';
|
|
118
118
|
}
|
|
@@ -175,9 +175,7 @@ export class ObservedPeerConnection extends EventEmitter {
|
|
|
175
175
|
Array.from(this._outboundAudioTracks.values()).forEach((track) => track.close());
|
|
176
176
|
Array.from(this._outboundVideoTracks.values()).forEach((track) => track.close());
|
|
177
177
|
|
|
178
|
-
this.
|
|
179
|
-
.catch(() => void 0)
|
|
180
|
-
.finally(() => this.emit('close'));
|
|
178
|
+
this.emit('close');
|
|
181
179
|
}
|
|
182
180
|
|
|
183
181
|
public getTrack(trackId: string): ObservedInboundTrack<'audio'> | ObservedInboundTrack<'video'> | ObservedOutboundTrack<'audio'> | ObservedOutboundTrack<'video'> | undefined {
|
|
@@ -297,14 +295,13 @@ export class ObservedPeerConnection extends EventEmitter {
|
|
|
297
295
|
this.avgRttInMs = 0 < nrOfBelongings ? sumRttInMs / nrOfBelongings : undefined;
|
|
298
296
|
}
|
|
299
297
|
|
|
300
|
-
public
|
|
298
|
+
public update(sample: PeerConnectionTransport, timestamp: number) {
|
|
301
299
|
if (this._closed) return;
|
|
302
300
|
if (sample.peerConnectionId !== this._model.peerConnectionId) throw new Error(`TransportId mismatch. PeerConnectionId: ${ this._model.peerConnectionId } TransportId: ${ sample.transportId}`);
|
|
303
301
|
|
|
304
302
|
this._sample = sample;
|
|
305
303
|
if (this._model.label !== sample.label) {
|
|
306
304
|
this._model.label = sample.label;
|
|
307
|
-
await this._save().catch(() => void 0);
|
|
308
305
|
}
|
|
309
306
|
|
|
310
307
|
const report: PeerConnectionTransportReport = {
|
|
@@ -321,138 +318,79 @@ export class ObservedPeerConnection extends EventEmitter {
|
|
|
321
318
|
|
|
322
319
|
this.reports.addPeerConnectionTransportReports(report);
|
|
323
320
|
|
|
324
|
-
this._updated =
|
|
321
|
+
this._updated = Date.now();
|
|
325
322
|
this.emit('update');
|
|
326
323
|
}
|
|
327
324
|
|
|
328
|
-
public
|
|
325
|
+
public createInboundAudioTrack(config: Omit<ObservedInboundTrackModel<'audio'>, 'kind'>): ObservedInboundTrack<'audio'> {
|
|
329
326
|
if (this._closed) throw new Error(`PeerConnection ${this.peerConnectionId} is closed`);
|
|
330
|
-
|
|
331
|
-
const result =
|
|
327
|
+
|
|
328
|
+
const result = new ObservedInboundTrack<'audio'>({
|
|
332
329
|
kind: 'audio',
|
|
333
|
-
|
|
334
|
-
}, this
|
|
335
|
-
|
|
336
|
-
const pendingTracksTimestamp = this.client.ωpendingCreatedTracksTimestamp.get(result.trackId);
|
|
330
|
+
...config,
|
|
331
|
+
}, this);
|
|
337
332
|
|
|
338
|
-
if (pendingTracksTimestamp) {
|
|
339
|
-
this.client.ωpendingCreatedTracksTimestamp.delete(result.trackId);
|
|
340
|
-
result.created = pendingTracksTimestamp;
|
|
341
|
-
}
|
|
342
|
-
|
|
343
333
|
result.on('close', () => {
|
|
344
334
|
this._inboundAudioTracks.delete(result.trackId);
|
|
345
|
-
this._model.inboundTrackIds = this._model.inboundTrackIds.filter((id) => id !== result.trackId);
|
|
346
|
-
!this._closed &&this._save().catch(() => void 0);
|
|
347
335
|
});
|
|
348
336
|
this._inboundAudioTracks.set(result.trackId, result);
|
|
349
|
-
this._model.inboundTrackIds = [ ...(new Set<string>([ ...this._model.inboundTrackIds, result.trackId ])) ];
|
|
350
|
-
await this._save();
|
|
351
337
|
|
|
352
338
|
this.emit('newinboudaudiotrack', result);
|
|
353
339
|
|
|
354
340
|
return result;
|
|
355
341
|
}
|
|
356
342
|
|
|
357
|
-
public
|
|
343
|
+
public createInboundVideoTrack(config: Omit<ObservedInboundTrackModel<'video'>, 'kind'>): ObservedInboundTrack<'video'> {
|
|
358
344
|
if (this._closed) throw new Error(`PeerConnection ${this.peerConnectionId} is closed`);
|
|
359
|
-
|
|
360
|
-
const result = await ObservedInboundTrack.create<'video'>({
|
|
361
|
-
kind: 'video',
|
|
362
|
-
trackId: config.trackId,
|
|
363
|
-
}, this, this._storageProvider);
|
|
364
345
|
|
|
365
|
-
const
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
result.created = pendingTracksTimestamp;
|
|
370
|
-
}
|
|
346
|
+
const result = new ObservedInboundTrack<'video'>({
|
|
347
|
+
kind: 'video',
|
|
348
|
+
...config,
|
|
349
|
+
}, this);
|
|
371
350
|
|
|
372
351
|
result.on('close', () => {
|
|
373
352
|
this._inboundVideoTracks.delete(result.trackId);
|
|
374
|
-
this._model.inboundTrackIds = this._model.inboundTrackIds.filter((id) => id !== result.trackId);
|
|
375
|
-
!this._closed &&this._save().catch(() => void 0);
|
|
376
353
|
});
|
|
377
354
|
this._inboundVideoTracks.set(result.trackId, result);
|
|
378
|
-
this._model.inboundTrackIds = [ ...(new Set<string>([ ...this._model.inboundTrackIds, result.trackId ])) ];
|
|
379
|
-
await this._save();
|
|
380
355
|
|
|
381
|
-
this.emit('newinboudvideotrack', result);
|
|
382
|
-
|
|
356
|
+
this.emit('newinboudvideotrack', result);
|
|
357
|
+
|
|
383
358
|
return result;
|
|
384
359
|
}
|
|
385
360
|
|
|
386
|
-
public
|
|
361
|
+
public createOutboundAudioTrack(config: Omit<ObservedOutboundTrackModel<'audio'>, 'kind'>): ObservedOutboundTrack<'audio'> {
|
|
387
362
|
if (this._closed) throw new Error(`PeerConnection ${this.peerConnectionId} is closed`);
|
|
388
363
|
|
|
389
|
-
const result =
|
|
364
|
+
const result = new ObservedOutboundTrack<'audio'>({
|
|
390
365
|
kind: 'audio',
|
|
391
|
-
|
|
392
|
-
}, this
|
|
393
|
-
|
|
394
|
-
const pendingTracksTimestamp = this.client.ωpendingCreatedTracksTimestamp.get(result.trackId);
|
|
395
|
-
|
|
396
|
-
if (pendingTracksTimestamp) {
|
|
397
|
-
this.client.ωpendingCreatedTracksTimestamp.delete(result.trackId);
|
|
398
|
-
result.created = pendingTracksTimestamp;
|
|
399
|
-
}
|
|
366
|
+
...config,
|
|
367
|
+
}, this);
|
|
400
368
|
|
|
401
369
|
result.on('close', () => {
|
|
402
370
|
this._outboundAudioTracks.delete(result.trackId);
|
|
403
|
-
this._model.outboundTrackIds = this._model.outboundTrackIds.filter((id) => id !== result.trackId);
|
|
404
|
-
|
|
405
|
-
result.sfuStreamId && this.client.call.sfuStreamIdToOutboundAudioTrack.delete(result.sfuStreamId);
|
|
406
|
-
!this._closed &&this._save().catch(() => void 0);
|
|
407
371
|
});
|
|
408
372
|
this._outboundAudioTracks.set(result.trackId, result);
|
|
409
|
-
this._model.outboundTrackIds = [ ...(new Set<string>([ ...this._model.outboundTrackIds, result.trackId ])) ];
|
|
410
|
-
|
|
411
|
-
result.sfuStreamId && this.client.call.sfuStreamIdToOutboundAudioTrack.set(result.sfuStreamId, result);
|
|
412
|
-
await this._save();
|
|
413
373
|
|
|
414
374
|
this.emit('newoutboundaudiotrack', result);
|
|
415
375
|
|
|
416
376
|
return result;
|
|
417
377
|
}
|
|
418
378
|
|
|
419
|
-
public
|
|
379
|
+
public createOutboundVideoTrack(config: Omit<ObservedOutboundTrackModel<'video'>, 'kind'>): ObservedOutboundTrack<'video'> {
|
|
420
380
|
if (this._closed) throw new Error(`PeerConnection ${this.peerConnectionId} is closed`);
|
|
421
381
|
|
|
422
|
-
const result =
|
|
382
|
+
const result = new ObservedOutboundTrack<'video'>({
|
|
423
383
|
kind: 'video',
|
|
424
|
-
|
|
425
|
-
}, this
|
|
426
|
-
|
|
427
|
-
const pendingTracksTimestamp = this.client.ωpendingCreatedTracksTimestamp.get(result.trackId);
|
|
428
|
-
|
|
429
|
-
if (pendingTracksTimestamp) {
|
|
430
|
-
this.client.ωpendingCreatedTracksTimestamp.delete(result.trackId);
|
|
431
|
-
result.created = pendingTracksTimestamp;
|
|
432
|
-
}
|
|
384
|
+
...config,
|
|
385
|
+
}, this);
|
|
433
386
|
|
|
434
387
|
result.on('close', () => {
|
|
435
388
|
this._outboundVideoTracks.delete(result.trackId);
|
|
436
|
-
result.sfuStreamId && this.client.call.sfuStreamIdToOutboundVideoTrack.set(result.sfuStreamId, result);
|
|
437
|
-
this._model.outboundTrackIds = this._model.outboundTrackIds.filter((id) => id !== result.trackId);
|
|
438
|
-
!this._closed && this._save().catch(() => void 0);
|
|
439
389
|
});
|
|
440
390
|
this._outboundVideoTracks.set(result.trackId, result);
|
|
441
|
-
result.sfuStreamId && this.client.call.sfuStreamIdToOutboundVideoTrack.set(result.sfuStreamId, result);
|
|
442
|
-
this._model.outboundTrackIds = [ ...(new Set<string>([ ...this._model.outboundTrackIds, result.trackId ])) ];
|
|
443
|
-
await this._save();
|
|
444
391
|
|
|
445
392
|
this.emit('newoutboundvideotrack', result);
|
|
446
|
-
|
|
447
|
-
return result;
|
|
448
|
-
}
|
|
449
393
|
|
|
450
|
-
|
|
451
|
-
if (this._closed) throw new Error(`PeerConnection ${this.peerConnectionId} is closed`);
|
|
452
|
-
|
|
453
|
-
return this._execute(async () => {
|
|
454
|
-
if (this._closed) throw new Error(`PeerConnection ${this.peerConnectionId} is closed`);
|
|
455
|
-
await this._storageProvider.peerConnectionStorage.set(this.peerConnectionId, this._model);
|
|
456
|
-
});
|
|
394
|
+
return result;
|
|
457
395
|
}
|
|
458
396
|
}
|