@observertc/observer-js 0.30.1-beta → 0.30.3-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/ObservedClient.d.ts +15 -6
- package/lib/ObservedClient.d.ts.map +1 -1
- package/lib/ObservedClient.js +146 -73
- package/lib/ObservedICE.d.ts +47 -0
- package/lib/ObservedICE.d.ts.map +1 -0
- package/lib/ObservedICE.js +105 -0
- package/lib/ObservedInboundTrack.d.ts +29 -1
- package/lib/ObservedInboundTrack.d.ts.map +1 -1
- package/lib/ObservedInboundTrack.js +78 -8
- package/lib/ObservedOutboundTrack.d.ts +20 -3
- package/lib/ObservedOutboundTrack.d.ts.map +1 -1
- package/lib/ObservedOutboundTrack.js +53 -9
- package/lib/ObservedPeerConnection.d.ts +47 -1
- package/lib/ObservedPeerConnection.d.ts.map +1 -1
- package/lib/ObservedPeerConnection.js +155 -0
- package/lib/common/CallEventType.d.ts +22 -0
- package/lib/common/CallEventType.d.ts.map +1 -0
- package/lib/common/CallEventType.js +26 -0
- package/lib/common/callEventReports.d.ts +0 -10
- package/lib/common/callEventReports.d.ts.map +1 -1
- package/lib/common/callEventReports.js +10 -21
- package/lib/models/Models.d.ts +3 -70
- package/lib/models/Models.d.ts.map +1 -1
- package/lib/models/Models.js +2 -72
- package/lib/models/samples_pb.js +1 -1
- package/package.json +1 -1
- package/src/ObservedClient.ts +146 -89
- package/src/ObservedICE.ts +176 -0
- package/src/ObservedInboundTrack.ts +97 -3
- package/src/ObservedOutboundTrack.ts +70 -9
- package/src/ObservedPeerConnection.ts +205 -1
- package/src/common/CallEventType.ts +23 -0
- package/src/common/callEventReports.ts +1 -11
- package/src/models/Models.ts +4 -113
- package/src/models/samples_pb.ts +1 -1
- package/lib/common/ReportsCollector.d.ts +0 -23
- package/lib/common/ReportsCollector.d.ts.map +0 -1
- package/lib/common/ReportsCollector.js +0 -26
- package/src/common/ReportsCollector.ts +0 -71
package/lib/ObservedClient.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { ClientSample
|
|
2
|
+
import { ClientSample } from '@observertc/sample-schemas-js';
|
|
3
3
|
import { ObservedCall } from './ObservedCall';
|
|
4
4
|
import { StorageProvider } from './storages/StorageProvider';
|
|
5
5
|
import { EventEmitter } from 'events';
|
|
@@ -21,7 +21,6 @@ export type ObservedClientEvents = {
|
|
|
21
21
|
update: [];
|
|
22
22
|
close: [];
|
|
23
23
|
'processing-sample-overflow': [];
|
|
24
|
-
'candidate-pair-change': [];
|
|
25
24
|
newpeerconnection: [ObservedPeerConnection];
|
|
26
25
|
};
|
|
27
26
|
export declare interface ObservedClient<AppData extends Record<string, unknown> = Record<string, unknown>> {
|
|
@@ -37,6 +36,7 @@ export declare class ObservedClient<AppData extends Record<string, unknown> = Re
|
|
|
37
36
|
private readonly _storageProvider;
|
|
38
37
|
readonly appData: AppData;
|
|
39
38
|
static create<T extends Record<string, unknown> = Record<string, unknown>>(config: ObservedClientConfig<T>, call: ObservedCall, storageProvider: StorageProvider): Promise<ObservedClient<T>>;
|
|
39
|
+
created: number;
|
|
40
40
|
private readonly _peerConnections;
|
|
41
41
|
private readonly _execute;
|
|
42
42
|
private _overflowingProcessingThreshold;
|
|
@@ -44,13 +44,23 @@ export declare class ObservedClient<AppData extends Record<string, unknown> = Re
|
|
|
44
44
|
private _updated;
|
|
45
45
|
private _acceptedSample;
|
|
46
46
|
private _processingSample;
|
|
47
|
-
private _selectedLocalIceCandidate?;
|
|
48
|
-
private _selectedRemoteIceCandidate?;
|
|
49
47
|
private _timeZoneOffsetInHours?;
|
|
50
48
|
private _leaveReported;
|
|
49
|
+
totalInboundPacketsLost: number;
|
|
50
|
+
totalInboundPacketsReceived: number;
|
|
51
|
+
totalOutboundPacketsSent: number;
|
|
52
|
+
totalDataChannelBytesSent: number;
|
|
53
|
+
totalDataChannelBytesReceived: number;
|
|
54
|
+
totalSentBytes: number;
|
|
55
|
+
totalReceivedBytes: number;
|
|
56
|
+
avgRttInS?: number;
|
|
57
|
+
sendingBitrate?: number;
|
|
58
|
+
receivingBitrate?: number;
|
|
51
59
|
readonly mediaDevices: string[];
|
|
52
60
|
readonly codecs: string[];
|
|
53
61
|
readonly userMediaErrors: string[];
|
|
62
|
+
readonly ωpendingCreatedTracksTimestamp: Map<string, number>;
|
|
63
|
+
readonly ωpendingCreatedPeerConnectionTimestamp: Map<string, number>;
|
|
54
64
|
private constructor();
|
|
55
65
|
get joined(): number;
|
|
56
66
|
get clientId(): string;
|
|
@@ -60,8 +70,6 @@ export declare class ObservedClient<AppData extends Record<string, unknown> = Re
|
|
|
60
70
|
get mediaUnitId(): string;
|
|
61
71
|
get reports(): import("./ReportsCollector").ReportsCollector;
|
|
62
72
|
get userId(): string | undefined;
|
|
63
|
-
get selectedLocalIceCandidate(): IceLocalCandidate | undefined;
|
|
64
|
-
get selectedRemoteIceCandidate(): IceLocalCandidate | undefined;
|
|
65
73
|
get timeZoneOffsetInHours(): number | undefined;
|
|
66
74
|
get marker(): string | undefined;
|
|
67
75
|
get browser(): Samples_ClientSample_Browser | undefined;
|
|
@@ -70,6 +78,7 @@ export declare class ObservedClient<AppData extends Record<string, unknown> = Re
|
|
|
70
78
|
get platform(): Samples_ClientSample_Platform | undefined;
|
|
71
79
|
get acceptedSample(): number;
|
|
72
80
|
get updated(): number;
|
|
81
|
+
get uptimeInMs(): number;
|
|
73
82
|
get closed(): boolean;
|
|
74
83
|
get peerConnections(): ReadonlyMap<string, ObservedPeerConnection>;
|
|
75
84
|
close(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ObservedClient.d.ts","sourceRoot":"","sources":["../src/ObservedClient.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"ObservedClient.d.ts","sourceRoot":"","sources":["../src/ObservedClient.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,MAA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.js
CHANGED
|
@@ -54,6 +54,7 @@ const callMetaReports_1 = require("./common/callMetaReports");
|
|
|
54
54
|
const samples_pb_1 = require("./models/samples_pb");
|
|
55
55
|
const utils_1 = require("./common/utils");
|
|
56
56
|
const callEventReports_1 = require("./common/callEventReports");
|
|
57
|
+
const CallEventType_1 = require("./common/CallEventType");
|
|
57
58
|
const logger = (0, logger_1.createLogger)('ObservedClient');
|
|
58
59
|
class ObservedClient extends events_1.EventEmitter {
|
|
59
60
|
static create(config, call, storageProvider) {
|
|
@@ -87,6 +88,7 @@ class ObservedClient extends events_1.EventEmitter {
|
|
|
87
88
|
this.call = call;
|
|
88
89
|
this._storageProvider = _storageProvider;
|
|
89
90
|
this.appData = appData;
|
|
91
|
+
this.created = Date.now();
|
|
90
92
|
this._peerConnections = new Map();
|
|
91
93
|
this._execute = (0, SingleExecutor_1.createSingleExecutor)();
|
|
92
94
|
this._overflowingProcessingThreshold = 0;
|
|
@@ -95,9 +97,18 @@ class ObservedClient extends events_1.EventEmitter {
|
|
|
95
97
|
this._acceptedSample = 0;
|
|
96
98
|
this._processingSample = 0;
|
|
97
99
|
this._leaveReported = false;
|
|
100
|
+
this.totalInboundPacketsLost = 0;
|
|
101
|
+
this.totalInboundPacketsReceived = 0;
|
|
102
|
+
this.totalOutboundPacketsSent = 0;
|
|
103
|
+
this.totalDataChannelBytesSent = 0;
|
|
104
|
+
this.totalDataChannelBytesReceived = 0;
|
|
105
|
+
this.totalSentBytes = 0;
|
|
106
|
+
this.totalReceivedBytes = 0;
|
|
98
107
|
this.mediaDevices = [];
|
|
99
108
|
this.codecs = [];
|
|
100
109
|
this.userMediaErrors = [];
|
|
110
|
+
this.ωpendingCreatedTracksTimestamp = new Map();
|
|
111
|
+
this.ωpendingCreatedPeerConnectionTimestamp = new Map();
|
|
101
112
|
}
|
|
102
113
|
get joined() {
|
|
103
114
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
@@ -129,12 +140,6 @@ class ObservedClient extends events_1.EventEmitter {
|
|
|
129
140
|
get userId() {
|
|
130
141
|
return this._model.userId;
|
|
131
142
|
}
|
|
132
|
-
get selectedLocalIceCandidate() {
|
|
133
|
-
return this._selectedLocalIceCandidate;
|
|
134
|
-
}
|
|
135
|
-
get selectedRemoteIceCandidate() {
|
|
136
|
-
return this._selectedRemoteIceCandidate;
|
|
137
|
-
}
|
|
138
143
|
get timeZoneOffsetInHours() {
|
|
139
144
|
return this._timeZoneOffsetInHours;
|
|
140
145
|
}
|
|
@@ -159,6 +164,9 @@ class ObservedClient extends events_1.EventEmitter {
|
|
|
159
164
|
get updated() {
|
|
160
165
|
return this._updated;
|
|
161
166
|
}
|
|
167
|
+
get uptimeInMs() {
|
|
168
|
+
return this._updated - this.created;
|
|
169
|
+
}
|
|
162
170
|
get closed() {
|
|
163
171
|
return this._closed;
|
|
164
172
|
}
|
|
@@ -188,6 +196,11 @@ class ObservedClient extends events_1.EventEmitter {
|
|
|
188
196
|
}
|
|
189
197
|
return this._execute(() => __awaiter(this, void 0, void 0, function* () {
|
|
190
198
|
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;
|
|
199
|
+
for (const peerConnection of this._peerConnections.values()) {
|
|
200
|
+
if (peerConnection.closed)
|
|
201
|
+
continue;
|
|
202
|
+
peerConnection.resetMetrics();
|
|
203
|
+
}
|
|
191
204
|
let executeSave = false;
|
|
192
205
|
if (this.userId !== sample.userId) {
|
|
193
206
|
this._model.userId = sample.userId;
|
|
@@ -271,12 +284,50 @@ class ObservedClient extends events_1.EventEmitter {
|
|
|
271
284
|
});
|
|
272
285
|
}
|
|
273
286
|
for (let _17 of (_p = sample.customCallEvents) !== null && _p !== void 0 ? _p : []) {
|
|
274
|
-
const { timestamp
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
287
|
+
const { timestamp } = _17, callEvent = __rest(_17, ["timestamp"]);
|
|
288
|
+
const peerConnection = this._peerConnections.get((_q = callEvent.peerConnectionId) !== null && _q !== void 0 ? _q : '');
|
|
289
|
+
switch (callEvent.name) {
|
|
290
|
+
case CallEventType_1.CallEventType.CLIENT_JOINED:
|
|
291
|
+
this.created = timestamp !== null && timestamp !== void 0 ? timestamp : this.created;
|
|
292
|
+
break;
|
|
293
|
+
case CallEventType_1.CallEventType.CLIENT_LEFT:
|
|
294
|
+
this._leaveReported = true;
|
|
295
|
+
break;
|
|
296
|
+
case CallEventType_1.CallEventType.ICE_CONNECTION_STATE_CHANGED:
|
|
297
|
+
peerConnection && callEvent.value && peerConnection.emit('iceconnectionstatechange', callEvent.value);
|
|
298
|
+
break;
|
|
299
|
+
case CallEventType_1.CallEventType.ICE_GATHERING_STATE_CHANGED:
|
|
300
|
+
peerConnection && callEvent.value && peerConnection.emit('icegatheringstatechange', callEvent.value);
|
|
301
|
+
break;
|
|
302
|
+
case CallEventType_1.CallEventType.PEER_CONNECTION_STATE_CHANGED:
|
|
303
|
+
peerConnection && callEvent.value && peerConnection.emit('connectionstatechange', callEvent.value);
|
|
304
|
+
break;
|
|
305
|
+
case CallEventType_1.CallEventType.PEER_CONNECTION_OPENED: {
|
|
306
|
+
if (!callEvent.peerConnectionId)
|
|
307
|
+
break;
|
|
308
|
+
if (peerConnection) {
|
|
309
|
+
peerConnection.created = timestamp !== null && timestamp !== void 0 ? timestamp : peerConnection.created;
|
|
310
|
+
}
|
|
311
|
+
else {
|
|
312
|
+
this.ωpendingCreatedPeerConnectionTimestamp.set(callEvent.peerConnectionId, timestamp !== null && timestamp !== void 0 ? timestamp : Date.now());
|
|
313
|
+
}
|
|
314
|
+
break;
|
|
315
|
+
}
|
|
316
|
+
case CallEventType_1.CallEventType.MEDIA_TRACK_ADDED: {
|
|
317
|
+
if (!callEvent.mediaTrackId)
|
|
318
|
+
break;
|
|
319
|
+
const track = peerConnection === null || peerConnection === void 0 ? void 0 : peerConnection.getTrack(callEvent.mediaTrackId);
|
|
320
|
+
if (track) {
|
|
321
|
+
track.created = timestamp !== null && timestamp !== void 0 ? timestamp : track.created;
|
|
322
|
+
}
|
|
323
|
+
else {
|
|
324
|
+
this.ωpendingCreatedTracksTimestamp.set(callEvent.mediaTrackId, timestamp !== null && timestamp !== void 0 ? timestamp : Date.now());
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
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));
|
|
278
329
|
}
|
|
279
|
-
for (const userMediaError of (
|
|
330
|
+
for (const userMediaError of (_r = sample.userMediaErrors) !== null && _r !== void 0 ? _r : []) {
|
|
280
331
|
const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
|
|
281
332
|
type: callMetaReports_1.CallMetaType.USER_MEDIA_ERROR,
|
|
282
333
|
payload: userMediaError,
|
|
@@ -284,14 +335,14 @@ class ObservedClient extends events_1.EventEmitter {
|
|
|
284
335
|
this.reports.addCallMetaReport(callMetaReport);
|
|
285
336
|
this.userMediaErrors.push(userMediaError);
|
|
286
337
|
}
|
|
287
|
-
for (const certificate of (
|
|
338
|
+
for (const certificate of (_s = sample.certificates) !== null && _s !== void 0 ? _s : []) {
|
|
288
339
|
const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
|
|
289
340
|
type: callMetaReports_1.CallMetaType.CERTIFICATE,
|
|
290
341
|
payload: certificate,
|
|
291
342
|
}, this.userId);
|
|
292
343
|
this.reports.addCallMetaReport(callMetaReport);
|
|
293
344
|
}
|
|
294
|
-
for (const codec of (
|
|
345
|
+
for (const codec of (_t = sample.codecs) !== null && _t !== void 0 ? _t : []) {
|
|
295
346
|
const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
|
|
296
347
|
type: callMetaReports_1.CallMetaType.CODEC,
|
|
297
348
|
payload: codec,
|
|
@@ -299,14 +350,14 @@ class ObservedClient extends events_1.EventEmitter {
|
|
|
299
350
|
this.reports.addCallMetaReport(callMetaReport);
|
|
300
351
|
codec.mimeType && this.codecs.push(codec.mimeType);
|
|
301
352
|
}
|
|
302
|
-
for (const iceServer of (
|
|
353
|
+
for (const iceServer of (_u = sample.iceServers) !== null && _u !== void 0 ? _u : []) {
|
|
303
354
|
const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
|
|
304
355
|
type: callMetaReports_1.CallMetaType.ICE_SERVER,
|
|
305
356
|
payload: iceServer,
|
|
306
357
|
}, this.userId);
|
|
307
358
|
this.reports.addCallMetaReport(callMetaReport);
|
|
308
359
|
}
|
|
309
|
-
for (const mediaDevice of (
|
|
360
|
+
for (const mediaDevice of (_v = sample.mediaDevices) !== null && _v !== void 0 ? _v : []) {
|
|
310
361
|
const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
|
|
311
362
|
type: callMetaReports_1.CallMetaType.MEDIA_DEVICE,
|
|
312
363
|
payload: mediaDevice,
|
|
@@ -314,77 +365,38 @@ class ObservedClient extends events_1.EventEmitter {
|
|
|
314
365
|
this.reports.addCallMetaReport(callMetaReport);
|
|
315
366
|
mediaDevice.label && this.mediaDevices.push(mediaDevice.label);
|
|
316
367
|
}
|
|
317
|
-
for (const mediaSource of (
|
|
368
|
+
for (const mediaSource of (_w = sample.mediaSources) !== null && _w !== void 0 ? _w : []) {
|
|
318
369
|
const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
|
|
319
370
|
type: callMetaReports_1.CallMetaType.MEDIA_SOURCE,
|
|
320
371
|
payload: mediaSource,
|
|
321
372
|
}, this.userId);
|
|
322
373
|
this.reports.addCallMetaReport(callMetaReport);
|
|
323
374
|
}
|
|
324
|
-
|
|
325
|
-
let selectedRemoteCandidateId;
|
|
326
|
-
for (const candidatePair of (_w = sample.iceCandidatePairs) !== null && _w !== void 0 ? _w : []) {
|
|
327
|
-
if (candidatePair.nominated) {
|
|
328
|
-
if (!selectedLocalCandidateId)
|
|
329
|
-
selectedLocalCandidateId = candidatePair.localCandidateId;
|
|
330
|
-
if (!selectedRemoteCandidateId)
|
|
331
|
-
selectedRemoteCandidateId = candidatePair.remoteCandidateId;
|
|
332
|
-
}
|
|
333
|
-
const report = Object.assign(Object.assign({ serviceId: this.serviceId, mediaUnitId: this.mediaUnitId, roomId: this.roomId, callId: this.callId, clientId: this.clientId, userId: this.userId, timestamp: sample.timestamp }, candidatePair), { sampleSeq: -1 });
|
|
334
|
-
this.reports.addIceCandidatePairReport(report);
|
|
335
|
-
}
|
|
336
|
-
let changeIceCandidatePair = false;
|
|
337
|
-
for (const iceLocalCandidate of (_x = sample.iceLocalCandidates) !== null && _x !== void 0 ? _x : []) {
|
|
338
|
-
if (iceLocalCandidate.id && selectedLocalCandidateId &&
|
|
339
|
-
iceLocalCandidate.id === selectedLocalCandidateId &&
|
|
340
|
-
((_y = this._selectedLocalIceCandidate) === null || _y === void 0 ? void 0 : _y.id) !== iceLocalCandidate.id) {
|
|
341
|
-
this._selectedLocalIceCandidate = iceLocalCandidate;
|
|
342
|
-
changeIceCandidatePair = true;
|
|
343
|
-
}
|
|
344
|
-
const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
|
|
345
|
-
type: callMetaReports_1.CallMetaType.ICE_LOCAL_CANDIDATE,
|
|
346
|
-
payload: iceLocalCandidate,
|
|
347
|
-
}, this.userId);
|
|
348
|
-
this.reports.addCallMetaReport(callMetaReport);
|
|
349
|
-
}
|
|
350
|
-
for (const iceRemoteCandidate of (_z = sample.iceRemoteCandidates) !== null && _z !== void 0 ? _z : []) {
|
|
351
|
-
if (iceRemoteCandidate.id && selectedRemoteCandidateId &&
|
|
352
|
-
iceRemoteCandidate.id === selectedRemoteCandidateId &&
|
|
353
|
-
((_0 = this._selectedRemoteIceCandidate) === null || _0 === void 0 ? void 0 : _0.id) !== iceRemoteCandidate.id) {
|
|
354
|
-
this._selectedRemoteIceCandidate = iceRemoteCandidate;
|
|
355
|
-
changeIceCandidatePair = true;
|
|
356
|
-
}
|
|
357
|
-
const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.serviceId, this.mediaUnitId, this.roomId, this.callId, this.clientId, {
|
|
358
|
-
type: callMetaReports_1.CallMetaType.ICE_REMOTE_CANDIDATE,
|
|
359
|
-
payload: iceRemoteCandidate,
|
|
360
|
-
}, this.userId);
|
|
361
|
-
this.reports.addCallMetaReport(callMetaReport);
|
|
362
|
-
}
|
|
363
|
-
for (const transport of (_1 = sample.pcTransports) !== null && _1 !== void 0 ? _1 : []) {
|
|
375
|
+
for (const transport of (_x = sample.pcTransports) !== null && _x !== void 0 ? _x : []) {
|
|
364
376
|
try {
|
|
365
|
-
const peerConnection = (
|
|
377
|
+
const peerConnection = (_y = this._peerConnections.get(transport.transportId)) !== null && _y !== void 0 ? _y : yield this._createPeerConnection(transport.peerConnectionId);
|
|
366
378
|
peerConnection.update(transport, sample.timestamp);
|
|
367
379
|
}
|
|
368
380
|
catch (err) {
|
|
369
381
|
logger.error(`Error creating peer connection: ${err === null || err === void 0 ? void 0 : err.message}`);
|
|
370
382
|
}
|
|
371
383
|
}
|
|
372
|
-
for (const track of (
|
|
384
|
+
for (const track of (_z = sample.inboundAudioTracks) !== null && _z !== void 0 ? _z : []) {
|
|
373
385
|
if (!track.peerConnectionId || !track.trackId) {
|
|
374
386
|
logger.warn(`InboundAudioTrack without peerConnectionId or trackId: ${JSON.stringify(track)}`);
|
|
375
387
|
continue;
|
|
376
388
|
}
|
|
377
389
|
try {
|
|
378
|
-
const peerConnection = (
|
|
390
|
+
const peerConnection = (_0 = this._peerConnections.get(track.peerConnectionId)) !== null && _0 !== void 0 ? _0 : yield this._createPeerConnection(track.peerConnectionId);
|
|
379
391
|
if (!peerConnection)
|
|
380
392
|
continue;
|
|
381
|
-
const inboundAudioTrack = (
|
|
393
|
+
const inboundAudioTrack = (_1 = peerConnection.inboundAudioTracks.get(track.trackId)) !== null && _1 !== void 0 ? _1 : yield peerConnection.createInboundAudioTrack({
|
|
382
394
|
trackId: track.trackId,
|
|
383
395
|
sfuStreamId: track.sfuStreamId,
|
|
384
396
|
sfuSinkId: track.sfuSinkId,
|
|
385
397
|
});
|
|
386
398
|
yield inboundAudioTrack.update(track, sample.timestamp);
|
|
387
|
-
const remoteOutboundTrack = this.call.sfuStreamIdToOutboundAudioTrack.get((
|
|
399
|
+
const remoteOutboundTrack = this.call.sfuStreamIdToOutboundAudioTrack.get((_2 = track.sfuStreamId) !== null && _2 !== void 0 ? _2 : '');
|
|
388
400
|
if (remoteOutboundTrack && inboundAudioTrack.sfuStreamId && !remoteOutboundTrack.remoteInboundTracks.has(inboundAudioTrack.sfuStreamId)) {
|
|
389
401
|
remoteOutboundTrack.connectInboundTrack(inboundAudioTrack);
|
|
390
402
|
}
|
|
@@ -393,7 +405,7 @@ class ObservedClient extends events_1.EventEmitter {
|
|
|
393
405
|
logger.error(`Error creating inbound audio track: ${err === null || err === void 0 ? void 0 : err.message}`);
|
|
394
406
|
}
|
|
395
407
|
}
|
|
396
|
-
for (const track of (
|
|
408
|
+
for (const track of (_3 = sample.inboundVideoTracks) !== null && _3 !== void 0 ? _3 : []) {
|
|
397
409
|
if (!track.peerConnectionId || !track.trackId) {
|
|
398
410
|
logger.warn(`InboundVideoTrack without peerConnectionId or trackId: ${JSON.stringify(track)}`);
|
|
399
411
|
continue;
|
|
@@ -406,16 +418,16 @@ class ObservedClient extends events_1.EventEmitter {
|
|
|
406
418
|
continue;
|
|
407
419
|
}
|
|
408
420
|
try {
|
|
409
|
-
const peerConnection = (
|
|
421
|
+
const peerConnection = (_4 = this._peerConnections.get(track.peerConnectionId)) !== null && _4 !== void 0 ? _4 : yield this._createPeerConnection(track.peerConnectionId);
|
|
410
422
|
if (!peerConnection)
|
|
411
423
|
continue;
|
|
412
|
-
const inboundVideoTrack = (
|
|
424
|
+
const inboundVideoTrack = (_5 = peerConnection.inboundVideoTracks.get(track.trackId)) !== null && _5 !== void 0 ? _5 : yield peerConnection.createInboundVideoTrack({
|
|
413
425
|
trackId: track.trackId,
|
|
414
426
|
sfuStreamId: track.sfuStreamId,
|
|
415
427
|
sfuSinkId: track.sfuSinkId,
|
|
416
428
|
});
|
|
417
429
|
yield inboundVideoTrack.update(track, sample.timestamp);
|
|
418
|
-
const remoteOutboundTrack = this.call.sfuStreamIdToOutboundVideoTrack.get((
|
|
430
|
+
const remoteOutboundTrack = this.call.sfuStreamIdToOutboundVideoTrack.get((_6 = inboundVideoTrack.sfuStreamId) !== null && _6 !== void 0 ? _6 : '');
|
|
419
431
|
if (remoteOutboundTrack && inboundVideoTrack.sfuStreamId && !remoteOutboundTrack.remoteInboundTracks.has(inboundVideoTrack.sfuStreamId)) {
|
|
420
432
|
remoteOutboundTrack.connectInboundTrack(inboundVideoTrack);
|
|
421
433
|
}
|
|
@@ -424,16 +436,16 @@ class ObservedClient extends events_1.EventEmitter {
|
|
|
424
436
|
logger.error(`Error creating inbound video track: ${err === null || err === void 0 ? void 0 : err.message}`);
|
|
425
437
|
}
|
|
426
438
|
}
|
|
427
|
-
for (const track of (
|
|
439
|
+
for (const track of (_7 = sample.outboundAudioTracks) !== null && _7 !== void 0 ? _7 : []) {
|
|
428
440
|
if (!track.peerConnectionId || !track.trackId) {
|
|
429
441
|
logger.warn(`OutboundAudioTrack without peerConnectionId or trackId: ${JSON.stringify(track)}`);
|
|
430
442
|
continue;
|
|
431
443
|
}
|
|
432
444
|
try {
|
|
433
|
-
const peerConnection = (
|
|
445
|
+
const peerConnection = (_8 = this._peerConnections.get(track.peerConnectionId)) !== null && _8 !== void 0 ? _8 : yield this._createPeerConnection(track.peerConnectionId);
|
|
434
446
|
if (!peerConnection)
|
|
435
447
|
continue;
|
|
436
|
-
const outboundAudioTrack = (
|
|
448
|
+
const outboundAudioTrack = (_9 = peerConnection.outboundAudioTracks.get(track.trackId)) !== null && _9 !== void 0 ? _9 : yield peerConnection.createOutboundAudioTrack({
|
|
437
449
|
trackId: track.trackId,
|
|
438
450
|
sfuStreamId: track.sfuStreamId,
|
|
439
451
|
});
|
|
@@ -443,16 +455,16 @@ class ObservedClient extends events_1.EventEmitter {
|
|
|
443
455
|
logger.error(`Error creating outbound audio track: ${err === null || err === void 0 ? void 0 : err.message}`);
|
|
444
456
|
}
|
|
445
457
|
}
|
|
446
|
-
for (const track of (
|
|
458
|
+
for (const track of (_10 = sample.outboundVideoTracks) !== null && _10 !== void 0 ? _10 : []) {
|
|
447
459
|
if (!track.peerConnectionId || !track.trackId) {
|
|
448
460
|
logger.warn(`OutboundVideoTrack without peerConnectionId or trackId: ${JSON.stringify(track)}`);
|
|
449
461
|
continue;
|
|
450
462
|
}
|
|
451
463
|
try {
|
|
452
|
-
const peerConnection = (
|
|
464
|
+
const peerConnection = (_11 = this._peerConnections.get(track.peerConnectionId)) !== null && _11 !== void 0 ? _11 : yield this._createPeerConnection(track.peerConnectionId);
|
|
453
465
|
if (!peerConnection)
|
|
454
466
|
continue;
|
|
455
|
-
const outboundVideoTrack = (
|
|
467
|
+
const outboundVideoTrack = (_12 = peerConnection.outboundVideoTracks.get(track.trackId)) !== null && _12 !== void 0 ? _12 : yield peerConnection.createOutboundVideoTrack({
|
|
456
468
|
trackId: track.trackId,
|
|
457
469
|
sfuStreamId: track.sfuStreamId,
|
|
458
470
|
});
|
|
@@ -462,6 +474,38 @@ class ObservedClient extends events_1.EventEmitter {
|
|
|
462
474
|
logger.error(`Error creating outbound video track: ${err === null || err === void 0 ? void 0 : err.message}`);
|
|
463
475
|
}
|
|
464
476
|
}
|
|
477
|
+
for (const iceLocalCandidate of (_13 = sample.iceLocalCandidates) !== null && _13 !== void 0 ? _13 : []) {
|
|
478
|
+
if (!iceLocalCandidate.peerConnectionId) {
|
|
479
|
+
logger.warn(`Local ice candidate without peerConnectionId: ${JSON.stringify(iceLocalCandidate)}`);
|
|
480
|
+
continue;
|
|
481
|
+
}
|
|
482
|
+
const peerConnection = this._peerConnections.get(iceLocalCandidate.peerConnectionId);
|
|
483
|
+
if (!peerConnection) {
|
|
484
|
+
logger.debug(`Peer connection ${iceLocalCandidate.peerConnectionId} not found for ice local candidate ${iceLocalCandidate.id}`);
|
|
485
|
+
continue;
|
|
486
|
+
}
|
|
487
|
+
peerConnection.ICE.addLocalCandidate(iceLocalCandidate);
|
|
488
|
+
}
|
|
489
|
+
for (const iceRemoteCandidate of (_14 = sample.iceRemoteCandidates) !== null && _14 !== void 0 ? _14 : []) {
|
|
490
|
+
if (!iceRemoteCandidate.peerConnectionId) {
|
|
491
|
+
logger.warn(`Remote ice candidate without peerConnectionId: ${JSON.stringify(iceRemoteCandidate)}`);
|
|
492
|
+
continue;
|
|
493
|
+
}
|
|
494
|
+
const peerConnection = this._peerConnections.get(iceRemoteCandidate.peerConnectionId);
|
|
495
|
+
if (!peerConnection) {
|
|
496
|
+
logger.debug(`Peer connection ${iceRemoteCandidate.peerConnectionId} not found for ice remote candidate ${iceRemoteCandidate.id}`);
|
|
497
|
+
continue;
|
|
498
|
+
}
|
|
499
|
+
peerConnection.ICE.addRemoteCandidate(iceRemoteCandidate);
|
|
500
|
+
}
|
|
501
|
+
for (const candidatePair of (_15 = sample.iceCandidatePairs) !== null && _15 !== void 0 ? _15 : []) {
|
|
502
|
+
const peerConnection = this._peerConnections.get(candidatePair.peerConnectionId);
|
|
503
|
+
if (!peerConnection) {
|
|
504
|
+
logger.debug(`Peer connection ${candidatePair.peerConnectionId} not found for ice candidate pair ${candidatePair.localCandidateId}, ${candidatePair.remoteCandidateId}`);
|
|
505
|
+
continue;
|
|
506
|
+
}
|
|
507
|
+
peerConnection.ICE.update(candidatePair, sample.timestamp);
|
|
508
|
+
}
|
|
465
509
|
// close entries that are idle for too long
|
|
466
510
|
if (this.call.observer.config.maxEntryIdleTimeInMs && this._updated < sample.timestamp) {
|
|
467
511
|
for (const peerConnection of this._peerConnections.values()) {
|
|
@@ -490,9 +534,33 @@ class ObservedClient extends events_1.EventEmitter {
|
|
|
490
534
|
}
|
|
491
535
|
}
|
|
492
536
|
}
|
|
493
|
-
|
|
494
|
-
|
|
537
|
+
// update metrics
|
|
538
|
+
this.totalSentBytes = 0;
|
|
539
|
+
this.totalReceivedBytes = 0;
|
|
540
|
+
this.totalOutboundPacketsSent = 0;
|
|
541
|
+
this.totalInboundPacketsReceived = 0;
|
|
542
|
+
this.totalInboundPacketsLost = 0;
|
|
543
|
+
this.totalDataChannelBytesSent = 0;
|
|
544
|
+
this.totalDataChannelBytesReceived = 0;
|
|
545
|
+
this.sendingBitrate = 0;
|
|
546
|
+
this.receivingBitrate = 0;
|
|
547
|
+
let sumRttInS = 0;
|
|
548
|
+
for (const peerConnection of this._peerConnections.values()) {
|
|
549
|
+
if (peerConnection.closed)
|
|
550
|
+
continue;
|
|
551
|
+
peerConnection.updateMetrics();
|
|
552
|
+
this.totalSentBytes += peerConnection.totalSentAudioBytes + peerConnection.totalSentVideoBytes;
|
|
553
|
+
this.totalReceivedBytes += peerConnection.totalReceivedAudioBytes + peerConnection.totalReceivedVideoBytes;
|
|
554
|
+
this.totalOutboundPacketsSent += peerConnection.totalOutboundPacketsSent;
|
|
555
|
+
this.totalInboundPacketsReceived += peerConnection.totalInboundPacketsReceived;
|
|
556
|
+
this.totalInboundPacketsLost += peerConnection.totalInboundPacketsLost;
|
|
557
|
+
this.totalDataChannelBytesSent += peerConnection.totalDataChannelBytesSent;
|
|
558
|
+
this.totalDataChannelBytesReceived += peerConnection.totalDataChannelBytesReceived;
|
|
559
|
+
this.sendingBitrate += peerConnection.sendingAudioBitrate + peerConnection.sendingVideoBitrate;
|
|
560
|
+
this.receivingBitrate += peerConnection.receivingAudioBitrate + peerConnection.receivingVideoBitrate;
|
|
561
|
+
sumRttInS += (_16 = peerConnection.avgRttInS) !== null && _16 !== void 0 ? _16 : 0;
|
|
495
562
|
}
|
|
563
|
+
this.avgRttInS = this._peerConnections.size ? sumRttInS / this._peerConnections.size : -1;
|
|
496
564
|
if (executeSave)
|
|
497
565
|
yield this._save();
|
|
498
566
|
this._updated = sample.timestamp;
|
|
@@ -507,6 +575,11 @@ class ObservedClient extends events_1.EventEmitter {
|
|
|
507
575
|
const result = yield ObservedPeerConnection_1.ObservedPeerConnection.create({
|
|
508
576
|
peerConnectionId,
|
|
509
577
|
}, this, this._storageProvider);
|
|
578
|
+
const pendingTracksTimestamp = this.ωpendingCreatedTracksTimestamp.get(peerConnectionId);
|
|
579
|
+
if (pendingTracksTimestamp) {
|
|
580
|
+
result.created = pendingTracksTimestamp;
|
|
581
|
+
this.ωpendingCreatedTracksTimestamp.delete(peerConnectionId);
|
|
582
|
+
}
|
|
510
583
|
result.once('close', () => {
|
|
511
584
|
this._peerConnections.delete(peerConnectionId);
|
|
512
585
|
this._model.peerConnectionIds = this._model.peerConnectionIds.filter((id) => id !== peerConnectionId);
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { IceCandidatePair, IceLocalCandidate, IceRemoteCandidate } from '@observertc/sample-schemas-js';
|
|
3
|
+
import { EventEmitter } from 'events';
|
|
4
|
+
import { ObservedPeerConnection } from './ObservedPeerConnection';
|
|
5
|
+
export type ObservedICEEvents = {
|
|
6
|
+
update: [];
|
|
7
|
+
'new-local-candidate': [IceLocalCandidate];
|
|
8
|
+
'new-remote-candidate': [IceRemoteCandidate];
|
|
9
|
+
'new-selected-candidate-pair': [
|
|
10
|
+
{
|
|
11
|
+
localCandidate: IceLocalCandidate;
|
|
12
|
+
remoteCandidate: IceRemoteCandidate;
|
|
13
|
+
}
|
|
14
|
+
];
|
|
15
|
+
close: [];
|
|
16
|
+
};
|
|
17
|
+
export declare interface ObservedICE {
|
|
18
|
+
on<U extends keyof ObservedICEEvents>(event: U, listener: (...args: ObservedICEEvents[U]) => void): this;
|
|
19
|
+
off<U extends keyof ObservedICEEvents>(event: U, listener: (...args: ObservedICEEvents[U]) => void): this;
|
|
20
|
+
once<U extends keyof ObservedICEEvents>(event: U, listener: (...args: ObservedICEEvents[U]) => void): this;
|
|
21
|
+
emit<U extends keyof ObservedICEEvents>(event: U, ...args: ObservedICEEvents[U]): boolean;
|
|
22
|
+
}
|
|
23
|
+
export declare class ObservedICE extends EventEmitter {
|
|
24
|
+
readonly peerConnection: ObservedPeerConnection;
|
|
25
|
+
static create(peerConnection: ObservedPeerConnection): ObservedICE;
|
|
26
|
+
private readonly _localCandidates;
|
|
27
|
+
private readonly _remoteCandidates;
|
|
28
|
+
private _selectedLocalCandidateId?;
|
|
29
|
+
private _selectedRemoteCandidateId?;
|
|
30
|
+
private _updated;
|
|
31
|
+
private _stats?;
|
|
32
|
+
private _closed;
|
|
33
|
+
private constructor();
|
|
34
|
+
get reports(): import("./ReportsCollector").ReportsCollector;
|
|
35
|
+
get localCandidates(): ReadonlyMap<string, IceLocalCandidate>;
|
|
36
|
+
get remoteCandidates(): ReadonlyMap<string, IceRemoteCandidate>;
|
|
37
|
+
get selectedLocalCandidate(): IceLocalCandidate | undefined;
|
|
38
|
+
get selectedRemoteCandidate(): IceLocalCandidate | undefined;
|
|
39
|
+
get stats(): IceCandidatePair | undefined;
|
|
40
|
+
get updated(): number;
|
|
41
|
+
get closed(): boolean;
|
|
42
|
+
close(): void;
|
|
43
|
+
addLocalCandidate(candidate: IceLocalCandidate): void;
|
|
44
|
+
addRemoteCandidate(candidate: IceRemoteCandidate): void;
|
|
45
|
+
update(candidatePair: IceCandidatePair, timestamp: number): void;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=ObservedICE.d.ts.map
|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EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC;CAC1F;AAED,qBAAa,WAAY,SAAQ,YAAY;aAe3B,cAAc,EAAE,sBAAsB;WAdzC,MAAM,CAAC,cAAc,EAAE,sBAAsB;IAI3D,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAwC;IACzE,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAwC;IAE1E,OAAO,CAAC,yBAAyB,CAAC,CAAS;IAC3C,OAAO,CAAC,0BAA0B,CAAC,CAAS;IAC5C,OAAO,CAAC,QAAQ,CAAc;IAC9B,OAAO,CAAC,MAAM,CAAC,CAAmB;IAClC,OAAO,CAAC,OAAO,CAAS;IAExB,OAAO;IAMP,IAAW,OAAO,kDAEjB;IAED,IAAW,eAAe,IAAI,WAAW,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAEnE;IAED,IAAW,gBAAgB,IAAI,WAAW,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAErE;IAED,IAAW,sBAAsB,kCAEhC;IAED,IAAW,uBAAuB,kCAEjC;IAED,IAAW,KAAK,iCAEf;IAED,IAAW,OAAO,WAEjB;IAED,IAAW,MAAM,YAEhB;IAEM,KAAK;IAML,iBAAiB,CAAC,SAAS,EAAE,iBAAiB;IAwB9C,kBAAkB,CAAC,SAAS,EAAE,kBAAkB;IAwBhD,MAAM,CAAC,aAAa,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM;CA6ChE"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ObservedICE = void 0;
|
|
4
|
+
const events_1 = require("events");
|
|
5
|
+
const callMetaReports_1 = require("./common/callMetaReports");
|
|
6
|
+
class ObservedICE extends events_1.EventEmitter {
|
|
7
|
+
static create(peerConnection) {
|
|
8
|
+
return new ObservedICE(peerConnection);
|
|
9
|
+
}
|
|
10
|
+
constructor(peerConnection) {
|
|
11
|
+
super();
|
|
12
|
+
this.peerConnection = peerConnection;
|
|
13
|
+
this._localCandidates = new Map();
|
|
14
|
+
this._remoteCandidates = new Map();
|
|
15
|
+
this._updated = Date.now();
|
|
16
|
+
this._closed = false;
|
|
17
|
+
}
|
|
18
|
+
get reports() {
|
|
19
|
+
return this.peerConnection.reports;
|
|
20
|
+
}
|
|
21
|
+
get localCandidates() {
|
|
22
|
+
return this._localCandidates;
|
|
23
|
+
}
|
|
24
|
+
get remoteCandidates() {
|
|
25
|
+
return this._remoteCandidates;
|
|
26
|
+
}
|
|
27
|
+
get selectedLocalCandidate() {
|
|
28
|
+
var _a;
|
|
29
|
+
return this._localCandidates.get((_a = this._selectedLocalCandidateId) !== null && _a !== void 0 ? _a : '');
|
|
30
|
+
}
|
|
31
|
+
get selectedRemoteCandidate() {
|
|
32
|
+
var _a;
|
|
33
|
+
return this._remoteCandidates.get((_a = this._selectedRemoteCandidateId) !== null && _a !== void 0 ? _a : '');
|
|
34
|
+
}
|
|
35
|
+
get stats() {
|
|
36
|
+
return this._stats;
|
|
37
|
+
}
|
|
38
|
+
get updated() {
|
|
39
|
+
return this._updated;
|
|
40
|
+
}
|
|
41
|
+
get closed() {
|
|
42
|
+
return this._closed;
|
|
43
|
+
}
|
|
44
|
+
close() {
|
|
45
|
+
if (this._closed)
|
|
46
|
+
return;
|
|
47
|
+
this._closed = true;
|
|
48
|
+
this.emit('close');
|
|
49
|
+
}
|
|
50
|
+
addLocalCandidate(candidate) {
|
|
51
|
+
if (!candidate.id)
|
|
52
|
+
return;
|
|
53
|
+
const newCandidate = !this._localCandidates.has(candidate.id);
|
|
54
|
+
this._localCandidates.set(candidate.id, candidate);
|
|
55
|
+
if (newCandidate) {
|
|
56
|
+
const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.peerConnection.client.serviceId, this.peerConnection.client.mediaUnitId, this.peerConnection.client.roomId, this.peerConnection.client.callId, this.peerConnection.client.clientId, {
|
|
57
|
+
type: callMetaReports_1.CallMetaType.ICE_LOCAL_CANDIDATE,
|
|
58
|
+
payload: candidate,
|
|
59
|
+
}, this.peerConnection.client.userId);
|
|
60
|
+
this.reports.addCallMetaReport(callMetaReport);
|
|
61
|
+
this.emit('new-local-candidate', candidate);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
addRemoteCandidate(candidate) {
|
|
65
|
+
if (!candidate.id)
|
|
66
|
+
return;
|
|
67
|
+
const newCandidate = !this._remoteCandidates.has(candidate.id);
|
|
68
|
+
this._remoteCandidates.set(candidate.id, candidate);
|
|
69
|
+
if (newCandidate) {
|
|
70
|
+
const callMetaReport = (0, callMetaReports_1.createCallMetaReport)(this.peerConnection.client.serviceId, this.peerConnection.client.mediaUnitId, this.peerConnection.client.roomId, this.peerConnection.client.callId, this.peerConnection.client.clientId, {
|
|
71
|
+
type: callMetaReports_1.CallMetaType.ICE_REMOTE_CANDIDATE,
|
|
72
|
+
payload: candidate,
|
|
73
|
+
}, this.peerConnection.client.userId);
|
|
74
|
+
this.reports.addCallMetaReport(callMetaReport);
|
|
75
|
+
this.emit('new-remote-candidate', candidate);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
update(candidatePair, timestamp) {
|
|
79
|
+
const report = Object.assign(Object.assign({ serviceId: this.peerConnection.client.serviceId, mediaUnitId: this.peerConnection.client.mediaUnitId, roomId: this.peerConnection.client.roomId, callId: this.peerConnection.client.callId, clientId: this.peerConnection.client.clientId, userId: this.peerConnection.client.userId, timestamp }, candidatePair), { sampleSeq: -1 });
|
|
80
|
+
this.reports.addIceCandidatePairReport(report);
|
|
81
|
+
if (!candidatePair.nominated)
|
|
82
|
+
return;
|
|
83
|
+
this._stats = candidatePair;
|
|
84
|
+
if (candidatePair.localCandidateId &&
|
|
85
|
+
candidatePair.localCandidateId !== this._selectedLocalCandidateId &&
|
|
86
|
+
this._localCandidates.has(candidatePair.localCandidateId) &&
|
|
87
|
+
candidatePair.remoteCandidateId &&
|
|
88
|
+
candidatePair.remoteCandidateId !== this._selectedRemoteCandidateId &&
|
|
89
|
+
this._remoteCandidates.has(candidatePair.remoteCandidateId)) {
|
|
90
|
+
this._selectedLocalCandidateId = candidatePair.localCandidateId;
|
|
91
|
+
this._selectedRemoteCandidateId = candidatePair.remoteCandidateId;
|
|
92
|
+
const localCandidate = this._localCandidates.get(candidatePair.localCandidateId);
|
|
93
|
+
const remoteCandidate = this._remoteCandidates.get(candidatePair.remoteCandidateId);
|
|
94
|
+
if (localCandidate && remoteCandidate) {
|
|
95
|
+
this.emit('new-selected-candidate-pair', {
|
|
96
|
+
localCandidate,
|
|
97
|
+
remoteCandidate,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
this._updated = timestamp;
|
|
102
|
+
this.emit('update');
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
exports.ObservedICE = ObservedICE;
|