@observertc/observer-js 0.30.6-beta → 0.40.1-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 -12
- package/lib/ObservedCall.d.ts.map +1 -1
- package/lib/ObservedCall.js +24 -104
- package/lib/ObservedClient.d.ts +16 -32
- package/lib/ObservedClient.d.ts.map +1 -1
- package/lib/ObservedClient.js +381 -521
- package/lib/ObservedDataChannel.d.ts +68 -0
- package/lib/ObservedDataChannel.d.ts.map +1 -0
- package/lib/ObservedDataChannel.js +110 -0
- package/lib/ObservedInboundTrack.d.ts +3 -9
- package/lib/ObservedInboundTrack.d.ts.map +1 -1
- package/lib/ObservedInboundTrack.js +75 -157
- package/lib/ObservedOutboundTrack.d.ts +9 -9
- package/lib/ObservedOutboundTrack.d.ts.map +1 -1
- package/lib/ObservedOutboundTrack.js +77 -133
- package/lib/ObservedPeerConnection.d.ts +21 -15
- package/lib/ObservedPeerConnection.d.ts.map +1 -1
- package/lib/ObservedPeerConnection.js +85 -171
- 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 +451 -586
- package/src/ObservedDataChannel.ts +186 -0
- package/src/ObservedInboundTrack.ts +18 -72
- package/src/ObservedOutboundTrack.ts +36 -60
- package/src/ObservedPeerConnection.ts +79 -112
- 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,65 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
3
|
exports.ObservedPeerConnection = void 0;
|
|
36
4
|
const events_1 = require("events");
|
|
37
|
-
const Models = __importStar(require("./models/Models"));
|
|
38
5
|
const ObservedInboundTrack_1 = require("./ObservedInboundTrack");
|
|
39
6
|
const ObservedOutboundTrack_1 = require("./ObservedOutboundTrack");
|
|
40
|
-
const SingleExecutor_1 = require("./common/SingleExecutor");
|
|
41
7
|
const ObservedICE_1 = require("./ObservedICE");
|
|
8
|
+
const ObservedDataChannel_1 = require("./ObservedDataChannel");
|
|
42
9
|
class ObservedPeerConnection extends events_1.EventEmitter {
|
|
43
|
-
|
|
44
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
-
const model = new Models.PeerConnection({
|
|
46
|
-
roomId: client.roomId,
|
|
47
|
-
serviceId: client.serviceId,
|
|
48
|
-
callId: client.callId,
|
|
49
|
-
clientId: client.clientId,
|
|
50
|
-
peerConnectionId: config.peerConnectionId,
|
|
51
|
-
});
|
|
52
|
-
const alreadyInserted = yield storageProvider.peerConnectionStorage.insert(config.peerConnectionId, model);
|
|
53
|
-
if (alreadyInserted)
|
|
54
|
-
throw new Error(`PeerConnection with id ${config.peerConnectionId} already exists`);
|
|
55
|
-
return new ObservedPeerConnection(model, client, storageProvider);
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
constructor(_model, client, _storageProvider) {
|
|
10
|
+
constructor(_model, client) {
|
|
59
11
|
super();
|
|
60
12
|
this._model = _model;
|
|
61
13
|
this.client = client;
|
|
62
|
-
this._storageProvider = _storageProvider;
|
|
63
14
|
this.created = Date.now();
|
|
64
15
|
this.totalInboundPacketsLost = 0;
|
|
65
16
|
this.totalInboundPacketsReceived = 0;
|
|
@@ -98,11 +49,29 @@ class ObservedPeerConnection extends events_1.EventEmitter {
|
|
|
98
49
|
this._inboundVideoTracks = new Map();
|
|
99
50
|
this._outboundAudioTracks = new Map();
|
|
100
51
|
this._outboundVideoTracks = new Map();
|
|
101
|
-
this.
|
|
52
|
+
this._dataChannels = new Map();
|
|
53
|
+
}
|
|
54
|
+
get serviceId() {
|
|
55
|
+
return this.client.serviceId;
|
|
56
|
+
}
|
|
57
|
+
get roomId() {
|
|
58
|
+
return this.client.roomId;
|
|
59
|
+
}
|
|
60
|
+
get callId() {
|
|
61
|
+
return this.client.callId;
|
|
62
|
+
}
|
|
63
|
+
get clientId() {
|
|
64
|
+
return this.client.clientId;
|
|
65
|
+
}
|
|
66
|
+
get mediaUnitId() {
|
|
67
|
+
return this.client.mediaUnitId;
|
|
102
68
|
}
|
|
103
69
|
get label() {
|
|
104
70
|
return this._model.label;
|
|
105
71
|
}
|
|
72
|
+
set label(value) {
|
|
73
|
+
this._model.label = value;
|
|
74
|
+
}
|
|
106
75
|
get usingTURN() {
|
|
107
76
|
var _a, _b;
|
|
108
77
|
return ((_b = (_a = this.ICE.selectedRemoteCandidate) === null || _a === void 0 ? void 0 : _a.candidateType) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === 'relay';
|
|
@@ -140,6 +109,9 @@ class ObservedPeerConnection extends events_1.EventEmitter {
|
|
|
140
109
|
get outboundVideoTracks() {
|
|
141
110
|
return this._outboundVideoTracks;
|
|
142
111
|
}
|
|
112
|
+
get dataChannels() {
|
|
113
|
+
return this._dataChannels;
|
|
114
|
+
}
|
|
143
115
|
get uptimeInMs() {
|
|
144
116
|
return this._updated - this.created;
|
|
145
117
|
}
|
|
@@ -154,9 +126,7 @@ class ObservedPeerConnection extends events_1.EventEmitter {
|
|
|
154
126
|
Array.from(this._inboundVideoTracks.values()).forEach((track) => track.close());
|
|
155
127
|
Array.from(this._outboundAudioTracks.values()).forEach((track) => track.close());
|
|
156
128
|
Array.from(this._outboundVideoTracks.values()).forEach((track) => track.close());
|
|
157
|
-
this.
|
|
158
|
-
.catch(() => void 0)
|
|
159
|
-
.finally(() => this.emit('close'));
|
|
129
|
+
this.emit('close');
|
|
160
130
|
}
|
|
161
131
|
getTrack(trackId) {
|
|
162
132
|
var _a, _b, _c;
|
|
@@ -245,6 +215,12 @@ class ObservedPeerConnection extends events_1.EventEmitter {
|
|
|
245
215
|
this.totalSentVideoPackets += track.totalSentPackets;
|
|
246
216
|
sumRttInMs = ((_a = track.rttInMs) !== null && _a !== void 0 ? _a : 0);
|
|
247
217
|
});
|
|
218
|
+
this._dataChannels.forEach((channel) => {
|
|
219
|
+
this.deltaDataChannelBytesSent += channel.deltaBytesSent;
|
|
220
|
+
this.deltaDataChannelBytesReceived += channel.deltaBytesReceived;
|
|
221
|
+
this.totalDataChannelBytesSent += channel.totalBytesSent;
|
|
222
|
+
this.totalDataChannelBytesReceived += channel.totalBytesReceived;
|
|
223
|
+
});
|
|
248
224
|
const iceRttInMs = (_a = this.ICE.stats) === null || _a === void 0 ? void 0 : _a.currentRoundTripTime;
|
|
249
225
|
let nrOfBelongings = this._inboundAudioTracks.size + this._inboundVideoTracks.size + this._outboundAudioTracks.size + this._outboundVideoTracks.size;
|
|
250
226
|
if (iceRttInMs) {
|
|
@@ -254,136 +230,74 @@ class ObservedPeerConnection extends events_1.EventEmitter {
|
|
|
254
230
|
this.avgRttInMs = 0 < nrOfBelongings ? sumRttInMs / nrOfBelongings : undefined;
|
|
255
231
|
}
|
|
256
232
|
update(sample, timestamp) {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
this._updated = timestamp;
|
|
270
|
-
this.emit('update');
|
|
271
|
-
});
|
|
233
|
+
if (this._closed)
|
|
234
|
+
return;
|
|
235
|
+
if (sample.peerConnectionId !== this._model.peerConnectionId)
|
|
236
|
+
throw new Error(`TransportId mismatch. PeerConnectionId: ${this._model.peerConnectionId} TransportId: ${sample.transportId}`);
|
|
237
|
+
this._sample = sample;
|
|
238
|
+
if (this._model.label !== sample.label) {
|
|
239
|
+
this._model.label = sample.label;
|
|
240
|
+
}
|
|
241
|
+
const report = Object.assign(Object.assign({ serviceId: this.client.call.serviceId, roomId: this.client.call.roomId, callId: this.client.call.callId, clientId: this.client.clientId, userId: this.client.userId, mediaUnitId: this.client.mediaUnitId }, sample), { timestamp, sampleSeq: -1 });
|
|
242
|
+
this.reports.addPeerConnectionTransportReports(report);
|
|
243
|
+
this._updated = Date.now();
|
|
244
|
+
this.emit('update');
|
|
272
245
|
}
|
|
273
246
|
createInboundAudioTrack(config) {
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
trackId: config.trackId,
|
|
280
|
-
}, this, this._storageProvider);
|
|
281
|
-
const pendingTracksTimestamp = this.client.ωpendingCreatedTracksTimestamp.get(result.trackId);
|
|
282
|
-
if (pendingTracksTimestamp) {
|
|
283
|
-
this.client.ωpendingCreatedTracksTimestamp.delete(result.trackId);
|
|
284
|
-
result.created = pendingTracksTimestamp;
|
|
285
|
-
}
|
|
286
|
-
result.on('close', () => {
|
|
287
|
-
this._inboundAudioTracks.delete(result.trackId);
|
|
288
|
-
this._model.inboundTrackIds = this._model.inboundTrackIds.filter((id) => id !== result.trackId);
|
|
289
|
-
!this._closed && this._save().catch(() => void 0);
|
|
290
|
-
});
|
|
291
|
-
this._inboundAudioTracks.set(result.trackId, result);
|
|
292
|
-
this._model.inboundTrackIds = [...(new Set([...this._model.inboundTrackIds, result.trackId]))];
|
|
293
|
-
yield this._save();
|
|
294
|
-
this.emit('newinboudaudiotrack', result);
|
|
295
|
-
return result;
|
|
247
|
+
if (this._closed)
|
|
248
|
+
throw new Error(`PeerConnection ${this.peerConnectionId} is closed`);
|
|
249
|
+
const result = new ObservedInboundTrack_1.ObservedInboundTrack(Object.assign({ kind: 'audio' }, config), this);
|
|
250
|
+
result.on('close', () => {
|
|
251
|
+
this._inboundAudioTracks.delete(result.trackId);
|
|
296
252
|
});
|
|
253
|
+
this._inboundAudioTracks.set(result.trackId, result);
|
|
254
|
+
this.emit('newinboudaudiotrack', result);
|
|
255
|
+
return result;
|
|
297
256
|
}
|
|
298
257
|
createInboundVideoTrack(config) {
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
trackId: config.trackId,
|
|
305
|
-
}, this, this._storageProvider);
|
|
306
|
-
const pendingTracksTimestamp = this.client.ωpendingCreatedTracksTimestamp.get(result.trackId);
|
|
307
|
-
if (pendingTracksTimestamp) {
|
|
308
|
-
this.client.ωpendingCreatedTracksTimestamp.delete(result.trackId);
|
|
309
|
-
result.created = pendingTracksTimestamp;
|
|
310
|
-
}
|
|
311
|
-
result.on('close', () => {
|
|
312
|
-
this._inboundVideoTracks.delete(result.trackId);
|
|
313
|
-
this._model.inboundTrackIds = this._model.inboundTrackIds.filter((id) => id !== result.trackId);
|
|
314
|
-
!this._closed && this._save().catch(() => void 0);
|
|
315
|
-
});
|
|
316
|
-
this._inboundVideoTracks.set(result.trackId, result);
|
|
317
|
-
this._model.inboundTrackIds = [...(new Set([...this._model.inboundTrackIds, result.trackId]))];
|
|
318
|
-
yield this._save();
|
|
319
|
-
this.emit('newinboudvideotrack', result);
|
|
320
|
-
return result;
|
|
258
|
+
if (this._closed)
|
|
259
|
+
throw new Error(`PeerConnection ${this.peerConnectionId} is closed`);
|
|
260
|
+
const result = new ObservedInboundTrack_1.ObservedInboundTrack(Object.assign({ kind: 'video' }, config), this);
|
|
261
|
+
result.on('close', () => {
|
|
262
|
+
this._inboundVideoTracks.delete(result.trackId);
|
|
321
263
|
});
|
|
264
|
+
this._inboundVideoTracks.set(result.trackId, result);
|
|
265
|
+
this.emit('newinboudvideotrack', result);
|
|
266
|
+
return result;
|
|
322
267
|
}
|
|
323
268
|
createOutboundAudioTrack(config) {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
trackId: config.trackId,
|
|
330
|
-
}, this, this._storageProvider);
|
|
331
|
-
const pendingTracksTimestamp = this.client.ωpendingCreatedTracksTimestamp.get(result.trackId);
|
|
332
|
-
if (pendingTracksTimestamp) {
|
|
333
|
-
this.client.ωpendingCreatedTracksTimestamp.delete(result.trackId);
|
|
334
|
-
result.created = pendingTracksTimestamp;
|
|
335
|
-
}
|
|
336
|
-
result.on('close', () => {
|
|
337
|
-
this._outboundAudioTracks.delete(result.trackId);
|
|
338
|
-
this._model.outboundTrackIds = this._model.outboundTrackIds.filter((id) => id !== result.trackId);
|
|
339
|
-
result.sfuStreamId && this.client.call.sfuStreamIdToOutboundAudioTrack.delete(result.sfuStreamId);
|
|
340
|
-
!this._closed && this._save().catch(() => void 0);
|
|
341
|
-
});
|
|
342
|
-
this._outboundAudioTracks.set(result.trackId, result);
|
|
343
|
-
this._model.outboundTrackIds = [...(new Set([...this._model.outboundTrackIds, result.trackId]))];
|
|
344
|
-
result.sfuStreamId && this.client.call.sfuStreamIdToOutboundAudioTrack.set(result.sfuStreamId, result);
|
|
345
|
-
yield this._save();
|
|
346
|
-
this.emit('newoutboundaudiotrack', result);
|
|
347
|
-
return result;
|
|
269
|
+
if (this._closed)
|
|
270
|
+
throw new Error(`PeerConnection ${this.peerConnectionId} is closed`);
|
|
271
|
+
const result = new ObservedOutboundTrack_1.ObservedOutboundTrack(Object.assign({ kind: 'audio' }, config), this);
|
|
272
|
+
result.on('close', () => {
|
|
273
|
+
this._outboundAudioTracks.delete(result.trackId);
|
|
348
274
|
});
|
|
275
|
+
this._outboundAudioTracks.set(result.trackId, result);
|
|
276
|
+
this.emit('newoutboundaudiotrack', result);
|
|
277
|
+
return result;
|
|
349
278
|
}
|
|
350
279
|
createOutboundVideoTrack(config) {
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
trackId: config.trackId,
|
|
357
|
-
}, this, this._storageProvider);
|
|
358
|
-
const pendingTracksTimestamp = this.client.ωpendingCreatedTracksTimestamp.get(result.trackId);
|
|
359
|
-
if (pendingTracksTimestamp) {
|
|
360
|
-
this.client.ωpendingCreatedTracksTimestamp.delete(result.trackId);
|
|
361
|
-
result.created = pendingTracksTimestamp;
|
|
362
|
-
}
|
|
363
|
-
result.on('close', () => {
|
|
364
|
-
this._outboundVideoTracks.delete(result.trackId);
|
|
365
|
-
result.sfuStreamId && this.client.call.sfuStreamIdToOutboundVideoTrack.set(result.sfuStreamId, result);
|
|
366
|
-
this._model.outboundTrackIds = this._model.outboundTrackIds.filter((id) => id !== result.trackId);
|
|
367
|
-
!this._closed && this._save().catch(() => void 0);
|
|
368
|
-
});
|
|
369
|
-
this._outboundVideoTracks.set(result.trackId, result);
|
|
370
|
-
result.sfuStreamId && this.client.call.sfuStreamIdToOutboundVideoTrack.set(result.sfuStreamId, result);
|
|
371
|
-
this._model.outboundTrackIds = [...(new Set([...this._model.outboundTrackIds, result.trackId]))];
|
|
372
|
-
yield this._save();
|
|
373
|
-
this.emit('newoutboundvideotrack', result);
|
|
374
|
-
return result;
|
|
280
|
+
if (this._closed)
|
|
281
|
+
throw new Error(`PeerConnection ${this.peerConnectionId} is closed`);
|
|
282
|
+
const result = new ObservedOutboundTrack_1.ObservedOutboundTrack(Object.assign({ kind: 'video' }, config), this);
|
|
283
|
+
result.on('close', () => {
|
|
284
|
+
this._outboundVideoTracks.delete(result.trackId);
|
|
375
285
|
});
|
|
286
|
+
this._outboundVideoTracks.set(result.trackId, result);
|
|
287
|
+
this.emit('newoutboundvideotrack', result);
|
|
288
|
+
return result;
|
|
376
289
|
}
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
}));
|
|
290
|
+
createDataChannel(channelId) {
|
|
291
|
+
if (this._closed)
|
|
292
|
+
throw new Error(`PeerConnection ${this.peerConnectionId} is closed`);
|
|
293
|
+
const result = new ObservedDataChannel_1.ObservedDataChannel({
|
|
294
|
+
channelId,
|
|
295
|
+
}, this);
|
|
296
|
+
result.on('close', () => {
|
|
297
|
+
this._dataChannels.delete(result.channelId);
|
|
386
298
|
});
|
|
299
|
+
this._dataChannels.set(result.channelId, result);
|
|
300
|
+
return result;
|
|
387
301
|
}
|
|
388
302
|
}
|
|
389
303
|
exports.ObservedPeerConnection = ObservedPeerConnection;
|
package/lib/ObservedSfu.d.ts
CHANGED
|
@@ -2,11 +2,10 @@
|
|
|
2
2
|
import { EventEmitter } from 'events';
|
|
3
3
|
import { Observer } from './Observer';
|
|
4
4
|
import { SfuSample } from '@observertc/sample-schemas-js';
|
|
5
|
-
export type
|
|
5
|
+
export type ObservedSfuModel = {
|
|
6
6
|
serviceId: string;
|
|
7
7
|
sfuId: string;
|
|
8
8
|
joined?: number;
|
|
9
|
-
appData: AppData;
|
|
10
9
|
};
|
|
11
10
|
export type ObservedSfuEvents = {
|
|
12
11
|
update: [];
|
|
@@ -22,17 +21,16 @@ export declare class ObservedSfu<AppData extends Record<string, unknown> = Recor
|
|
|
22
21
|
private readonly _model;
|
|
23
22
|
readonly observer: Observer;
|
|
24
23
|
readonly appData: AppData;
|
|
25
|
-
|
|
24
|
+
readonly created: number;
|
|
26
25
|
private _updated;
|
|
27
|
-
private readonly _execute;
|
|
28
26
|
private _closed;
|
|
29
|
-
|
|
27
|
+
constructor(_model: ObservedSfuModel, observer: Observer, appData: AppData);
|
|
30
28
|
get serviceId(): string;
|
|
31
29
|
get sfuId(): string;
|
|
32
30
|
get joined(): number;
|
|
31
|
+
get updated(): number;
|
|
33
32
|
get closed(): boolean;
|
|
34
33
|
close(): void;
|
|
35
|
-
update(sample: SfuSample):
|
|
36
|
-
private _save;
|
|
34
|
+
update(sample: SfuSample): void;
|
|
37
35
|
}
|
|
38
36
|
//# sourceMappingURL=ObservedSfu.d.ts.map
|
package/lib/ObservedSfu.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ObservedSfu.d.ts","sourceRoot":"","sources":["../src/ObservedSfu.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"ObservedSfu.d.ts","sourceRoot":"","sources":["../src/ObservedSfu.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAE1D,MAAM,MAAM,gBAAgB,GAAE;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC/B,MAAM,EAAE,EAAE,CAAC;IACX,KAAK,EAAE,EAAE,CAAC;CACV,CAAC;AAEF,MAAM,CAAC,OAAO,WAAW,WAAW;IACnC,EAAE,CAAC,CAAC,SAAS,MAAM,iBAAiB,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,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object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
3
|
exports.ObservedSfu = void 0;
|
|
36
4
|
const events_1 = require("events");
|
|
37
|
-
const Models = __importStar(require("./models/Models"));
|
|
38
|
-
const SingleExecutor_1 = require("./common/SingleExecutor");
|
|
39
5
|
class ObservedSfu extends events_1.EventEmitter {
|
|
40
|
-
static create(config, observer) {
|
|
41
|
-
var _a;
|
|
42
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
-
const model = new Models.Sfu({
|
|
44
|
-
serviceId: config.serviceId,
|
|
45
|
-
sfuId: config.sfuId,
|
|
46
|
-
sfuTransportIds: [],
|
|
47
|
-
joined: BigInt((_a = config.joined) !== null && _a !== void 0 ? _a : Date.now()),
|
|
48
|
-
});
|
|
49
|
-
const result = new ObservedSfu(model, observer, config.appData);
|
|
50
|
-
const alreadyInserted = yield observer.storage.sfuStorage.insert(config.sfuId, model);
|
|
51
|
-
if (alreadyInserted)
|
|
52
|
-
throw new Error(`Sfu with id ${config.sfuId} already exists`);
|
|
53
|
-
return result;
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
6
|
constructor(_model, observer, appData) {
|
|
57
7
|
super();
|
|
58
8
|
this._model = _model;
|
|
59
9
|
this.observer = observer;
|
|
60
10
|
this.appData = appData;
|
|
11
|
+
this.created = Date.now();
|
|
61
12
|
this._updated = Date.now();
|
|
62
|
-
this._execute = (0, SingleExecutor_1.createSingleExecutor)();
|
|
63
13
|
this._closed = false;
|
|
64
14
|
}
|
|
65
15
|
get serviceId() {
|
|
@@ -74,6 +24,9 @@ class ObservedSfu extends events_1.EventEmitter {
|
|
|
74
24
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
75
25
|
return Number(this._model.joined);
|
|
76
26
|
}
|
|
27
|
+
get updated() {
|
|
28
|
+
return this._updated;
|
|
29
|
+
}
|
|
77
30
|
get closed() {
|
|
78
31
|
return this._closed;
|
|
79
32
|
}
|
|
@@ -84,29 +37,12 @@ class ObservedSfu extends events_1.EventEmitter {
|
|
|
84
37
|
this.emit('close');
|
|
85
38
|
}
|
|
86
39
|
update(sample) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if (this._closed)
|
|
94
|
-
throw new Error(`Sfu ${this.sfuId} is closed`);
|
|
95
|
-
yield this._save();
|
|
96
|
-
this.emit('update');
|
|
97
|
-
}));
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
_save() {
|
|
101
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
-
if (this._closed)
|
|
103
|
-
throw new Error(`Sfu ${this.sfuId} is closed`);
|
|
104
|
-
return this._execute(() => __awaiter(this, void 0, void 0, function* () {
|
|
105
|
-
if (this._closed)
|
|
106
|
-
throw new Error(`Sfu ${this.sfuId} is closed`);
|
|
107
|
-
yield this.observer.storage.sfuStorage.set(this.sfuId, this._model);
|
|
108
|
-
}));
|
|
109
|
-
});
|
|
40
|
+
if (this._closed)
|
|
41
|
+
throw new Error(`Sfu ${this.sfuId} is closed`);
|
|
42
|
+
if (sample.sfuId !== this.sfuId)
|
|
43
|
+
throw new Error(`Sfu ${this.sfuId} is not the same as sample.sfuId`);
|
|
44
|
+
this._updated = Date.now();
|
|
45
|
+
this.emit('update');
|
|
110
46
|
}
|
|
111
47
|
}
|
|
112
48
|
exports.ObservedSfu = ObservedSfu;
|
package/lib/Observer.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import {
|
|
3
|
-
import { ObservedCall, ObservedCallConfig } from './ObservedCall';
|
|
2
|
+
import { ObservedCall, ObservedCallModel } from './ObservedCall';
|
|
4
3
|
import { ReportsCollector } from './ReportsCollector';
|
|
5
4
|
import { EventEmitter } from 'events';
|
|
6
5
|
import { PartialBy } from './common/utils';
|
|
@@ -26,7 +25,6 @@ export type ObserverConfig = {
|
|
|
26
25
|
maxReports?: number | undefined;
|
|
27
26
|
maxCollectingTimeInMs?: number | undefined;
|
|
28
27
|
maxEntryIdleTimeInMs?: number | undefined;
|
|
29
|
-
storages?: StorageProvider;
|
|
30
28
|
};
|
|
31
29
|
export declare interface Observer {
|
|
32
30
|
on<U extends keyof ObserverEvents>(event: U, listener: (...args: ObserverEvents[U]) => void): this;
|
|
@@ -36,14 +34,15 @@ export declare interface Observer {
|
|
|
36
34
|
}
|
|
37
35
|
export declare class Observer extends EventEmitter {
|
|
38
36
|
readonly config: ObserverConfig;
|
|
39
|
-
readonly storage: StorageProvider;
|
|
40
37
|
static create(providedConfig: Partial<ObserverConfig>): Observer;
|
|
41
38
|
readonly reports: ReportsCollector;
|
|
42
39
|
private readonly _observedCalls;
|
|
43
40
|
private _reportTimer?;
|
|
44
41
|
private _closed;
|
|
45
|
-
constructor(config: ObserverConfig
|
|
46
|
-
createObservedCall<T extends Record<string, unknown> = Record<string, unknown>>(config: PartialBy<
|
|
42
|
+
constructor(config: ObserverConfig);
|
|
43
|
+
createObservedCall<T extends Record<string, unknown> = Record<string, unknown>>(config: PartialBy<ObservedCallModel, 'serviceId' | 'started'> & {
|
|
44
|
+
appData: T;
|
|
45
|
+
}): ObservedCall<T>;
|
|
47
46
|
get observedCalls(): ReadonlyMap<string, ObservedCall>;
|
|
48
47
|
get closed(): boolean;
|
|
49
48
|
close(): void;
|
package/lib/Observer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Observer.d.ts","sourceRoot":"","sources":["../src/Observer.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"Observer.d.ts","sourceRoot":"","sources":["../src/Observer.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAK3C,M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OAAO,CAAC,QAAQ,CAAC,cAAc,CAAmC;IAClE,OAAO,CAAC,YAAY,CAAC,CAAgC;IACrD,OAAO,CAAC,OAAO,CAAS;gBAEP,MAAM,EAAE,cAAc;IAiBhC,kBAAkB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACpF,MAAM,EAAE,SAAS,CAAC,iBAAiB,EAAE,WAAW,GAAG,SAAS,CAAC,GAAG;QAAE,OAAO,EAAE,CAAC,CAAA;KAAE,GAC5E,YAAY,CAAC,CAAC,CAAC;IAsClB,IAAW,aAAa,IAAI,WAAW,CAAC,MAAM,EAAE,YAAY,CAAC,CAE5D;IAED,IAAW,MAAM,YAEhB;IAEM,KAAK;IASZ,OAAO,CAAC,YAAY;CAepB"}
|
package/lib/Observer.js
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
10
12
|
};
|
|
11
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
14
|
exports.Observer = void 0;
|
|
13
15
|
const logger_1 = require("./common/logger");
|
|
14
|
-
const StorageProvider_1 = require("./storages/StorageProvider");
|
|
15
16
|
const ObservedCall_1 = require("./ObservedCall");
|
|
16
17
|
const ReportsCollector_1 = require("./ReportsCollector");
|
|
17
18
|
const events_1 = require("events");
|
|
@@ -19,7 +20,6 @@ const callEventReports_1 = require("./common/callEventReports");
|
|
|
19
20
|
const logger = (0, logger_1.createLogger)('Observer');
|
|
20
21
|
class Observer extends events_1.EventEmitter {
|
|
21
22
|
static create(providedConfig) {
|
|
22
|
-
var _a;
|
|
23
23
|
const config = Object.assign({
|
|
24
24
|
defaultServiceId: 'default-service-id',
|
|
25
25
|
defaultMediaUnitId: 'default-media-unit-id',
|
|
@@ -30,13 +30,11 @@ class Observer extends events_1.EventEmitter {
|
|
|
30
30
|
sink: {},
|
|
31
31
|
logLevel: 'info',
|
|
32
32
|
}, providedConfig);
|
|
33
|
-
|
|
34
|
-
return new Observer(config, storages);
|
|
33
|
+
return new Observer(config);
|
|
35
34
|
}
|
|
36
|
-
constructor(config
|
|
35
|
+
constructor(config) {
|
|
37
36
|
super();
|
|
38
37
|
this.config = config;
|
|
39
|
-
this.storage = storage;
|
|
40
38
|
this.reports = new ReportsCollector_1.ReportsCollector();
|
|
41
39
|
this._observedCalls = new Map();
|
|
42
40
|
this._closed = false;
|
|
@@ -53,24 +51,23 @@ class Observer extends events_1.EventEmitter {
|
|
|
53
51
|
this.reports.on('newreport', onNewReport);
|
|
54
52
|
}
|
|
55
53
|
createObservedCall(config) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
});
|
|
69
|
-
this._observedCalls.set(call.callId, call);
|
|
70
|
-
this.reports.addCallEventReport((0, callEventReports_1.createCallStartedEventReport)(call.serviceId, call.roomId, call.callId, call.started));
|
|
71
|
-
this.emit('newcall', call);
|
|
72
|
-
return call;
|
|
54
|
+
if (this._closed) {
|
|
55
|
+
throw new Error('Attempted to create a call source on a closed observer');
|
|
56
|
+
}
|
|
57
|
+
const { appData } = config, model = __rest(config, ["appData"]);
|
|
58
|
+
const call = new ObservedCall_1.ObservedCall(Object.assign(Object.assign({}, model), { serviceId: this.config.defaultServiceId, started: Date.now() }), this, appData);
|
|
59
|
+
if (this._closed)
|
|
60
|
+
throw new Error('Cannot create an observed call on a closed observer');
|
|
61
|
+
if (this._observedCalls.has(call.callId))
|
|
62
|
+
throw new Error(`Observed Call with id ${call.callId} already exists`);
|
|
63
|
+
call.once('close', () => {
|
|
64
|
+
this._observedCalls.delete(call.callId);
|
|
65
|
+
this.reports.addCallEventReport((0, callEventReports_1.createCallEndedEventReport)(call.serviceId, call.roomId, call.callId, Date.now()));
|
|
73
66
|
});
|
|
67
|
+
this._observedCalls.set(call.callId, call);
|
|
68
|
+
this.reports.addCallEventReport((0, callEventReports_1.createCallStartedEventReport)(call.serviceId, call.roomId, call.callId, call.started));
|
|
69
|
+
this.emit('newcall', call);
|
|
70
|
+
return call;
|
|
74
71
|
}
|
|
75
72
|
get observedCalls() {
|
|
76
73
|
return this._observedCalls;
|