@observertc/observer-js 0.30.5-beta → 0.40.0-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/CallSummary.d.ts +22 -0
- package/lib/CallSummary.d.ts.map +1 -0
- package/lib/ObservedCall.d.ts +6 -13
- package/lib/ObservedCall.d.ts.map +1 -1
- package/lib/ObservedCall.js +24 -104
- package/lib/ObservedClient.d.ts +16 -27
- package/lib/ObservedClient.d.ts.map +1 -1
- package/lib/ObservedClient.js +360 -523
- package/lib/ObservedInboundTrack.d.ts +3 -8
- package/lib/ObservedInboundTrack.d.ts.map +1 -1
- package/lib/ObservedInboundTrack.js +74 -154
- package/lib/ObservedOutboundTrack.d.ts +9 -8
- package/lib/ObservedOutboundTrack.d.ts.map +1 -1
- package/lib/ObservedOutboundTrack.js +76 -130
- package/lib/ObservedPeerConnection.d.ts +17 -15
- package/lib/ObservedPeerConnection.d.ts.map +1 -1
- package/lib/ObservedPeerConnection.js +64 -173
- package/lib/ObservedSfu.d.ts +14 -4
- package/lib/ObservedSfu.d.ts.map +1 -1
- package/lib/ObservedSfu.js +37 -50
- package/lib/Observer.d.ts +5 -6
- package/lib/Observer.d.ts.map +1 -1
- package/lib/Observer.js +28 -31
- package/lib/common/types.d.ts +0 -55
- package/lib/common/types.d.ts.map +1 -1
- package/lib/index.d.ts +5 -7
- package/lib/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/CallSummary.ts +23 -0
- package/src/ObservedCall.ts +27 -87
- package/src/ObservedClient.ts +425 -582
- package/src/ObservedInboundTrack.ts +14 -65
- package/src/ObservedOutboundTrack.ts +32 -53
- package/src/ObservedPeerConnection.ts +55 -117
- package/src/ObservedSfu.ts +45 -27
- package/src/Observer.ts +11 -16
- package/src/common/types.ts +0 -69
- package/src/index.ts +5 -7
- package/lib/models/Models.d.ts +0 -642
- package/lib/models/Models.d.ts.map +0 -1
- package/lib/models/Models.js +0 -481
- package/lib/models/samples_pb.d.ts +0 -2452
- package/lib/models/samples_pb.d.ts.map +0 -1
- package/lib/models/samples_pb.js +0 -1495
- package/lib/storages/ObserverStorage.d.ts +0 -87
- package/lib/storages/ObserverStorage.d.ts.map +0 -1
- package/lib/storages/SimpleStorage.d.ts +0 -19
- package/lib/storages/SimpleStorage.d.ts.map +0 -1
- package/lib/storages/SimpleStorage.js +0 -106
- package/lib/storages/StorageProvider.d.ts +0 -16
- package/lib/storages/StorageProvider.d.ts.map +0 -1
- package/lib/storages/StorageProvider.js +0 -29
- package/src/models/Models.ts +0 -1103
- package/src/models/samples_pb.ts +0 -4061
- package/src/storages/ObserverStorage.ts +0 -99
- package/src/storages/SimpleStorage.ts +0 -120
- package/src/storages/StorageProvider.ts +0 -42
- /package/lib/{storages/ObserverStorage.js → CallSummary.js} +0 -0
package/src/ObservedSfu.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
|
-
import * as Models from './models/Models';
|
|
3
2
|
import { Observer } from './Observer';
|
|
3
|
+
import { SfuSample } from '@observertc/sample-schemas-js';
|
|
4
4
|
|
|
5
|
-
export type
|
|
5
|
+
export type ObservedSfuModel= {
|
|
6
6
|
serviceId: string;
|
|
7
7
|
sfuId: string;
|
|
8
8
|
joined?: number;
|
|
9
|
-
appData: AppData;
|
|
10
9
|
};
|
|
11
10
|
|
|
12
11
|
export type ObservedSfuEvents = {
|
|
@@ -22,34 +21,53 @@ export declare interface ObservedSfu {
|
|
|
22
21
|
}
|
|
23
22
|
|
|
24
23
|
export class ObservedSfu<AppData extends Record<string, unknown> = Record<string, unknown>> extends EventEmitter {
|
|
25
|
-
public
|
|
26
|
-
config: ObservedSfuConfig<T>,
|
|
27
|
-
observer: Observer,
|
|
28
|
-
// reportsCollector: ReportsCollector,
|
|
29
|
-
) {
|
|
30
|
-
const model = new Models.Sfu({
|
|
31
|
-
serviceId: config.serviceId,
|
|
32
|
-
sfuId: config.sfuId,
|
|
33
|
-
sfuTransportIds: [],
|
|
34
|
-
joined: BigInt(config.joined ?? Date.now()),
|
|
35
|
-
});
|
|
36
|
-
const result = new ObservedSfu(
|
|
37
|
-
model,
|
|
38
|
-
config.appData,
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
const alreadyInserted = await observer.storage.sfuStorage.insert(config.sfuId, model);
|
|
42
|
-
|
|
43
|
-
if (alreadyInserted) throw new Error(`Sfu with id ${config.sfuId} already exists`);
|
|
24
|
+
public readonly created = Date.now();
|
|
44
25
|
|
|
45
|
-
|
|
46
|
-
|
|
26
|
+
private _updated = Date.now();
|
|
27
|
+
private _closed = false;
|
|
47
28
|
|
|
48
|
-
|
|
49
|
-
private readonly _model:
|
|
29
|
+
public constructor(
|
|
30
|
+
private readonly _model: ObservedSfuModel,
|
|
31
|
+
public readonly observer: Observer,
|
|
50
32
|
public readonly appData: AppData,
|
|
51
33
|
) {
|
|
52
34
|
super();
|
|
53
35
|
}
|
|
54
|
-
|
|
36
|
+
|
|
37
|
+
public get serviceId() {
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
39
|
+
return this._model.serviceId!;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public get sfuId() {
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
44
|
+
return this._model.sfuId!;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public get joined() {
|
|
48
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
49
|
+
return Number(this._model.joined!);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public get updated() {
|
|
53
|
+
return this._updated;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public get closed() {
|
|
57
|
+
return this._closed;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public close() {
|
|
61
|
+
if (this._closed) return;
|
|
62
|
+
this._closed = true;
|
|
63
|
+
this.emit('close');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
public update(sample: SfuSample) {
|
|
67
|
+
if (this._closed) throw new Error(`Sfu ${this.sfuId} is closed`);
|
|
68
|
+
if (sample.sfuId !== this.sfuId) throw new Error(`Sfu ${this.sfuId} is not the same as sample.sfuId`);
|
|
69
|
+
|
|
70
|
+
this._updated = Date.now();
|
|
71
|
+
this.emit('update');
|
|
72
|
+
}
|
|
55
73
|
}
|
package/src/Observer.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { createLogger } from './common/logger';
|
|
2
|
-
import {
|
|
3
|
-
import { ObservedCall, ObservedCallConfig } from './ObservedCall';
|
|
2
|
+
import { ObservedCall, ObservedCallModel } from './ObservedCall';
|
|
4
3
|
import { ReportsCollector } from './ReportsCollector';
|
|
5
4
|
import { EventEmitter } from 'events';
|
|
6
5
|
import { PartialBy } from './common/utils';
|
|
7
|
-
import { createCallStartedEventReport } from './common/callEventReports';
|
|
6
|
+
import { createCallEndedEventReport, createCallStartedEventReport } from './common/callEventReports';
|
|
8
7
|
|
|
9
8
|
const logger = createLogger('Observer');
|
|
10
9
|
|
|
@@ -36,8 +35,6 @@ export type ObserverConfig = {
|
|
|
36
35
|
maxCollectingTimeInMs?: number | undefined;
|
|
37
36
|
|
|
38
37
|
maxEntryIdleTimeInMs?: number | undefined;
|
|
39
|
-
|
|
40
|
-
storages?: StorageProvider;
|
|
41
38
|
};
|
|
42
39
|
|
|
43
40
|
export declare interface Observer {
|
|
@@ -63,9 +60,7 @@ export class Observer extends EventEmitter {
|
|
|
63
60
|
providedConfig
|
|
64
61
|
);
|
|
65
62
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return new Observer(config, storages);
|
|
63
|
+
return new Observer(config);
|
|
69
64
|
}
|
|
70
65
|
|
|
71
66
|
public readonly reports = new ReportsCollector();
|
|
@@ -74,7 +69,6 @@ export class Observer extends EventEmitter {
|
|
|
74
69
|
private _closed = false;
|
|
75
70
|
public constructor(
|
|
76
71
|
public readonly config: ObserverConfig,
|
|
77
|
-
public readonly storage: StorageProvider,
|
|
78
72
|
) {
|
|
79
73
|
super();
|
|
80
74
|
logger.debug('Observer is created with config', this.config);
|
|
@@ -91,25 +85,26 @@ export class Observer extends EventEmitter {
|
|
|
91
85
|
this.reports.on('newreport', onNewReport);
|
|
92
86
|
}
|
|
93
87
|
|
|
94
|
-
public
|
|
95
|
-
config: PartialBy<
|
|
96
|
-
):
|
|
88
|
+
public createObservedCall<T extends Record<string, unknown> = Record<string, unknown>>(
|
|
89
|
+
config: PartialBy<ObservedCallModel, 'serviceId' | 'started'> & { appData: T }
|
|
90
|
+
): ObservedCall<T> {
|
|
97
91
|
if (this._closed) {
|
|
98
92
|
throw new Error('Attempted to create a call source on a closed observer');
|
|
99
93
|
}
|
|
100
94
|
|
|
101
|
-
const
|
|
95
|
+
const { appData, ...model } = config;
|
|
96
|
+
const call = new ObservedCall({
|
|
97
|
+
...model,
|
|
102
98
|
serviceId: this.config.defaultServiceId,
|
|
103
99
|
started: Date.now(),
|
|
104
|
-
|
|
105
|
-
}, this);
|
|
100
|
+
}, this, appData);
|
|
106
101
|
|
|
107
102
|
if (this._closed) throw new Error('Cannot create an observed call on a closed observer');
|
|
108
103
|
if (this._observedCalls.has(call.callId)) throw new Error(`Observed Call with id ${call.callId} already exists`);
|
|
109
104
|
|
|
110
105
|
call.once('close', () => {
|
|
111
106
|
this._observedCalls.delete(call.callId);
|
|
112
|
-
this.reports.addCallEventReport(
|
|
107
|
+
this.reports.addCallEventReport(createCallEndedEventReport(
|
|
113
108
|
call.serviceId,
|
|
114
109
|
call.roomId,
|
|
115
110
|
call.callId,
|
package/src/common/types.ts
CHANGED
|
@@ -18,78 +18,9 @@ import {
|
|
|
18
18
|
SfuSctpStreamReport,
|
|
19
19
|
SFUTransportReport,
|
|
20
20
|
} from '@observertc/report-schemas-js';
|
|
21
|
-
import * as Models from '../models/Models';
|
|
22
|
-
import { StorageProvider } from '../storages/StorageProvider';
|
|
23
|
-
import { Message } from '@bufbuild/protobuf';
|
|
24
21
|
|
|
25
22
|
export type MediaKind = 'audio' | 'video';
|
|
26
23
|
|
|
27
|
-
export interface EvaluatorContext {
|
|
28
|
-
readonly startedCallIds: string[];
|
|
29
|
-
readonly endedCalls: (Omit<Models.Call, keyof Message> & {
|
|
30
|
-
ended: number;
|
|
31
|
-
})[];
|
|
32
|
-
|
|
33
|
-
readonly joinedClientIds: string[];
|
|
34
|
-
readonly detachedClients: (Omit<Models.Client, keyof Message> & {
|
|
35
|
-
detached: number;
|
|
36
|
-
})[];
|
|
37
|
-
|
|
38
|
-
readonly openedPeerConnectionIds: string[];
|
|
39
|
-
readonly closedPeerConnections: (Omit<Models.PeerConnection, keyof Message> & {
|
|
40
|
-
closed: number;
|
|
41
|
-
})[];
|
|
42
|
-
|
|
43
|
-
readonly addedInboundAudioTrackIds: string[];
|
|
44
|
-
readonly removedInboundAudioTracks: (Omit<Models.InboundTrack, keyof Message> & {
|
|
45
|
-
removed: number;
|
|
46
|
-
})[];
|
|
47
|
-
|
|
48
|
-
readonly addedInboundVideoTrackIds: string[];
|
|
49
|
-
readonly removedInboundVideoTracks: (Omit<Models.InboundTrack, keyof Message> & {
|
|
50
|
-
removed: number;
|
|
51
|
-
})[];
|
|
52
|
-
|
|
53
|
-
readonly addedOutboundAudioTrackIds: string[];
|
|
54
|
-
readonly removedOutboundAudioTracks: (Omit<Models.OutboundTrack, keyof Message> & {
|
|
55
|
-
removed: number;
|
|
56
|
-
})[];
|
|
57
|
-
|
|
58
|
-
readonly addedOutboundVideoTrackIds: string[];
|
|
59
|
-
readonly removedOutboundVideoTracks: (Omit<Models.OutboundTrack, keyof Message> & {
|
|
60
|
-
removed: number;
|
|
61
|
-
})[];
|
|
62
|
-
|
|
63
|
-
readonly joinedSfuIds: string[];
|
|
64
|
-
readonly detachedSfus: (Omit<Models.Sfu, keyof Message> & {
|
|
65
|
-
detached: number;
|
|
66
|
-
})[];
|
|
67
|
-
|
|
68
|
-
readonly openedSfuTransportIds: string[];
|
|
69
|
-
readonly closedSfuTransports: (Omit<Models.SfuTransport, keyof Message> & {
|
|
70
|
-
closed: number;
|
|
71
|
-
})[];
|
|
72
|
-
|
|
73
|
-
readonly addedSfuInbounRtpPadIds: string[];
|
|
74
|
-
readonly removedSfuInbounRtpPadIds: (Omit<Models.SfuInboundRtpPad, keyof Message> & {
|
|
75
|
-
removed: number;
|
|
76
|
-
})[];
|
|
77
|
-
|
|
78
|
-
readonly addedSfuOutbounRtpPadIds: string[];
|
|
79
|
-
readonly removedSfuOutbounRtpPadIds: (Omit<Models.SfuOutboundRtpPad, keyof Message> & {
|
|
80
|
-
removed: number;
|
|
81
|
-
})[];
|
|
82
|
-
|
|
83
|
-
readonly openedSfuSctpChannelIds: string[];
|
|
84
|
-
readonly closedSfuSctpChannels: (Omit<Models.SfuSctpChannel, keyof Message> & {
|
|
85
|
-
closed: number;
|
|
86
|
-
})[];
|
|
87
|
-
|
|
88
|
-
readonly storages: StorageProvider;
|
|
89
|
-
readonly reports: ObserverSinkContext;
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
|
|
93
24
|
// export type EvaluatorMiddleware = Middleware<EvaluatorContext>;
|
|
94
25
|
|
|
95
26
|
export interface ObserverSinkContext {
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
export type { ObserverConfig, ObserverEvents } from './Observer';
|
|
2
2
|
|
|
3
3
|
export { Observer } from './Observer';
|
|
4
|
-
export type { ObserverStorage } from './storages/ObserverStorage';
|
|
5
|
-
export type { StorageProvider } from './storages/StorageProvider';
|
|
6
4
|
|
|
7
5
|
export * as SampleSchema from '@observertc/sample-schemas-js';
|
|
8
6
|
export * as ReportSchema from '@observertc/report-schemas-js';
|
|
@@ -54,12 +52,12 @@ export type {
|
|
|
54
52
|
SFUTransportReport,
|
|
55
53
|
} from '@observertc/report-schemas-js';
|
|
56
54
|
|
|
57
|
-
export type { ObservedClient,
|
|
58
|
-
export type { ObservedPeerConnection,
|
|
59
|
-
export type { ObservedInboundTrack,
|
|
60
|
-
export type { ObservedOutboundTrack,
|
|
55
|
+
export type { ObservedClient, ObservedClientModel } from './ObservedClient';
|
|
56
|
+
export type { ObservedPeerConnection, ObservedPeerConnectionModel, ObservedPeerConnectionEvents } from './ObservedPeerConnection';
|
|
57
|
+
export type { ObservedInboundTrack, ObservedInboundTrackModel, ObservedInboundTrackEvents } from './ObservedInboundTrack';
|
|
58
|
+
export type { ObservedOutboundTrack, ObservedOutboundTrackModel, ObservedOutboundTrackEvents } from './ObservedOutboundTrack';
|
|
61
59
|
|
|
62
|
-
export type {
|
|
60
|
+
export type { ObserverSinkContext } from './common/types';
|
|
63
61
|
|
|
64
62
|
import { Observer, ObserverConfig } from './Observer';
|
|
65
63
|
export function createObserver(config?: Partial<ObserverConfig>) {
|