@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
package/lib/ObservedClient.js
CHANGED
|
@@ -1,36 +1,4 @@
|
|
|
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
|
var __rest = (this && this.__rest) || function (s, e) {
|
|
35
3
|
var t = {};
|
|
36
4
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
@@ -44,58 +12,26 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
44
12
|
};
|
|
45
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
14
|
exports.ObservedClient = void 0;
|
|
47
|
-
const Models = __importStar(require("./models/Models"));
|
|
48
15
|
const events_1 = require("events");
|
|
49
|
-
const SingleExecutor_1 = require("./common/SingleExecutor");
|
|
50
16
|
const ObservedPeerConnection_1 = require("./ObservedPeerConnection");
|
|
51
17
|
const logger_1 = require("./common/logger");
|
|
52
18
|
const callMetaReports_1 = require("./common/callMetaReports");
|
|
53
19
|
// eslint-disable-next-line camelcase
|
|
54
|
-
const samples_pb_1 = require("./models/samples_pb");
|
|
55
20
|
const utils_1 = require("./common/utils");
|
|
56
21
|
const callEventReports_1 = require("./common/callEventReports");
|
|
57
22
|
const CallEventType_1 = require("./common/CallEventType");
|
|
58
23
|
const logger = (0, logger_1.createLogger)('ObservedClient');
|
|
59
24
|
class ObservedClient extends events_1.EventEmitter {
|
|
60
|
-
|
|
61
|
-
var _a, _b;
|
|
62
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
-
const { callId, clientId, mediaUnitId } = config;
|
|
64
|
-
const model = new Models.Client({
|
|
65
|
-
roomId: call.roomId,
|
|
66
|
-
serviceId: call.serviceId,
|
|
67
|
-
callId,
|
|
68
|
-
clientId,
|
|
69
|
-
mediaUnitId,
|
|
70
|
-
peerConnectionIds: [],
|
|
71
|
-
joined: BigInt((_a = config.joined) !== null && _a !== void 0 ? _a : Date.now()),
|
|
72
|
-
});
|
|
73
|
-
const result = new ObservedClient(model, call, storageProvider, config.appData);
|
|
74
|
-
const alreadyInserted = yield storageProvider.clientStorage.insert(clientId, model);
|
|
75
|
-
if (alreadyInserted)
|
|
76
|
-
throw new Error(`Client with id ${clientId} already exists`);
|
|
77
|
-
result._overflowingProcessingThreshold = (_b = config.overflowingProcessingThreshold) !== null && _b !== void 0 ? _b : 0;
|
|
78
|
-
if (config.addJoinAndDetachClientEvent) {
|
|
79
|
-
call.reports.addCallEventReport((0, callEventReports_1.createClientJoinedEventReport)(call.serviceId, result.mediaUnitId, call.roomId, call.callId, result.clientId, result.joined, result.userId, result.marker));
|
|
80
|
-
}
|
|
81
|
-
return result;
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
constructor(_model, call, _storageProvider, appData) {
|
|
25
|
+
constructor(_model, call, appData) {
|
|
85
26
|
super();
|
|
86
27
|
this._model = _model;
|
|
87
28
|
this.call = call;
|
|
88
|
-
this._storageProvider = _storageProvider;
|
|
89
29
|
this.appData = appData;
|
|
90
30
|
this.created = Date.now();
|
|
31
|
+
this._updated = Date.now();
|
|
91
32
|
this._peerConnections = new Map();
|
|
92
|
-
this._execute = (0, SingleExecutor_1.createSingleExecutor)();
|
|
93
|
-
this._overflowingProcessingThreshold = 0;
|
|
94
33
|
this._closed = false;
|
|
95
|
-
this._updated = Date.now();
|
|
96
34
|
this._acceptedSample = 0;
|
|
97
|
-
this._processingSample = 0;
|
|
98
|
-
this._numberOfAcceptedUpdates = 0;
|
|
99
35
|
this.usingTURN = false;
|
|
100
36
|
this.availableOutgoingBitrate = 0;
|
|
101
37
|
this.availableIncomingBitrate = 0;
|
|
@@ -112,25 +48,21 @@ class ObservedClient extends events_1.EventEmitter {
|
|
|
112
48
|
this.ωpendingCreatedTracksTimestamp = new Map();
|
|
113
49
|
this.ωpendingCreatedPeerConnectionTimestamp = new Map();
|
|
114
50
|
}
|
|
115
|
-
get joined() {
|
|
116
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
117
|
-
return Number(this._model.joined);
|
|
118
|
-
}
|
|
119
51
|
get clientId() {
|
|
120
52
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
121
53
|
return this._model.clientId;
|
|
122
54
|
}
|
|
123
55
|
get roomId() {
|
|
124
56
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
125
|
-
return this.
|
|
57
|
+
return this.call.roomId;
|
|
126
58
|
}
|
|
127
59
|
get serviceId() {
|
|
128
60
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
129
|
-
return this.
|
|
61
|
+
return this.call.serviceId;
|
|
130
62
|
}
|
|
131
63
|
get callId() {
|
|
132
64
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
133
|
-
return this.
|
|
65
|
+
return this.call.callId;
|
|
134
66
|
}
|
|
135
67
|
get mediaUnitId() {
|
|
136
68
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
@@ -166,17 +98,6 @@ class ObservedClient extends events_1.EventEmitter {
|
|
|
166
98
|
get updated() {
|
|
167
99
|
return this._updated;
|
|
168
100
|
}
|
|
169
|
-
get numberOfAcceptedUpdates() {
|
|
170
|
-
return this._numberOfAcceptedUpdates;
|
|
171
|
-
}
|
|
172
|
-
get uptimeInMs() {
|
|
173
|
-
return this._updated - this.created;
|
|
174
|
-
}
|
|
175
|
-
get durationInMs() {
|
|
176
|
-
if (!this._left)
|
|
177
|
-
return;
|
|
178
|
-
return this._left - this.joined;
|
|
179
|
-
}
|
|
180
101
|
get closed() {
|
|
181
102
|
return this._closed;
|
|
182
103
|
}
|
|
@@ -187,467 +108,406 @@ class ObservedClient extends events_1.EventEmitter {
|
|
|
187
108
|
if (this._closed)
|
|
188
109
|
return;
|
|
189
110
|
this._closed = true;
|
|
190
|
-
!this._left
|
|
111
|
+
if (!this._left) {
|
|
112
|
+
this._addClientLeftReport();
|
|
113
|
+
}
|
|
191
114
|
Array.from(this._peerConnections.values()).forEach((peerConnection) => peerConnection.close());
|
|
192
|
-
this.
|
|
193
|
-
.catch(() => void 0)
|
|
194
|
-
.finally(() => this.emit('close'));
|
|
115
|
+
this.emit('close');
|
|
195
116
|
}
|
|
196
117
|
accept(sample) {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
118
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20;
|
|
119
|
+
if (this._closed)
|
|
120
|
+
throw new Error(`Client ${this.clientId} is closed`);
|
|
121
|
+
if (sample.clientId && sample.clientId !== 'NULL' && sample.clientId !== this.clientId) {
|
|
122
|
+
throw new Error(`Sample client id (${sample.clientId}) does not match the client id of the observed client (${this.clientId})`);
|
|
123
|
+
}
|
|
124
|
+
const now = Date.now();
|
|
125
|
+
++this._acceptedSample;
|
|
126
|
+
for (const peerConnection of this._peerConnections.values()) {
|
|
127
|
+
if (peerConnection.closed)
|
|
128
|
+
continue;
|
|
129
|
+
peerConnection.resetMetrics();
|
|
130
|
+
}
|
|
131
|
+
if (this.userId !== sample.userId) {
|
|
132
|
+
this._model.userId = sample.userId;
|
|
133
|
+
}
|
|
134
|
+
if (this._model.marker !== sample.marker) {
|
|
135
|
+
this._model.marker = sample.marker;
|
|
136
|
+
}
|
|
137
|
+
if (this._timeZoneOffsetInHours !== sample.timeZoneOffsetInHours) {
|
|
138
|
+
this._timeZoneOffsetInHours = sample.timeZoneOffsetInHours;
|
|
139
|
+
}
|
|
140
|
+
if (sample.os && (((_a = this._model.operationSystem) === null || _a === void 0 ? void 0 : _a.name) !== sample.os.name ||
|
|
141
|
+
((_b = this._model.operationSystem) === null || _b === void 0 ? void 0 : _b.version) !== sample.os.version ||
|
|
142
|
+
((_c = this._model.operationSystem) === null || _c === void 0 ? void 0 : _c.versionName) !== sample.os.versionName)) {
|
|
143
|
+
this._model.operationSystem = sample.os;
|
|
144
|
+
const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
|
|
145
|
+
type: callMetaReports_1.CallMetaType.OPERATION_SYSTEM,
|
|
146
|
+
payload: sample.os,
|
|
147
|
+
}, this.userId);
|
|
148
|
+
this.reports.addCallMetaReport(callMetaReport);
|
|
149
|
+
}
|
|
150
|
+
if (sample.engine && (((_d = this._model.engine) === null || _d === void 0 ? void 0 : _d.name) !== sample.engine.name ||
|
|
151
|
+
((_e = this._model.engine) === null || _e === void 0 ? void 0 : _e.version) !== sample.engine.version)) {
|
|
152
|
+
this._model.engine = sample.engine;
|
|
153
|
+
const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
|
|
154
|
+
type: callMetaReports_1.CallMetaType.ENGINE,
|
|
155
|
+
payload: sample.engine,
|
|
156
|
+
}, this.userId);
|
|
157
|
+
this.reports.addCallMetaReport(callMetaReport);
|
|
158
|
+
}
|
|
159
|
+
if (sample.platform && (((_f = this._model.platform) === null || _f === void 0 ? void 0 : _f.model) !== sample.platform.model ||
|
|
160
|
+
((_g = this._model.platform) === null || _g === void 0 ? void 0 : _g.type) !== sample.platform.type ||
|
|
161
|
+
((_h = this._model.platform) === null || _h === void 0 ? void 0 : _h.vendor) !== sample.platform.vendor)) {
|
|
162
|
+
this._model.platform = sample.platform;
|
|
163
|
+
const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
|
|
164
|
+
type: callMetaReports_1.CallMetaType.PLATFORM,
|
|
165
|
+
payload: sample.platform,
|
|
166
|
+
}, this.userId);
|
|
167
|
+
this.reports.addCallMetaReport(callMetaReport);
|
|
168
|
+
}
|
|
169
|
+
if (sample.browser && (((_j = this._model.browser) === null || _j === void 0 ? void 0 : _j.name) !== sample.browser.name ||
|
|
170
|
+
((_k = this._model.browser) === null || _k === void 0 ? void 0 : _k.version) !== sample.browser.version)) {
|
|
171
|
+
this._model.browser = sample.browser;
|
|
172
|
+
const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
|
|
173
|
+
type: callMetaReports_1.CallMetaType.BROWSER,
|
|
174
|
+
payload: sample.browser,
|
|
175
|
+
}, this.userId);
|
|
176
|
+
this.reports.addCallMetaReport(callMetaReport);
|
|
177
|
+
}
|
|
178
|
+
for (const mediaConstraint of (_l = sample.mediaConstraints) !== null && _l !== void 0 ? _l : []) {
|
|
179
|
+
const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
|
|
180
|
+
type: callMetaReports_1.CallMetaType.MEDIA_CONSTRAINT,
|
|
181
|
+
payload: mediaConstraint,
|
|
182
|
+
}, this.userId);
|
|
183
|
+
this.reports.addCallMetaReport(callMetaReport);
|
|
184
|
+
}
|
|
185
|
+
for (const localSDP of (_m = sample.localSDPs) !== null && _m !== void 0 ? _m : []) {
|
|
186
|
+
const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
|
|
187
|
+
type: callMetaReports_1.CallMetaType.LOCAL_SDP,
|
|
188
|
+
payload: localSDP,
|
|
189
|
+
}, this.userId);
|
|
190
|
+
this.reports.addCallMetaReport(callMetaReport);
|
|
191
|
+
}
|
|
192
|
+
for (const extensionStats of (_o = sample.extensionStats) !== null && _o !== void 0 ? _o : []) {
|
|
193
|
+
this.reports.addClientExtensionReport({
|
|
194
|
+
serviceId: this.serviceId,
|
|
195
|
+
mediaUnitId: this.mediaUnitId,
|
|
196
|
+
roomId: this.roomId,
|
|
197
|
+
callId: this.callId,
|
|
198
|
+
clientId: this.clientId,
|
|
199
|
+
userId: this.userId,
|
|
200
|
+
timestamp: Date.now(),
|
|
201
|
+
payload: extensionStats.payload,
|
|
202
|
+
extensionType: extensionStats.type,
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
for (let _21 of (_p = sample.customCallEvents) !== null && _p !== void 0 ? _p : []) {
|
|
206
|
+
const { timestamp } = _21, callEvent = __rest(_21, ["timestamp"]);
|
|
207
|
+
switch (callEvent.name) {
|
|
208
|
+
case CallEventType_1.CallEventType.CLIENT_LEFT: {
|
|
209
|
+
this._left = timestamp;
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
202
212
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
213
|
+
this.reports.addCallEventReport(Object.assign({ serviceId: this.serviceId, mediaUnitId: this.mediaUnitId, roomId: this.roomId, callId: this.callId, clientId: this.clientId, userId: this.userId, timestamp: timestamp !== null && timestamp !== void 0 ? timestamp : Date.now() }, callEvent));
|
|
214
|
+
}
|
|
215
|
+
for (const userMediaError of (_q = sample.userMediaErrors) !== null && _q !== void 0 ? _q : []) {
|
|
216
|
+
const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
|
|
217
|
+
type: callMetaReports_1.CallMetaType.USER_MEDIA_ERROR,
|
|
218
|
+
payload: userMediaError,
|
|
219
|
+
}, this.userId);
|
|
220
|
+
this.reports.addCallMetaReport(callMetaReport);
|
|
221
|
+
this.userMediaErrors.push(userMediaError);
|
|
222
|
+
}
|
|
223
|
+
for (const certificate of (_r = sample.certificates) !== null && _r !== void 0 ? _r : []) {
|
|
224
|
+
const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
|
|
225
|
+
type: callMetaReports_1.CallMetaType.CERTIFICATE,
|
|
226
|
+
payload: certificate,
|
|
227
|
+
}, this.userId);
|
|
228
|
+
this.reports.addCallMetaReport(callMetaReport);
|
|
229
|
+
}
|
|
230
|
+
for (const codec of (_s = sample.codecs) !== null && _s !== void 0 ? _s : []) {
|
|
231
|
+
const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
|
|
232
|
+
type: callMetaReports_1.CallMetaType.CODEC,
|
|
233
|
+
payload: codec,
|
|
234
|
+
}, this.userId);
|
|
235
|
+
this.reports.addCallMetaReport(callMetaReport);
|
|
236
|
+
codec.mimeType && this.codecs.push(codec.mimeType);
|
|
237
|
+
}
|
|
238
|
+
for (const iceServer of (_t = sample.iceServers) !== null && _t !== void 0 ? _t : []) {
|
|
239
|
+
const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
|
|
240
|
+
type: callMetaReports_1.CallMetaType.ICE_SERVER,
|
|
241
|
+
payload: iceServer,
|
|
242
|
+
}, this.userId);
|
|
243
|
+
this.reports.addCallMetaReport(callMetaReport);
|
|
244
|
+
}
|
|
245
|
+
for (const mediaDevice of (_u = sample.mediaDevices) !== null && _u !== void 0 ? _u : []) {
|
|
246
|
+
const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
|
|
247
|
+
type: callMetaReports_1.CallMetaType.MEDIA_DEVICE,
|
|
248
|
+
payload: mediaDevice,
|
|
249
|
+
}, this.userId);
|
|
250
|
+
this.reports.addCallMetaReport(callMetaReport);
|
|
251
|
+
mediaDevice.label && this.mediaDevices.push(mediaDevice.label);
|
|
252
|
+
}
|
|
253
|
+
for (const mediaSource of (_v = sample.mediaSources) !== null && _v !== void 0 ? _v : []) {
|
|
254
|
+
const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
|
|
255
|
+
type: callMetaReports_1.CallMetaType.MEDIA_SOURCE,
|
|
256
|
+
payload: mediaSource,
|
|
257
|
+
}, this.userId);
|
|
258
|
+
this.reports.addCallMetaReport(callMetaReport);
|
|
259
|
+
}
|
|
260
|
+
for (const transport of (_w = sample.pcTransports) !== null && _w !== void 0 ? _w : []) {
|
|
261
|
+
try {
|
|
262
|
+
const peerConnection = (_x = this._peerConnections.get(transport.transportId)) !== null && _x !== void 0 ? _x : this._createPeerConnection(transport.peerConnectionId);
|
|
263
|
+
!peerConnection.label && transport.label && (peerConnection.label = transport.label);
|
|
264
|
+
peerConnection.update(transport, sample.timestamp);
|
|
207
265
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
((_b = this._model.operationSystem) === null || _b === void 0 ? void 0 : _b.version) !== sample.os.version ||
|
|
231
|
-
((_c = this._model.operationSystem) === null || _c === void 0 ? void 0 : _c.versionName) !== sample.os.versionName)) {
|
|
232
|
-
this._model.operationSystem = new samples_pb_1.Samples_ClientSample_OperationSystem(Object.assign({}, sample.os));
|
|
233
|
-
const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
|
|
234
|
-
type: callMetaReports_1.CallMetaType.OPERATION_SYSTEM,
|
|
235
|
-
payload: sample.os,
|
|
236
|
-
}, this.userId);
|
|
237
|
-
this.reports.addCallMetaReport(callMetaReport);
|
|
238
|
-
executeSave = true;
|
|
239
|
-
}
|
|
240
|
-
if (sample.engine && (((_d = this._model.engine) === null || _d === void 0 ? void 0 : _d.name) !== sample.engine.name ||
|
|
241
|
-
((_e = this._model.engine) === null || _e === void 0 ? void 0 : _e.version) !== sample.engine.version)) {
|
|
242
|
-
this._model.engine = new samples_pb_1.Samples_ClientSample_Engine(Object.assign({}, sample.engine));
|
|
243
|
-
const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
|
|
244
|
-
type: callMetaReports_1.CallMetaType.ENGINE,
|
|
245
|
-
payload: sample.engine,
|
|
246
|
-
}, this.userId);
|
|
247
|
-
this.reports.addCallMetaReport(callMetaReport);
|
|
248
|
-
executeSave = true;
|
|
249
|
-
}
|
|
250
|
-
if (sample.platform && (((_f = this._model.platform) === null || _f === void 0 ? void 0 : _f.model) !== sample.platform.model ||
|
|
251
|
-
((_g = this._model.platform) === null || _g === void 0 ? void 0 : _g.type) !== sample.platform.type ||
|
|
252
|
-
((_h = this._model.platform) === null || _h === void 0 ? void 0 : _h.vendor) !== sample.platform.vendor)) {
|
|
253
|
-
this._model.platform = new samples_pb_1.Samples_ClientSample_Platform(Object.assign({}, sample.platform));
|
|
254
|
-
const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
|
|
255
|
-
type: callMetaReports_1.CallMetaType.PLATFORM,
|
|
256
|
-
payload: sample.platform,
|
|
257
|
-
}, this.userId);
|
|
258
|
-
this.reports.addCallMetaReport(callMetaReport);
|
|
259
|
-
executeSave = true;
|
|
260
|
-
}
|
|
261
|
-
if (sample.browser && (((_j = this._model.browser) === null || _j === void 0 ? void 0 : _j.name) !== sample.browser.name ||
|
|
262
|
-
((_k = this._model.browser) === null || _k === void 0 ? void 0 : _k.version) !== sample.browser.version)) {
|
|
263
|
-
this._model.browser = new samples_pb_1.Samples_ClientSample_Browser(Object.assign({}, sample.browser));
|
|
264
|
-
const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
|
|
265
|
-
type: callMetaReports_1.CallMetaType.BROWSER,
|
|
266
|
-
payload: sample.browser,
|
|
267
|
-
}, this.userId);
|
|
268
|
-
this.reports.addCallMetaReport(callMetaReport);
|
|
269
|
-
executeSave = true;
|
|
270
|
-
}
|
|
271
|
-
for (const mediaConstraint of (_l = sample.mediaConstraints) !== null && _l !== void 0 ? _l : []) {
|
|
272
|
-
const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
|
|
273
|
-
type: callMetaReports_1.CallMetaType.MEDIA_CONSTRAINT,
|
|
274
|
-
payload: mediaConstraint,
|
|
275
|
-
}, this.userId);
|
|
276
|
-
this.reports.addCallMetaReport(callMetaReport);
|
|
277
|
-
}
|
|
278
|
-
for (const localSDP of (_m = sample.localSDPs) !== null && _m !== void 0 ? _m : []) {
|
|
279
|
-
const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
|
|
280
|
-
type: callMetaReports_1.CallMetaType.LOCAL_SDP,
|
|
281
|
-
payload: localSDP,
|
|
282
|
-
}, this.userId);
|
|
283
|
-
this.reports.addCallMetaReport(callMetaReport);
|
|
284
|
-
}
|
|
285
|
-
for (const extensionStats of (_o = sample.extensionStats) !== null && _o !== void 0 ? _o : []) {
|
|
286
|
-
this.reports.addClientExtensionReport({
|
|
287
|
-
serviceId: this.serviceId,
|
|
288
|
-
mediaUnitId: this.mediaUnitId,
|
|
289
|
-
roomId: this.roomId,
|
|
290
|
-
callId: this.callId,
|
|
291
|
-
clientId: this.clientId,
|
|
292
|
-
userId: this.userId,
|
|
293
|
-
timestamp: Date.now(),
|
|
294
|
-
payload: extensionStats.payload,
|
|
295
|
-
extensionType: extensionStats.type,
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
for (let _19 of (_p = sample.customCallEvents) !== null && _p !== void 0 ? _p : []) {
|
|
299
|
-
const { timestamp } = _19, callEvent = __rest(_19, ["timestamp"]);
|
|
300
|
-
const peerConnection = this._peerConnections.get((_q = callEvent.peerConnectionId) !== null && _q !== void 0 ? _q : '');
|
|
301
|
-
switch (callEvent.name) {
|
|
302
|
-
case CallEventType_1.CallEventType.CLIENT_JOINED:
|
|
303
|
-
if (timestamp) {
|
|
304
|
-
this.created = timestamp;
|
|
305
|
-
this._model.joined = BigInt(timestamp);
|
|
306
|
-
yield this._save();
|
|
307
|
-
}
|
|
308
|
-
break;
|
|
309
|
-
case CallEventType_1.CallEventType.CLIENT_LEFT:
|
|
310
|
-
this._left = timestamp !== null && timestamp !== void 0 ? timestamp : Date.now();
|
|
311
|
-
break;
|
|
312
|
-
case CallEventType_1.CallEventType.ICE_CONNECTION_STATE_CHANGED:
|
|
313
|
-
peerConnection && callEvent.value && this.emit('iceconnectionstatechange', {
|
|
314
|
-
peerConnection,
|
|
315
|
-
state: callEvent.value,
|
|
316
|
-
});
|
|
317
|
-
break;
|
|
318
|
-
case CallEventType_1.CallEventType.ICE_GATHERING_STATE_CHANGED:
|
|
319
|
-
peerConnection && callEvent.value && this.emit('icegatheringstatechange', {
|
|
320
|
-
peerConnection,
|
|
321
|
-
state: callEvent.value,
|
|
322
|
-
});
|
|
323
|
-
break;
|
|
324
|
-
case CallEventType_1.CallEventType.PEER_CONNECTION_STATE_CHANGED:
|
|
325
|
-
peerConnection && callEvent.value && this.emit('connectionstatechange', {
|
|
326
|
-
peerConnection,
|
|
327
|
-
state: callEvent.value,
|
|
328
|
-
});
|
|
329
|
-
break;
|
|
330
|
-
case CallEventType_1.CallEventType.PEER_CONNECTION_OPENED: {
|
|
331
|
-
if (!callEvent.peerConnectionId)
|
|
332
|
-
break;
|
|
333
|
-
if (peerConnection) {
|
|
334
|
-
peerConnection.created = timestamp !== null && timestamp !== void 0 ? timestamp : peerConnection.created;
|
|
335
|
-
}
|
|
336
|
-
else {
|
|
337
|
-
this.ωpendingCreatedPeerConnectionTimestamp.set(callEvent.peerConnectionId, timestamp !== null && timestamp !== void 0 ? timestamp : Date.now());
|
|
338
|
-
}
|
|
339
|
-
break;
|
|
340
|
-
}
|
|
341
|
-
case CallEventType_1.CallEventType.MEDIA_TRACK_ADDED: {
|
|
342
|
-
if (!callEvent.mediaTrackId)
|
|
343
|
-
break;
|
|
344
|
-
const track = peerConnection === null || peerConnection === void 0 ? void 0 : peerConnection.getTrack(callEvent.mediaTrackId);
|
|
345
|
-
if (track) {
|
|
346
|
-
track.created = timestamp !== null && timestamp !== void 0 ? timestamp : track.created;
|
|
347
|
-
}
|
|
348
|
-
else {
|
|
349
|
-
this.ωpendingCreatedTracksTimestamp.set(callEvent.mediaTrackId, timestamp !== null && timestamp !== void 0 ? timestamp : Date.now());
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
this.reports.addCallEventReport(Object.assign({ serviceId: this.serviceId, mediaUnitId: this.mediaUnitId, roomId: this.roomId, callId: this.callId, clientId: this.clientId, userId: this.userId, timestamp: timestamp !== null && timestamp !== void 0 ? timestamp : Date.now() }, callEvent));
|
|
354
|
-
}
|
|
355
|
-
for (const userMediaError of (_r = sample.userMediaErrors) !== null && _r !== void 0 ? _r : []) {
|
|
356
|
-
const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
|
|
357
|
-
type: callMetaReports_1.CallMetaType.USER_MEDIA_ERROR,
|
|
358
|
-
payload: userMediaError,
|
|
359
|
-
}, this.userId);
|
|
360
|
-
this.reports.addCallMetaReport(callMetaReport);
|
|
361
|
-
this.userMediaErrors.push(userMediaError);
|
|
362
|
-
}
|
|
363
|
-
for (const certificate of (_s = sample.certificates) !== null && _s !== void 0 ? _s : []) {
|
|
364
|
-
const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
|
|
365
|
-
type: callMetaReports_1.CallMetaType.CERTIFICATE,
|
|
366
|
-
payload: certificate,
|
|
367
|
-
}, this.userId);
|
|
368
|
-
this.reports.addCallMetaReport(callMetaReport);
|
|
369
|
-
}
|
|
370
|
-
for (const codec of (_t = sample.codecs) !== null && _t !== void 0 ? _t : []) {
|
|
371
|
-
const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
|
|
372
|
-
type: callMetaReports_1.CallMetaType.CODEC,
|
|
373
|
-
payload: codec,
|
|
374
|
-
}, this.userId);
|
|
375
|
-
this.reports.addCallMetaReport(callMetaReport);
|
|
376
|
-
codec.mimeType && this.codecs.push(codec.mimeType);
|
|
377
|
-
}
|
|
378
|
-
for (const iceServer of (_u = sample.iceServers) !== null && _u !== void 0 ? _u : []) {
|
|
379
|
-
const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
|
|
380
|
-
type: callMetaReports_1.CallMetaType.ICE_SERVER,
|
|
381
|
-
payload: iceServer,
|
|
382
|
-
}, this.userId);
|
|
383
|
-
this.reports.addCallMetaReport(callMetaReport);
|
|
384
|
-
}
|
|
385
|
-
for (const mediaDevice of (_v = sample.mediaDevices) !== null && _v !== void 0 ? _v : []) {
|
|
386
|
-
const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
|
|
387
|
-
type: callMetaReports_1.CallMetaType.MEDIA_DEVICE,
|
|
388
|
-
payload: mediaDevice,
|
|
389
|
-
}, this.userId);
|
|
390
|
-
this.reports.addCallMetaReport(callMetaReport);
|
|
391
|
-
mediaDevice.label && this.mediaDevices.push(mediaDevice.label);
|
|
392
|
-
}
|
|
393
|
-
for (const mediaSource of (_w = sample.mediaSources) !== null && _w !== void 0 ? _w : []) {
|
|
394
|
-
const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
|
|
395
|
-
type: callMetaReports_1.CallMetaType.MEDIA_SOURCE,
|
|
396
|
-
payload: mediaSource,
|
|
397
|
-
}, this.userId);
|
|
398
|
-
this.reports.addCallMetaReport(callMetaReport);
|
|
399
|
-
}
|
|
400
|
-
for (const transport of (_x = sample.pcTransports) !== null && _x !== void 0 ? _x : []) {
|
|
401
|
-
try {
|
|
402
|
-
const peerConnection = (_y = this._peerConnections.get(transport.transportId)) !== null && _y !== void 0 ? _y : yield this._createPeerConnection(transport.peerConnectionId);
|
|
403
|
-
yield peerConnection.update(transport, sample.timestamp);
|
|
404
|
-
}
|
|
405
|
-
catch (err) {
|
|
406
|
-
logger.error(`Error creating peer connection: ${err === null || err === void 0 ? void 0 : err.message}`);
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
for (const track of (_z = sample.inboundAudioTracks) !== null && _z !== void 0 ? _z : []) {
|
|
410
|
-
if (!track.peerConnectionId || !track.trackId) {
|
|
411
|
-
logger.warn(`InboundAudioTrack without peerConnectionId or trackId: ${JSON.stringify(track)}`);
|
|
412
|
-
continue;
|
|
413
|
-
}
|
|
414
|
-
try {
|
|
415
|
-
const peerConnection = (_0 = this._peerConnections.get(track.peerConnectionId)) !== null && _0 !== void 0 ? _0 : yield this._createPeerConnection(track.peerConnectionId);
|
|
416
|
-
if (!peerConnection)
|
|
417
|
-
continue;
|
|
418
|
-
const inboundAudioTrack = (_1 = peerConnection.inboundAudioTracks.get(track.trackId)) !== null && _1 !== void 0 ? _1 : yield peerConnection.createInboundAudioTrack({
|
|
419
|
-
trackId: track.trackId,
|
|
420
|
-
sfuStreamId: track.sfuStreamId,
|
|
421
|
-
sfuSinkId: track.sfuSinkId,
|
|
422
|
-
});
|
|
423
|
-
yield inboundAudioTrack.update(track, sample.timestamp);
|
|
424
|
-
const remoteOutboundTrack = this.call.sfuStreamIdToOutboundAudioTrack.get((_2 = track.sfuStreamId) !== null && _2 !== void 0 ? _2 : '');
|
|
425
|
-
if (remoteOutboundTrack && inboundAudioTrack.sfuStreamId && !remoteOutboundTrack.remoteInboundTracks.has(inboundAudioTrack.sfuStreamId)) {
|
|
426
|
-
remoteOutboundTrack.connectInboundTrack(inboundAudioTrack);
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
catch (err) {
|
|
430
|
-
logger.error(`Error creating inbound audio track: ${err === null || err === void 0 ? void 0 : err.message}`);
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
for (const track of (_3 = sample.inboundVideoTracks) !== null && _3 !== void 0 ? _3 : []) {
|
|
434
|
-
if (!track.peerConnectionId || !track.trackId) {
|
|
435
|
-
logger.warn(`InboundVideoTrack without peerConnectionId or trackId: ${JSON.stringify(track)}`);
|
|
436
|
-
continue;
|
|
437
|
-
}
|
|
438
|
-
if ((0, utils_1.isValidUuid)(track.trackId) === false) {
|
|
439
|
-
// mediasoup-probator trackId is not a valid UUID, no need to warn about it
|
|
440
|
-
if (track.trackId === 'probator')
|
|
441
|
-
continue;
|
|
442
|
-
logger.warn(`InboundVideoTrack with invalid trackId: ${track.trackId}`);
|
|
443
|
-
continue;
|
|
444
|
-
}
|
|
445
|
-
try {
|
|
446
|
-
const peerConnection = (_4 = this._peerConnections.get(track.peerConnectionId)) !== null && _4 !== void 0 ? _4 : yield this._createPeerConnection(track.peerConnectionId);
|
|
447
|
-
if (!peerConnection)
|
|
448
|
-
continue;
|
|
449
|
-
const inboundVideoTrack = (_5 = peerConnection.inboundVideoTracks.get(track.trackId)) !== null && _5 !== void 0 ? _5 : yield peerConnection.createInboundVideoTrack({
|
|
450
|
-
trackId: track.trackId,
|
|
451
|
-
sfuStreamId: track.sfuStreamId,
|
|
452
|
-
sfuSinkId: track.sfuSinkId,
|
|
453
|
-
});
|
|
454
|
-
yield inboundVideoTrack.update(track, sample.timestamp);
|
|
455
|
-
const remoteOutboundTrack = this.call.sfuStreamIdToOutboundVideoTrack.get((_6 = inboundVideoTrack.sfuStreamId) !== null && _6 !== void 0 ? _6 : '');
|
|
456
|
-
if (remoteOutboundTrack && inboundVideoTrack.sfuStreamId && !remoteOutboundTrack.remoteInboundTracks.has(inboundVideoTrack.sfuStreamId)) {
|
|
457
|
-
remoteOutboundTrack.connectInboundTrack(inboundVideoTrack);
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
catch (err) {
|
|
461
|
-
logger.error(`Error creating inbound video track: ${err === null || err === void 0 ? void 0 : err.message}`);
|
|
462
|
-
}
|
|
266
|
+
catch (err) {
|
|
267
|
+
logger.error(`Error creating peer connection: ${err === null || err === void 0 ? void 0 : err.message}`);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
for (const track of (_y = sample.inboundAudioTracks) !== null && _y !== void 0 ? _y : []) {
|
|
271
|
+
if (!track.peerConnectionId || !track.trackId) {
|
|
272
|
+
logger.warn(`InboundAudioTrack without peerConnectionId or trackId: ${JSON.stringify(track)}`);
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
try {
|
|
276
|
+
const peerConnection = (_z = this._peerConnections.get(track.peerConnectionId)) !== null && _z !== void 0 ? _z : this._createPeerConnection(track.peerConnectionId);
|
|
277
|
+
if (!peerConnection)
|
|
278
|
+
continue;
|
|
279
|
+
const inboundAudioTrack = (_0 = peerConnection.inboundAudioTracks.get(track.trackId)) !== null && _0 !== void 0 ? _0 : peerConnection.createInboundAudioTrack({
|
|
280
|
+
trackId: track.trackId,
|
|
281
|
+
sfuStreamId: track.sfuStreamId,
|
|
282
|
+
sfuSinkId: track.sfuSinkId,
|
|
283
|
+
});
|
|
284
|
+
inboundAudioTrack.update(track, sample.timestamp);
|
|
285
|
+
const remoteOutboundTrack = this.call.sfuStreamIdToOutboundAudioTrack.get((_1 = track.sfuStreamId) !== null && _1 !== void 0 ? _1 : '');
|
|
286
|
+
if (remoteOutboundTrack && inboundAudioTrack.sfuStreamId && !remoteOutboundTrack.remoteInboundTracks.has(inboundAudioTrack.sfuStreamId)) {
|
|
287
|
+
remoteOutboundTrack.connectInboundTrack(inboundAudioTrack);
|
|
463
288
|
}
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
289
|
+
}
|
|
290
|
+
catch (err) {
|
|
291
|
+
logger.error(`Error creating inbound audio track: ${err === null || err === void 0 ? void 0 : err.message}`);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
for (const track of (_2 = sample.inboundVideoTracks) !== null && _2 !== void 0 ? _2 : []) {
|
|
295
|
+
if (!track.peerConnectionId || !track.trackId) {
|
|
296
|
+
logger.warn(`InboundVideoTrack without peerConnectionId or trackId: ${JSON.stringify(track)}`);
|
|
297
|
+
continue;
|
|
298
|
+
}
|
|
299
|
+
if ((0, utils_1.isValidUuid)(track.trackId) === false) {
|
|
300
|
+
// mediasoup-probator trackId is not a valid UUID, no need to warn about it
|
|
301
|
+
if (track.trackId === 'probator')
|
|
302
|
+
continue;
|
|
303
|
+
logger.warn(`InboundVideoTrack with invalid trackId: ${track.trackId}`);
|
|
304
|
+
continue;
|
|
305
|
+
}
|
|
306
|
+
try {
|
|
307
|
+
const peerConnection = (_3 = this._peerConnections.get(track.peerConnectionId)) !== null && _3 !== void 0 ? _3 : this._createPeerConnection(track.peerConnectionId);
|
|
308
|
+
if (!peerConnection)
|
|
309
|
+
continue;
|
|
310
|
+
const inboundVideoTrack = (_4 = peerConnection.inboundVideoTracks.get(track.trackId)) !== null && _4 !== void 0 ? _4 : peerConnection.createInboundVideoTrack({
|
|
311
|
+
trackId: track.trackId,
|
|
312
|
+
sfuStreamId: track.sfuStreamId,
|
|
313
|
+
sfuSinkId: track.sfuSinkId,
|
|
314
|
+
});
|
|
315
|
+
inboundVideoTrack.update(track, sample.timestamp);
|
|
316
|
+
const remoteOutboundTrack = this.call.sfuStreamIdToOutboundVideoTrack.get((_5 = inboundVideoTrack.sfuStreamId) !== null && _5 !== void 0 ? _5 : '');
|
|
317
|
+
if (remoteOutboundTrack && inboundVideoTrack.sfuStreamId && !remoteOutboundTrack.remoteInboundTracks.has(inboundVideoTrack.sfuStreamId)) {
|
|
318
|
+
remoteOutboundTrack.connectInboundTrack(inboundVideoTrack);
|
|
482
319
|
}
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
320
|
+
}
|
|
321
|
+
catch (err) {
|
|
322
|
+
logger.error(`Error creating inbound video track: ${err === null || err === void 0 ? void 0 : err.message}`);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
for (const track of (_6 = sample.outboundAudioTracks) !== null && _6 !== void 0 ? _6 : []) {
|
|
326
|
+
if (!track.peerConnectionId || !track.trackId) {
|
|
327
|
+
logger.warn(`OutboundAudioTrack without peerConnectionId or trackId: ${JSON.stringify(track)}`);
|
|
328
|
+
continue;
|
|
329
|
+
}
|
|
330
|
+
try {
|
|
331
|
+
const peerConnection = (_7 = this._peerConnections.get(track.peerConnectionId)) !== null && _7 !== void 0 ? _7 : this._createPeerConnection(track.peerConnectionId);
|
|
332
|
+
if (!peerConnection)
|
|
333
|
+
continue;
|
|
334
|
+
const outboundAudioTrack = (_8 = peerConnection.outboundAudioTracks.get(track.trackId)) !== null && _8 !== void 0 ? _8 : peerConnection.createOutboundAudioTrack({
|
|
335
|
+
trackId: track.trackId,
|
|
336
|
+
sfuStreamId: track.sfuStreamId,
|
|
337
|
+
});
|
|
338
|
+
outboundAudioTrack.update(track, sample.timestamp);
|
|
339
|
+
}
|
|
340
|
+
catch (err) {
|
|
341
|
+
logger.error(`Error creating outbound audio track: ${err === null || err === void 0 ? void 0 : err.message}`);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
for (const track of (_9 = sample.outboundVideoTracks) !== null && _9 !== void 0 ? _9 : []) {
|
|
345
|
+
if (!track.peerConnectionId || !track.trackId) {
|
|
346
|
+
logger.warn(`OutboundVideoTrack without peerConnectionId or trackId: ${JSON.stringify(track)}`);
|
|
347
|
+
continue;
|
|
348
|
+
}
|
|
349
|
+
try {
|
|
350
|
+
const peerConnection = (_10 = this._peerConnections.get(track.peerConnectionId)) !== null && _10 !== void 0 ? _10 : this._createPeerConnection(track.peerConnectionId);
|
|
351
|
+
if (!peerConnection)
|
|
352
|
+
continue;
|
|
353
|
+
const outboundVideoTrack = (_11 = peerConnection.outboundVideoTracks.get(track.trackId)) !== null && _11 !== void 0 ? _11 : peerConnection.createOutboundVideoTrack({
|
|
354
|
+
trackId: track.trackId,
|
|
355
|
+
sfuStreamId: track.sfuStreamId,
|
|
356
|
+
});
|
|
357
|
+
outboundVideoTrack.update(track, sample.timestamp);
|
|
358
|
+
}
|
|
359
|
+
catch (err) {
|
|
360
|
+
logger.error(`Error creating outbound video track: ${err === null || err === void 0 ? void 0 : err.message}`);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
for (const iceLocalCandidate of (_12 = sample.iceLocalCandidates) !== null && _12 !== void 0 ? _12 : []) {
|
|
364
|
+
if (!iceLocalCandidate.peerConnectionId) {
|
|
365
|
+
logger.warn(`Local ice candidate without peerConnectionId: ${JSON.stringify(iceLocalCandidate)}`);
|
|
366
|
+
continue;
|
|
367
|
+
}
|
|
368
|
+
const peerConnection = this._peerConnections.get(iceLocalCandidate.peerConnectionId);
|
|
369
|
+
if (!peerConnection) {
|
|
370
|
+
logger.debug(`Peer connection ${iceLocalCandidate.peerConnectionId} not found for ice local candidate ${iceLocalCandidate.id}`);
|
|
371
|
+
continue;
|
|
372
|
+
}
|
|
373
|
+
peerConnection.ICE.addLocalCandidate(iceLocalCandidate);
|
|
374
|
+
}
|
|
375
|
+
for (const iceRemoteCandidate of (_13 = sample.iceRemoteCandidates) !== null && _13 !== void 0 ? _13 : []) {
|
|
376
|
+
if (!iceRemoteCandidate.peerConnectionId) {
|
|
377
|
+
logger.warn(`Remote ice candidate without peerConnectionId: ${JSON.stringify(iceRemoteCandidate)}`);
|
|
378
|
+
continue;
|
|
379
|
+
}
|
|
380
|
+
const peerConnection = this._peerConnections.get(iceRemoteCandidate.peerConnectionId);
|
|
381
|
+
if (!peerConnection) {
|
|
382
|
+
logger.debug(`Peer connection ${iceRemoteCandidate.peerConnectionId} not found for ice remote candidate ${iceRemoteCandidate.id}`);
|
|
383
|
+
continue;
|
|
384
|
+
}
|
|
385
|
+
peerConnection.ICE.addRemoteCandidate(iceRemoteCandidate);
|
|
386
|
+
}
|
|
387
|
+
for (const candidatePair of (_14 = sample.iceCandidatePairs) !== null && _14 !== void 0 ? _14 : []) {
|
|
388
|
+
const peerConnection = this._peerConnections.get(candidatePair.peerConnectionId);
|
|
389
|
+
if (!peerConnection) {
|
|
390
|
+
logger.debug(`Peer connection ${candidatePair.peerConnectionId} not found for ice candidate pair ${candidatePair.localCandidateId}, ${candidatePair.remoteCandidateId}`);
|
|
391
|
+
continue;
|
|
392
|
+
}
|
|
393
|
+
peerConnection.ICE.update(candidatePair, sample.timestamp);
|
|
394
|
+
}
|
|
395
|
+
for (const dataChannel of (_15 = sample.dataChannels) !== null && _15 !== void 0 ? _15 : []) {
|
|
396
|
+
if (!dataChannel.peerConnectionId || !dataChannel.dataChannelIdentifier) {
|
|
397
|
+
logger.warn(`DataChannel without peerConnectionId or dataChannelIdentifier: ${JSON.stringify(dataChannel)}`);
|
|
398
|
+
continue;
|
|
399
|
+
}
|
|
400
|
+
try {
|
|
401
|
+
const peerConnection = (_16 = this._peerConnections.get(dataChannel.peerConnectionId)) !== null && _16 !== void 0 ? _16 : this._createPeerConnection(dataChannel.peerConnectionId);
|
|
402
|
+
if (!peerConnection)
|
|
403
|
+
continue;
|
|
404
|
+
const observedDataChannel = (_17 = peerConnection.dataChannels.get(dataChannel.dataChannelIdentifier)) !== null && _17 !== void 0 ? _17 : peerConnection.createDataChannel(dataChannel.dataChannelIdentifier);
|
|
405
|
+
observedDataChannel.update(dataChannel, sample.timestamp);
|
|
406
|
+
}
|
|
407
|
+
catch (err) {
|
|
408
|
+
logger.error(`Error creating data channel: ${err === null || err === void 0 ? void 0 : err.message}`);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
// close entries that are idle for too long
|
|
412
|
+
if (this.call.observer.config.maxEntryIdleTimeInMs && this._updated < sample.timestamp) {
|
|
413
|
+
for (const peerConnection of this._peerConnections.values()) {
|
|
414
|
+
if (this.call.observer.config.maxEntryIdleTimeInMs < peerConnection.created - peerConnection.updated) {
|
|
415
|
+
logger.debug(`Closing peer connection ${peerConnection.peerConnectionId} due to inactivity`);
|
|
416
|
+
peerConnection.close();
|
|
417
|
+
continue;
|
|
501
418
|
}
|
|
502
|
-
for (const
|
|
503
|
-
if (
|
|
504
|
-
logger.
|
|
505
|
-
|
|
419
|
+
for (const track of peerConnection.inboundAudioTracks.values()) {
|
|
420
|
+
if (this.call.observer.config.maxEntryIdleTimeInMs < track.created - track.updated) {
|
|
421
|
+
logger.debug(`Closing inbound audio track ${track.trackId} due to inactivity`);
|
|
422
|
+
track.close();
|
|
506
423
|
}
|
|
507
|
-
const peerConnection = this._peerConnections.get(iceLocalCandidate.peerConnectionId);
|
|
508
|
-
if (!peerConnection) {
|
|
509
|
-
logger.debug(`Peer connection ${iceLocalCandidate.peerConnectionId} not found for ice local candidate ${iceLocalCandidate.id}`);
|
|
510
|
-
continue;
|
|
511
|
-
}
|
|
512
|
-
peerConnection.ICE.addLocalCandidate(iceLocalCandidate);
|
|
513
424
|
}
|
|
514
|
-
for (const
|
|
515
|
-
if (
|
|
516
|
-
logger.
|
|
517
|
-
|
|
518
|
-
}
|
|
519
|
-
const peerConnection = this._peerConnections.get(iceRemoteCandidate.peerConnectionId);
|
|
520
|
-
if (!peerConnection) {
|
|
521
|
-
logger.debug(`Peer connection ${iceRemoteCandidate.peerConnectionId} not found for ice remote candidate ${iceRemoteCandidate.id}`);
|
|
522
|
-
continue;
|
|
425
|
+
for (const track of peerConnection.inboundVideoTracks.values()) {
|
|
426
|
+
if (this.call.observer.config.maxEntryIdleTimeInMs < track.created - track.updated) {
|
|
427
|
+
logger.debug(`Closing inbound video track ${track.trackId} due to inactivity`);
|
|
428
|
+
track.close();
|
|
523
429
|
}
|
|
524
|
-
peerConnection.ICE.addRemoteCandidate(iceRemoteCandidate);
|
|
525
430
|
}
|
|
526
|
-
for (const
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
continue;
|
|
431
|
+
for (const track of peerConnection.outboundAudioTracks.values()) {
|
|
432
|
+
if (this.call.observer.config.maxEntryIdleTimeInMs < track.created - track.updated) {
|
|
433
|
+
logger.debug(`Closing outbound audio track ${track.trackId} due to inactivity`);
|
|
434
|
+
track.close();
|
|
531
435
|
}
|
|
532
|
-
peerConnection.ICE.update(candidatePair, sample.timestamp);
|
|
533
436
|
}
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
logger.debug(`Closing peer connection ${peerConnection.peerConnectionId} due to inactivity`);
|
|
539
|
-
peerConnection.close();
|
|
540
|
-
continue;
|
|
541
|
-
}
|
|
542
|
-
for (const track of peerConnection.inboundAudioTracks.values()) {
|
|
543
|
-
if (this.call.observer.config.maxEntryIdleTimeInMs < sample.timestamp - track.updated) {
|
|
544
|
-
logger.debug(`Closing inbound audio track ${track.trackId} due to inactivity`);
|
|
545
|
-
track.close();
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
for (const track of peerConnection.inboundVideoTracks.values()) {
|
|
549
|
-
if (this.call.observer.config.maxEntryIdleTimeInMs < sample.timestamp - track.updated) {
|
|
550
|
-
logger.debug(`Closing inbound video track ${track.trackId} due to inactivity`);
|
|
551
|
-
track.close();
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
for (const track of peerConnection.outboundAudioTracks.values()) {
|
|
555
|
-
if (this.call.observer.config.maxEntryIdleTimeInMs < sample.timestamp - track.updated) {
|
|
556
|
-
logger.debug(`Closing outbound audio track ${track.trackId} due to inactivity`);
|
|
557
|
-
track.close();
|
|
558
|
-
}
|
|
559
|
-
}
|
|
437
|
+
for (const dataChannel of peerConnection.dataChannels.values()) {
|
|
438
|
+
if (this.call.observer.config.maxEntryIdleTimeInMs < dataChannel.created - dataChannel.updated) {
|
|
439
|
+
logger.debug(`Closing DataChannel ${dataChannel.channelId} due to inactivity`);
|
|
440
|
+
dataChannel.close();
|
|
560
441
|
}
|
|
561
442
|
}
|
|
562
|
-
// update metrics
|
|
563
|
-
const wasUsingTURN = this.usingTURN;
|
|
564
|
-
this.usingTURN = false;
|
|
565
|
-
this.availableIncomingBitrate = 0;
|
|
566
|
-
this.availableOutgoingBitrate = 0;
|
|
567
|
-
this.totalSentBytes = 0;
|
|
568
|
-
this.totalReceivedBytes = 0;
|
|
569
|
-
this.totalOutboundPacketsSent = 0;
|
|
570
|
-
this.totalInboundPacketsReceived = 0;
|
|
571
|
-
this.totalInboundPacketsLost = 0;
|
|
572
|
-
this.totalDataChannelBytesSent = 0;
|
|
573
|
-
this.totalDataChannelBytesReceived = 0;
|
|
574
|
-
this.sendingBitrate = 0;
|
|
575
|
-
this.receivingBitrate = 0;
|
|
576
|
-
let sumRttInMs = 0;
|
|
577
|
-
for (const peerConnection of this._peerConnections.values()) {
|
|
578
|
-
if (peerConnection.closed)
|
|
579
|
-
continue;
|
|
580
|
-
peerConnection.updateMetrics();
|
|
581
|
-
this.totalSentBytes += peerConnection.totalSentAudioBytes + peerConnection.totalSentVideoBytes;
|
|
582
|
-
this.totalReceivedBytes += peerConnection.totalReceivedAudioBytes + peerConnection.totalReceivedVideoBytes;
|
|
583
|
-
this.totalOutboundPacketsSent += peerConnection.totalOutboundPacketsSent;
|
|
584
|
-
this.totalInboundPacketsReceived += peerConnection.totalInboundPacketsReceived;
|
|
585
|
-
this.totalInboundPacketsLost += peerConnection.totalInboundPacketsLost;
|
|
586
|
-
this.totalDataChannelBytesSent += peerConnection.totalDataChannelBytesSent;
|
|
587
|
-
this.totalDataChannelBytesReceived += peerConnection.totalDataChannelBytesReceived;
|
|
588
|
-
this.sendingBitrate += peerConnection.sendingAudioBitrate + peerConnection.sendingVideoBitrate;
|
|
589
|
-
this.receivingBitrate += peerConnection.receivingAudioBitrate + peerConnection.receivingVideoBitrate;
|
|
590
|
-
this.availableIncomingBitrate += (_16 = peerConnection.availableIncomingBitrate) !== null && _16 !== void 0 ? _16 : 0;
|
|
591
|
-
this.availableOutgoingBitrate += (_17 = peerConnection.availableOutgoingBitrate) !== null && _17 !== void 0 ? _17 : 0;
|
|
592
|
-
sumRttInMs += (_18 = peerConnection.avgRttInMs) !== null && _18 !== void 0 ? _18 : 0;
|
|
593
|
-
if (peerConnection.usingTURN)
|
|
594
|
-
this.usingTURN = true;
|
|
595
|
-
}
|
|
596
|
-
this.avgRttInMs = this._peerConnections.size ? sumRttInMs / this._peerConnections.size : undefined;
|
|
597
|
-
if (executeSave)
|
|
598
|
-
yield this._save();
|
|
599
|
-
if (wasUsingTURN !== this.usingTURN)
|
|
600
|
-
this.emit('usingturn', this.usingTURN);
|
|
601
|
-
this._updated = sample.timestamp;
|
|
602
|
-
this.emit('update');
|
|
603
|
-
})).finally(() => {
|
|
604
|
-
--this._processingSample;
|
|
605
|
-
});
|
|
606
|
-
});
|
|
607
|
-
}
|
|
608
|
-
_createPeerConnection(peerConnectionId) {
|
|
609
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
610
|
-
const result = yield ObservedPeerConnection_1.ObservedPeerConnection.create({
|
|
611
|
-
peerConnectionId,
|
|
612
|
-
}, this, this._storageProvider);
|
|
613
|
-
const pendingTracksTimestamp = this.ωpendingCreatedTracksTimestamp.get(peerConnectionId);
|
|
614
|
-
if (pendingTracksTimestamp) {
|
|
615
|
-
result.created = pendingTracksTimestamp;
|
|
616
|
-
this.ωpendingCreatedTracksTimestamp.delete(peerConnectionId);
|
|
617
443
|
}
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
444
|
+
}
|
|
445
|
+
// update metrics
|
|
446
|
+
const wasUsingTURN = this.usingTURN;
|
|
447
|
+
this.usingTURN = false;
|
|
448
|
+
this.availableIncomingBitrate = 0;
|
|
449
|
+
this.availableOutgoingBitrate = 0;
|
|
450
|
+
this.totalSentBytes = 0;
|
|
451
|
+
this.totalReceivedBytes = 0;
|
|
452
|
+
this.totalOutboundPacketsSent = 0;
|
|
453
|
+
this.totalInboundPacketsReceived = 0;
|
|
454
|
+
this.totalInboundPacketsLost = 0;
|
|
455
|
+
this.totalDataChannelBytesSent = 0;
|
|
456
|
+
this.totalDataChannelBytesReceived = 0;
|
|
457
|
+
this.sendingBitrate = 0;
|
|
458
|
+
this.receivingBitrate = 0;
|
|
459
|
+
let sumRttInMs = 0;
|
|
460
|
+
for (const peerConnection of this._peerConnections.values()) {
|
|
461
|
+
if (peerConnection.closed)
|
|
462
|
+
continue;
|
|
463
|
+
peerConnection.updateMetrics();
|
|
464
|
+
this.totalSentBytes += peerConnection.totalSentAudioBytes + peerConnection.totalSentVideoBytes;
|
|
465
|
+
this.totalReceivedBytes += peerConnection.totalReceivedAudioBytes + peerConnection.totalReceivedVideoBytes;
|
|
466
|
+
this.totalOutboundPacketsSent += peerConnection.totalOutboundPacketsSent;
|
|
467
|
+
this.totalInboundPacketsReceived += peerConnection.totalInboundPacketsReceived;
|
|
468
|
+
this.totalInboundPacketsLost += peerConnection.totalInboundPacketsLost;
|
|
469
|
+
this.totalDataChannelBytesSent += peerConnection.totalDataChannelBytesSent;
|
|
470
|
+
this.totalDataChannelBytesReceived += peerConnection.totalDataChannelBytesReceived;
|
|
471
|
+
this.sendingBitrate += peerConnection.sendingAudioBitrate + peerConnection.sendingVideoBitrate;
|
|
472
|
+
this.receivingBitrate += peerConnection.receivingAudioBitrate + peerConnection.receivingVideoBitrate;
|
|
473
|
+
this.availableIncomingBitrate += (_18 = peerConnection.availableIncomingBitrate) !== null && _18 !== void 0 ? _18 : 0;
|
|
474
|
+
this.availableOutgoingBitrate += (_19 = peerConnection.availableOutgoingBitrate) !== null && _19 !== void 0 ? _19 : 0;
|
|
475
|
+
sumRttInMs += (_20 = peerConnection.avgRttInMs) !== null && _20 !== void 0 ? _20 : 0;
|
|
476
|
+
if (peerConnection.usingTURN)
|
|
477
|
+
this.usingTURN = true;
|
|
478
|
+
}
|
|
479
|
+
this.avgRttInMs = this._peerConnections.size ? sumRttInMs / this._peerConnections.size : undefined;
|
|
480
|
+
if (wasUsingTURN !== this.usingTURN)
|
|
481
|
+
this.emit('usingturn', this.usingTURN);
|
|
482
|
+
this._updated = now;
|
|
483
|
+
this.emit('update');
|
|
638
484
|
}
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
485
|
+
_createPeerConnection(peerConnectionId, label) {
|
|
486
|
+
const result = new ObservedPeerConnection_1.ObservedPeerConnection({
|
|
487
|
+
peerConnectionId,
|
|
488
|
+
label,
|
|
489
|
+
}, this);
|
|
490
|
+
const onNewSelectedCandidatePair = ({ localCandidate, remoteCandidate }) => {
|
|
491
|
+
this.emit('selectedcandidatepair', {
|
|
492
|
+
peerConnection: result,
|
|
493
|
+
localCandidate,
|
|
494
|
+
remoteCandidate,
|
|
495
|
+
});
|
|
496
|
+
};
|
|
497
|
+
result.once('close', () => {
|
|
498
|
+
result.ICE.off('new-selected-candidate-pair', onNewSelectedCandidatePair);
|
|
499
|
+
this._peerConnections.delete(peerConnectionId);
|
|
644
500
|
});
|
|
501
|
+
result.ICE.on('new-selected-candidate-pair', onNewSelectedCandidatePair);
|
|
502
|
+
this._peerConnections.set(peerConnectionId, result);
|
|
503
|
+
this.emit('newpeerconnection', result);
|
|
504
|
+
return result;
|
|
645
505
|
}
|
|
646
506
|
_addClientLeftReport() {
|
|
647
507
|
if (this._left)
|
|
648
508
|
return;
|
|
649
509
|
this._left = Date.now();
|
|
650
|
-
this.reports.addCallEventReport((0, callEventReports_1.createClientLeftEventReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, this.
|
|
510
|
+
this.reports.addCallEventReport((0, callEventReports_1.createClientLeftEventReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, this._left, this.userId, this.marker));
|
|
651
511
|
}
|
|
652
512
|
}
|
|
653
513
|
exports.ObservedClient = ObservedClient;
|