@observertc/observer-js 1.0.1-ec27289.0 → 1.1.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/README.md +2184 -1
- package/dist/index.d.mts +6842 -0
- package/dist/index.d.ts +6842 -0
- package/dist/index.js +7736 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +7608 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +44 -18
- package/.eslintrc.json +0 -143
- package/.prettierignore +0 -5
- package/.prettierrc +0 -7
- package/jest.config.js +0 -9
- package/lib/ObservedCall.d.ts +0 -83
- package/lib/ObservedCall.d.ts.map +0 -1
- package/lib/ObservedCall.js +0 -203
- package/lib/ObservedCallSummary.d.ts +0 -18
- package/lib/ObservedCallSummary.d.ts.map +0 -1
- package/lib/ObservedCallSummary.js +0 -2
- package/lib/ObservedCertificate.d.ts +0 -19
- package/lib/ObservedCertificate.d.ts.map +0 -1
- package/lib/ObservedCertificate.js +0 -38
- package/lib/ObservedClient.d.ts +0 -131
- package/lib/ObservedClient.d.ts.map +0 -1
- package/lib/ObservedClient.js +0 -520
- package/lib/ObservedClientEventMonitor.d.ts +0 -89
- package/lib/ObservedClientEventMonitor.d.ts.map +0 -1
- package/lib/ObservedClientEventMonitor.js +0 -247
- package/lib/ObservedClientSummary.d.ts +0 -23
- package/lib/ObservedClientSummary.d.ts.map +0 -1
- package/lib/ObservedClientSummary.js +0 -2
- package/lib/ObservedCodec.d.ts +0 -22
- package/lib/ObservedCodec.d.ts.map +0 -1
- package/lib/ObservedCodec.js +0 -45
- package/lib/ObservedDataChannel.d.ts +0 -30
- package/lib/ObservedDataChannel.d.ts.map +0 -1
- package/lib/ObservedDataChannel.js +0 -75
- package/lib/ObservedIceCandidate.d.ts +0 -29
- package/lib/ObservedIceCandidate.d.ts.map +0 -1
- package/lib/ObservedIceCandidate.js +0 -59
- package/lib/ObservedIceCandidatePair.d.ts +0 -44
- package/lib/ObservedIceCandidatePair.d.ts.map +0 -1
- package/lib/ObservedIceCandidatePair.js +0 -111
- package/lib/ObservedIceTransport.d.ts +0 -36
- package/lib/ObservedIceTransport.d.ts.map +0 -1
- package/lib/ObservedIceTransport.js +0 -93
- package/lib/ObservedInboundRtp.d.ts +0 -92
- package/lib/ObservedInboundRtp.d.ts.map +0 -1
- package/lib/ObservedInboundRtp.js +0 -193
- package/lib/ObservedInboundTrack.d.ts +0 -31
- package/lib/ObservedInboundTrack.d.ts.map +0 -1
- package/lib/ObservedInboundTrack.js +0 -59
- package/lib/ObservedMediaPlayout.d.ts +0 -22
- package/lib/ObservedMediaPlayout.d.ts.map +0 -1
- package/lib/ObservedMediaPlayout.js +0 -42
- package/lib/ObservedMediaSource.d.ts +0 -28
- package/lib/ObservedMediaSource.d.ts.map +0 -1
- package/lib/ObservedMediaSource.js +0 -55
- package/lib/ObservedOutboundRtp.d.ts +0 -62
- package/lib/ObservedOutboundRtp.d.ts.map +0 -1
- package/lib/ObservedOutboundRtp.js +0 -144
- package/lib/ObservedOutboundTrack.d.ts +0 -31
- package/lib/ObservedOutboundTrack.d.ts.map +0 -1
- package/lib/ObservedOutboundTrack.js +0 -59
- package/lib/ObservedPeerConnection.d.ts +0 -185
- package/lib/ObservedPeerConnection.d.ts.map +0 -1
- package/lib/ObservedPeerConnection.js +0 -710
- package/lib/ObservedPeerConnectionTransport.d.ts +0 -17
- package/lib/ObservedPeerConnectionTransport.d.ts.map +0 -1
- package/lib/ObservedPeerConnectionTransport.js +0 -34
- package/lib/ObservedRemoteInboundRtp.d.ts +0 -30
- package/lib/ObservedRemoteInboundRtp.d.ts.map +0 -1
- package/lib/ObservedRemoteInboundRtp.js +0 -60
- package/lib/ObservedRemoteOutboundRtp.d.ts +0 -30
- package/lib/ObservedRemoteOutboundRtp.d.ts.map +0 -1
- package/lib/ObservedRemoteOutboundRtp.js +0 -60
- package/lib/ObservedTURN.d.ts +0 -31
- package/lib/ObservedTURN.d.ts.map +0 -1
- package/lib/ObservedTURN.js +0 -58
- package/lib/ObservedTurnServer.d.ts +0 -25
- package/lib/ObservedTurnServer.d.ts.map +0 -1
- package/lib/ObservedTurnServer.js +0 -59
- package/lib/Observer.d.ts +0 -61
- package/lib/Observer.d.ts.map +0 -1
- package/lib/Observer.js +0 -156
- package/lib/ObserverSummary.d.ts +0 -13
- package/lib/ObserverSummary.d.ts.map +0 -1
- package/lib/ObserverSummary.js +0 -2
- package/lib/common/Middleware.d.ts +0 -17
- package/lib/common/Middleware.d.ts.map +0 -1
- package/lib/common/Middleware.js +0 -60
- package/lib/common/SingleExecutor.d.ts +0 -3
- package/lib/common/SingleExecutor.d.ts.map +0 -1
- package/lib/common/SingleExecutor.js +0 -31
- package/lib/common/logger.d.ts +0 -17
- package/lib/common/logger.d.ts.map +0 -1
- package/lib/common/logger.js +0 -50
- package/lib/common/types.d.ts +0 -3
- package/lib/common/types.d.ts.map +0 -1
- package/lib/common/types.js +0 -3
- package/lib/common/utils.d.ts +0 -11
- package/lib/common/utils.d.ts.map +0 -1
- package/lib/common/utils.js +0 -63
- package/lib/detectors/Detector.d.ts +0 -5
- package/lib/detectors/Detector.d.ts.map +0 -1
- package/lib/detectors/Detector.js +0 -3
- package/lib/detectors/Detectors.d.ts +0 -11
- package/lib/detectors/Detectors.d.ts.map +0 -1
- package/lib/detectors/Detectors.js +0 -34
- package/lib/index.d.ts +0 -27
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -47
- package/lib/monitors/TurnUsageMonitor.d.ts +0 -1
- package/lib/monitors/TurnUsageMonitor.d.ts.map +0 -1
- package/lib/monitors/TurnUsageMonitor.js +0 -146
- package/lib/schema/ClientEventTypes.d.ts +0 -100
- package/lib/schema/ClientEventTypes.d.ts.map +0 -1
- package/lib/schema/ClientEventTypes.js +0 -38
- package/lib/schema/ClientMetaTypes.d.ts +0 -34
- package/lib/schema/ClientMetaTypes.d.ts.map +0 -1
- package/lib/schema/ClientMetaTypes.js +0 -16
- package/lib/schema/ClientSample.d.ts +0 -1333
- package/lib/schema/ClientSample.d.ts.map +0 -1
- package/lib/schema/ClientSample.js +0 -4
- package/lib/scores/CalculatedScore.d.ts +0 -6
- package/lib/scores/CalculatedScore.d.ts.map +0 -1
- package/lib/scores/CalculatedScore.js +0 -2
- package/lib/scores/DefaultCallScoreCalculator.d.ts +0 -7
- package/lib/scores/DefaultCallScoreCalculator.d.ts.map +0 -1
- package/lib/scores/DefaultCallScoreCalculator.js +0 -21
- package/lib/scores/ScoreCalculator.d.ts +0 -4
- package/lib/scores/ScoreCalculator.d.ts.map +0 -1
- package/lib/scores/ScoreCalculator.js +0 -2
- package/lib/updaters/CallUpdater.d.ts +0 -5
- package/lib/updaters/CallUpdater.d.ts.map +0 -1
- package/lib/updaters/CallUpdater.js +0 -2
- package/lib/updaters/ObserverUpdater.d.ts +0 -5
- package/lib/updaters/ObserverUpdater.d.ts.map +0 -1
- package/lib/updaters/ObserverUpdater.js +0 -2
- package/lib/updaters/OnAllCallObserverUpdater_.d.ts +0 -13
- package/lib/updaters/OnAllCallObserverUpdater_.d.ts.map +0 -1
- package/lib/updaters/OnAllCallObserverUpdater_.js +0 -38
- package/lib/updaters/OnAllClientCallUpdater.d.ts +0 -13
- package/lib/updaters/OnAllClientCallUpdater.d.ts.map +0 -1
- package/lib/updaters/OnAllClientCallUpdater.js +0 -37
- package/lib/updaters/OnAnyCallObserverUpdater_.d.ts +0 -11
- package/lib/updaters/OnAnyCallObserverUpdater_.d.ts.map +0 -1
- package/lib/updaters/OnAnyCallObserverUpdater_.js +0 -27
- package/lib/updaters/OnAnyClientCallUpdater.d.ts +0 -11
- package/lib/updaters/OnAnyClientCallUpdater.d.ts.map +0 -1
- package/lib/updaters/OnAnyClientCallUpdater.js +0 -27
- package/lib/updaters/OnIntervalUpdater.d.ts +0 -10
- package/lib/updaters/OnIntervalUpdater.d.ts.map +0 -1
- package/lib/updaters/OnIntervalUpdater.js +0 -17
- package/lib/updaters/Updater.d.ts +0 -6
- package/lib/updaters/Updater.d.ts.map +0 -1
- package/lib/updaters/Updater.js +0 -2
- package/lib/utils/RemoteTrackResolver.d.ts +0 -7
- package/lib/utils/RemoteTrackResolver.d.ts.map +0 -1
- package/lib/utils/RemoteTrackResolver.js +0 -2
- package/src/ObservedCall.ts +0 -322
- package/src/ObservedCallSummary.ts +0 -22
- package/src/ObservedCertificate.ts +0 -43
- package/src/ObservedClient.ts +0 -673
- package/src/ObservedClientEventMonitor.ts +0 -301
- package/src/ObservedClientSummary.ts +0 -24
- package/src/ObservedCodec.ts +0 -49
- package/src/ObservedDataChannel.ts +0 -85
- package/src/ObservedIceCandidate.ts +0 -64
- package/src/ObservedIceCandidatePair.ts +0 -118
- package/src/ObservedIceTransport.ts +0 -99
- package/src/ObservedInboundRtp.ts +0 -205
- package/src/ObservedInboundTrack.ts +0 -73
- package/src/ObservedMediaPlayout.ts +0 -49
- package/src/ObservedMediaSource.ts +0 -60
- package/src/ObservedOutboundRtp.ts +0 -156
- package/src/ObservedOutboundTrack.ts +0 -72
- package/src/ObservedPeerConnection.ts +0 -1019
- package/src/ObservedPeerConnectionTransport.ts +0 -38
- package/src/ObservedRemoteInboundRtp.ts +0 -64
- package/src/ObservedRemoteOutboundRtp.ts +0 -65
- package/src/ObservedTURN.ts +0 -86
- package/src/ObservedTurnServer.ts +0 -72
- package/src/Observer.ts +0 -239
- package/src/ObserverSummary.ts +0 -15
- package/src/common/Middleware.ts +0 -84
- package/src/common/SingleExecutor.ts +0 -36
- package/src/common/logger.ts +0 -82
- package/src/common/types.ts +0 -4
- package/src/common/utils.ts +0 -69
- package/src/detectors/Detector.ts +0 -6
- package/src/detectors/Detectors.ts +0 -38
- package/src/index.ts +0 -28
- package/src/monitors/TurnUsageMonitor.ts +0 -187
- package/src/schema/ClientEventTypes.ts +0 -112
- package/src/schema/ClientMetaTypes.ts +0 -41
- package/src/schema/ClientSample.ts +0 -1682
- package/src/scores/CalculatedScore.ts +0 -6
- package/src/scores/DefaultCallScoreCalculator.ts +0 -23
- package/src/scores/ScoreCalculator.ts +0 -3
- package/src/updaters/CallUpdater.ts +0 -5
- package/src/updaters/ObserverUpdater.ts +0 -5
- package/src/updaters/OnAllCallObserverUpdater_.ts +0 -46
- package/src/updaters/OnAllClientCallUpdater.ts +0 -46
- package/src/updaters/OnAnyCallObserverUpdater_.ts +0 -32
- package/src/updaters/OnAnyClientCallUpdater.ts +0 -32
- package/src/updaters/OnIntervalUpdater.ts +0 -19
- package/src/updaters/Updater.ts +0 -5
- package/src/utils/RemoteTrackResolver.ts +0 -12
- package/tsconfig.json +0 -19
- package/tslint.json +0 -6
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { ObservedPeerConnection } from './ObservedPeerConnection';
|
|
2
|
-
import { PeerConnectionTransportStats } from './schema/ClientSample';
|
|
3
|
-
|
|
4
|
-
export class ObservedPeerConnectionTransport implements PeerConnectionTransportStats {
|
|
5
|
-
private _visited = false;
|
|
6
|
-
public appData?: Record<string, unknown>;
|
|
7
|
-
|
|
8
|
-
dataChannelsOpened?: number | undefined;
|
|
9
|
-
dataChannelsClosed?: number | undefined;
|
|
10
|
-
attachments?: Record<string, unknown> | undefined;
|
|
11
|
-
|
|
12
|
-
public constructor(
|
|
13
|
-
public timestamp: number,
|
|
14
|
-
public id: string,
|
|
15
|
-
private readonly _peerConnection: ObservedPeerConnection
|
|
16
|
-
) {}
|
|
17
|
-
|
|
18
|
-
public get visited() {
|
|
19
|
-
const visited = this._visited;
|
|
20
|
-
|
|
21
|
-
this._visited = false;
|
|
22
|
-
|
|
23
|
-
return visited;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
public getPeerConnection() {
|
|
27
|
-
return this._peerConnection;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
public update(stats: PeerConnectionTransportStats) {
|
|
31
|
-
this._visited = true;
|
|
32
|
-
|
|
33
|
-
this.timestamp = stats.timestamp;
|
|
34
|
-
this.dataChannelsOpened = stats.dataChannelsOpened;
|
|
35
|
-
this.dataChannelsClosed = stats.dataChannelsClosed;
|
|
36
|
-
this.attachments = stats.attachments;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { MediaKind } from './common/types';
|
|
2
|
-
import { ObservedPeerConnection } from './ObservedPeerConnection';
|
|
3
|
-
import { RemoteInboundRtpStats } from './schema/ClientSample';
|
|
4
|
-
|
|
5
|
-
export class ObservedRemoteInboundRtp implements RemoteInboundRtpStats {
|
|
6
|
-
private _visited = false;
|
|
7
|
-
public appData?: Record<string, unknown>;
|
|
8
|
-
transportId?: string | undefined;
|
|
9
|
-
codecId?: string | undefined;
|
|
10
|
-
packetsReceived?: number | undefined;
|
|
11
|
-
packetsLost?: number | undefined;
|
|
12
|
-
jitter?: number | undefined;
|
|
13
|
-
localId?: string | undefined;
|
|
14
|
-
roundTripTime?: number | undefined;
|
|
15
|
-
totalRoundTripTime?: number | undefined;
|
|
16
|
-
fractionLost?: number | undefined;
|
|
17
|
-
roundTripTimeMeasurements?: number | undefined;
|
|
18
|
-
attachments?: Record<string, unknown> | undefined;
|
|
19
|
-
|
|
20
|
-
public constructor(
|
|
21
|
-
public timestamp: number,
|
|
22
|
-
public id: string,
|
|
23
|
-
public ssrc: number,
|
|
24
|
-
public kind: MediaKind,
|
|
25
|
-
private readonly _peerConnection: ObservedPeerConnection
|
|
26
|
-
) {}
|
|
27
|
-
|
|
28
|
-
public get visited() {
|
|
29
|
-
const visited = this._visited;
|
|
30
|
-
|
|
31
|
-
this._visited = false;
|
|
32
|
-
|
|
33
|
-
return visited;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
public getPeerConnection() {
|
|
37
|
-
return this._peerConnection;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
public getOutboundRtp() {
|
|
41
|
-
return this._peerConnection.observedOutboundRtps.get(this.ssrc);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
public getCodec() {
|
|
45
|
-
return this._peerConnection.observedCodecs.get(this.codecId ?? '');
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
public update(stats: RemoteInboundRtpStats) {
|
|
49
|
-
this._visited = true;
|
|
50
|
-
|
|
51
|
-
this.timestamp = stats.timestamp;
|
|
52
|
-
this.transportId = stats.transportId;
|
|
53
|
-
this.codecId = stats.codecId;
|
|
54
|
-
this.packetsReceived = stats.packetsReceived;
|
|
55
|
-
this.packetsLost = stats.packetsLost;
|
|
56
|
-
this.jitter = stats.jitter;
|
|
57
|
-
this.localId = stats.localId;
|
|
58
|
-
this.roundTripTime = stats.roundTripTime;
|
|
59
|
-
this.totalRoundTripTime = stats.totalRoundTripTime;
|
|
60
|
-
this.fractionLost = stats.fractionLost;
|
|
61
|
-
this.roundTripTimeMeasurements = stats.roundTripTimeMeasurements;
|
|
62
|
-
this.attachments = stats.attachments;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { MediaKind } from './common/types';
|
|
2
|
-
import { ObservedPeerConnection } from './ObservedPeerConnection';
|
|
3
|
-
import { RemoteOutboundRtpStats } from './schema/ClientSample';
|
|
4
|
-
|
|
5
|
-
export class ObservedRemoteOutboundRtp implements RemoteOutboundRtpStats {
|
|
6
|
-
private _visited = false;
|
|
7
|
-
public appData?: Record<string, unknown>;
|
|
8
|
-
|
|
9
|
-
transportId?: string | undefined;
|
|
10
|
-
codecId?: string | undefined;
|
|
11
|
-
packetsSent?: number | undefined;
|
|
12
|
-
bytesSent?: number | undefined;
|
|
13
|
-
localId?: string | undefined;
|
|
14
|
-
remoteTimestamp?: number | undefined;
|
|
15
|
-
reportsSent?: number | undefined;
|
|
16
|
-
roundTripTime?: number | undefined;
|
|
17
|
-
totalRoundTripTime?: number | undefined;
|
|
18
|
-
roundTripTimeMeasurements?: number | undefined;
|
|
19
|
-
attachments?: Record<string, unknown> | undefined;
|
|
20
|
-
|
|
21
|
-
public constructor(
|
|
22
|
-
public timestamp: number,
|
|
23
|
-
public id: string,
|
|
24
|
-
public ssrc: number,
|
|
25
|
-
public kind: MediaKind,
|
|
26
|
-
private readonly _peerConnection: ObservedPeerConnection
|
|
27
|
-
) {}
|
|
28
|
-
|
|
29
|
-
public get visited() {
|
|
30
|
-
const visited = this._visited;
|
|
31
|
-
|
|
32
|
-
this._visited = false;
|
|
33
|
-
|
|
34
|
-
return visited;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
public getPeerConnection() {
|
|
38
|
-
return this._peerConnection;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
public getInboundRtp() {
|
|
42
|
-
return this._peerConnection.observedInboundRtps.get(this.ssrc);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
public getCodec() {
|
|
46
|
-
return this._peerConnection.observedCodecs.get(this.codecId ?? '');
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
public update(stats: RemoteOutboundRtpStats) {
|
|
50
|
-
this._visited = true;
|
|
51
|
-
|
|
52
|
-
this.timestamp = stats.timestamp;
|
|
53
|
-
this.transportId = stats.transportId;
|
|
54
|
-
this.codecId = stats.codecId;
|
|
55
|
-
this.packetsSent = stats.packetsSent;
|
|
56
|
-
this.bytesSent = stats.bytesSent;
|
|
57
|
-
this.localId = stats.localId;
|
|
58
|
-
this.remoteTimestamp = stats.remoteTimestamp;
|
|
59
|
-
this.reportsSent = stats.reportsSent;
|
|
60
|
-
this.roundTripTime = stats.roundTripTime;
|
|
61
|
-
this.totalRoundTripTime = stats.totalRoundTripTime;
|
|
62
|
-
this.roundTripTimeMeasurements = stats.roundTripTimeMeasurements;
|
|
63
|
-
this.attachments = stats.attachments;
|
|
64
|
-
}
|
|
65
|
-
}
|
package/src/ObservedTURN.ts
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from 'stream';
|
|
2
|
-
import { ObservedPeerConnection } from './ObservedPeerConnection';
|
|
3
|
-
import { ObservedTurnServer } from './ObservedTurnServer';
|
|
4
|
-
import { createLogger } from './common/logger';
|
|
5
|
-
|
|
6
|
-
const logger = createLogger('ObservedTURN');
|
|
7
|
-
|
|
8
|
-
export type ObservedTURNEventMap = {
|
|
9
|
-
'update': [ObservedTURN];
|
|
10
|
-
'close': [];
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export declare interface ObservedTURN {
|
|
14
|
-
on<U extends keyof ObservedTURNEventMap>(event: U, listener: (...args: ObservedTURNEventMap[U]) => void): this;
|
|
15
|
-
off<U extends keyof ObservedTURNEventMap>(event: U, listener: (...args: ObservedTURNEventMap[U]) => void): this;
|
|
16
|
-
once<U extends keyof ObservedTURNEventMap>(event: U, listener: (...args: ObservedTURNEventMap[U]) => void): this;
|
|
17
|
-
emit<U extends keyof ObservedTURNEventMap>(event: U, ...args: ObservedTURNEventMap[U]): boolean;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export class ObservedTURN extends EventEmitter {
|
|
21
|
-
public totalBytesSent = 0;
|
|
22
|
-
public totalBytesReceived = 0;
|
|
23
|
-
public totalPacketsSent = 0;
|
|
24
|
-
public totalPacketsReceived = 0;
|
|
25
|
-
|
|
26
|
-
public packetsSentPerSecond = 0;
|
|
27
|
-
public packetsReceivedPerSecond = 0;
|
|
28
|
-
public outboundBitrate = 0;
|
|
29
|
-
public inboundBitrate = 0;
|
|
30
|
-
public numberOfClients = 0;
|
|
31
|
-
|
|
32
|
-
public readonly servers = new Map<string, ObservedTurnServer>();
|
|
33
|
-
|
|
34
|
-
public constructor(
|
|
35
|
-
) {
|
|
36
|
-
super();
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
public update() {
|
|
40
|
-
const clientIds = new Set<string>();
|
|
41
|
-
|
|
42
|
-
this.packetsReceivedPerSecond = 0;
|
|
43
|
-
this.packetsSentPerSecond = 0;
|
|
44
|
-
this.outboundBitrate = 0;
|
|
45
|
-
this.inboundBitrate = 0;
|
|
46
|
-
|
|
47
|
-
for (const server of this.servers.values()) {
|
|
48
|
-
server.update();
|
|
49
|
-
server.observedPeerConnections.forEach((pc) => clientIds.add(pc.client.clientId));
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
this.numberOfClients = clientIds.size;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
public addPeerConnection(peerConnection: ObservedPeerConnection) {
|
|
56
|
-
const turnPairs = peerConnection.selectedIceCandidatePairs.filter((pair) => pair.getLocalCandidate()?.candidateType === 'relay' && pair.getRemoteCandidate()?.url?.startsWith('turn:'));
|
|
57
|
-
|
|
58
|
-
if (turnPairs.length !== 1) {
|
|
59
|
-
return (logger.warn(`Expected exactly one TURN pair, but found for peerconnection ${peerConnection.peerConnectionId}`, turnPairs.length), undefined);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const candidatePair = turnPairs[0];
|
|
63
|
-
const rawUrl = candidatePair.getRemoteCandidate()?.url;
|
|
64
|
-
|
|
65
|
-
if (!rawUrl) {
|
|
66
|
-
return (logger.warn(`No remote candidate URL found for peerconnection ${peerConnection.peerConnectionId}`), undefined);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const turnUrl = new URL(rawUrl);
|
|
70
|
-
const turnServerUrl = `${turnUrl.protocol}//${turnUrl.hostname}:${turnUrl.port}`;
|
|
71
|
-
let turnServer = this.servers.get(turnServerUrl);
|
|
72
|
-
|
|
73
|
-
if (!turnServer) {
|
|
74
|
-
turnServer = new ObservedTurnServer(turnServerUrl, this);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return turnServer;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
public removePeerConnection(peerConnection: ObservedPeerConnection) {
|
|
81
|
-
for (const turnServer of this.servers.values()) {
|
|
82
|
-
turnServer.observedPeerConnections.delete(peerConnection.peerConnectionId);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { ObservedIceCandidatePair } from './ObservedIceCandidatePair';
|
|
2
|
-
import { ObservedPeerConnection } from './ObservedPeerConnection';
|
|
3
|
-
import { ObservedTURN } from './ObservedTURN';
|
|
4
|
-
|
|
5
|
-
export class ObservedTurnServer {
|
|
6
|
-
public totalBytesSent = 0;
|
|
7
|
-
public totalBytesReceived = 0;
|
|
8
|
-
public totalPacketsSent = 0;
|
|
9
|
-
public totalPacketsReceived = 0;
|
|
10
|
-
|
|
11
|
-
public packetsSentPerSecond = 0;
|
|
12
|
-
public packetsReceivedPerSecond = 0;
|
|
13
|
-
public outboundBitrate = 0;
|
|
14
|
-
public inboundBitrate = 0;
|
|
15
|
-
|
|
16
|
-
public deltaBytesSent = 0;
|
|
17
|
-
public deltaBytesReceived = 0;
|
|
18
|
-
public deltaPacketsSent = 0;
|
|
19
|
-
public deltaPacketsReceived = 0;
|
|
20
|
-
|
|
21
|
-
public readonly observedPeerConnections = new Map<string, ObservedPeerConnection>();
|
|
22
|
-
|
|
23
|
-
public updated = Date.now();
|
|
24
|
-
|
|
25
|
-
public constructor(
|
|
26
|
-
public readonly url: string,
|
|
27
|
-
public readonly observedTURN: ObservedTURN,
|
|
28
|
-
) {
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
public updateTurnUsage(...selectedcandidatepairs: ObservedIceCandidatePair[]) {
|
|
33
|
-
for (const selectedcandidatepair of selectedcandidatepairs) {
|
|
34
|
-
this.deltaBytesReceived += selectedcandidatepair.deltaBytesReceived;
|
|
35
|
-
this.deltaBytesSent += selectedcandidatepair.deltaBytesSent;
|
|
36
|
-
this.deltaPacketsReceived += selectedcandidatepair.deltaPacketsReceived;
|
|
37
|
-
this.deltaPacketsSent += selectedcandidatepair.deltaPacketsSent;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
public update() {
|
|
42
|
-
const now = Date.now();
|
|
43
|
-
const deltaInS = (now - this.updated) / 1000;
|
|
44
|
-
|
|
45
|
-
this.packetsSentPerSecond = this.deltaPacketsSent / deltaInS;
|
|
46
|
-
this.packetsReceivedPerSecond = this.deltaPacketsReceived / deltaInS;
|
|
47
|
-
this.outboundBitrate = (this.deltaBytesReceived * 8) / deltaInS;
|
|
48
|
-
this.inboundBitrate = (this.deltaBytesSent * 8) / deltaInS;
|
|
49
|
-
|
|
50
|
-
this.totalBytesSent += this.deltaBytesSent;
|
|
51
|
-
this.totalBytesReceived += this.deltaBytesReceived;
|
|
52
|
-
this.totalPacketsSent += this.deltaPacketsSent;
|
|
53
|
-
this.totalPacketsReceived += this.deltaPacketsReceived;
|
|
54
|
-
|
|
55
|
-
this.observedTURN.totalBytesSent += this.deltaBytesSent;
|
|
56
|
-
this.observedTURN.totalBytesReceived += this.deltaBytesReceived;
|
|
57
|
-
this.observedTURN.totalPacketsSent += this.deltaPacketsSent;
|
|
58
|
-
this.observedTURN.totalPacketsReceived += this.deltaPacketsReceived;
|
|
59
|
-
|
|
60
|
-
this.observedTURN.inboundBitrate += this.inboundBitrate;
|
|
61
|
-
this.observedTURN.outboundBitrate += this.outboundBitrate;
|
|
62
|
-
this.observedTURN.packetsReceivedPerSecond += this.packetsReceivedPerSecond;
|
|
63
|
-
this.observedTURN.packetsSentPerSecond += this.packetsSentPerSecond;
|
|
64
|
-
|
|
65
|
-
this.deltaBytesSent = 0;
|
|
66
|
-
this.deltaBytesReceived = 0;
|
|
67
|
-
this.deltaPacketsSent = 0;
|
|
68
|
-
this.deltaPacketsReceived = 0;
|
|
69
|
-
|
|
70
|
-
this.updated = now;
|
|
71
|
-
}
|
|
72
|
-
}
|
package/src/Observer.ts
DELETED
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
import { createLogger } from './common/logger';
|
|
2
|
-
import { ObservedCall, ObservedCallSettings } from './ObservedCall';
|
|
3
|
-
import { EventEmitter } from 'events';
|
|
4
|
-
import { ClientEvent, ClientMetaData, ClientIssue, ExtensionStat, ClientSample } from './schema/ClientSample';
|
|
5
|
-
import { ObservedClient } from './ObservedClient';
|
|
6
|
-
import { ObservedTURN } from './ObservedTURN';
|
|
7
|
-
import { Detectors } from './detectors/Detectors';
|
|
8
|
-
import { Updater } from './updaters/Updater';
|
|
9
|
-
import { OnIntervalUpdater } from './updaters/OnIntervalUpdater';
|
|
10
|
-
import { OnAllCallObserverUpdater } from './updaters/OnAllCallObserverUpdater_';
|
|
11
|
-
import { OnAnyCallObserverUpdater } from './updaters/OnAnyCallObserverUpdater_';
|
|
12
|
-
|
|
13
|
-
const logger = createLogger('Observer');
|
|
14
|
-
|
|
15
|
-
export type ObserverEvents = {
|
|
16
|
-
'client-event': [ObservedClient, ClientEvent];
|
|
17
|
-
'call-updated': [ObservedCall],
|
|
18
|
-
'client-issue': [ObservedClient, ClientIssue],
|
|
19
|
-
'client-metadata': [ObservedClient, ClientMetaData],
|
|
20
|
-
'client-extension-stats': [ObservedClient, ExtensionStat],
|
|
21
|
-
'newcall': [ObservedCall],
|
|
22
|
-
'update': [],
|
|
23
|
-
'close': [],
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export type ObserverConfig = {
|
|
27
|
-
updatePolicy?: 'update-on-any-call-updated' | 'update-when-all-call-updated' | 'update-on-interval',
|
|
28
|
-
updateIntervalInMs?: number,
|
|
29
|
-
defaultCallUpdatePolicy?: ObservedCallSettings['updatePolicy'],
|
|
30
|
-
defaultCallUpdateIntervalInMs?: number,
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export declare interface Observer {
|
|
34
|
-
on<U extends keyof ObserverEvents>(event: U, listener: (...args: ObserverEvents[U]) => void): this;
|
|
35
|
-
off<U extends keyof ObserverEvents>(event: U, listener: (...args: ObserverEvents[U]) => void): this;
|
|
36
|
-
once<U extends keyof ObserverEvents>(event: U, listener: (...args: ObserverEvents[U]) => void): this;
|
|
37
|
-
emit<U extends keyof ObserverEvents>(event: U, ...args: ObserverEvents[U]): boolean;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export class Observer extends EventEmitter {
|
|
41
|
-
public readonly detectors: Detectors;
|
|
42
|
-
|
|
43
|
-
public readonly observedTURN = new ObservedTURN();
|
|
44
|
-
public readonly observedCalls = new Map<string, ObservedCall>();
|
|
45
|
-
public updater?: Updater;
|
|
46
|
-
|
|
47
|
-
public closed = false;
|
|
48
|
-
|
|
49
|
-
public totalAddedCall = 0;
|
|
50
|
-
public totalRemovedCall = 0;
|
|
51
|
-
public totalRttLt50Measurements = 0;
|
|
52
|
-
public totalRttLt150Measurements = 0;
|
|
53
|
-
public totalRttLt300Measurements = 0;
|
|
54
|
-
public totalRttGtOrEq300Measurements = 0;
|
|
55
|
-
public totalClientIssues = 0;
|
|
56
|
-
|
|
57
|
-
public numberOfClientsUsingTurn = 0;
|
|
58
|
-
public numberOfClients = 0;
|
|
59
|
-
public numberOfInboundRtpStreams = 0;
|
|
60
|
-
public numberOfOutboundRtpStreams = 0;
|
|
61
|
-
public numberOfDataChannels = 0;
|
|
62
|
-
public numberOfPeerConnections = 0;
|
|
63
|
-
|
|
64
|
-
public get numberOfCalls() {
|
|
65
|
-
return this.observedCalls.size;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
private _timer?: ReturnType<typeof setInterval>;
|
|
69
|
-
|
|
70
|
-
public constructor(public readonly config: ObserverConfig = {
|
|
71
|
-
updatePolicy: 'update-when-all-call-updated',
|
|
72
|
-
updateIntervalInMs: undefined,
|
|
73
|
-
}) {
|
|
74
|
-
super();
|
|
75
|
-
this.setMaxListeners(Infinity);
|
|
76
|
-
this.update = this.update.bind(this);
|
|
77
|
-
|
|
78
|
-
if (this.config.updateIntervalInMs) {
|
|
79
|
-
if (this.config.updatePolicy && this.config.updatePolicy !== 'update-on-interval') {
|
|
80
|
-
throw new Error('update policy must be update-on-interval if updateIntervalInMs is set in config');
|
|
81
|
-
}
|
|
82
|
-
this._timer = setInterval(this.update.bind(this), this.config.updateIntervalInMs);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (this.config.updateIntervalInMs) {
|
|
86
|
-
if (this.config.updatePolicy !== 'update-on-interval') {
|
|
87
|
-
throw new Error('updatePolicy must be update-on-interval if updateIntervalInMs is set in config');
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
switch (this.config.updatePolicy) {
|
|
91
|
-
case 'update-on-any-call-updated':
|
|
92
|
-
this.updater = new OnAllCallObserverUpdater(this);
|
|
93
|
-
break;
|
|
94
|
-
case 'update-when-all-call-updated':
|
|
95
|
-
this.updater = new OnAnyCallObserverUpdater(this);
|
|
96
|
-
break;
|
|
97
|
-
case 'update-on-interval':
|
|
98
|
-
if (!this.config.updateIntervalInMs) {
|
|
99
|
-
throw new Error('updateIntervalInMs setting in config must be set if updatePolicy is update-on-interval');
|
|
100
|
-
}
|
|
101
|
-
this.updater = new OnIntervalUpdater(
|
|
102
|
-
this.config.updateIntervalInMs,
|
|
103
|
-
this.update.bind(this),
|
|
104
|
-
);
|
|
105
|
-
break;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
this.detectors = new Detectors();
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
public getObservedCall<T extends Record<string, unknown> = Record<string, unknown>>(callId: string): ObservedCall<T> | undefined {
|
|
112
|
-
if (this.closed || !this.observedCalls.has(callId)) return;
|
|
113
|
-
|
|
114
|
-
return this.observedCalls.get(callId) as ObservedCall<T>;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
public createObservedCall<T extends Record<string, unknown> = Record<string, unknown>>(
|
|
118
|
-
settings: ObservedCallSettings<T>
|
|
119
|
-
): ObservedCall<T> {
|
|
120
|
-
if (this.closed) {
|
|
121
|
-
throw new Error('Attempted to create a call source on a closed observer');
|
|
122
|
-
}
|
|
123
|
-
if (!settings.updatePolicy) {
|
|
124
|
-
settings.updatePolicy = this.config.defaultCallUpdatePolicy;
|
|
125
|
-
settings.updateIntervalInMs = this.config.defaultCallUpdateIntervalInMs;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const observedCall = new ObservedCall(settings, this);
|
|
129
|
-
const onCallUpdated = () => this._onObservedCallUpdated(observedCall);
|
|
130
|
-
|
|
131
|
-
if (this.observedCalls.has(observedCall.callId)) throw new Error(`Observed Call with id ${observedCall.callId} already exists`);
|
|
132
|
-
|
|
133
|
-
observedCall.once('close', () => {
|
|
134
|
-
this.observedCalls.delete(observedCall.callId);
|
|
135
|
-
observedCall.off('update', onCallUpdated);
|
|
136
|
-
++this.totalRemovedCall;
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
this.observedCalls.set(observedCall.callId, observedCall);
|
|
140
|
-
observedCall.on('update', onCallUpdated);
|
|
141
|
-
++this.totalAddedCall;
|
|
142
|
-
|
|
143
|
-
this.emit('newcall', observedCall);
|
|
144
|
-
|
|
145
|
-
return observedCall;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
public close() {
|
|
149
|
-
if (this.closed) {
|
|
150
|
-
return logger.debug('Attempted to close twice');
|
|
151
|
-
}
|
|
152
|
-
this.closed = true;
|
|
153
|
-
clearInterval(this._timer);
|
|
154
|
-
this._timer = undefined;
|
|
155
|
-
|
|
156
|
-
this.observedCalls.forEach((call) => call.close());
|
|
157
|
-
|
|
158
|
-
this.emit('close');
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
public accept(sample: ClientSample) {
|
|
162
|
-
if (this.closed) return;
|
|
163
|
-
if (!sample.callId) return logger.warn('Received sample without callId. %o', sample);
|
|
164
|
-
if (!sample.clientId) return logger.warn('Received sample without clientId %o', sample);
|
|
165
|
-
|
|
166
|
-
const call = this.getObservedCall(sample.callId) ?? this.createObservedCall({
|
|
167
|
-
callId: sample.callId,
|
|
168
|
-
updateIntervalInMs: this.config.defaultCallUpdateIntervalInMs,
|
|
169
|
-
updatePolicy: this.config.defaultCallUpdatePolicy,
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
const client = call.getObservedClient(sample.clientId) ?? call.createObservedClient({
|
|
173
|
-
clientId: sample.clientId,
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
client.accept(sample);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
public update() {
|
|
180
|
-
if (this.closed) {
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
this.numberOfInboundRtpStreams = 0;
|
|
185
|
-
this.numberOfOutboundRtpStreams = 0;
|
|
186
|
-
this.numberOfPeerConnections = 0;
|
|
187
|
-
this.numberOfDataChannels = 0;
|
|
188
|
-
this.numberOfClients = 0;
|
|
189
|
-
this.numberOfClientsUsingTurn = 0;
|
|
190
|
-
|
|
191
|
-
for (const call of this.observedCalls.values()) {
|
|
192
|
-
this.numberOfInboundRtpStreams += call.numberOfInboundRtpStreams;
|
|
193
|
-
this.numberOfOutboundRtpStreams += call.numberOfOutboundRtpStreams;
|
|
194
|
-
this.numberOfPeerConnections += call.numberOfPeerConnections;
|
|
195
|
-
this.numberOfDataChannels += call.numberOfDataChannels;
|
|
196
|
-
this.numberOfClients += call.numberOfClients;
|
|
197
|
-
this.numberOfClientsUsingTurn += call.clientsUsedTurn.size;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
this.observedTURN.update();
|
|
201
|
-
|
|
202
|
-
this.emit('update');
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
private _onObservedCallUpdated(call: ObservedCall) {
|
|
206
|
-
this.totalRttLt50Measurements += call.deltaRttLt50Measurements;
|
|
207
|
-
this.totalRttLt150Measurements += call.deltaRttLt150Measurements;
|
|
208
|
-
this.totalRttLt300Measurements += call.deltaRttLt300Measurements;
|
|
209
|
-
this.totalRttGtOrEq300Measurements += call.deltaRttGtOrEq300Measurements;
|
|
210
|
-
this.totalClientIssues += call.deltaNumberOfIssues;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// public resetSummaryMetrics() {
|
|
214
|
-
// this.totalAddedCall = 0;
|
|
215
|
-
// this.totalRemovedCall = 0;
|
|
216
|
-
// this.totalRttLt50Measurements = 0;
|
|
217
|
-
// this.totalRttLt150Measurements = 0;
|
|
218
|
-
// this.totalRttLt300Measurements = 0;
|
|
219
|
-
// this.totalRttGtOrEq300Measurements = 0;
|
|
220
|
-
// this.totalClientIssues = 0;
|
|
221
|
-
// }
|
|
222
|
-
|
|
223
|
-
// public createSummary(): ObserverSummary {
|
|
224
|
-
// return {
|
|
225
|
-
// totalAddedCall: this.totalAddedCall,
|
|
226
|
-
// totalRemovedCall: this.totalRemovedCall,
|
|
227
|
-
// totalRttLt50Measurements: this.totalRttLt50Measurements,
|
|
228
|
-
// totalRttLt150Measurements: this.totalRttLt150Measurements,
|
|
229
|
-
// totalRttLt300Measurements: this.totalRttLt300Measurements,
|
|
230
|
-
// totalRttGtOrEq300Measurements: this.totalRttGtOrEq300Measurements,
|
|
231
|
-
|
|
232
|
-
// totalClientIssues: this.totalClientIssues,
|
|
233
|
-
// currentActiveCalls: this.observedCalls.size,
|
|
234
|
-
// currentNumberOfClients: this.numberOfClients,
|
|
235
|
-
// currentNumberOfClientsUsingTURN: this.numberOfClientsUsedTurn,
|
|
236
|
-
// };
|
|
237
|
-
// }
|
|
238
|
-
|
|
239
|
-
}
|
package/src/ObserverSummary.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export type ObserverSummary = {
|
|
2
|
-
currentActiveCalls: number;
|
|
3
|
-
currentNumberOfClientsUsingTURN: number;
|
|
4
|
-
currentNumberOfClients: number;
|
|
5
|
-
|
|
6
|
-
totalAddedCall: number;
|
|
7
|
-
totalRemovedCall: number;
|
|
8
|
-
|
|
9
|
-
totalRttLt50Measurements: number,
|
|
10
|
-
totalRttLt150Measurements: number,
|
|
11
|
-
totalRttLt300Measurements: number,
|
|
12
|
-
totalRttGtOrEq300Measurements: number,
|
|
13
|
-
|
|
14
|
-
totalClientIssues: number,
|
|
15
|
-
}
|
package/src/common/Middleware.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
export type Middleware<T> = (
|
|
2
|
-
input: T,
|
|
3
|
-
next: (nextInput: T) => void
|
|
4
|
-
) => void;
|
|
5
|
-
|
|
6
|
-
export interface Processor<T> {
|
|
7
|
-
finalCallback?: Callback<T>;
|
|
8
|
-
process(value: T): void;
|
|
9
|
-
addMiddleware(...middlewares: Middleware<T>[]): Processor<T>;
|
|
10
|
-
removeMiddleware(...middlewares: Middleware<T>[]): Processor<T>;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
type Callback<T> = (input: T) => void;
|
|
14
|
-
|
|
15
|
-
class Executor<T> {
|
|
16
|
-
public done = false;
|
|
17
|
-
private index = 0;
|
|
18
|
-
private prevIndex = -1;
|
|
19
|
-
|
|
20
|
-
constructor(
|
|
21
|
-
private readonly stack: Middleware<T>[],
|
|
22
|
-
private readonly finalCallback?: Callback<T>
|
|
23
|
-
) {
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// Executes the middleware stack
|
|
27
|
-
public execute(input: T): void {
|
|
28
|
-
if (this.index <= this.prevIndex) {
|
|
29
|
-
throw new Error('Middleware must call next() only once!');
|
|
30
|
-
} else if (this.done) {
|
|
31
|
-
throw new Error('Middleware stack has already been executed!');
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
this.prevIndex = this.index;
|
|
35
|
-
|
|
36
|
-
const middleware = this.stack[this.index];
|
|
37
|
-
|
|
38
|
-
this.index++;
|
|
39
|
-
|
|
40
|
-
if (middleware) {
|
|
41
|
-
return middleware(input, (nextInput: T) => this.execute(nextInput));
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
this.done = true;
|
|
45
|
-
this.finalCallback?.(input);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export class MiddlewareProcessor<T> implements Processor<T> {
|
|
50
|
-
private stack: Middleware<T>[] = [];
|
|
51
|
-
public finalCallback?: Callback<T>;
|
|
52
|
-
|
|
53
|
-
public addMiddleware(...middlewares: Middleware<T>[]): Processor<T> {
|
|
54
|
-
if (middlewares && middlewares.length > 0) {
|
|
55
|
-
this.stack.push(...middlewares);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return this;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
public removeMiddleware(...middlewares: Middleware<T>[]): Processor<T> {
|
|
62
|
-
if (middlewares && middlewares.length > 0) {
|
|
63
|
-
for (const middleware of middlewares) {
|
|
64
|
-
const index = this.stack.indexOf(middleware);
|
|
65
|
-
|
|
66
|
-
if (index >= 0) {
|
|
67
|
-
this.stack.splice(index, 1);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return this;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
public process(value: T): void {
|
|
76
|
-
if (this.stack.length === 0) {
|
|
77
|
-
return this.finalCallback?.(value);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const executor = new Executor(this.stack, this.finalCallback);
|
|
81
|
-
|
|
82
|
-
executor.execute(value);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
export type SingleExecutor = ReturnType<typeof createSingleExecutor>;
|
|
2
|
-
|
|
3
|
-
export function createSingleExecutor() {
|
|
4
|
-
let semaphore = 1;
|
|
5
|
-
const tasks: (() => Promise<unknown>)[] = [];
|
|
6
|
-
|
|
7
|
-
const execute = <T = unknown>(task: () => Promise<T>) => {
|
|
8
|
-
return new Promise<T>((resolve, reject) => {
|
|
9
|
-
tasks.push(() => task().then(resolve)
|
|
10
|
-
.catch(reject));
|
|
11
|
-
run();
|
|
12
|
-
});
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const run = () => {
|
|
16
|
-
if (semaphore < 1) return;
|
|
17
|
-
|
|
18
|
-
const task = tasks.shift();
|
|
19
|
-
|
|
20
|
-
if (!task) return;
|
|
21
|
-
|
|
22
|
-
const postProcess = () => {
|
|
23
|
-
++semaphore;
|
|
24
|
-
run();
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
--semaphore;
|
|
28
|
-
|
|
29
|
-
task()
|
|
30
|
-
.then(postProcess)
|
|
31
|
-
.catch(postProcess);
|
|
32
|
-
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
return execute;
|
|
36
|
-
}
|