@observertc/observer-js 1.0.1-797e5af.0 → 1.0.1-9341fcd.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/ObservedCall.d.ts +2 -0
- package/lib/ObservedCall.d.ts.map +1 -1
- package/lib/ObservedCall.js +4 -0
- package/lib/ObservedCallEventMonitor.d.ts +104 -0
- package/lib/ObservedCallEventMonitor.d.ts.map +1 -0
- package/lib/ObservedCallEventMonitor.js +314 -0
- package/lib/ObservedClient.d.ts +2 -2
- package/lib/ObservedClient.d.ts.map +1 -1
- package/lib/ObservedClient.js +2 -4
- package/lib/ObservedIceCandidatePair.d.ts +2 -1
- package/lib/ObservedIceCandidatePair.d.ts.map +1 -1
- package/lib/ObservedIceCandidatePair.js +17 -1
- package/lib/Observer.d.ts +8 -4
- package/lib/Observer.d.ts.map +1 -1
- package/lib/Observer.js +14 -2
- package/lib/ObserverEventMonitor.d.ts +106 -0
- package/lib/ObserverEventMonitor.d.ts.map +1 -0
- package/lib/ObserverEventMonitor.js +320 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -1
- package/lib/schema/ClientEventTypes.d.ts +17 -0
- package/lib/schema/ClientEventTypes.d.ts.map +1 -1
- package/lib/schema/ClientSample.d.ts +1 -1
- package/lib/schema/ClientSample.d.ts.map +1 -1
- package/lib/updaters/{OnAllCallObserverUpdater_.d.ts → OnAllCallObserverUpdater.d.ts} +3 -1
- package/lib/updaters/OnAllCallObserverUpdater.d.ts.map +1 -0
- package/lib/updaters/{OnAllCallObserverUpdater_.js → OnAllCallObserverUpdater.js} +13 -1
- package/lib/updaters/OnAllClientCallUpdater.d.ts +2 -0
- package/lib/updaters/OnAllClientCallUpdater.d.ts.map +1 -1
- package/lib/updaters/OnAllClientCallUpdater.js +16 -0
- package/lib/updaters/{OnAnyCallObserverUpdater_.d.ts → OnAnyCallObserverUpdater.d.ts} +2 -1
- package/lib/updaters/OnAnyCallObserverUpdater.d.ts.map +1 -0
- package/lib/updaters/{OnAnyCallObserverUpdater_.js → OnAnyCallObserverUpdater.js} +11 -1
- package/lib/updaters/OnAnyClientCallUpdater.d.ts +1 -0
- package/lib/updaters/OnAnyClientCallUpdater.d.ts.map +1 -1
- package/lib/updaters/OnAnyClientCallUpdater.js +11 -2
- package/lib/utils/MediasoupRemoteTrackResolver.d.ts +25 -0
- package/lib/utils/MediasoupRemoteTrackResolver.d.ts.map +1 -0
- package/lib/utils/MediasoupRemoteTrackResolver.js +110 -0
- package/package.json +1 -1
- package/src/ObservedCall.ts +5 -0
- package/src/ObservedCallEventMonitor.ts +392 -0
- package/src/ObservedClient.ts +4 -7
- package/src/ObservedIceCandidatePair.ts +18 -2
- package/src/Observer.ts +21 -6
- package/src/ObserverEventMonitor.ts +398 -0
- package/src/index.ts +1 -0
- package/src/schema/ClientEventTypes.ts +18 -0
- package/src/schema/ClientSample.ts +1 -1
- package/src/updaters/{OnAllCallObserverUpdater_.ts → OnAllCallObserverUpdater.ts} +14 -1
- package/src/updaters/OnAllClientCallUpdater.ts +15 -0
- package/src/updaters/{OnAnyCallObserverUpdater_.ts → OnAnyCallObserverUpdater.ts} +11 -2
- package/src/updaters/OnAnyClientCallUpdater.ts +9 -2
- package/src/utils/MediasoupRemoteTrackResolver.ts +155 -0
- package/lib/updaters/OnAllCallObserverUpdater_.d.ts.map +0 -1
- package/lib/updaters/OnAnyCallObserverUpdater_.d.ts.map +0 -1
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { ObservedCall } from '../ObservedCall';
|
|
2
|
+
import { ObservedCallEventMonitor } from '../ObservedCallEventMonitor';
|
|
3
|
+
import { ObservedInboundTrack } from '../ObservedInboundTrack';
|
|
4
|
+
import { ObservedOutboundTrack } from '../ObservedOutboundTrack';
|
|
5
|
+
import { RemoteTrackResolver } from './RemoteTrackResolver';
|
|
6
|
+
|
|
7
|
+
export class MediasoupRemoteTrackResolver implements RemoteTrackResolver {
|
|
8
|
+
public readonly eventMonitor: ObservedCallEventMonitor<{
|
|
9
|
+
// empty
|
|
10
|
+
}>;
|
|
11
|
+
|
|
12
|
+
private _consumerIdToProducerId = new Map<string, string>();
|
|
13
|
+
private _producerIdToOutboundTrack = new Map<string, ObservedOutboundTrack>();
|
|
14
|
+
private _consumerIdToInboundTrack = new Map<string, ObservedInboundTrack>();
|
|
15
|
+
// private _producerIdToOutboundTrack = new Map<string, ObservedOutboundTrack>();
|
|
16
|
+
|
|
17
|
+
private _inboundTrackToConsumerId = new Map<string, string>();
|
|
18
|
+
private _producerIdToConsumerIds = new Map<string, string[]>();
|
|
19
|
+
private _outboundTrackToProducerId = new Map<string, string>();
|
|
20
|
+
|
|
21
|
+
public constructor(
|
|
22
|
+
public readonly observedCall: ObservedCall
|
|
23
|
+
) {
|
|
24
|
+
this.eventMonitor = this.observedCall.createEventMonitor({});
|
|
25
|
+
|
|
26
|
+
this.eventMonitor.onInboundTrackAdded = this._addInboundTrack.bind(this);
|
|
27
|
+
this.eventMonitor.onInboundTrackRemoved = this._removeInboundTrack.bind(this);
|
|
28
|
+
this.eventMonitor.onOutboundTrackAdded = this._addOutboundTrack.bind(this);
|
|
29
|
+
this.eventMonitor.onOutboundTrackRemoved = this._removeOutboundTrack.bind(this);
|
|
30
|
+
|
|
31
|
+
// this.eventMonitor.onClientEvent = (client, event) => {
|
|
32
|
+
|
|
33
|
+
// };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public resolveRemoteOutboundTrack(inboundTrack: ObservedInboundTrack): ObservedOutboundTrack | undefined {
|
|
37
|
+
const consumerId = this._inboundTrackToConsumerId.get(inboundTrack.id);
|
|
38
|
+
|
|
39
|
+
if (!consumerId) return;
|
|
40
|
+
|
|
41
|
+
const producerId = this._consumerIdToProducerId.get(consumerId);
|
|
42
|
+
|
|
43
|
+
if (!producerId) return;
|
|
44
|
+
|
|
45
|
+
return this._producerIdToOutboundTrack.get(producerId);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public resolveRemoteInboundTracks(outboundTrack: ObservedOutboundTrack): ObservedInboundTrack[] | undefined {
|
|
49
|
+
const producerId = this._outboundTrackToProducerId.get(outboundTrack.id);
|
|
50
|
+
|
|
51
|
+
if (!producerId) return;
|
|
52
|
+
|
|
53
|
+
const consumerIds = this._producerIdToConsumerIds.get(producerId);
|
|
54
|
+
|
|
55
|
+
if (!consumerIds) return;
|
|
56
|
+
|
|
57
|
+
return consumerIds
|
|
58
|
+
.map((consumerId) => this._consumerIdToInboundTrack.get(consumerId))
|
|
59
|
+
.filter((inboundTrack) => Boolean(inboundTrack)) as ObservedInboundTrack[]
|
|
60
|
+
;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
private _addInboundTrack(inboundTrack: ObservedInboundTrack) {
|
|
64
|
+
const attachments = this._getInboundTrackAttachments(inboundTrack);
|
|
65
|
+
|
|
66
|
+
if (!attachments) return;
|
|
67
|
+
|
|
68
|
+
const {
|
|
69
|
+
producerId,
|
|
70
|
+
consumerId
|
|
71
|
+
} = attachments;
|
|
72
|
+
|
|
73
|
+
this._inboundTrackToConsumerId.set(inboundTrack.id, consumerId);
|
|
74
|
+
this._consumerIdToProducerId.set(consumerId, producerId);
|
|
75
|
+
this._consumerIdToInboundTrack.set(consumerId, inboundTrack);
|
|
76
|
+
|
|
77
|
+
let producerConsumers = this._producerIdToConsumerIds.get(producerId);
|
|
78
|
+
|
|
79
|
+
if (!producerConsumers) {
|
|
80
|
+
producerConsumers = [];
|
|
81
|
+
this._producerIdToConsumerIds.set(producerId, producerConsumers);
|
|
82
|
+
}
|
|
83
|
+
producerConsumers.push(consumerId);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
private _removeInboundTrack(inboundTrack: ObservedInboundTrack) {
|
|
87
|
+
const consumerId = this._inboundTrackToConsumerId.get(inboundTrack.id);
|
|
88
|
+
|
|
89
|
+
if (!consumerId) return;
|
|
90
|
+
|
|
91
|
+
this._inboundTrackToConsumerId.delete(inboundTrack.id);
|
|
92
|
+
this._consumerIdToProducerId.delete(consumerId);
|
|
93
|
+
this._consumerIdToInboundTrack.delete(consumerId);
|
|
94
|
+
|
|
95
|
+
const producerConsumers = this._producerIdToConsumerIds.get(consumerId);
|
|
96
|
+
|
|
97
|
+
if (!producerConsumers) return;
|
|
98
|
+
|
|
99
|
+
const filteredProducerConsumers = producerConsumers.filter((id) => id !== consumerId);
|
|
100
|
+
|
|
101
|
+
if (filteredProducerConsumers.length === 0) {
|
|
102
|
+
this._producerIdToConsumerIds.delete(consumerId);
|
|
103
|
+
} else {
|
|
104
|
+
this._producerIdToConsumerIds.set(consumerId, filteredProducerConsumers);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
private _addOutboundTrack(outboundTrack: ObservedOutboundTrack) {
|
|
109
|
+
const attachments = this._getOutboundTrackAttachments(outboundTrack);
|
|
110
|
+
|
|
111
|
+
if (!attachments) return;
|
|
112
|
+
|
|
113
|
+
const {
|
|
114
|
+
producerId,
|
|
115
|
+
} = attachments;
|
|
116
|
+
|
|
117
|
+
this._producerIdToOutboundTrack.set(producerId, outboundTrack);
|
|
118
|
+
this._outboundTrackToProducerId.set(outboundTrack.id, producerId);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
private _removeOutboundTrack(outboundTrack: ObservedOutboundTrack) {
|
|
122
|
+
const producerId = this._outboundTrackToProducerId.get(outboundTrack.id);
|
|
123
|
+
|
|
124
|
+
if (!producerId) return;
|
|
125
|
+
|
|
126
|
+
this._producerIdToOutboundTrack.delete(producerId);
|
|
127
|
+
this._outboundTrackToProducerId.delete(outboundTrack.id);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
private _getInboundTrackAttachments(inboundTrack: ObservedInboundTrack) {
|
|
131
|
+
const {
|
|
132
|
+
producerId,
|
|
133
|
+
consumerId
|
|
134
|
+
} = inboundTrack.attachments ?? {};
|
|
135
|
+
|
|
136
|
+
if (!producerId || !consumerId || typeof producerId !== 'string' || typeof consumerId !== 'string') return;
|
|
137
|
+
|
|
138
|
+
return {
|
|
139
|
+
producerId,
|
|
140
|
+
consumerId
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
private _getOutboundTrackAttachments(outboundTrack: ObservedOutboundTrack) {
|
|
145
|
+
const {
|
|
146
|
+
producerId,
|
|
147
|
+
} = outboundTrack.attachments ?? {};
|
|
148
|
+
|
|
149
|
+
if (!producerId || typeof producerId !== 'string') return;
|
|
150
|
+
|
|
151
|
+
return {
|
|
152
|
+
producerId,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"OnAllCallObserverUpdater_.d.ts","sourceRoot":"","sources":["../../src/updaters/OnAllCallObserverUpdater_.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,qBAAa,wBAAyB,YAAW,OAAO;IAOtD,OAAO,CAAC,QAAQ;IANjB,SAAgB,IAAI,8BAA8B;IAClD,SAAgB,WAAW,+EAAgF;IAE3G,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAqB;gBAG1C,QAAQ,EAAE,QAAQ;IAU3B,KAAK,IAAI,IAAI;IAIb,OAAO,CAAC,kBAAkB;IAU1B,OAAO,CAAC,sBAAsB;CAU9B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"OnAnyCallObserverUpdater_.d.ts","sourceRoot":"","sources":["../../src/updaters/OnAnyCallObserverUpdater_.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,qBAAa,wBAAyB,YAAW,OAAO;IAKtD,OAAO,CAAC,SAAS;IAJlB,SAAgB,IAAI,8BAA8B;IAClD,SAAgB,WAAW,2EAA4E;gBAG9F,SAAS,EAAE,QAAQ;IAU5B,KAAK,IAAI,IAAI;IAIb,OAAO,CAAC,kBAAkB;CAQ1B"}
|