@observertc/observer-js 0.30.5-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/CallSummary.d.ts +22 -0
- package/lib/CallSummary.d.ts.map +1 -0
- 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 +14 -4
- package/lib/ObservedSfu.d.ts.map +1 -1
- package/lib/ObservedSfu.js +37 -50
- 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/CallSummary.ts +23 -0
- 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 +45 -27
- 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/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/{storages/ObserverStorage.js → CallSummary.js} +0 -0
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,383 @@ 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;
|
|
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
|
+
++this._acceptedSample;
|
|
125
|
+
for (const peerConnection of this._peerConnections.values()) {
|
|
126
|
+
if (peerConnection.closed)
|
|
127
|
+
continue;
|
|
128
|
+
peerConnection.resetMetrics();
|
|
129
|
+
}
|
|
130
|
+
if (this.userId !== sample.userId) {
|
|
131
|
+
this._model.userId = sample.userId;
|
|
132
|
+
}
|
|
133
|
+
if (this._model.marker !== sample.marker) {
|
|
134
|
+
this._model.marker = sample.marker;
|
|
135
|
+
}
|
|
136
|
+
if (this._timeZoneOffsetInHours !== sample.timeZoneOffsetInHours) {
|
|
137
|
+
this._timeZoneOffsetInHours = sample.timeZoneOffsetInHours;
|
|
138
|
+
}
|
|
139
|
+
if (sample.os && (((_a = this._model.operationSystem) === null || _a === void 0 ? void 0 : _a.name) !== sample.os.name ||
|
|
140
|
+
((_b = this._model.operationSystem) === null || _b === void 0 ? void 0 : _b.version) !== sample.os.version ||
|
|
141
|
+
((_c = this._model.operationSystem) === null || _c === void 0 ? void 0 : _c.versionName) !== sample.os.versionName)) {
|
|
142
|
+
this._model.operationSystem = sample.os;
|
|
143
|
+
const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
|
|
144
|
+
type: callMetaReports_1.CallMetaType.OPERATION_SYSTEM,
|
|
145
|
+
payload: sample.os,
|
|
146
|
+
}, this.userId);
|
|
147
|
+
this.reports.addCallMetaReport(callMetaReport);
|
|
148
|
+
}
|
|
149
|
+
if (sample.engine && (((_d = this._model.engine) === null || _d === void 0 ? void 0 : _d.name) !== sample.engine.name ||
|
|
150
|
+
((_e = this._model.engine) === null || _e === void 0 ? void 0 : _e.version) !== sample.engine.version)) {
|
|
151
|
+
this._model.engine = sample.engine;
|
|
152
|
+
const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
|
|
153
|
+
type: callMetaReports_1.CallMetaType.ENGINE,
|
|
154
|
+
payload: sample.engine,
|
|
155
|
+
}, this.userId);
|
|
156
|
+
this.reports.addCallMetaReport(callMetaReport);
|
|
157
|
+
}
|
|
158
|
+
if (sample.platform && (((_f = this._model.platform) === null || _f === void 0 ? void 0 : _f.model) !== sample.platform.model ||
|
|
159
|
+
((_g = this._model.platform) === null || _g === void 0 ? void 0 : _g.type) !== sample.platform.type ||
|
|
160
|
+
((_h = this._model.platform) === null || _h === void 0 ? void 0 : _h.vendor) !== sample.platform.vendor)) {
|
|
161
|
+
this._model.platform = sample.platform;
|
|
162
|
+
const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
|
|
163
|
+
type: callMetaReports_1.CallMetaType.PLATFORM,
|
|
164
|
+
payload: sample.platform,
|
|
165
|
+
}, this.userId);
|
|
166
|
+
this.reports.addCallMetaReport(callMetaReport);
|
|
167
|
+
}
|
|
168
|
+
if (sample.browser && (((_j = this._model.browser) === null || _j === void 0 ? void 0 : _j.name) !== sample.browser.name ||
|
|
169
|
+
((_k = this._model.browser) === null || _k === void 0 ? void 0 : _k.version) !== sample.browser.version)) {
|
|
170
|
+
this._model.browser = sample.browser;
|
|
171
|
+
const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
|
|
172
|
+
type: callMetaReports_1.CallMetaType.BROWSER,
|
|
173
|
+
payload: sample.browser,
|
|
174
|
+
}, this.userId);
|
|
175
|
+
this.reports.addCallMetaReport(callMetaReport);
|
|
176
|
+
}
|
|
177
|
+
for (const mediaConstraint of (_l = sample.mediaConstraints) !== null && _l !== void 0 ? _l : []) {
|
|
178
|
+
const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
|
|
179
|
+
type: callMetaReports_1.CallMetaType.MEDIA_CONSTRAINT,
|
|
180
|
+
payload: mediaConstraint,
|
|
181
|
+
}, this.userId);
|
|
182
|
+
this.reports.addCallMetaReport(callMetaReport);
|
|
183
|
+
}
|
|
184
|
+
for (const localSDP of (_m = sample.localSDPs) !== null && _m !== void 0 ? _m : []) {
|
|
185
|
+
const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
|
|
186
|
+
type: callMetaReports_1.CallMetaType.LOCAL_SDP,
|
|
187
|
+
payload: localSDP,
|
|
188
|
+
}, this.userId);
|
|
189
|
+
this.reports.addCallMetaReport(callMetaReport);
|
|
190
|
+
}
|
|
191
|
+
for (const extensionStats of (_o = sample.extensionStats) !== null && _o !== void 0 ? _o : []) {
|
|
192
|
+
this.reports.addClientExtensionReport({
|
|
193
|
+
serviceId: this.serviceId,
|
|
194
|
+
mediaUnitId: this.mediaUnitId,
|
|
195
|
+
roomId: this.roomId,
|
|
196
|
+
callId: this.callId,
|
|
197
|
+
clientId: this.clientId,
|
|
198
|
+
userId: this.userId,
|
|
199
|
+
timestamp: Date.now(),
|
|
200
|
+
payload: extensionStats.payload,
|
|
201
|
+
extensionType: extensionStats.type,
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
for (let _18 of (_p = sample.customCallEvents) !== null && _p !== void 0 ? _p : []) {
|
|
205
|
+
const { timestamp } = _18, callEvent = __rest(_18, ["timestamp"]);
|
|
206
|
+
switch (callEvent.name) {
|
|
207
|
+
case CallEventType_1.CallEventType.CLIENT_LEFT: {
|
|
208
|
+
this._left = timestamp;
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
202
211
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
212
|
+
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));
|
|
213
|
+
}
|
|
214
|
+
for (const userMediaError of (_q = sample.userMediaErrors) !== null && _q !== void 0 ? _q : []) {
|
|
215
|
+
const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
|
|
216
|
+
type: callMetaReports_1.CallMetaType.USER_MEDIA_ERROR,
|
|
217
|
+
payload: userMediaError,
|
|
218
|
+
}, this.userId);
|
|
219
|
+
this.reports.addCallMetaReport(callMetaReport);
|
|
220
|
+
this.userMediaErrors.push(userMediaError);
|
|
221
|
+
}
|
|
222
|
+
for (const certificate of (_r = sample.certificates) !== null && _r !== void 0 ? _r : []) {
|
|
223
|
+
const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
|
|
224
|
+
type: callMetaReports_1.CallMetaType.CERTIFICATE,
|
|
225
|
+
payload: certificate,
|
|
226
|
+
}, this.userId);
|
|
227
|
+
this.reports.addCallMetaReport(callMetaReport);
|
|
228
|
+
}
|
|
229
|
+
for (const codec of (_s = sample.codecs) !== null && _s !== void 0 ? _s : []) {
|
|
230
|
+
const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
|
|
231
|
+
type: callMetaReports_1.CallMetaType.CODEC,
|
|
232
|
+
payload: codec,
|
|
233
|
+
}, this.userId);
|
|
234
|
+
this.reports.addCallMetaReport(callMetaReport);
|
|
235
|
+
codec.mimeType && this.codecs.push(codec.mimeType);
|
|
236
|
+
}
|
|
237
|
+
for (const iceServer of (_t = sample.iceServers) !== null && _t !== void 0 ? _t : []) {
|
|
238
|
+
const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
|
|
239
|
+
type: callMetaReports_1.CallMetaType.ICE_SERVER,
|
|
240
|
+
payload: iceServer,
|
|
241
|
+
}, this.userId);
|
|
242
|
+
this.reports.addCallMetaReport(callMetaReport);
|
|
243
|
+
}
|
|
244
|
+
for (const mediaDevice of (_u = sample.mediaDevices) !== null && _u !== void 0 ? _u : []) {
|
|
245
|
+
const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
|
|
246
|
+
type: callMetaReports_1.CallMetaType.MEDIA_DEVICE,
|
|
247
|
+
payload: mediaDevice,
|
|
248
|
+
}, this.userId);
|
|
249
|
+
this.reports.addCallMetaReport(callMetaReport);
|
|
250
|
+
mediaDevice.label && this.mediaDevices.push(mediaDevice.label);
|
|
251
|
+
}
|
|
252
|
+
for (const mediaSource of (_v = sample.mediaSources) !== null && _v !== void 0 ? _v : []) {
|
|
253
|
+
const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
|
|
254
|
+
type: callMetaReports_1.CallMetaType.MEDIA_SOURCE,
|
|
255
|
+
payload: mediaSource,
|
|
256
|
+
}, this.userId);
|
|
257
|
+
this.reports.addCallMetaReport(callMetaReport);
|
|
258
|
+
}
|
|
259
|
+
for (const transport of (_w = sample.pcTransports) !== null && _w !== void 0 ? _w : []) {
|
|
260
|
+
try {
|
|
261
|
+
const peerConnection = (_x = this._peerConnections.get(transport.transportId)) !== null && _x !== void 0 ? _x : this._createPeerConnection(transport.peerConnectionId);
|
|
262
|
+
!peerConnection.label && transport.label && (peerConnection.label = transport.label);
|
|
263
|
+
peerConnection.update(transport, sample.timestamp);
|
|
207
264
|
}
|
|
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
|
-
}
|
|
463
|
-
}
|
|
464
|
-
for (const track of (_7 = sample.outboundAudioTracks) !== null && _7 !== void 0 ? _7 : []) {
|
|
465
|
-
if (!track.peerConnectionId || !track.trackId) {
|
|
466
|
-
logger.warn(`OutboundAudioTrack without peerConnectionId or trackId: ${JSON.stringify(track)}`);
|
|
467
|
-
continue;
|
|
468
|
-
}
|
|
469
|
-
try {
|
|
470
|
-
const peerConnection = (_8 = this._peerConnections.get(track.peerConnectionId)) !== null && _8 !== void 0 ? _8 : yield this._createPeerConnection(track.peerConnectionId);
|
|
471
|
-
if (!peerConnection)
|
|
472
|
-
continue;
|
|
473
|
-
const outboundAudioTrack = (_9 = peerConnection.outboundAudioTracks.get(track.trackId)) !== null && _9 !== void 0 ? _9 : yield peerConnection.createOutboundAudioTrack({
|
|
474
|
-
trackId: track.trackId,
|
|
475
|
-
sfuStreamId: track.sfuStreamId,
|
|
476
|
-
});
|
|
477
|
-
yield outboundAudioTrack.update(track, sample.timestamp);
|
|
478
|
-
}
|
|
479
|
-
catch (err) {
|
|
480
|
-
logger.error(`Error creating outbound audio track: ${err === null || err === void 0 ? void 0 : err.message}`);
|
|
481
|
-
}
|
|
265
|
+
catch (err) {
|
|
266
|
+
logger.error(`Error creating peer connection: ${err === null || err === void 0 ? void 0 : err.message}`);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
for (const track of (_y = sample.inboundAudioTracks) !== null && _y !== void 0 ? _y : []) {
|
|
270
|
+
if (!track.peerConnectionId || !track.trackId) {
|
|
271
|
+
logger.warn(`InboundAudioTrack without peerConnectionId or trackId: ${JSON.stringify(track)}`);
|
|
272
|
+
continue;
|
|
273
|
+
}
|
|
274
|
+
try {
|
|
275
|
+
const peerConnection = (_z = this._peerConnections.get(track.peerConnectionId)) !== null && _z !== void 0 ? _z : this._createPeerConnection(track.peerConnectionId);
|
|
276
|
+
if (!peerConnection)
|
|
277
|
+
continue;
|
|
278
|
+
const inboundAudioTrack = (_0 = peerConnection.inboundAudioTracks.get(track.trackId)) !== null && _0 !== void 0 ? _0 : peerConnection.createInboundAudioTrack({
|
|
279
|
+
trackId: track.trackId,
|
|
280
|
+
sfuStreamId: track.sfuStreamId,
|
|
281
|
+
sfuSinkId: track.sfuSinkId,
|
|
282
|
+
});
|
|
283
|
+
inboundAudioTrack.update(track, sample.timestamp);
|
|
284
|
+
const remoteOutboundTrack = this.call.sfuStreamIdToOutboundAudioTrack.get((_1 = track.sfuStreamId) !== null && _1 !== void 0 ? _1 : '');
|
|
285
|
+
if (remoteOutboundTrack && inboundAudioTrack.sfuStreamId && !remoteOutboundTrack.remoteInboundTracks.has(inboundAudioTrack.sfuStreamId)) {
|
|
286
|
+
remoteOutboundTrack.connectInboundTrack(inboundAudioTrack);
|
|
482
287
|
}
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
288
|
+
}
|
|
289
|
+
catch (err) {
|
|
290
|
+
logger.error(`Error creating inbound audio track: ${err === null || err === void 0 ? void 0 : err.message}`);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
for (const track of (_2 = sample.inboundVideoTracks) !== null && _2 !== void 0 ? _2 : []) {
|
|
294
|
+
if (!track.peerConnectionId || !track.trackId) {
|
|
295
|
+
logger.warn(`InboundVideoTrack without peerConnectionId or trackId: ${JSON.stringify(track)}`);
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
if ((0, utils_1.isValidUuid)(track.trackId) === false) {
|
|
299
|
+
// mediasoup-probator trackId is not a valid UUID, no need to warn about it
|
|
300
|
+
if (track.trackId === 'probator')
|
|
301
|
+
continue;
|
|
302
|
+
logger.warn(`InboundVideoTrack with invalid trackId: ${track.trackId}`);
|
|
303
|
+
continue;
|
|
304
|
+
}
|
|
305
|
+
try {
|
|
306
|
+
const peerConnection = (_3 = this._peerConnections.get(track.peerConnectionId)) !== null && _3 !== void 0 ? _3 : this._createPeerConnection(track.peerConnectionId);
|
|
307
|
+
if (!peerConnection)
|
|
308
|
+
continue;
|
|
309
|
+
const inboundVideoTrack = (_4 = peerConnection.inboundVideoTracks.get(track.trackId)) !== null && _4 !== void 0 ? _4 : peerConnection.createInboundVideoTrack({
|
|
310
|
+
trackId: track.trackId,
|
|
311
|
+
sfuStreamId: track.sfuStreamId,
|
|
312
|
+
sfuSinkId: track.sfuSinkId,
|
|
313
|
+
});
|
|
314
|
+
inboundVideoTrack.update(track, sample.timestamp);
|
|
315
|
+
const remoteOutboundTrack = this.call.sfuStreamIdToOutboundVideoTrack.get((_5 = inboundVideoTrack.sfuStreamId) !== null && _5 !== void 0 ? _5 : '');
|
|
316
|
+
if (remoteOutboundTrack && inboundVideoTrack.sfuStreamId && !remoteOutboundTrack.remoteInboundTracks.has(inboundVideoTrack.sfuStreamId)) {
|
|
317
|
+
remoteOutboundTrack.connectInboundTrack(inboundVideoTrack);
|
|
501
318
|
}
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
319
|
+
}
|
|
320
|
+
catch (err) {
|
|
321
|
+
logger.error(`Error creating inbound video track: ${err === null || err === void 0 ? void 0 : err.message}`);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
for (const track of (_6 = sample.outboundAudioTracks) !== null && _6 !== void 0 ? _6 : []) {
|
|
325
|
+
if (!track.peerConnectionId || !track.trackId) {
|
|
326
|
+
logger.warn(`OutboundAudioTrack without peerConnectionId or trackId: ${JSON.stringify(track)}`);
|
|
327
|
+
continue;
|
|
328
|
+
}
|
|
329
|
+
try {
|
|
330
|
+
const peerConnection = (_7 = this._peerConnections.get(track.peerConnectionId)) !== null && _7 !== void 0 ? _7 : this._createPeerConnection(track.peerConnectionId);
|
|
331
|
+
if (!peerConnection)
|
|
332
|
+
continue;
|
|
333
|
+
const outboundAudioTrack = (_8 = peerConnection.outboundAudioTracks.get(track.trackId)) !== null && _8 !== void 0 ? _8 : peerConnection.createOutboundAudioTrack({
|
|
334
|
+
trackId: track.trackId,
|
|
335
|
+
sfuStreamId: track.sfuStreamId,
|
|
336
|
+
});
|
|
337
|
+
outboundAudioTrack.update(track, sample.timestamp);
|
|
338
|
+
}
|
|
339
|
+
catch (err) {
|
|
340
|
+
logger.error(`Error creating outbound audio track: ${err === null || err === void 0 ? void 0 : err.message}`);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
for (const track of (_9 = sample.outboundVideoTracks) !== null && _9 !== void 0 ? _9 : []) {
|
|
344
|
+
if (!track.peerConnectionId || !track.trackId) {
|
|
345
|
+
logger.warn(`OutboundVideoTrack without peerConnectionId or trackId: ${JSON.stringify(track)}`);
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
try {
|
|
349
|
+
const peerConnection = (_10 = this._peerConnections.get(track.peerConnectionId)) !== null && _10 !== void 0 ? _10 : this._createPeerConnection(track.peerConnectionId);
|
|
350
|
+
if (!peerConnection)
|
|
351
|
+
continue;
|
|
352
|
+
const outboundVideoTrack = (_11 = peerConnection.outboundVideoTracks.get(track.trackId)) !== null && _11 !== void 0 ? _11 : peerConnection.createOutboundVideoTrack({
|
|
353
|
+
trackId: track.trackId,
|
|
354
|
+
sfuStreamId: track.sfuStreamId,
|
|
355
|
+
});
|
|
356
|
+
outboundVideoTrack.update(track, sample.timestamp);
|
|
357
|
+
}
|
|
358
|
+
catch (err) {
|
|
359
|
+
logger.error(`Error creating outbound video track: ${err === null || err === void 0 ? void 0 : err.message}`);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
for (const iceLocalCandidate of (_12 = sample.iceLocalCandidates) !== null && _12 !== void 0 ? _12 : []) {
|
|
363
|
+
if (!iceLocalCandidate.peerConnectionId) {
|
|
364
|
+
logger.warn(`Local ice candidate without peerConnectionId: ${JSON.stringify(iceLocalCandidate)}`);
|
|
365
|
+
continue;
|
|
366
|
+
}
|
|
367
|
+
const peerConnection = this._peerConnections.get(iceLocalCandidate.peerConnectionId);
|
|
368
|
+
if (!peerConnection) {
|
|
369
|
+
logger.debug(`Peer connection ${iceLocalCandidate.peerConnectionId} not found for ice local candidate ${iceLocalCandidate.id}`);
|
|
370
|
+
continue;
|
|
371
|
+
}
|
|
372
|
+
peerConnection.ICE.addLocalCandidate(iceLocalCandidate);
|
|
373
|
+
}
|
|
374
|
+
for (const iceRemoteCandidate of (_13 = sample.iceRemoteCandidates) !== null && _13 !== void 0 ? _13 : []) {
|
|
375
|
+
if (!iceRemoteCandidate.peerConnectionId) {
|
|
376
|
+
logger.warn(`Remote ice candidate without peerConnectionId: ${JSON.stringify(iceRemoteCandidate)}`);
|
|
377
|
+
continue;
|
|
378
|
+
}
|
|
379
|
+
const peerConnection = this._peerConnections.get(iceRemoteCandidate.peerConnectionId);
|
|
380
|
+
if (!peerConnection) {
|
|
381
|
+
logger.debug(`Peer connection ${iceRemoteCandidate.peerConnectionId} not found for ice remote candidate ${iceRemoteCandidate.id}`);
|
|
382
|
+
continue;
|
|
383
|
+
}
|
|
384
|
+
peerConnection.ICE.addRemoteCandidate(iceRemoteCandidate);
|
|
385
|
+
}
|
|
386
|
+
for (const candidatePair of (_14 = sample.iceCandidatePairs) !== null && _14 !== void 0 ? _14 : []) {
|
|
387
|
+
const peerConnection = this._peerConnections.get(candidatePair.peerConnectionId);
|
|
388
|
+
if (!peerConnection) {
|
|
389
|
+
logger.debug(`Peer connection ${candidatePair.peerConnectionId} not found for ice candidate pair ${candidatePair.localCandidateId}, ${candidatePair.remoteCandidateId}`);
|
|
390
|
+
continue;
|
|
391
|
+
}
|
|
392
|
+
peerConnection.ICE.update(candidatePair, sample.timestamp);
|
|
393
|
+
}
|
|
394
|
+
// close entries that are idle for too long
|
|
395
|
+
if (this.call.observer.config.maxEntryIdleTimeInMs && this._updated < sample.timestamp) {
|
|
396
|
+
for (const peerConnection of this._peerConnections.values()) {
|
|
397
|
+
if (this.call.observer.config.maxEntryIdleTimeInMs < sample.timestamp - peerConnection.updated) {
|
|
398
|
+
logger.debug(`Closing peer connection ${peerConnection.peerConnectionId} due to inactivity`);
|
|
399
|
+
peerConnection.close();
|
|
400
|
+
continue;
|
|
513
401
|
}
|
|
514
|
-
for (const
|
|
515
|
-
if (
|
|
516
|
-
logger.
|
|
517
|
-
|
|
402
|
+
for (const track of peerConnection.inboundAudioTracks.values()) {
|
|
403
|
+
if (this.call.observer.config.maxEntryIdleTimeInMs < sample.timestamp - track.updated) {
|
|
404
|
+
logger.debug(`Closing inbound audio track ${track.trackId} due to inactivity`);
|
|
405
|
+
track.close();
|
|
518
406
|
}
|
|
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;
|
|
523
|
-
}
|
|
524
|
-
peerConnection.ICE.addRemoteCandidate(iceRemoteCandidate);
|
|
525
407
|
}
|
|
526
|
-
for (const
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
continue;
|
|
408
|
+
for (const track of peerConnection.inboundVideoTracks.values()) {
|
|
409
|
+
if (this.call.observer.config.maxEntryIdleTimeInMs < sample.timestamp - track.updated) {
|
|
410
|
+
logger.debug(`Closing inbound video track ${track.trackId} due to inactivity`);
|
|
411
|
+
track.close();
|
|
531
412
|
}
|
|
532
|
-
peerConnection.ICE.update(candidatePair, sample.timestamp);
|
|
533
413
|
}
|
|
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
|
-
}
|
|
414
|
+
for (const track of peerConnection.outboundAudioTracks.values()) {
|
|
415
|
+
if (this.call.observer.config.maxEntryIdleTimeInMs < sample.timestamp - track.updated) {
|
|
416
|
+
logger.debug(`Closing outbound audio track ${track.trackId} due to inactivity`);
|
|
417
|
+
track.close();
|
|
560
418
|
}
|
|
561
419
|
}
|
|
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
420
|
}
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
421
|
+
}
|
|
422
|
+
// update metrics
|
|
423
|
+
const wasUsingTURN = this.usingTURN;
|
|
424
|
+
this.usingTURN = false;
|
|
425
|
+
this.availableIncomingBitrate = 0;
|
|
426
|
+
this.availableOutgoingBitrate = 0;
|
|
427
|
+
this.totalSentBytes = 0;
|
|
428
|
+
this.totalReceivedBytes = 0;
|
|
429
|
+
this.totalOutboundPacketsSent = 0;
|
|
430
|
+
this.totalInboundPacketsReceived = 0;
|
|
431
|
+
this.totalInboundPacketsLost = 0;
|
|
432
|
+
this.totalDataChannelBytesSent = 0;
|
|
433
|
+
this.totalDataChannelBytesReceived = 0;
|
|
434
|
+
this.sendingBitrate = 0;
|
|
435
|
+
this.receivingBitrate = 0;
|
|
436
|
+
let sumRttInMs = 0;
|
|
437
|
+
for (const peerConnection of this._peerConnections.values()) {
|
|
438
|
+
if (peerConnection.closed)
|
|
439
|
+
continue;
|
|
440
|
+
peerConnection.updateMetrics();
|
|
441
|
+
this.totalSentBytes += peerConnection.totalSentAudioBytes + peerConnection.totalSentVideoBytes;
|
|
442
|
+
this.totalReceivedBytes += peerConnection.totalReceivedAudioBytes + peerConnection.totalReceivedVideoBytes;
|
|
443
|
+
this.totalOutboundPacketsSent += peerConnection.totalOutboundPacketsSent;
|
|
444
|
+
this.totalInboundPacketsReceived += peerConnection.totalInboundPacketsReceived;
|
|
445
|
+
this.totalInboundPacketsLost += peerConnection.totalInboundPacketsLost;
|
|
446
|
+
this.totalDataChannelBytesSent += peerConnection.totalDataChannelBytesSent;
|
|
447
|
+
this.totalDataChannelBytesReceived += peerConnection.totalDataChannelBytesReceived;
|
|
448
|
+
this.sendingBitrate += peerConnection.sendingAudioBitrate + peerConnection.sendingVideoBitrate;
|
|
449
|
+
this.receivingBitrate += peerConnection.receivingAudioBitrate + peerConnection.receivingVideoBitrate;
|
|
450
|
+
this.availableIncomingBitrate += (_15 = peerConnection.availableIncomingBitrate) !== null && _15 !== void 0 ? _15 : 0;
|
|
451
|
+
this.availableOutgoingBitrate += (_16 = peerConnection.availableOutgoingBitrate) !== null && _16 !== void 0 ? _16 : 0;
|
|
452
|
+
sumRttInMs += (_17 = peerConnection.avgRttInMs) !== null && _17 !== void 0 ? _17 : 0;
|
|
453
|
+
if (peerConnection.usingTURN)
|
|
454
|
+
this.usingTURN = true;
|
|
455
|
+
}
|
|
456
|
+
this.avgRttInMs = this._peerConnections.size ? sumRttInMs / this._peerConnections.size : undefined;
|
|
457
|
+
if (wasUsingTURN !== this.usingTURN)
|
|
458
|
+
this.emit('usingturn', this.usingTURN);
|
|
459
|
+
this._updated = Date.now();
|
|
460
|
+
this.emit('update');
|
|
638
461
|
}
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
462
|
+
_createPeerConnection(peerConnectionId, label) {
|
|
463
|
+
const result = new ObservedPeerConnection_1.ObservedPeerConnection({
|
|
464
|
+
peerConnectionId,
|
|
465
|
+
label,
|
|
466
|
+
}, this);
|
|
467
|
+
const onNewSelectedCandidatePair = ({ localCandidate, remoteCandidate }) => {
|
|
468
|
+
this.emit('selectedcandidatepair', {
|
|
469
|
+
peerConnection: result,
|
|
470
|
+
localCandidate,
|
|
471
|
+
remoteCandidate,
|
|
472
|
+
});
|
|
473
|
+
};
|
|
474
|
+
result.once('close', () => {
|
|
475
|
+
result.ICE.off('new-selected-candidate-pair', onNewSelectedCandidatePair);
|
|
476
|
+
this._peerConnections.delete(peerConnectionId);
|
|
644
477
|
});
|
|
478
|
+
result.ICE.on('new-selected-candidate-pair', onNewSelectedCandidatePair);
|
|
479
|
+
this._peerConnections.set(peerConnectionId, result);
|
|
480
|
+
this.emit('newpeerconnection', result);
|
|
481
|
+
return result;
|
|
645
482
|
}
|
|
646
483
|
_addClientLeftReport() {
|
|
647
484
|
if (this._left)
|
|
648
485
|
return;
|
|
649
486
|
this._left = Date.now();
|
|
650
|
-
this.reports.addCallEventReport((0, callEventReports_1.createClientLeftEventReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, this.
|
|
487
|
+
this.reports.addCallEventReport((0, callEventReports_1.createClientLeftEventReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, this._left, this.userId, this.marker));
|
|
651
488
|
}
|
|
652
489
|
}
|
|
653
490
|
exports.ObservedClient = ObservedClient;
|