@observertc/observer-js 1.0.0-beta.10 → 1.0.0-beta.12
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/README.md +151 -55
- package/dist/index.d.mts +24 -8
- package/dist/index.d.ts +24 -8
- package/dist/index.js +145 -162
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +145 -162
- package/dist/index.mjs.map +1 -1
- package/llms-full.txt +153 -57
- package/package.json +3 -2
package/dist/index.mjs
CHANGED
|
@@ -2181,7 +2181,8 @@ var ObservedClient = class extends EventEmitter2 {
|
|
|
2181
2181
|
// public totalNumberOfIssues = 0;
|
|
2182
2182
|
mediaDevices = [];
|
|
2183
2183
|
issues = [];
|
|
2184
|
-
|
|
2184
|
+
_pendingInjections = {};
|
|
2185
|
+
_activeSample;
|
|
2185
2186
|
closeTimer;
|
|
2186
2187
|
get numberOfPeerConnections() {
|
|
2187
2188
|
return this.observedPeerConnections.size;
|
|
@@ -2191,11 +2192,8 @@ var ObservedClient = class extends EventEmitter2 {
|
|
|
2191
2192
|
}
|
|
2192
2193
|
close() {
|
|
2193
2194
|
if (this.closed) return;
|
|
2195
|
+
this._flushPendingInjections();
|
|
2194
2196
|
this.closed = true;
|
|
2195
|
-
this._injections.clientEvents?.forEach((clientEvent) => this._processClientEvent(clientEvent));
|
|
2196
|
-
this._injections.clientIssues?.forEach((clientIssue) => this.addIssue(clientIssue));
|
|
2197
|
-
this._injections.extensionStats?.forEach((extensionStat) => this.addExtensionStats(extensionStat));
|
|
2198
|
-
this._injections.clientMetaItems?.forEach((clientMetaItem) => this.addMetadata(clientMetaItem));
|
|
2199
2197
|
Array.from(this.observedPeerConnections.values()).forEach((peerConnection) => peerConnection.close());
|
|
2200
2198
|
if (!this.leftAt) {
|
|
2201
2199
|
this.leftAt = this.lastSampleTimestamp;
|
|
@@ -2218,7 +2216,6 @@ var ObservedClient = class extends EventEmitter2 {
|
|
|
2218
2216
|
logger2.warn("Attempted to accept a sample on a closed client %s", this.clientId);
|
|
2219
2217
|
return;
|
|
2220
2218
|
}
|
|
2221
|
-
this.sink?.write(sample);
|
|
2222
2219
|
if (this.closeTimer) {
|
|
2223
2220
|
clearTimeout(this.closeTimer);
|
|
2224
2221
|
this.closeTimer = void 0;
|
|
@@ -2258,7 +2255,8 @@ var ObservedClient = class extends EventEmitter2 {
|
|
|
2258
2255
|
this.usingTCP = false;
|
|
2259
2256
|
this.currentMinRttInMs = void 0;
|
|
2260
2257
|
this.currentMaxRttInMs = void 0;
|
|
2261
|
-
this.
|
|
2258
|
+
this._mergePendingInjections(sample);
|
|
2259
|
+
this._activeSample = sample;
|
|
2262
2260
|
const clientEventsPostBuffer = [];
|
|
2263
2261
|
for (const clientEvent of sample.clientEvents ?? []) {
|
|
2264
2262
|
this._processClientEvent(clientEvent, clientEventsPostBuffer);
|
|
@@ -2346,31 +2344,68 @@ var ObservedClient = class extends EventEmitter2 {
|
|
|
2346
2344
|
this.close();
|
|
2347
2345
|
}, this.settings.closeClientIfIdleForMs);
|
|
2348
2346
|
}
|
|
2347
|
+
this._activeSample = void 0;
|
|
2348
|
+
try {
|
|
2349
|
+
this.sink?.write(sample);
|
|
2350
|
+
} catch (err) {
|
|
2351
|
+
logger2.warn("ClientSampleSink.write failed for client %s: %o", this.clientId, err);
|
|
2352
|
+
}
|
|
2349
2353
|
}
|
|
2350
2354
|
injectMetaData(metaData) {
|
|
2351
2355
|
if (this.closed) return;
|
|
2352
|
-
if (
|
|
2353
|
-
|
|
2356
|
+
if (this._activeSample) {
|
|
2357
|
+
if (!this._activeSample.clientMetaItems) this._activeSample.clientMetaItems = [];
|
|
2358
|
+
this._activeSample.clientMetaItems.push(metaData);
|
|
2359
|
+
this.addMetadata(metaData);
|
|
2360
|
+
return;
|
|
2361
|
+
}
|
|
2362
|
+
if (!this._pendingInjections.clientMetaItems) this._pendingInjections.clientMetaItems = [];
|
|
2363
|
+
this._pendingInjections.clientMetaItems.push(metaData);
|
|
2354
2364
|
}
|
|
2355
2365
|
injectEvent(event) {
|
|
2356
2366
|
if (this.closed) return;
|
|
2357
|
-
if (
|
|
2358
|
-
|
|
2367
|
+
if (this._activeSample) {
|
|
2368
|
+
if (!this._activeSample.clientEvents) this._activeSample.clientEvents = [];
|
|
2369
|
+
this._activeSample.clientEvents.push(event);
|
|
2370
|
+
this._processClientEvent(event);
|
|
2371
|
+
return;
|
|
2372
|
+
}
|
|
2373
|
+
if (!this._pendingInjections.clientEvents) this._pendingInjections.clientEvents = [];
|
|
2374
|
+
this._pendingInjections.clientEvents.push(event);
|
|
2359
2375
|
}
|
|
2360
2376
|
injectIssue(issue) {
|
|
2361
2377
|
if (this.closed) return;
|
|
2362
|
-
if (
|
|
2363
|
-
|
|
2378
|
+
if (this._activeSample) {
|
|
2379
|
+
if (!this._activeSample.clientIssues) this._activeSample.clientIssues = [];
|
|
2380
|
+
this._activeSample.clientIssues.push(issue);
|
|
2381
|
+
this.addIssue(issue);
|
|
2382
|
+
++this.deltaNumberOfIssues;
|
|
2383
|
+
return;
|
|
2384
|
+
}
|
|
2385
|
+
if (!this._pendingInjections.clientIssues) this._pendingInjections.clientIssues = [];
|
|
2386
|
+
this._pendingInjections.clientIssues.push(issue);
|
|
2364
2387
|
}
|
|
2365
2388
|
injectExtensionStat(stat) {
|
|
2366
2389
|
if (this.closed) return;
|
|
2367
|
-
if (
|
|
2368
|
-
|
|
2390
|
+
if (this._activeSample) {
|
|
2391
|
+
if (!this._activeSample.extensionStats) this._activeSample.extensionStats = [];
|
|
2392
|
+
this._activeSample.extensionStats.push(stat);
|
|
2393
|
+
this.addExtensionStats(stat);
|
|
2394
|
+
return;
|
|
2395
|
+
}
|
|
2396
|
+
if (!this._pendingInjections.extensionStats) this._pendingInjections.extensionStats = [];
|
|
2397
|
+
this._pendingInjections.extensionStats.push(stat);
|
|
2369
2398
|
}
|
|
2370
|
-
injectAttachment(
|
|
2399
|
+
injectAttachment(attachments) {
|
|
2371
2400
|
if (this.closed) return;
|
|
2372
|
-
if (
|
|
2373
|
-
|
|
2401
|
+
if (this._activeSample) {
|
|
2402
|
+
if (!this._activeSample.attachments) this._activeSample.attachments = {};
|
|
2403
|
+
Object.assign(this._activeSample.attachments, attachments);
|
|
2404
|
+
this.attachments = this._activeSample.attachments;
|
|
2405
|
+
return;
|
|
2406
|
+
}
|
|
2407
|
+
if (!this._pendingInjections.attachments) this._pendingInjections.attachments = {};
|
|
2408
|
+
Object.assign(this._pendingInjections.attachments, attachments);
|
|
2374
2409
|
}
|
|
2375
2410
|
addMetadata(metadata) {
|
|
2376
2411
|
if (this.closed) return;
|
|
@@ -2632,35 +2667,53 @@ var ObservedClient = class extends EventEmitter2 {
|
|
|
2632
2667
|
observedPeerConnection.accept(sample, context);
|
|
2633
2668
|
return observedPeerConnection;
|
|
2634
2669
|
}
|
|
2635
|
-
|
|
2670
|
+
_mergePendingInjections(sample) {
|
|
2636
2671
|
if (this.closed) return sample;
|
|
2637
|
-
if (this.
|
|
2672
|
+
if (this._pendingInjections.clientEvents) {
|
|
2638
2673
|
if (!sample.clientEvents) sample.clientEvents = [];
|
|
2639
|
-
sample.clientEvents.push(...this.
|
|
2640
|
-
this.
|
|
2674
|
+
sample.clientEvents.push(...this._pendingInjections.clientEvents);
|
|
2675
|
+
this._pendingInjections.clientEvents = void 0;
|
|
2641
2676
|
}
|
|
2642
|
-
if (this.
|
|
2677
|
+
if (this._pendingInjections.clientIssues) {
|
|
2643
2678
|
if (!sample.clientIssues) sample.clientIssues = [];
|
|
2644
|
-
sample.clientIssues.push(...this.
|
|
2645
|
-
this.
|
|
2679
|
+
sample.clientIssues.push(...this._pendingInjections.clientIssues);
|
|
2680
|
+
this._pendingInjections.clientIssues = void 0;
|
|
2646
2681
|
}
|
|
2647
|
-
if (this.
|
|
2682
|
+
if (this._pendingInjections.extensionStats) {
|
|
2648
2683
|
if (!sample.extensionStats) sample.extensionStats = [];
|
|
2649
|
-
sample.extensionStats.push(...this.
|
|
2650
|
-
this.
|
|
2684
|
+
sample.extensionStats.push(...this._pendingInjections.extensionStats);
|
|
2685
|
+
this._pendingInjections.extensionStats = void 0;
|
|
2651
2686
|
}
|
|
2652
|
-
if (this.
|
|
2687
|
+
if (this._pendingInjections.attachments) {
|
|
2653
2688
|
if (!sample.attachments) sample.attachments = {};
|
|
2654
|
-
Object.assign(sample.attachments, this.
|
|
2655
|
-
this.
|
|
2689
|
+
Object.assign(sample.attachments, this._pendingInjections.attachments);
|
|
2690
|
+
this._pendingInjections.attachments = void 0;
|
|
2656
2691
|
}
|
|
2657
|
-
if (this.
|
|
2692
|
+
if (this._pendingInjections.clientMetaItems) {
|
|
2658
2693
|
if (!sample.clientMetaItems) sample.clientMetaItems = [];
|
|
2659
|
-
sample.clientMetaItems.push(...this.
|
|
2660
|
-
this.
|
|
2694
|
+
sample.clientMetaItems.push(...this._pendingInjections.clientMetaItems);
|
|
2695
|
+
this._pendingInjections.clientMetaItems = void 0;
|
|
2661
2696
|
}
|
|
2662
2697
|
return sample;
|
|
2663
2698
|
}
|
|
2699
|
+
_flushPendingInjections() {
|
|
2700
|
+
const hasPending = Boolean(
|
|
2701
|
+
this._pendingInjections.clientEvents || this._pendingInjections.clientIssues || this._pendingInjections.extensionStats || this._pendingInjections.clientMetaItems || this._pendingInjections.attachments
|
|
2702
|
+
);
|
|
2703
|
+
if (!hasPending) return;
|
|
2704
|
+
const finalSample = { timestamp: Date.now() };
|
|
2705
|
+
this._mergePendingInjections(finalSample);
|
|
2706
|
+
for (const clientEvent of finalSample.clientEvents ?? []) this._processClientEvent(clientEvent);
|
|
2707
|
+
for (const metaData of finalSample.clientMetaItems ?? []) this.addMetadata(metaData);
|
|
2708
|
+
for (const issue of finalSample.clientIssues ?? []) this.addIssue(issue);
|
|
2709
|
+
for (const extensionStat of finalSample.extensionStats ?? []) this.addExtensionStats(extensionStat);
|
|
2710
|
+
if (finalSample.attachments) this.attachments = { ...this.attachments, ...finalSample.attachments };
|
|
2711
|
+
try {
|
|
2712
|
+
this.sink?.write(finalSample);
|
|
2713
|
+
} catch (err) {
|
|
2714
|
+
logger2.warn("ClientSampleSink.write failed during injection flush for client %s: %o", this.clientId, err);
|
|
2715
|
+
}
|
|
2716
|
+
}
|
|
2664
2717
|
/** Emit an Observer-bus event scoped to this client (or a peer connection under it). */
|
|
2665
2718
|
_notify(type, ...args) {
|
|
2666
2719
|
this.call.observer.emit(type, ...args);
|
|
@@ -3236,12 +3289,9 @@ import { EventEmitter as EventEmitter5 } from "events";
|
|
|
3236
3289
|
var logger6 = createLogger("ObservedMediasoupRouter");
|
|
3237
3290
|
var ObservedMediasoupRouter = class extends EventEmitter5 {
|
|
3238
3291
|
router;
|
|
3239
|
-
sample;
|
|
3240
3292
|
appData;
|
|
3293
|
+
sample;
|
|
3241
3294
|
webrtcTransportIds = /* @__PURE__ */ new Set();
|
|
3242
|
-
get attachments() {
|
|
3243
|
-
return this.sample.attachments;
|
|
3244
|
-
}
|
|
3245
3295
|
closed = false;
|
|
3246
3296
|
constructor(settings) {
|
|
3247
3297
|
super();
|
|
@@ -3262,6 +3312,15 @@ var ObservedMediasoupRouter = class extends EventEmitter5 {
|
|
|
3262
3312
|
get id() {
|
|
3263
3313
|
return this.router.id;
|
|
3264
3314
|
}
|
|
3315
|
+
get attachments() {
|
|
3316
|
+
return this.sample.attachments;
|
|
3317
|
+
}
|
|
3318
|
+
close() {
|
|
3319
|
+
if (this.closed) return;
|
|
3320
|
+
this.closed = true;
|
|
3321
|
+
if (this.sample.closedAt === void 0) this.sample.closedAt = Date.now();
|
|
3322
|
+
this.emit("close");
|
|
3323
|
+
}
|
|
3265
3324
|
addTransport = (transport) => {
|
|
3266
3325
|
let transportType = transport.type;
|
|
3267
3326
|
if (!transportType) {
|
|
@@ -3294,35 +3353,17 @@ var ObservedMediasoupRouter = class extends EventEmitter5 {
|
|
|
3294
3353
|
history
|
|
3295
3354
|
};
|
|
3296
3355
|
this.sample.transports.push(transportSample);
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
type: `icestate-changed-to-${iceState}`,
|
|
3300
|
-
timestamp: Date.now()
|
|
3301
|
-
});
|
|
3302
|
-
};
|
|
3356
|
+
this.webrtcTransportIds.add(transport.id);
|
|
3357
|
+
const onIceStateChange = (iceState) => history.push({ type: `icestate-changed-to-${iceState}`, timestamp: Date.now() });
|
|
3303
3358
|
const onIceSelectedTupleChange = (tuple) => {
|
|
3304
3359
|
transportSample.tuple = tuple;
|
|
3305
|
-
history.push({
|
|
3306
|
-
type: "iceselectedtuple-changed",
|
|
3307
|
-
timestamp: Date.now(),
|
|
3308
|
-
...tuple
|
|
3309
|
-
});
|
|
3360
|
+
history.push({ type: "iceselectedtuple-changed", timestamp: Date.now(), ...tuple });
|
|
3310
3361
|
};
|
|
3311
3362
|
const onDtlsStateChange = (dtlsState) => {
|
|
3312
|
-
history.push({
|
|
3313
|
-
|
|
3314
|
-
timestamp: Date.now()
|
|
3315
|
-
});
|
|
3316
|
-
if (dtlsState === "connected" && transportSample.connectedAt === void 0) {
|
|
3317
|
-
transportSample.connectedAt = Date.now();
|
|
3318
|
-
}
|
|
3319
|
-
};
|
|
3320
|
-
const onSctpStateChange = (sctpState) => {
|
|
3321
|
-
history.push({
|
|
3322
|
-
type: `sctpstate-changed-to-${sctpState}`,
|
|
3323
|
-
timestamp: Date.now()
|
|
3324
|
-
});
|
|
3363
|
+
history.push({ type: `dtlsstate-changed-to-${dtlsState}`, timestamp: Date.now() });
|
|
3364
|
+
if (dtlsState === "connected" && transportSample.connectedAt === void 0) transportSample.connectedAt = Date.now();
|
|
3325
3365
|
};
|
|
3366
|
+
const onSctpStateChange = (sctpState) => history.push({ type: `sctpstate-changed-to-${sctpState}`, timestamp: Date.now() });
|
|
3326
3367
|
this._attachTransportObserverListeners(transport, transportSample, () => {
|
|
3327
3368
|
transport.observer.off("icestatechange", onIceStateChange);
|
|
3328
3369
|
transport.observer.off("iceselectedtuplechange", onIceSelectedTupleChange);
|
|
@@ -3334,7 +3375,6 @@ var ObservedMediasoupRouter = class extends EventEmitter5 {
|
|
|
3334
3375
|
transport.observer.on("iceselectedtuplechange", onIceSelectedTupleChange);
|
|
3335
3376
|
transport.observer.on("dtlsstatechange", onDtlsStateChange);
|
|
3336
3377
|
transport.observer.on("sctpstatechange", onSctpStateChange);
|
|
3337
|
-
this.webrtcTransportIds.add(transport.id);
|
|
3338
3378
|
}
|
|
3339
3379
|
addPlainTransport(transport) {
|
|
3340
3380
|
const history = [];
|
|
@@ -3357,13 +3397,8 @@ var ObservedMediasoupRouter = class extends EventEmitter5 {
|
|
|
3357
3397
|
history.push({ type: "rtcptuple-changed", timestamp: Date.now(), ...rtcpTuple });
|
|
3358
3398
|
};
|
|
3359
3399
|
const onSctpStateChange = (sctpState) => {
|
|
3360
|
-
if (sctpState === "connected" && transportSample.connectedAt === void 0)
|
|
3361
|
-
|
|
3362
|
-
}
|
|
3363
|
-
history.push({
|
|
3364
|
-
type: `sctpstate-changed-to-${sctpState}`,
|
|
3365
|
-
timestamp: Date.now()
|
|
3366
|
-
});
|
|
3400
|
+
if (sctpState === "connected" && transportSample.connectedAt === void 0) transportSample.connectedAt = Date.now();
|
|
3401
|
+
history.push({ type: `sctpstate-changed-to-${sctpState}`, timestamp: Date.now() });
|
|
3367
3402
|
};
|
|
3368
3403
|
this._attachTransportObserverListeners(transport, transportSample, () => {
|
|
3369
3404
|
transport.observer.off("tuple", onTuple);
|
|
@@ -3385,13 +3420,8 @@ var ObservedMediasoupRouter = class extends EventEmitter5 {
|
|
|
3385
3420
|
};
|
|
3386
3421
|
this.sample.transports.push(transportSample);
|
|
3387
3422
|
const onSctpStateChange = (sctpState) => {
|
|
3388
|
-
if (sctpState === "connected" && transportSample.connectedAt === void 0)
|
|
3389
|
-
|
|
3390
|
-
}
|
|
3391
|
-
history.push({
|
|
3392
|
-
type: `sctpstate-changed-to-${sctpState}`,
|
|
3393
|
-
timestamp: Date.now()
|
|
3394
|
-
});
|
|
3423
|
+
if (sctpState === "connected" && transportSample.connectedAt === void 0) transportSample.connectedAt = Date.now();
|
|
3424
|
+
history.push({ type: `sctpstate-changed-to-${sctpState}`, timestamp: Date.now() });
|
|
3395
3425
|
};
|
|
3396
3426
|
this._attachTransportObserverListeners(transport, transportSample, () => {
|
|
3397
3427
|
transport.observer.off("sctpstatechange", onSctpStateChange);
|
|
@@ -3404,7 +3434,6 @@ var ObservedMediasoupRouter = class extends EventEmitter5 {
|
|
|
3404
3434
|
id: transport.id,
|
|
3405
3435
|
type: "direct",
|
|
3406
3436
|
createdAt: now,
|
|
3407
|
-
// A DirectTransport has no network layer — it is connected the instant it exists.
|
|
3408
3437
|
connectedAt: now,
|
|
3409
3438
|
history: []
|
|
3410
3439
|
};
|
|
@@ -3413,37 +3442,26 @@ var ObservedMediasoupRouter = class extends EventEmitter5 {
|
|
|
3413
3442
|
}
|
|
3414
3443
|
addProducer(transport, producer) {
|
|
3415
3444
|
const firstCodec = producer.rtpParameters.codecs[0];
|
|
3416
|
-
const codecInfo = {
|
|
3417
|
-
mimeType: firstCodec?.mimeType ?? "unknown/unknown",
|
|
3418
|
-
payloadType: firstCodec?.payloadType ?? 0,
|
|
3419
|
-
clockRate: firstCodec?.clockRate ?? 0,
|
|
3420
|
-
channels: firstCodec?.channels,
|
|
3421
|
-
parameters: firstCodec?.parameters,
|
|
3422
|
-
rtcpFeedback: firstCodec?.rtcpFeedback
|
|
3423
|
-
};
|
|
3424
3445
|
const producerSample = {
|
|
3425
3446
|
id: producer.id,
|
|
3447
|
+
transportId: transport.id,
|
|
3426
3448
|
createdAt: Date.now(),
|
|
3427
3449
|
kind: producer.kind,
|
|
3428
|
-
codecInfo
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3450
|
+
codecInfo: {
|
|
3451
|
+
mimeType: firstCodec?.mimeType ?? "unknown/unknown",
|
|
3452
|
+
payloadType: firstCodec?.payloadType ?? 0,
|
|
3453
|
+
clockRate: firstCodec?.clockRate ?? 0,
|
|
3454
|
+
channels: firstCodec?.channels,
|
|
3455
|
+
parameters: firstCodec?.parameters,
|
|
3456
|
+
rtcpFeedback: firstCodec?.rtcpFeedback
|
|
3457
|
+
},
|
|
3458
|
+
ssrcs: producer.rtpParameters.encodings?.map((e) => e.ssrc).filter((s) => typeof s === "number"),
|
|
3459
|
+
rids: producer.rtpParameters.encodings?.map((e) => e.rid).filter((r) => typeof r === "string"),
|
|
3460
|
+
history: []
|
|
3433
3461
|
};
|
|
3434
3462
|
this.sample.producers.push(producerSample);
|
|
3435
|
-
const onPause = () => {
|
|
3436
|
-
|
|
3437
|
-
type: "pause",
|
|
3438
|
-
timestamp: Date.now()
|
|
3439
|
-
});
|
|
3440
|
-
};
|
|
3441
|
-
const onResume = () => {
|
|
3442
|
-
producerSample.history.push({
|
|
3443
|
-
type: "resume",
|
|
3444
|
-
timestamp: Date.now()
|
|
3445
|
-
});
|
|
3446
|
-
};
|
|
3463
|
+
const onPause = () => producerSample.history.push({ type: "pause", timestamp: Date.now() });
|
|
3464
|
+
const onResume = () => producerSample.history.push({ type: "resume", timestamp: Date.now() });
|
|
3447
3465
|
producer.observer.once("close", () => {
|
|
3448
3466
|
producer.observer.off("pause", onPause);
|
|
3449
3467
|
producer.observer.off("resume", onResume);
|
|
@@ -3462,30 +3480,10 @@ var ObservedMediasoupRouter = class extends EventEmitter5 {
|
|
|
3462
3480
|
history: []
|
|
3463
3481
|
};
|
|
3464
3482
|
this.sample.consumers.push(consumerSample);
|
|
3465
|
-
const onPause = () => {
|
|
3466
|
-
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
});
|
|
3470
|
-
};
|
|
3471
|
-
const onResume = () => {
|
|
3472
|
-
consumerSample.history.push({
|
|
3473
|
-
type: "resume",
|
|
3474
|
-
timestamp: Date.now()
|
|
3475
|
-
});
|
|
3476
|
-
};
|
|
3477
|
-
const onProducerPause = () => {
|
|
3478
|
-
consumerSample.history.push({
|
|
3479
|
-
type: "producerPaused",
|
|
3480
|
-
timestamp: Date.now()
|
|
3481
|
-
});
|
|
3482
|
-
};
|
|
3483
|
-
const onProducerResume = () => {
|
|
3484
|
-
consumerSample.history.push({
|
|
3485
|
-
type: "producerResumed",
|
|
3486
|
-
timestamp: Date.now()
|
|
3487
|
-
});
|
|
3488
|
-
};
|
|
3483
|
+
const onPause = () => consumerSample.history.push({ type: "pause", timestamp: Date.now() });
|
|
3484
|
+
const onResume = () => consumerSample.history.push({ type: "resume", timestamp: Date.now() });
|
|
3485
|
+
const onProducerPause = () => consumerSample.history.push({ type: "producerPaused", timestamp: Date.now() });
|
|
3486
|
+
const onProducerResume = () => consumerSample.history.push({ type: "producerResumed", timestamp: Date.now() });
|
|
3489
3487
|
consumer.observer.once("close", () => {
|
|
3490
3488
|
consumer.observer.off("pause", onPause);
|
|
3491
3489
|
consumer.observer.off("resume", onResume);
|
|
@@ -3507,9 +3505,7 @@ var ObservedMediasoupRouter = class extends EventEmitter5 {
|
|
|
3507
3505
|
protocol: dataProducer.protocol
|
|
3508
3506
|
};
|
|
3509
3507
|
this.sample.dataProducers.push(dataProducerSample);
|
|
3510
|
-
dataProducer.observer.once("close", () =>
|
|
3511
|
-
dataProducerSample.closedAt = Date.now();
|
|
3512
|
-
});
|
|
3508
|
+
dataProducer.observer.once("close", () => dataProducerSample.closedAt = Date.now());
|
|
3513
3509
|
}
|
|
3514
3510
|
addDataConsumer(transport, dataConsumer) {
|
|
3515
3511
|
const dataConsumerSample = {
|
|
@@ -3521,14 +3517,7 @@ var ObservedMediasoupRouter = class extends EventEmitter5 {
|
|
|
3521
3517
|
protocol: dataConsumer.protocol
|
|
3522
3518
|
};
|
|
3523
3519
|
this.sample.dataConsumers.push(dataConsumerSample);
|
|
3524
|
-
dataConsumer.observer.once("close", () =>
|
|
3525
|
-
dataConsumerSample.closedAt = Date.now();
|
|
3526
|
-
});
|
|
3527
|
-
}
|
|
3528
|
-
close() {
|
|
3529
|
-
if (this.closed) return;
|
|
3530
|
-
this.closed = true;
|
|
3531
|
-
this.emit("close");
|
|
3520
|
+
dataConsumer.observer.once("close", () => dataConsumerSample.closedAt = Date.now());
|
|
3532
3521
|
}
|
|
3533
3522
|
attachRouterListeners() {
|
|
3534
3523
|
this.router.observer.once("close", () => {
|
|
@@ -3539,18 +3528,10 @@ var ObservedMediasoupRouter = class extends EventEmitter5 {
|
|
|
3539
3528
|
this.router.observer.on("newtransport", this.addTransport);
|
|
3540
3529
|
}
|
|
3541
3530
|
_attachTransportObserverListeners(transport, transportSample, onClose) {
|
|
3542
|
-
const onNewProducer = (producer) =>
|
|
3543
|
-
|
|
3544
|
-
|
|
3545
|
-
const
|
|
3546
|
-
this.addConsumer(transport, consumer);
|
|
3547
|
-
};
|
|
3548
|
-
const onNewDataProducer = (dataProducer) => {
|
|
3549
|
-
this.addDataProducer(transport, dataProducer);
|
|
3550
|
-
};
|
|
3551
|
-
const onNewDataConsumer = (dataConsumer) => {
|
|
3552
|
-
this.addDataConsumer(transport, dataConsumer);
|
|
3553
|
-
};
|
|
3531
|
+
const onNewProducer = (producer) => this.addProducer(transport, producer);
|
|
3532
|
+
const onNewConsumer = (consumer) => this.addConsumer(transport, consumer);
|
|
3533
|
+
const onNewDataProducer = (dataProducer) => this.addDataProducer(transport, dataProducer);
|
|
3534
|
+
const onNewDataConsumer = (dataConsumer) => this.addDataConsumer(transport, dataConsumer);
|
|
3554
3535
|
transport.observer.once("close", () => {
|
|
3555
3536
|
transport.observer.off("newproducer", onNewProducer);
|
|
3556
3537
|
transport.observer.off("newconsumer", onNewConsumer);
|
|
@@ -3633,7 +3614,7 @@ var Observer = class extends EventEmitter6 {
|
|
|
3633
3614
|
appData: settings.appData ?? this.config.createCallAppData?.({ callId: settings.callId, observer: this })
|
|
3634
3615
|
};
|
|
3635
3616
|
const observedCall = new ObservedCall(callSettings, this);
|
|
3636
|
-
observedCall.remoteTrackResolver = this.config.
|
|
3617
|
+
observedCall.remoteTrackResolver = this.config.createRemoteTrackResolver?.(observedCall);
|
|
3637
3618
|
observedCall.once("close", () => {
|
|
3638
3619
|
this.observedCalls.delete(observedCall.callId);
|
|
3639
3620
|
++this.totalRemovedCall;
|
|
@@ -3660,17 +3641,19 @@ var Observer = class extends EventEmitter6 {
|
|
|
3660
3641
|
observedMediasoupRouter,
|
|
3661
3642
|
observer: this
|
|
3662
3643
|
};
|
|
3663
|
-
|
|
3664
|
-
|
|
3665
|
-
|
|
3666
|
-
|
|
3667
|
-
|
|
3668
|
-
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
3673
|
-
|
|
3644
|
+
if (settings.matchPeerConnectionByWebRtcTransportId) {
|
|
3645
|
+
const onPeerConnectionAdded = (observedPeerConnectionScope) => {
|
|
3646
|
+
if (!observedMediasoupRouter.webrtcTransportIds.has(observedPeerConnectionScope.observedPeerConnection.peerConnectionId)) return;
|
|
3647
|
+
this.emit("mediasoup-router-matched-with-peer-connection", {
|
|
3648
|
+
...observedMediasoupRouterScope,
|
|
3649
|
+
...observedPeerConnectionScope
|
|
3650
|
+
});
|
|
3651
|
+
};
|
|
3652
|
+
const stopMatching = () => this.off("peer-connection-added", onPeerConnectionAdded);
|
|
3653
|
+
this.on("peer-connection-added", onPeerConnectionAdded);
|
|
3654
|
+
this.once("observer-closed", stopMatching);
|
|
3655
|
+
observedMediasoupRouter.once("close", stopMatching);
|
|
3656
|
+
}
|
|
3674
3657
|
observedMediasoupRouter.once("close", () => {
|
|
3675
3658
|
this.observedMediasoupRouters.delete(observedMediasoupRouter.id);
|
|
3676
3659
|
this.emit("mediasoup-router-removed", observedMediasoupRouterScope);
|