@observertc/observer-js 0.30.1-beta → 0.30.2-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.
@@ -1,12 +1,13 @@
1
1
  import { EventEmitter } from 'events';
2
2
  import * as Models from './models/Models';
3
3
  import { StorageProvider } from './storages/StorageProvider';
4
- import { PeerConnectionTransport } from '@observertc/sample-schemas-js';
4
+ import { IceLocalCandidate, IceRemoteCandidate, PeerConnectionTransport } from '@observertc/sample-schemas-js';
5
5
  import { ObservedClient } from './ObservedClient';
6
6
  import { ObservedInboundTrack, ObservedInboundTrackConfig } from './ObservedInboundTrack';
7
7
  import { ObservedOutboundTrack, ObservedOutboundTrackConfig } from './ObservedOutboundTrack';
8
8
  import { PeerConnectionTransportReport } from '@observertc/report-schemas-js';
9
9
  import { createSingleExecutor } from './common/SingleExecutor';
10
+ import { ObservedICE } from './ObservedICE';
10
11
 
11
12
  export type ObservedPeerConnectionEvents = {
12
13
  update: [],
@@ -15,6 +16,10 @@ export type ObservedPeerConnectionEvents = {
15
16
  newinboudvideotrack: [ObservedInboundTrack<'video'>],
16
17
  newoutboundaudiotrack: [ObservedOutboundTrack<'audio'>],
17
18
  newoutboundvideotrack: [ObservedOutboundTrack<'video'>],
19
+
20
+ iceconnectionstatechange: [string],
21
+ icegatheringstatechange: [string],
22
+ connectionstatechange: [string],
18
23
  };
19
24
 
20
25
  export type ObservedPeerConnectionConfig = {
@@ -51,10 +56,43 @@ export class ObservedPeerConnection extends EventEmitter {
51
56
  return new ObservedPeerConnection(model, client, storageProvider);
52
57
  }
53
58
 
59
+ public totalInboundPacketsLost = 0;
60
+ public totalInboundPacketsReceived = 0;
61
+ public totalOutboundPacketsLost = 0;
62
+ public totalOutboundPacketsReceived = 0;
63
+ public totalOutboundPacketsSent = 0;
64
+ public totalDataChannelBytesSent = 0;
65
+ public totalDataChannelBytesReceived = 0;
66
+ public totalSentAudioBytes = 0;
67
+ public totalSentVideoBytes = 0;
68
+ public totalReceivedAudioBytes = 0;
69
+ public totalReceivedVideoBytes = 0;
70
+
71
+ public deltaInboundPacketsLost = 0;
72
+ public deltaInboundPacketsReceived = 0;
73
+ public deltaOutboundPacketsLost = 0;
74
+ public deltaOutboundPacketsReceived = 0;
75
+ public deltaOutboundPacketsSent = 0;
76
+ public deltaDataChannelBytesSent = 0;
77
+ public deltaDataChannelBytesReceived = 0;
78
+ public deltaReceivedAudioBytes = 0;
79
+ public deltaReceivedVideoBytes = 0;
80
+ public deltaSentAudioBytes = 0;
81
+ public deltaSentVideoBytes = 0;
82
+ public sendingAudioBitrate = 0;
83
+ public sendingVideoBitrate = 0;
84
+ public receivingAudioBitrate = 0;
85
+ public receivingVideoBitrate = 0;
86
+
87
+ public avgRttInS?: number;
88
+
54
89
  private _closed = false;
55
90
  private _updated = Date.now();
56
91
  private _sample?: ObservedPeerConnectionStats;
92
+ private _selectedLocalIceCandidate?: IceLocalCandidate;
93
+ private _selectedRemoteIceCandidate?: IceRemoteCandidate;
57
94
 
95
+ public readonly ICE = ObservedICE.create(this);
58
96
  private readonly _inboundAudioTracks = new Map<string, ObservedInboundTrack<'audio'>>();
59
97
  private readonly _inboundVideoTracks = new Map<string, ObservedInboundTrack<'video'>>();
60
98
  private readonly _outboundAudioTracks = new Map<string, ObservedOutboundTrack<'audio'>>();
@@ -86,6 +124,14 @@ export class ObservedPeerConnection extends EventEmitter {
86
124
  return this._updated;
87
125
  }
88
126
 
127
+ public get selectedLocalIceCandidate() {
128
+ return this._selectedLocalIceCandidate;
129
+ }
130
+
131
+ public get selectedRemoteIceCandidate() {
132
+ return this._selectedRemoteIceCandidate;
133
+ }
134
+
89
135
  public get inboundAudioTracks(): ReadonlyMap<string, ObservedInboundTrack<'audio'>> {
90
136
  return this._inboundAudioTracks;
91
137
  }
@@ -120,6 +166,32 @@ export class ObservedPeerConnection extends EventEmitter {
120
166
  .finally(() => this.emit('close'));
121
167
  }
122
168
 
169
+ public updateMetrics() {
170
+ this.deltaInboundPacketsLost = 0;
171
+ this.deltaInboundPacketsReceived = 0;
172
+ this.deltaOutboundPacketsLost = 0;
173
+ this.deltaOutboundPacketsReceived = 0;
174
+ this.deltaOutboundPacketsSent = 0;
175
+ this.sendingAudioBitrate = 0;
176
+ this.sendingVideoBitrate = 0;
177
+ this.receivingAudioBitrate = 0;
178
+ this.receivingVideoBitrate = 0;
179
+ this.deltaDataChannelBytesSent = 0;
180
+ this.deltaDataChannelBytesReceived = 0;
181
+ this.deltaReceivedAudioBytes = 0;
182
+ this.deltaReceivedVideoBytes = 0;
183
+ this.deltaSentAudioBytes = 0;
184
+ this.deltaSentVideoBytes = 0;
185
+
186
+ this._inboundAudioTracks.forEach((track) => {
187
+ this.deltaReceivedAudioBytes += track.receivedPackets;
188
+ });
189
+
190
+ this._inboundVideoTracks.forEach((track) => {
191
+ this.deltaReceivedVideoBytes += track.receivedPackets;
192
+ });
193
+ }
194
+
123
195
  public update(sample: PeerConnectionTransport, timestamp: number) {
124
196
  if (this._closed) return;
125
197
  if (sample.peerConnectionId !== this._model.peerConnectionId) throw new Error(`TransportId mismatch. PeerConnectionId: ${ this._model.peerConnectionId } TransportId: ${ sample.transportId}`);
@@ -144,6 +216,11 @@ export class ObservedPeerConnection extends EventEmitter {
144
216
  this.emit('update');
145
217
  }
146
218
 
219
+ public updateSelectedCandidate(localCandidate: IceLocalCandidate, remoteCandidate: IceRemoteCandidate) {
220
+ this._selectedLocalIceCandidate = localCandidate;
221
+ this._selectedRemoteIceCandidate = remoteCandidate;
222
+ }
223
+
147
224
  public async createInboundAudioTrack(config: Omit<ObservedInboundTrackConfig<'audio'>, 'kind'>): Promise<ObservedInboundTrack<'audio'>> {
148
225
  if (this._closed) throw new Error(`PeerConnection ${this.peerConnectionId} is closed`);
149
226
 
@@ -151,7 +228,7 @@ export class ObservedPeerConnection extends EventEmitter {
151
228
  kind: 'audio',
152
229
  trackId: config.trackId,
153
230
  }, this, this._storageProvider);
154
-
231
+
155
232
  result.on('close', () => {
156
233
  this._inboundAudioTracks.delete(result.trackId);
157
234
  this._model.inboundTrackIds = this._model.inboundTrackIds.filter((id) => id !== result.trackId);
@@ -0,0 +1,23 @@
1
+ // eslint-disable-next-line no-shadow
2
+
3
+ export enum CallEventType {
4
+ CALL_STARTED = 'CALL_STARTED',
5
+ CALL_ENDED = 'CALL_ENDED',
6
+ CLIENT_JOINED = 'CLIENT_JOINED',
7
+ CLIENT_LEFT = 'CLIENT_LEFT',
8
+ PEER_CONNECTION_OPENED = 'PEER_CONNECTION_OPENED',
9
+ PEER_CONNECTION_CLOSED = 'PEER_CONNECTION_CLOSED',
10
+ MEDIA_TRACK_ADDED = 'MEDIA_TRACK_ADDED',
11
+ MEDIA_TRACK_REMOVED = 'MEDIA_TRACK_REMOVED',
12
+ MEDIA_TRACK_RESUMED = 'MEDIA_TRACK_RESUMED',
13
+ MEDIA_TRACK_MUTED = 'MEDIA_TRACK_MUTED',
14
+ MEDIA_TRACK_UNMUTED = 'MEDIA_TRACK_UNMUTED',
15
+ ICE_GATHERING_STATE_CHANGED = 'ICE_GATHERING_STATE_CHANGED',
16
+ PEER_CONNECTION_STATE_CHANGED = 'PEER_CONNECTION_STATE_CHANGED',
17
+ ICE_CONNECTION_STATE_CHANGED = 'ICE_CONNECTION_STATE_CHANGED',
18
+ DATA_CHANNEL_OPEN = 'DATA_CHANNEL_OPEN',
19
+ DATA_CHANNEL_CLOSED = 'DATA_CHANNEL_CLOSED',
20
+ DATA_CHANNEL_ERROR = 'DATA_CHANNEL_ERROR',
21
+ NEGOTIATION_NEEDED = 'NEGOTIATION_NEEDED',
22
+ SIGNALING_STATE_CHANGE = 'SIGNALING_STATE_CHANGE',
23
+ }
@@ -1,16 +1,6 @@
1
1
  import { CallEventReport } from '@observertc/report-schemas-js';
2
+ import { CallEventType } from './CallEventType';
2
3
 
3
- // eslint-disable-next-line no-shadow
4
- export enum CallEventType {
5
- CALL_STARTED = 'CALL_STARTED',
6
- CALL_ENDED = 'CALL_ENDED',
7
- CLIENT_JOINED = 'CLIENT_JOINED',
8
- CLIENT_LEFT = 'CLIENT_LEFT',
9
- PEER_CONNECTION_OPENED = 'PEER_CONNECTION_OPENED',
10
- PEER_CONNECTION_CLOSED = 'PEER_CONNECTION_CLOSED',
11
- MEDIA_TRACK_ADDED = 'MEDIA_TRACK_ADDED',
12
- MEDIA_TRACK_REMOVED = 'MEDIA_TRACK_REMOVED',
13
- }
14
4
  export function createCallStartedEventReport(
15
5
  serviceId: string,
16
6
  roomId: string,
@@ -1,11 +1,11 @@
1
- // @generated by protoc-gen-es v1.1.1 with parameter "target=ts"
1
+ // @generated by protoc-gen-es v1.7.2 with parameter "target=ts"
2
2
  // @generated from file models.proto (package org.observertc.observer.models, syntax proto2)
3
3
  /* eslint-disable */
4
4
  // @ts-nocheck
5
5
 
6
6
  import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "@bufbuild/protobuf";
7
7
  import { Message, proto2 } from "@bufbuild/protobuf";
8
- import { Samples_ClientSample_Browser, Samples_ClientSample_Engine, Samples_ClientSample_IceCandidatePair, Samples_ClientSample_IceLocalCandidate, Samples_ClientSample_IceRemoteCandidate, Samples_ClientSample_InboundAudioTrack, Samples_ClientSample_InboundVideoTrack, Samples_ClientSample_OperationSystem, Samples_ClientSample_OutboundAudioTrack, Samples_ClientSample_OutboundVideoTrack, Samples_ClientSample_PeerConnectionTransport, Samples_ClientSample_Platform } from "./samples_pb";
8
+ import { Samples_ClientSample_Browser, Samples_ClientSample_Engine, Samples_ClientSample_OperationSystem, Samples_ClientSample_Platform } from "./samples_pb";
9
9
 
10
10
  /**
11
11
  * @generated from message org.observertc.observer.models.Call
@@ -68,49 +68,6 @@ export class Call extends Message<Call> {
68
68
  }
69
69
  }
70
70
 
71
- /**
72
- * @generated from message org.observertc.observer.models.ClientCoordinate
73
- */
74
- export class ClientCoordinate extends Message<ClientCoordinate> {
75
- /**
76
- * @generated from field: required float latitude = 1;
77
- */
78
- latitude?: number;
79
-
80
- /**
81
- * @generated from field: required float longitude = 2;
82
- */
83
- longitude?: number;
84
-
85
- constructor(data?: PartialMessage<ClientCoordinate>) {
86
- super();
87
- proto2.util.initPartial(data, this);
88
- }
89
-
90
- static readonly runtime: typeof proto2 = proto2;
91
- static readonly typeName = "org.observertc.observer.models.ClientCoordinate";
92
- static readonly fields: FieldList = proto2.util.newFieldList(() => [
93
- { no: 1, name: "latitude", kind: "scalar", T: 2 /* ScalarType.FLOAT */ },
94
- { no: 2, name: "longitude", kind: "scalar", T: 2 /* ScalarType.FLOAT */ },
95
- ]);
96
-
97
- static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): ClientCoordinate {
98
- return new ClientCoordinate().fromBinary(bytes, options);
99
- }
100
-
101
- static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): ClientCoordinate {
102
- return new ClientCoordinate().fromJson(jsonValue, options);
103
- }
104
-
105
- static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): ClientCoordinate {
106
- return new ClientCoordinate().fromJsonString(jsonString, options);
107
- }
108
-
109
- static equals(a: ClientCoordinate | PlainMessage<ClientCoordinate> | undefined, b: ClientCoordinate | PlainMessage<ClientCoordinate> | undefined): boolean {
110
- return proto2.util.equals(ClientCoordinate, a, b);
111
- }
112
- }
113
-
114
71
  /**
115
72
  * @generated from message org.observertc.observer.models.Client
116
73
  */
@@ -190,19 +147,6 @@ export class Client extends Message<Client> {
190
147
  */
191
148
  engine?: Samples_ClientSample_Engine;
192
149
 
193
- /**
194
- * message Stats {
195
- * optional double maxRttInS = 1;
196
- * optional double minRttInS = 2;
197
- * optional string location = 3;
198
- * }
199
- *
200
- * optional Stats stats = 13;
201
- *
202
- * @generated from field: optional org.observertc.observer.models.ClientCoordinate coordinates = 16;
203
- */
204
- coordinates?: ClientCoordinate;
205
-
206
150
  constructor(data?: PartialMessage<Client>) {
207
151
  super();
208
152
  proto2.util.initPartial(data, this);
@@ -226,7 +170,6 @@ export class Client extends Message<Client> {
226
170
  { no: 13, name: "operationSystem", kind: "message", T: Samples_ClientSample_OperationSystem, opt: true },
227
171
  { no: 14, name: "platform", kind: "message", T: Samples_ClientSample_Platform, opt: true },
228
172
  { no: 15, name: "engine", kind: "message", T: Samples_ClientSample_Engine, opt: true },
229
- { no: 16, name: "coordinates", kind: "message", T: ClientCoordinate, opt: true },
230
173
  ]);
231
174
 
232
175
  static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): Client {
@@ -310,26 +253,6 @@ export class PeerConnection extends Message<PeerConnection> {
310
253
  */
311
254
  outboundTrackIds: string[] = [];
312
255
 
313
- /**
314
- * @generated from field: repeated org.observertc.schemas.protobuf.Samples.ClientSample.IceLocalCandidate icelocalCandidates = 13;
315
- */
316
- icelocalCandidates: Samples_ClientSample_IceLocalCandidate[] = [];
317
-
318
- /**
319
- * @generated from field: repeated org.observertc.schemas.protobuf.Samples.ClientSample.IceRemoteCandidate iceRemoteCandidates = 14;
320
- */
321
- iceRemoteCandidates: Samples_ClientSample_IceRemoteCandidate[] = [];
322
-
323
- /**
324
- * @generated from field: repeated org.observertc.schemas.protobuf.Samples.ClientSample.IceCandidatePair iceCandidatePairs = 15;
325
- */
326
- iceCandidatePairs: Samples_ClientSample_IceCandidatePair[] = [];
327
-
328
- /**
329
- * @generated from field: repeated org.observertc.schemas.protobuf.Samples.ClientSample.PeerConnectionTransport transports = 16;
330
- */
331
- transports: Samples_ClientSample_PeerConnectionTransport[] = [];
332
-
333
256
  /**
334
257
  * @generated from field: optional uint64 touched = 17;
335
258
  */
@@ -355,10 +278,6 @@ export class PeerConnection extends Message<PeerConnection> {
355
278
  { no: 10, name: "label", kind: "scalar", T: 9 /* ScalarType.STRING */, opt: true },
356
279
  { no: 11, name: "inboundTrackIds", kind: "scalar", T: 9 /* ScalarType.STRING */, repeated: true },
357
280
  { no: 12, name: "outboundTrackIds", kind: "scalar", T: 9 /* ScalarType.STRING */, repeated: true },
358
- { no: 13, name: "icelocalCandidates", kind: "message", T: Samples_ClientSample_IceLocalCandidate, repeated: true },
359
- { no: 14, name: "iceRemoteCandidates", kind: "message", T: Samples_ClientSample_IceRemoteCandidate, repeated: true },
360
- { no: 15, name: "iceCandidatePairs", kind: "message", T: Samples_ClientSample_IceCandidatePair, repeated: true },
361
- { no: 16, name: "transports", kind: "message", T: Samples_ClientSample_PeerConnectionTransport, repeated: true },
362
281
  { no: 17, name: "touched", kind: "scalar", T: 4 /* ScalarType.UINT64 */, opt: true },
363
282
  ]);
364
283
 
@@ -389,15 +308,12 @@ export class InboundTrackVideoStats extends Message<InboundTrackVideoStats> {
389
308
  ssrc?: number;
390
309
 
391
310
  /**
311
+ * optional org.observertc.schemas.protobuf.Samples.ClientSample.InboundVideoTrack sample = 4;
312
+ *
392
313
  * @generated from field: optional float fps = 2;
393
314
  */
394
315
  fps?: number;
395
316
 
396
- /**
397
- * @generated from field: optional org.observertc.schemas.protobuf.Samples.ClientSample.InboundVideoTrack sample = 4;
398
- */
399
- sample?: Samples_ClientSample_InboundVideoTrack;
400
-
401
317
  constructor(data?: PartialMessage<InboundTrackVideoStats>) {
402
318
  super();
403
319
  proto2.util.initPartial(data, this);
@@ -408,7 +324,6 @@ export class InboundTrackVideoStats extends Message<InboundTrackVideoStats> {
408
324
  static readonly fields: FieldList = proto2.util.newFieldList(() => [
409
325
  { no: 1, name: "ssrc", kind: "scalar", T: 5 /* ScalarType.INT32 */ },
410
326
  { no: 2, name: "fps", kind: "scalar", T: 2 /* ScalarType.FLOAT */, opt: true },
411
- { no: 4, name: "sample", kind: "message", T: Samples_ClientSample_InboundVideoTrack, opt: true },
412
327
  ]);
413
328
 
414
329
  static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): InboundTrackVideoStats {
@@ -551,16 +466,6 @@ export class InboundTrack extends Message<InboundTrack> {
551
466
  */
552
467
  ssrc: bigint[] = [];
553
468
 
554
- /**
555
- * @generated from field: repeated org.observertc.schemas.protobuf.Samples.ClientSample.InboundAudioTrack audioStats = 15;
556
- */
557
- audioStats: Samples_ClientSample_InboundAudioTrack[] = [];
558
-
559
- /**
560
- * @generated from field: repeated org.observertc.schemas.protobuf.Samples.ClientSample.InboundVideoTrack videoStats = 16;
561
- */
562
- videoStats: Samples_ClientSample_InboundVideoTrack[] = [];
563
-
564
469
  /**
565
470
  * @generated from field: optional uint64 touched = 17;
566
471
  */
@@ -588,8 +493,6 @@ export class InboundTrack extends Message<InboundTrack> {
588
493
  { no: 12, name: "sfuSinkId", kind: "scalar", T: 9 /* ScalarType.STRING */, opt: true },
589
494
  { no: 13, name: "sfuStreamId", kind: "scalar", T: 9 /* ScalarType.STRING */, opt: true },
590
495
  { no: 14, name: "ssrc", kind: "scalar", T: 3 /* ScalarType.INT64 */, repeated: true },
591
- { no: 15, name: "audioStats", kind: "message", T: Samples_ClientSample_InboundAudioTrack, repeated: true },
592
- { no: 16, name: "videoStats", kind: "message", T: Samples_ClientSample_InboundVideoTrack, repeated: true },
593
496
  { no: 17, name: "touched", kind: "scalar", T: 4 /* ScalarType.UINT64 */, opt: true },
594
497
  ]);
595
498
 
@@ -679,16 +582,6 @@ export class OutboundTrack extends Message<OutboundTrack> {
679
582
  */
680
583
  ssrc: bigint[] = [];
681
584
 
682
- /**
683
- * @generated from field: repeated org.observertc.schemas.protobuf.Samples.ClientSample.OutboundAudioTrack audioStats = 14;
684
- */
685
- audioStats: Samples_ClientSample_OutboundAudioTrack[] = [];
686
-
687
- /**
688
- * @generated from field: repeated org.observertc.schemas.protobuf.Samples.ClientSample.OutboundVideoTrack videoStats = 15;
689
- */
690
- videoStats: Samples_ClientSample_OutboundVideoTrack[] = [];
691
-
692
585
  /**
693
586
  * @generated from field: optional uint64 touched = 16;
694
587
  */
@@ -715,8 +608,6 @@ export class OutboundTrack extends Message<OutboundTrack> {
715
608
  { no: 11, name: "marker", kind: "scalar", T: 9 /* ScalarType.STRING */, opt: true },
716
609
  { no: 12, name: "sfuStreamId", kind: "scalar", T: 9 /* ScalarType.STRING */, opt: true },
717
610
  { no: 13, name: "ssrc", kind: "scalar", T: 3 /* ScalarType.INT64 */, repeated: true },
718
- { no: 14, name: "audioStats", kind: "message", T: Samples_ClientSample_OutboundAudioTrack, repeated: true },
719
- { no: 15, name: "videoStats", kind: "message", T: Samples_ClientSample_OutboundVideoTrack, repeated: true },
720
611
  { no: 16, name: "touched", kind: "scalar", T: 4 /* ScalarType.UINT64 */, opt: true },
721
612
  ]);
722
613
 
@@ -1,4 +1,4 @@
1
- // @generated by protoc-gen-es v1.1.1 with parameter "target=ts"
1
+ // @generated by protoc-gen-es v1.7.2 with parameter "target=ts"
2
2
  // @generated from file samples.proto (package org.observertc.schemas.protobuf, syntax proto2)
3
3
  /* eslint-disable */
4
4
  // @ts-nocheck