livekit-client 1.15.6 → 1.15.8
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/livekit-client.e2ee.worker.js +1 -1
- package/dist/livekit-client.e2ee.worker.js.map +1 -1
- package/dist/livekit-client.e2ee.worker.mjs +14 -1
- package/dist/livekit-client.e2ee.worker.mjs.map +1 -1
- package/dist/livekit-client.esm.mjs +556 -348
- package/dist/livekit-client.esm.mjs.map +1 -1
- package/dist/livekit-client.umd.js +1 -1
- package/dist/livekit-client.umd.js.map +1 -1
- package/dist/src/api/SignalClient.d.ts +5 -1
- package/dist/src/api/SignalClient.d.ts.map +1 -1
- package/dist/src/index.d.ts +2 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/logger.d.ts +19 -3
- package/dist/src/logger.d.ts.map +1 -1
- package/dist/src/options.d.ts +1 -0
- package/dist/src/options.d.ts.map +1 -1
- package/dist/src/room/PCTransport.d.ts +5 -1
- package/dist/src/room/PCTransport.d.ts.map +1 -1
- package/dist/src/room/PCTransportManager.d.ts +5 -1
- package/dist/src/room/PCTransportManager.d.ts.map +1 -1
- package/dist/src/room/RTCEngine.d.ts +8 -0
- package/dist/src/room/RTCEngine.d.ts.map +1 -1
- package/dist/src/room/Room.d.ts +2 -0
- package/dist/src/room/Room.d.ts.map +1 -1
- package/dist/src/room/participant/LocalParticipant.d.ts.map +1 -1
- package/dist/src/room/participant/Participant.d.ts +9 -1
- package/dist/src/room/participant/Participant.d.ts.map +1 -1
- package/dist/src/room/participant/RemoteParticipant.d.ts +2 -1
- package/dist/src/room/participant/RemoteParticipant.d.ts.map +1 -1
- package/dist/src/room/participant/publishUtils.d.ts +2 -1
- package/dist/src/room/participant/publishUtils.d.ts.map +1 -1
- package/dist/src/room/timers.d.ts +5 -4
- package/dist/src/room/timers.d.ts.map +1 -1
- package/dist/src/room/track/LocalAudioTrack.d.ts +2 -1
- package/dist/src/room/track/LocalAudioTrack.d.ts.map +1 -1
- package/dist/src/room/track/LocalTrack.d.ts +2 -1
- package/dist/src/room/track/LocalTrack.d.ts.map +1 -1
- package/dist/src/room/track/LocalTrackPublication.d.ts +2 -1
- package/dist/src/room/track/LocalTrackPublication.d.ts.map +1 -1
- package/dist/src/room/track/LocalVideoTrack.d.ts +2 -1
- package/dist/src/room/track/LocalVideoTrack.d.ts.map +1 -1
- package/dist/src/room/track/RemoteAudioTrack.d.ts +2 -1
- package/dist/src/room/track/RemoteAudioTrack.d.ts.map +1 -1
- package/dist/src/room/track/RemoteTrack.d.ts +2 -1
- package/dist/src/room/track/RemoteTrack.d.ts.map +1 -1
- package/dist/src/room/track/RemoteTrackPublication.d.ts +2 -1
- package/dist/src/room/track/RemoteTrackPublication.d.ts.map +1 -1
- package/dist/src/room/track/RemoteVideoTrack.d.ts +2 -1
- package/dist/src/room/track/RemoteVideoTrack.d.ts.map +1 -1
- package/dist/src/room/track/Track.d.ts +10 -1
- package/dist/src/room/track/Track.d.ts.map +1 -1
- package/dist/src/room/track/TrackPublication.d.ts +7 -1
- package/dist/src/room/track/TrackPublication.d.ts.map +1 -1
- package/dist/src/room/track/create.d.ts.map +1 -1
- package/dist/src/room/track/options.d.ts +8 -3
- package/dist/src/room/track/options.d.ts.map +1 -1
- package/dist/src/room/track/utils.d.ts +1 -0
- package/dist/src/room/track/utils.d.ts.map +1 -1
- package/dist/src/room/types.d.ts +4 -0
- package/dist/src/room/types.d.ts.map +1 -1
- package/dist/src/room/utils.d.ts +1 -0
- package/dist/src/room/utils.d.ts.map +1 -1
- package/dist/ts4.2/src/api/SignalClient.d.ts +5 -1
- package/dist/ts4.2/src/index.d.ts +2 -2
- package/dist/ts4.2/src/logger.d.ts +19 -3
- package/dist/ts4.2/src/options.d.ts +1 -0
- package/dist/ts4.2/src/room/PCTransport.d.ts +5 -1
- package/dist/ts4.2/src/room/PCTransportManager.d.ts +5 -1
- package/dist/ts4.2/src/room/RTCEngine.d.ts +8 -0
- package/dist/ts4.2/src/room/Room.d.ts +2 -0
- package/dist/ts4.2/src/room/participant/Participant.d.ts +9 -1
- package/dist/ts4.2/src/room/participant/RemoteParticipant.d.ts +2 -1
- package/dist/ts4.2/src/room/participant/publishUtils.d.ts +2 -1
- package/dist/ts4.2/src/room/timers.d.ts +5 -4
- package/dist/ts4.2/src/room/track/LocalAudioTrack.d.ts +2 -1
- package/dist/ts4.2/src/room/track/LocalTrack.d.ts +2 -1
- package/dist/ts4.2/src/room/track/LocalTrackPublication.d.ts +2 -1
- package/dist/ts4.2/src/room/track/LocalVideoTrack.d.ts +2 -1
- package/dist/ts4.2/src/room/track/RemoteAudioTrack.d.ts +2 -1
- package/dist/ts4.2/src/room/track/RemoteTrack.d.ts +2 -1
- package/dist/ts4.2/src/room/track/RemoteTrackPublication.d.ts +2 -1
- package/dist/ts4.2/src/room/track/RemoteVideoTrack.d.ts +2 -1
- package/dist/ts4.2/src/room/track/Track.d.ts +10 -1
- package/dist/ts4.2/src/room/track/TrackPublication.d.ts +7 -1
- package/dist/ts4.2/src/room/track/options.d.ts +8 -3
- package/dist/ts4.2/src/room/track/utils.d.ts +1 -0
- package/dist/ts4.2/src/room/types.d.ts +4 -0
- package/dist/ts4.2/src/room/utils.d.ts +1 -0
- package/package.json +2 -2
- package/src/api/SignalClient.ts +43 -21
- package/src/index.ts +2 -1
- package/src/logger.ts +32 -8
- package/src/options.ts +2 -0
- package/src/room/PCTransport.ts +29 -8
- package/src/room/PCTransportManager.ts +29 -9
- package/src/room/RTCEngine.ts +71 -34
- package/src/room/Room.ts +91 -60
- package/src/room/participant/LocalParticipant.ts +165 -47
- package/src/room/participant/Participant.ts +26 -3
- package/src/room/participant/RemoteParticipant.ts +23 -15
- package/src/room/participant/publishUtils.test.ts +2 -2
- package/src/room/participant/publishUtils.ts +7 -4
- package/src/room/track/LocalAudioTrack.ts +8 -7
- package/src/room/track/LocalTrack.ts +23 -19
- package/src/room/track/LocalTrackPublication.ts +3 -2
- package/src/room/track/LocalVideoTrack.ts +31 -13
- package/src/room/track/RemoteAudioTrack.ts +4 -3
- package/src/room/track/RemoteTrack.ts +4 -1
- package/src/room/track/RemoteTrackPublication.ts +21 -13
- package/src/room/track/RemoteVideoTrack.ts +5 -4
- package/src/room/track/Track.ts +32 -2
- package/src/room/track/TrackPublication.ts +18 -3
- package/src/room/track/create.ts +4 -3
- package/src/room/track/options.ts +12 -5
- package/src/room/track/utils.ts +23 -1
- package/src/room/types.ts +5 -0
- package/src/room/utils.ts +5 -0
@@ -1,9 +1,10 @@
|
|
1
|
-
import log from '../logger';
|
1
|
+
import log, { LoggerNames, getLogger } from '../logger';
|
2
2
|
import { SignalTarget } from '../proto/livekit_rtc_pb';
|
3
3
|
import PCTransport, { PCEvents } from './PCTransport';
|
4
4
|
import { roomConnectOptionDefaults } from './defaults';
|
5
5
|
import { ConnectionError, ConnectionErrorReason } from './errors';
|
6
6
|
import CriticalTimers from './timers';
|
7
|
+
import type { LoggerOptions } from './types';
|
7
8
|
import { Mutex, sleep } from './utils';
|
8
9
|
|
9
10
|
export enum PCTransportState {
|
@@ -56,12 +57,23 @@ export class PCTransportManager {
|
|
56
57
|
|
57
58
|
private connectionLock: Mutex;
|
58
59
|
|
59
|
-
|
60
|
+
private log = log;
|
61
|
+
|
62
|
+
private loggerOptions: LoggerOptions;
|
63
|
+
|
64
|
+
constructor(
|
65
|
+
rtcConfig: RTCConfiguration,
|
66
|
+
subscriberPrimary: boolean,
|
67
|
+
loggerOptions: LoggerOptions,
|
68
|
+
) {
|
69
|
+
this.log = getLogger(loggerOptions.loggerName ?? LoggerNames.PCManager);
|
70
|
+
this.loggerOptions = loggerOptions;
|
71
|
+
|
60
72
|
this.isPublisherConnectionRequired = !subscriberPrimary;
|
61
73
|
this.isSubscriberConnectionRequired = subscriberPrimary;
|
62
74
|
const googConstraints = { optional: [{ googDscp: true }] };
|
63
|
-
this.publisher = new PCTransport(rtcConfig, googConstraints);
|
64
|
-
this.subscriber = new PCTransport(rtcConfig);
|
75
|
+
this.publisher = new PCTransport(rtcConfig, googConstraints, loggerOptions);
|
76
|
+
this.subscriber = new PCTransport(rtcConfig, loggerOptions);
|
65
77
|
|
66
78
|
this.publisher.onConnectionStateChange = this.updateState;
|
67
79
|
this.subscriber.onConnectionStateChange = this.updateState;
|
@@ -91,6 +103,12 @@ export class PCTransportManager {
|
|
91
103
|
this.connectionLock = new Mutex();
|
92
104
|
}
|
93
105
|
|
106
|
+
private get logContext() {
|
107
|
+
return {
|
108
|
+
...this.loggerOptions.loggerContextCb?.(),
|
109
|
+
};
|
110
|
+
}
|
111
|
+
|
94
112
|
requirePublisher(require = true) {
|
95
113
|
this.isPublisherConnectionRequired = require;
|
96
114
|
this.updateState();
|
@@ -123,7 +141,7 @@ export class PCTransportManager {
|
|
123
141
|
publisher.removeTrack(sender);
|
124
142
|
}
|
125
143
|
} catch (e) {
|
126
|
-
log.warn('could not removeTrack', { error: e });
|
144
|
+
this.log.warn('could not removeTrack', { ...this.logContext, error: e });
|
127
145
|
}
|
128
146
|
}
|
129
147
|
}
|
@@ -148,7 +166,8 @@ export class PCTransportManager {
|
|
148
166
|
}
|
149
167
|
|
150
168
|
async createSubscriberAnswerFromOffer(sd: RTCSessionDescriptionInit) {
|
151
|
-
log.debug('received server offer', {
|
169
|
+
this.log.debug('received server offer', {
|
170
|
+
...this.logContext,
|
152
171
|
RTCSdpType: sd.type,
|
153
172
|
signalingState: this.subscriber.getSignallingState().toString(),
|
154
173
|
});
|
@@ -175,7 +194,7 @@ export class PCTransportManager {
|
|
175
194
|
this.publisher.getConnectionState() !== 'connected' &&
|
176
195
|
this.publisher.getConnectionState() !== 'connecting'
|
177
196
|
) {
|
178
|
-
log.debug('negotiation required, start negotiating');
|
197
|
+
this.log.debug('negotiation required, start negotiating', this.logContext);
|
179
198
|
this.publisher.negotiate();
|
180
199
|
}
|
181
200
|
await Promise.all(
|
@@ -271,10 +290,11 @@ export class PCTransportManager {
|
|
271
290
|
}
|
272
291
|
|
273
292
|
if (previousState !== this.state) {
|
274
|
-
log.debug(
|
293
|
+
this.log.debug(
|
275
294
|
`pc state change: from ${PCTransportState[previousState]} to ${
|
276
295
|
PCTransportState[this.state]
|
277
296
|
}`,
|
297
|
+
this.logContext,
|
278
298
|
);
|
279
299
|
this.onStateChange?.(
|
280
300
|
this.state,
|
@@ -296,7 +316,7 @@ export class PCTransportManager {
|
|
296
316
|
|
297
317
|
return new Promise<void>(async (resolve, reject) => {
|
298
318
|
const abortHandler = () => {
|
299
|
-
log.warn('abort transport connection');
|
319
|
+
this.log.warn('abort transport connection', this.logContext);
|
300
320
|
CriticalTimers.clearTimeout(connectTimeout);
|
301
321
|
|
302
322
|
reject(
|
package/src/room/RTCEngine.ts
CHANGED
@@ -7,7 +7,7 @@ import {
|
|
7
7
|
SignalConnectionState,
|
8
8
|
toProtoSessionDescription,
|
9
9
|
} from '../api/SignalClient';
|
10
|
-
import log from '../logger';
|
10
|
+
import log, { LoggerNames, getLogger } from '../logger';
|
11
11
|
import type { InternalRoomOptions } from '../options';
|
12
12
|
import {
|
13
13
|
ClientConfigSetting,
|
@@ -61,6 +61,7 @@ import type RemoteTrackPublication from './track/RemoteTrackPublication';
|
|
61
61
|
import { Track } from './track/Track';
|
62
62
|
import type { TrackPublishOptions, VideoCodec } from './track/options';
|
63
63
|
import { getTrackPublicationInfo } from './track/utils';
|
64
|
+
import type { LoggerOptions } from './types';
|
64
65
|
import {
|
65
66
|
Mutex,
|
66
67
|
isVideoCodec,
|
@@ -162,9 +163,18 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
|
|
162
163
|
|
163
164
|
private regionUrlProvider?: RegionUrlProvider;
|
164
165
|
|
166
|
+
private log = log;
|
167
|
+
|
168
|
+
private loggerOptions: LoggerOptions;
|
169
|
+
|
165
170
|
constructor(private options: InternalRoomOptions) {
|
166
171
|
super();
|
167
|
-
this.
|
172
|
+
this.log = getLogger(options.loggerName ?? LoggerNames.Engine);
|
173
|
+
this.loggerOptions = {
|
174
|
+
loggerName: options.loggerName,
|
175
|
+
loggerContextCb: () => this.logContext,
|
176
|
+
};
|
177
|
+
this.client = new SignalClient(undefined, this.loggerOptions);
|
168
178
|
this.client.signalLatency = this.options.expSignalLatency;
|
169
179
|
this.reconnectPolicy = this.options.reconnectPolicy;
|
170
180
|
this.registerOnLineListener();
|
@@ -187,6 +197,15 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
|
|
187
197
|
this.client.onStreamStateUpdate = (update) => this.emit(EngineEvent.StreamStateChanged, update);
|
188
198
|
}
|
189
199
|
|
200
|
+
/** @internal */
|
201
|
+
get logContext() {
|
202
|
+
return {
|
203
|
+
room: this.latestJoinResponse?.room?.name,
|
204
|
+
roomSid: this.latestJoinResponse?.room?.sid,
|
205
|
+
identity: this.latestJoinResponse?.participant?.identity,
|
206
|
+
};
|
207
|
+
}
|
208
|
+
|
190
209
|
async join(
|
191
210
|
url: string,
|
192
211
|
token: string,
|
@@ -220,8 +239,9 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
|
|
220
239
|
} catch (e) {
|
221
240
|
if (e instanceof ConnectionError) {
|
222
241
|
if (e.reason === ConnectionErrorReason.ServerUnreachable) {
|
223
|
-
log.warn(
|
242
|
+
this.log.warn(
|
224
243
|
`Couldn't connect to server, attempt ${this.joinAttempts} of ${this.maxJoinAttempts}`,
|
244
|
+
this.logContext,
|
225
245
|
);
|
226
246
|
if (this.joinAttempts < this.maxJoinAttempts) {
|
227
247
|
return this.join(url, token, opts, abortSignal);
|
@@ -324,7 +344,7 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
|
|
324
344
|
this.pcManager!.removeTrack(sender);
|
325
345
|
return true;
|
326
346
|
} catch (e: unknown) {
|
327
|
-
log.warn('failed to remove track', { error: e
|
347
|
+
this.log.warn('failed to remove track', { ...this.logContext, error: e });
|
328
348
|
}
|
329
349
|
return false;
|
330
350
|
}
|
@@ -356,7 +376,11 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
|
|
356
376
|
|
357
377
|
const rtcConfig = this.makeRTCConfiguration(joinResponse);
|
358
378
|
|
359
|
-
this.pcManager = new PCTransportManager(
|
379
|
+
this.pcManager = new PCTransportManager(
|
380
|
+
rtcConfig,
|
381
|
+
joinResponse.subscriberPrimary,
|
382
|
+
this.loggerOptions,
|
383
|
+
);
|
360
384
|
|
361
385
|
this.emit(EngineEvent.TransportsCreated, this.pcManager.publisher, this.pcManager.subscriber);
|
362
386
|
|
@@ -370,7 +394,7 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
|
|
370
394
|
|
371
395
|
this.pcManager.onDataChannel = this.handleDataChannel;
|
372
396
|
this.pcManager.onStateChange = async (connectionState, publisherState, subscriberState) => {
|
373
|
-
log.debug(`primary PC state changed ${connectionState}
|
397
|
+
this.log.debug(`primary PC state changed ${connectionState}`, this.logContext);
|
374
398
|
if (connectionState === PCTransportState.CONNECTED) {
|
375
399
|
const shouldEmit = this.pcState === PCState.New;
|
376
400
|
this.pcState = PCState.Connected;
|
@@ -404,9 +428,7 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
|
|
404
428
|
if (!this.pcManager) {
|
405
429
|
return;
|
406
430
|
}
|
407
|
-
log.debug('received server answer', {
|
408
|
-
RTCSdpType: sd.type,
|
409
|
-
});
|
431
|
+
this.log.debug('received server answer', { ...this.logContext, RTCSdpType: sd.type });
|
410
432
|
await this.pcManager.setPublisherAnswer(sd);
|
411
433
|
};
|
412
434
|
|
@@ -415,7 +437,7 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
|
|
415
437
|
if (!this.pcManager) {
|
416
438
|
return;
|
417
439
|
}
|
418
|
-
log.trace('got ICE candidate from peer', { candidate, target });
|
440
|
+
this.log.trace('got ICE candidate from peer', { ...this.logContext, candidate, target });
|
419
441
|
this.pcManager.addIceCandidate(candidate, target);
|
420
442
|
};
|
421
443
|
|
@@ -429,9 +451,16 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
|
|
429
451
|
};
|
430
452
|
|
431
453
|
this.client.onLocalTrackPublished = (res: TrackPublishedResponse) => {
|
432
|
-
log.debug('received trackPublishedResponse',
|
454
|
+
this.log.debug('received trackPublishedResponse', {
|
455
|
+
...this.logContext,
|
456
|
+
cid: res.cid,
|
457
|
+
track: res.track?.sid,
|
458
|
+
});
|
433
459
|
if (!this.pendingTrackResolvers[res.cid]) {
|
434
|
-
log.error(`missing track resolver for ${res.cid}
|
460
|
+
this.log.error(`missing track resolver for ${res.cid}`, {
|
461
|
+
...this.logContext,
|
462
|
+
cid: res.cid,
|
463
|
+
});
|
435
464
|
return;
|
436
465
|
}
|
437
466
|
const { resolve } = this.pendingTrackResolvers[res.cid];
|
@@ -464,7 +493,7 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
|
|
464
493
|
this.emit(EngineEvent.Disconnected, leave?.reason);
|
465
494
|
this.close();
|
466
495
|
}
|
467
|
-
log.
|
496
|
+
this.log.debug('client leave request', { ...this.logContext, reason: leave?.reason });
|
468
497
|
};
|
469
498
|
}
|
470
499
|
|
@@ -472,7 +501,7 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
|
|
472
501
|
const rtcConfig = { ...this.rtcConfig };
|
473
502
|
|
474
503
|
if (this.signalOpts?.e2eeEnabled) {
|
475
|
-
log.debug('E2EE - setting up transports with insertable streams');
|
504
|
+
this.log.debug('E2EE - setting up transports with insertable streams', this.logContext);
|
476
505
|
// this makes sure that no data is sent before the transforms are ready
|
477
506
|
// @ts-ignore
|
478
507
|
rtcConfig.encodedInsertableStreams = true;
|
@@ -562,7 +591,7 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
|
|
562
591
|
} else {
|
563
592
|
return;
|
564
593
|
}
|
565
|
-
log.debug(`on data channel ${channel.id}, ${channel.label}
|
594
|
+
this.log.debug(`on data channel ${channel.id}, ${channel.label}`, this.logContext);
|
566
595
|
channel.onmessage = this.handleDataMessage;
|
567
596
|
};
|
568
597
|
|
@@ -577,7 +606,7 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
|
|
577
606
|
} else if (message.data instanceof Blob) {
|
578
607
|
buffer = await message.data.arrayBuffer();
|
579
608
|
} else {
|
580
|
-
log.error('unsupported data type', message.data);
|
609
|
+
this.log.error('unsupported data type', { ...this.logContext, data: message.data });
|
581
610
|
return;
|
582
611
|
}
|
583
612
|
const dp = DataPacket.fromBinary(new Uint8Array(buffer));
|
@@ -598,9 +627,12 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
|
|
598
627
|
|
599
628
|
if (event instanceof ErrorEvent && event.error) {
|
600
629
|
const { error } = event.error;
|
601
|
-
log.error(`DataChannel error on ${channelKind}: ${event.message}`,
|
630
|
+
this.log.error(`DataChannel error on ${channelKind}: ${event.message}`, {
|
631
|
+
...this.logContext,
|
632
|
+
error,
|
633
|
+
});
|
602
634
|
} else {
|
603
|
-
log.error(`Unknown DataChannel error on ${channelKind}`, event);
|
635
|
+
this.log.error(`Unknown DataChannel error on ${channelKind}`, { ...this.logContext, event });
|
604
636
|
}
|
605
637
|
};
|
606
638
|
|
@@ -622,7 +654,7 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
|
|
622
654
|
}
|
623
655
|
const cap = RTCRtpSender.getCapabilities(kind);
|
624
656
|
if (!cap) return;
|
625
|
-
log.debug('get capabilities', cap);
|
657
|
+
this.log.debug('get sender capabilities', { ...this.logContext, cap });
|
626
658
|
const matched: RTCRtpCodecCapability[] = [];
|
627
659
|
const partialMatched: RTCRtpCodecCapability[] = [];
|
628
660
|
const unmatched: RTCRtpCodecCapability[] = [];
|
@@ -666,7 +698,7 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
|
|
666
698
|
return sender;
|
667
699
|
}
|
668
700
|
if (supportsAddTrack()) {
|
669
|
-
log.warn('using add-track fallback');
|
701
|
+
this.log.warn('using add-track fallback', this.logContext);
|
670
702
|
const sender = await this.createRTCRtpSender(track.mediaStreamTrack);
|
671
703
|
return sender;
|
672
704
|
}
|
@@ -684,7 +716,7 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
|
|
684
716
|
return this.createSimulcastTransceiverSender(track, simulcastTrack, opts, encodings);
|
685
717
|
}
|
686
718
|
if (supportsAddTrack()) {
|
687
|
-
log.debug('using add-track fallback');
|
719
|
+
this.log.debug('using add-track fallback', this.logContext);
|
688
720
|
return this.createRTCRtpSender(track.mediaStreamTrack);
|
689
721
|
}
|
690
722
|
|
@@ -764,15 +796,16 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
|
|
764
796
|
return;
|
765
797
|
}
|
766
798
|
|
767
|
-
log.warn(`${connection} disconnected
|
799
|
+
this.log.warn(`${connection} disconnected`, this.logContext);
|
768
800
|
if (this.reconnectAttempts === 0) {
|
769
801
|
// only reset start time on the first try
|
770
802
|
this.reconnectStart = Date.now();
|
771
803
|
}
|
772
804
|
|
773
805
|
const disconnect = (duration: number) => {
|
774
|
-
log.warn(
|
806
|
+
this.log.warn(
|
775
807
|
`could not recover connection after ${this.reconnectAttempts} attempts, ${duration}ms. giving up`,
|
808
|
+
this.logContext,
|
776
809
|
);
|
777
810
|
this.emit(EngineEvent.Disconnected);
|
778
811
|
this.close();
|
@@ -792,7 +825,7 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
|
|
792
825
|
delay = 0;
|
793
826
|
}
|
794
827
|
|
795
|
-
log.debug(`reconnecting in ${delay}ms
|
828
|
+
this.log.debug(`reconnecting in ${delay}ms`, this.logContext);
|
796
829
|
|
797
830
|
this.clearReconnectTimeout();
|
798
831
|
if (this.token && this.regionUrlProvider) {
|
@@ -836,7 +869,7 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
|
|
836
869
|
this.reconnectAttempts += 1;
|
837
870
|
let recoverable = true;
|
838
871
|
if (e instanceof UnexpectedConnectionState) {
|
839
|
-
log.debug('received unrecoverable error', { error: e });
|
872
|
+
this.log.debug('received unrecoverable error', { ...this.logContext, error: e });
|
840
873
|
// unrecoverable
|
841
874
|
recoverable = false;
|
842
875
|
} else if (!(e instanceof SignalReconnectError)) {
|
@@ -847,10 +880,11 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
|
|
847
880
|
if (recoverable) {
|
848
881
|
this.handleDisconnect('reconnect', ReconnectReason.RR_UNKNOWN);
|
849
882
|
} else {
|
850
|
-
log.info(
|
883
|
+
this.log.info(
|
851
884
|
`could not recover connection after ${this.reconnectAttempts} attempts, ${
|
852
885
|
Date.now() - this.reconnectStart
|
853
886
|
}ms. giving up`,
|
887
|
+
this.logContext,
|
854
888
|
);
|
855
889
|
this.emit(EngineEvent.Disconnected);
|
856
890
|
await this.close();
|
@@ -864,7 +898,7 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
|
|
864
898
|
try {
|
865
899
|
return this.reconnectPolicy.nextRetryDelayInMs(context);
|
866
900
|
} catch (e) {
|
867
|
-
log.warn('encountered error in reconnect policy', { error: e });
|
901
|
+
this.log.warn('encountered error in reconnect policy', { ...this.logContext, error: e });
|
868
902
|
}
|
869
903
|
|
870
904
|
// error in user code with provided reconnect policy, stop reconnecting
|
@@ -878,7 +912,7 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
|
|
878
912
|
throw new UnexpectedConnectionState('could not reconnect, url or token not saved');
|
879
913
|
}
|
880
914
|
|
881
|
-
log.info(`reconnecting, attempt: ${this.reconnectAttempts}
|
915
|
+
this.log.info(`reconnecting, attempt: ${this.reconnectAttempts}`, this.logContext);
|
882
916
|
this.emit(EngineEvent.Restarting);
|
883
917
|
|
884
918
|
if (!this.client.isDisconnected) {
|
@@ -890,7 +924,10 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
|
|
890
924
|
let joinResponse: JoinResponse;
|
891
925
|
try {
|
892
926
|
if (!this.signalOpts) {
|
893
|
-
log.warn(
|
927
|
+
this.log.warn(
|
928
|
+
'attempted connection restart, without signal options present',
|
929
|
+
this.logContext,
|
930
|
+
);
|
894
931
|
throw new SignalReconnectError();
|
895
932
|
}
|
896
933
|
// in case a regionUrl is passed, the region URL takes precedence
|
@@ -937,7 +974,7 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
|
|
937
974
|
throw new UnexpectedConnectionState('publisher and subscriber connections unset');
|
938
975
|
}
|
939
976
|
|
940
|
-
log.info(`resuming signal connection, attempt ${this.reconnectAttempts}
|
977
|
+
this.log.info(`resuming signal connection, attempt ${this.reconnectAttempts}`, this.logContext);
|
941
978
|
this.emit(EngineEvent.Resuming);
|
942
979
|
|
943
980
|
try {
|
@@ -951,7 +988,7 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
|
|
951
988
|
let message = '';
|
952
989
|
if (e instanceof Error) {
|
953
990
|
message = e.message;
|
954
|
-
log.error(e.message);
|
991
|
+
this.log.error(e.message, this.logContext);
|
955
992
|
}
|
956
993
|
if (e instanceof ConnectionError && e.reason === ConnectionErrorReason.NotAllowed) {
|
957
994
|
throw new UnexpectedConnectionState('could not reconnect, token might be expired');
|
@@ -990,7 +1027,7 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
|
|
990
1027
|
private async waitForPCReconnected() {
|
991
1028
|
this.pcState = PCState.Reconnecting;
|
992
1029
|
|
993
|
-
log.debug('waiting for peer connection to reconnect');
|
1030
|
+
this.log.debug('waiting for peer connection to reconnect', this.logContext);
|
994
1031
|
try {
|
995
1032
|
await sleep(minReconnectWait); // FIXME setTimeout again not ideal for a connection critical path
|
996
1033
|
if (!this.pcManager) {
|
@@ -1136,7 +1173,7 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
|
|
1136
1173
|
|
1137
1174
|
const handleClosed = () => {
|
1138
1175
|
abortController.abort();
|
1139
|
-
log.debug('engine disconnected while negotiation was ongoing');
|
1176
|
+
this.log.debug('engine disconnected while negotiation was ongoing', this.logContext);
|
1140
1177
|
resolve();
|
1141
1178
|
return;
|
1142
1179
|
};
|
@@ -1196,7 +1233,7 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
|
|
1196
1233
|
/** @internal */
|
1197
1234
|
sendSyncState(remoteTracks: RemoteTrackPublication[], localTracks: LocalTrackPublication[]) {
|
1198
1235
|
if (!this.pcManager) {
|
1199
|
-
log.warn('sync state cannot be sent without peer connection setup');
|
1236
|
+
this.log.warn('sync state cannot be sent without peer connection setup', this.logContext);
|
1200
1237
|
return;
|
1201
1238
|
}
|
1202
1239
|
const previousAnswer = this.pcManager.subscriber.getLocalDescription();
|