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.
Files changed (117) hide show
  1. package/dist/livekit-client.e2ee.worker.js +1 -1
  2. package/dist/livekit-client.e2ee.worker.js.map +1 -1
  3. package/dist/livekit-client.e2ee.worker.mjs +14 -1
  4. package/dist/livekit-client.e2ee.worker.mjs.map +1 -1
  5. package/dist/livekit-client.esm.mjs +556 -348
  6. package/dist/livekit-client.esm.mjs.map +1 -1
  7. package/dist/livekit-client.umd.js +1 -1
  8. package/dist/livekit-client.umd.js.map +1 -1
  9. package/dist/src/api/SignalClient.d.ts +5 -1
  10. package/dist/src/api/SignalClient.d.ts.map +1 -1
  11. package/dist/src/index.d.ts +2 -2
  12. package/dist/src/index.d.ts.map +1 -1
  13. package/dist/src/logger.d.ts +19 -3
  14. package/dist/src/logger.d.ts.map +1 -1
  15. package/dist/src/options.d.ts +1 -0
  16. package/dist/src/options.d.ts.map +1 -1
  17. package/dist/src/room/PCTransport.d.ts +5 -1
  18. package/dist/src/room/PCTransport.d.ts.map +1 -1
  19. package/dist/src/room/PCTransportManager.d.ts +5 -1
  20. package/dist/src/room/PCTransportManager.d.ts.map +1 -1
  21. package/dist/src/room/RTCEngine.d.ts +8 -0
  22. package/dist/src/room/RTCEngine.d.ts.map +1 -1
  23. package/dist/src/room/Room.d.ts +2 -0
  24. package/dist/src/room/Room.d.ts.map +1 -1
  25. package/dist/src/room/participant/LocalParticipant.d.ts.map +1 -1
  26. package/dist/src/room/participant/Participant.d.ts +9 -1
  27. package/dist/src/room/participant/Participant.d.ts.map +1 -1
  28. package/dist/src/room/participant/RemoteParticipant.d.ts +2 -1
  29. package/dist/src/room/participant/RemoteParticipant.d.ts.map +1 -1
  30. package/dist/src/room/participant/publishUtils.d.ts +2 -1
  31. package/dist/src/room/participant/publishUtils.d.ts.map +1 -1
  32. package/dist/src/room/timers.d.ts +5 -4
  33. package/dist/src/room/timers.d.ts.map +1 -1
  34. package/dist/src/room/track/LocalAudioTrack.d.ts +2 -1
  35. package/dist/src/room/track/LocalAudioTrack.d.ts.map +1 -1
  36. package/dist/src/room/track/LocalTrack.d.ts +2 -1
  37. package/dist/src/room/track/LocalTrack.d.ts.map +1 -1
  38. package/dist/src/room/track/LocalTrackPublication.d.ts +2 -1
  39. package/dist/src/room/track/LocalTrackPublication.d.ts.map +1 -1
  40. package/dist/src/room/track/LocalVideoTrack.d.ts +2 -1
  41. package/dist/src/room/track/LocalVideoTrack.d.ts.map +1 -1
  42. package/dist/src/room/track/RemoteAudioTrack.d.ts +2 -1
  43. package/dist/src/room/track/RemoteAudioTrack.d.ts.map +1 -1
  44. package/dist/src/room/track/RemoteTrack.d.ts +2 -1
  45. package/dist/src/room/track/RemoteTrack.d.ts.map +1 -1
  46. package/dist/src/room/track/RemoteTrackPublication.d.ts +2 -1
  47. package/dist/src/room/track/RemoteTrackPublication.d.ts.map +1 -1
  48. package/dist/src/room/track/RemoteVideoTrack.d.ts +2 -1
  49. package/dist/src/room/track/RemoteVideoTrack.d.ts.map +1 -1
  50. package/dist/src/room/track/Track.d.ts +10 -1
  51. package/dist/src/room/track/Track.d.ts.map +1 -1
  52. package/dist/src/room/track/TrackPublication.d.ts +7 -1
  53. package/dist/src/room/track/TrackPublication.d.ts.map +1 -1
  54. package/dist/src/room/track/create.d.ts.map +1 -1
  55. package/dist/src/room/track/options.d.ts +8 -3
  56. package/dist/src/room/track/options.d.ts.map +1 -1
  57. package/dist/src/room/track/utils.d.ts +1 -0
  58. package/dist/src/room/track/utils.d.ts.map +1 -1
  59. package/dist/src/room/types.d.ts +4 -0
  60. package/dist/src/room/types.d.ts.map +1 -1
  61. package/dist/src/room/utils.d.ts +1 -0
  62. package/dist/src/room/utils.d.ts.map +1 -1
  63. package/dist/ts4.2/src/api/SignalClient.d.ts +5 -1
  64. package/dist/ts4.2/src/index.d.ts +2 -2
  65. package/dist/ts4.2/src/logger.d.ts +19 -3
  66. package/dist/ts4.2/src/options.d.ts +1 -0
  67. package/dist/ts4.2/src/room/PCTransport.d.ts +5 -1
  68. package/dist/ts4.2/src/room/PCTransportManager.d.ts +5 -1
  69. package/dist/ts4.2/src/room/RTCEngine.d.ts +8 -0
  70. package/dist/ts4.2/src/room/Room.d.ts +2 -0
  71. package/dist/ts4.2/src/room/participant/Participant.d.ts +9 -1
  72. package/dist/ts4.2/src/room/participant/RemoteParticipant.d.ts +2 -1
  73. package/dist/ts4.2/src/room/participant/publishUtils.d.ts +2 -1
  74. package/dist/ts4.2/src/room/timers.d.ts +5 -4
  75. package/dist/ts4.2/src/room/track/LocalAudioTrack.d.ts +2 -1
  76. package/dist/ts4.2/src/room/track/LocalTrack.d.ts +2 -1
  77. package/dist/ts4.2/src/room/track/LocalTrackPublication.d.ts +2 -1
  78. package/dist/ts4.2/src/room/track/LocalVideoTrack.d.ts +2 -1
  79. package/dist/ts4.2/src/room/track/RemoteAudioTrack.d.ts +2 -1
  80. package/dist/ts4.2/src/room/track/RemoteTrack.d.ts +2 -1
  81. package/dist/ts4.2/src/room/track/RemoteTrackPublication.d.ts +2 -1
  82. package/dist/ts4.2/src/room/track/RemoteVideoTrack.d.ts +2 -1
  83. package/dist/ts4.2/src/room/track/Track.d.ts +10 -1
  84. package/dist/ts4.2/src/room/track/TrackPublication.d.ts +7 -1
  85. package/dist/ts4.2/src/room/track/options.d.ts +8 -3
  86. package/dist/ts4.2/src/room/track/utils.d.ts +1 -0
  87. package/dist/ts4.2/src/room/types.d.ts +4 -0
  88. package/dist/ts4.2/src/room/utils.d.ts +1 -0
  89. package/package.json +2 -2
  90. package/src/api/SignalClient.ts +43 -21
  91. package/src/index.ts +2 -1
  92. package/src/logger.ts +32 -8
  93. package/src/options.ts +2 -0
  94. package/src/room/PCTransport.ts +29 -8
  95. package/src/room/PCTransportManager.ts +29 -9
  96. package/src/room/RTCEngine.ts +71 -34
  97. package/src/room/Room.ts +91 -60
  98. package/src/room/participant/LocalParticipant.ts +165 -47
  99. package/src/room/participant/Participant.ts +26 -3
  100. package/src/room/participant/RemoteParticipant.ts +23 -15
  101. package/src/room/participant/publishUtils.test.ts +2 -2
  102. package/src/room/participant/publishUtils.ts +7 -4
  103. package/src/room/track/LocalAudioTrack.ts +8 -7
  104. package/src/room/track/LocalTrack.ts +23 -19
  105. package/src/room/track/LocalTrackPublication.ts +3 -2
  106. package/src/room/track/LocalVideoTrack.ts +31 -13
  107. package/src/room/track/RemoteAudioTrack.ts +4 -3
  108. package/src/room/track/RemoteTrack.ts +4 -1
  109. package/src/room/track/RemoteTrackPublication.ts +21 -13
  110. package/src/room/track/RemoteVideoTrack.ts +5 -4
  111. package/src/room/track/Track.ts +32 -2
  112. package/src/room/track/TrackPublication.ts +18 -3
  113. package/src/room/track/create.ts +4 -3
  114. package/src/room/track/options.ts +12 -5
  115. package/src/room/track/utils.ts +23 -1
  116. package/src/room/types.ts +5 -0
  117. package/src/room/utils.ts +5 -0
@@ -295,13 +295,40 @@ var LogLevel;
295
295
  LogLevel[LogLevel["error"] = 4] = "error";
296
296
  LogLevel[LogLevel["silent"] = 5] = "silent";
297
297
  })(LogLevel || (LogLevel = {}));
298
- const livekitLogger = loglevelExports.getLogger('livekit');
298
+ var LoggerNames;
299
+ (function (LoggerNames) {
300
+ LoggerNames["Default"] = "livekit";
301
+ LoggerNames["Room"] = "livekit-room";
302
+ LoggerNames["Participant"] = "livekit-participant";
303
+ LoggerNames["Track"] = "livekit-track";
304
+ LoggerNames["Publication"] = "livekit-track-publication";
305
+ LoggerNames["Engine"] = "livekit-engine";
306
+ LoggerNames["Signal"] = "livekit-signal";
307
+ LoggerNames["PCManager"] = "livekit-pc-manager";
308
+ LoggerNames["PCTransport"] = "livekit-pc-transport";
309
+ LoggerNames["E2EE"] = "lk-e2ee";
310
+ })(LoggerNames || (LoggerNames = {}));
311
+ let livekitLogger = loglevelExports.getLogger('livekit');
299
312
  livekitLogger.setDefaultLevel(LogLevel.info);
313
+ /**
314
+ * @internal
315
+ */
316
+ function getLogger(name) {
317
+ const logger = loglevelExports.getLogger(name);
318
+ logger.setDefaultLevel(livekitLogger.getLevel());
319
+ return logger;
320
+ }
300
321
  function setLogLevel(level, loggerName) {
301
322
  if (loggerName) {
302
323
  loglevelExports.getLogger(loggerName).setLevel(level);
303
324
  }
304
- for (const logger of Object.values(loglevelExports.getLoggers())) {
325
+ for (const logger of Object.entries(loglevelExports.getLoggers()).filter(_ref => {
326
+ let [logrName] = _ref;
327
+ return logrName.startsWith('livekit');
328
+ }).map(_ref2 => {
329
+ let [, logr] = _ref2;
330
+ return logr;
331
+ })) {
305
332
  logger.setLevel(level);
306
333
  }
307
334
  }
@@ -310,8 +337,9 @@ function setLogLevel(level, loggerName) {
310
337
  * if set, the browser logs will lose their stacktrace information (see https://github.com/pimterry/loglevel#writing-plugins)
311
338
  */
312
339
  function setLogExtension(extension) {
313
- const originalFactory = livekitLogger.methodFactory;
314
- livekitLogger.methodFactory = (methodName, configLevel, loggerName) => {
340
+ let logger = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : livekitLogger;
341
+ const originalFactory = logger.methodFactory;
342
+ logger.methodFactory = (methodName, configLevel, loggerName) => {
315
343
  const rawMethod = originalFactory(methodName, configLevel, loggerName);
316
344
  const logLevel = LogLevel[methodName];
317
345
  const needLog = logLevel >= configLevel && logLevel < LogLevel.silent;
@@ -322,7 +350,7 @@ function setLogExtension(extension) {
322
350
  }
323
351
  };
324
352
  };
325
- livekitLogger.setLevel(livekitLogger.getLevel()); // Be sure to call setLevel method in order to apply plugin
353
+ logger.setLevel(logger.getLevel()); // Be sure to call setLevel method in order to apply plugin
326
354
  }
327
355
  loglevelExports.getLogger('lk-e2ee');
328
356
 
@@ -10586,7 +10614,7 @@ function getMatch(exp, ua) {
10586
10614
  return match && match.length >= id && match[id] || '';
10587
10615
  }
10588
10616
 
10589
- var version$1 = "1.15.6";
10617
+ var version$1 = "1.15.7";
10590
10618
 
10591
10619
  const version = version$1;
10592
10620
  const protocolVersion = 11;
@@ -10687,11 +10715,14 @@ const VideoPresets43 = {
10687
10715
  };
10688
10716
  const ScreenSharePresets = {
10689
10717
  h360fps3: new VideoPreset(640, 360, 200000, 3, 'medium'),
10690
- h720fps5: new VideoPreset(1280, 720, 400000, 5, 'medium'),
10718
+ h360fps15: new VideoPreset(640, 360, 400000, 15, 'medium'),
10719
+ h720fps5: new VideoPreset(1280, 720, 800000, 5, 'medium'),
10691
10720
  h720fps15: new VideoPreset(1280, 720, 1500000, 15, 'medium'),
10692
10721
  h720fps30: new VideoPreset(1280, 720, 2000000, 30, 'medium'),
10693
10722
  h1080fps15: new VideoPreset(1920, 1080, 2500000, 15, 'medium'),
10694
- h1080fps30: new VideoPreset(1920, 1080, 4000000, 30, 'medium')
10723
+ h1080fps30: new VideoPreset(1920, 1080, 5000000, 30, 'medium'),
10724
+ // original resolution, without resizing
10725
+ original: new VideoPreset(0, 0, 7000000, 30, 'medium')
10695
10726
  };
10696
10727
 
10697
10728
  // Copyright 2023 LiveKit, Inc.
@@ -12956,6 +12987,8 @@ const BACKGROUND_REACTION_DELAY = 5000;
12956
12987
  const recycledElements = [];
12957
12988
  class Track extends eventsExports.EventEmitter {
12958
12989
  constructor(mediaTrack, kind) {
12990
+ let loggerOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
12991
+ var _a;
12959
12992
  super();
12960
12993
  this.attachedElements = [];
12961
12994
  this.isMuted = false;
@@ -12966,6 +12999,7 @@ class Track extends eventsExports.EventEmitter {
12966
12999
  this.streamState = Track.StreamState.Active;
12967
13000
  this.isInBackground = false;
12968
13001
  this._currentBitrate = 0;
13002
+ this.log = livekitLogger;
12969
13003
  this.appVisibilityChangedListener = () => {
12970
13004
  if (this.backgroundTimeout) {
12971
13005
  clearTimeout(this.backgroundTimeout);
@@ -12978,12 +13012,18 @@ class Track extends eventsExports.EventEmitter {
12978
13012
  this.handleAppVisibilityChanged();
12979
13013
  }
12980
13014
  };
13015
+ this.log = getLogger((_a = loggerOptions.loggerName) !== null && _a !== void 0 ? _a : LoggerNames.Track);
13016
+ this.loggerContextCb = loggerOptions.loggerContextCb;
12981
13017
  this.setMaxListeners(100);
12982
13018
  this.kind = kind;
12983
13019
  this._mediaStreamTrack = mediaTrack;
12984
13020
  this._mediaStreamID = mediaTrack.id;
12985
13021
  this.source = Track.Source.Unknown;
12986
13022
  }
13023
+ get logContext() {
13024
+ var _a;
13025
+ return Object.assign(Object.assign({}, (_a = this.loggerContextCb) === null || _a === void 0 ? void 0 : _a.call(this)), getLogContextFromTrack(this));
13026
+ }
12987
13027
  /** current receive bits per second */
12988
13028
  get currentBitrate() {
12989
13029
  return this._currentBitrate;
@@ -13101,6 +13141,15 @@ class Track extends eventsExports.EventEmitter {
13101
13141
  clearInterval(this.monitorInterval);
13102
13142
  }
13103
13143
  }
13144
+ /** @internal */
13145
+ updateLoggerOptions(loggerOptions) {
13146
+ if (loggerOptions.loggerName) {
13147
+ this.log = getLogger(loggerOptions.loggerName);
13148
+ }
13149
+ if (loggerOptions.loggerContextCb) {
13150
+ this.loggerContextCb = loggerOptions.loggerContextCb;
13151
+ }
13152
+ }
13104
13153
  recycleElement(element) {
13105
13154
  if (element instanceof HTMLAudioElement) {
13106
13155
  // we only need to re-use a single element
@@ -13403,7 +13452,8 @@ function sourceToKind(source) {
13403
13452
  function screenCaptureToDisplayMediaStreamOptions(options) {
13404
13453
  var _a, _b;
13405
13454
  let videoConstraints = (_a = options.video) !== null && _a !== void 0 ? _a : true;
13406
- if (options.resolution) {
13455
+ // treat 0 as uncapped
13456
+ if (options.resolution && options.resolution.width > 0 && options.resolution.height > 0) {
13407
13457
  videoConstraints = typeof videoConstraints === 'boolean' ? {} : videoConstraints;
13408
13458
  if (isSafari()) {
13409
13459
  videoConstraints = Object.assign(Object.assign({}, videoConstraints), {
@@ -13456,6 +13506,26 @@ function getTrackPublicationInfo(tracks) {
13456
13506
  });
13457
13507
  return infos;
13458
13508
  }
13509
+ function getLogContextFromTrack(track) {
13510
+ if (track instanceof Track) {
13511
+ return {
13512
+ trackSid: track.sid,
13513
+ trackSource: track.source,
13514
+ trackMuted: track.isMuted,
13515
+ trackEnabled: track.mediaStreamTrack.enabled,
13516
+ trackKind: track.kind
13517
+ };
13518
+ } else {
13519
+ return {
13520
+ trackSid: track.trackSid,
13521
+ trackName: track.trackName,
13522
+ track: track.track ? getLogContextFromTrack(track.track) : undefined,
13523
+ trackEnabled: track.isEnabled,
13524
+ trackEncrypted: track.isEncrypted,
13525
+ trackMimeType: track.mimeType
13526
+ };
13527
+ }
13528
+ }
13459
13529
 
13460
13530
  const separator = '|';
13461
13531
  const ddExtensionURI = 'https://aomediacodec.github.io/av1-rtp-spec/#dependency-descriptor-rtp-header-extension';
@@ -13583,6 +13653,10 @@ function isSafari() {
13583
13653
  var _a;
13584
13654
  return ((_a = getBrowser()) === null || _a === void 0 ? void 0 : _a.name) === 'Safari';
13585
13655
  }
13656
+ function isSafari17() {
13657
+ const b = getBrowser();
13658
+ return (b === null || b === void 0 ? void 0 : b.name) === 'Safari' && b.version.startsWith('17.');
13659
+ }
13586
13660
  function isMobile() {
13587
13661
  if (!isWeb()) return false;
13588
13662
  return /Tablet|iPad|Mobile|Android|BlackBerry/.test(navigator.userAgent);
@@ -13943,9 +14017,10 @@ class LocalTrack extends Track {
13943
14017
  */
13944
14018
  constructor(mediaTrack, kind, constraints) {
13945
14019
  let userProvidedTrack = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
13946
- super(mediaTrack, kind);
14020
+ let loggerOptions = arguments.length > 4 ? arguments[4] : undefined;
14021
+ super(mediaTrack, kind, loggerOptions);
13947
14022
  this._isUpstreamPaused = false;
13948
- this.handleTrackMuteEvent = () => this.debouncedTrackMuteHandler().catch(() => livekitLogger.debug('track mute bounce got cancelled by an unmute event'));
14023
+ this.handleTrackMuteEvent = () => this.debouncedTrackMuteHandler().catch(() => this.log.debug('track mute bounce got cancelled by an unmute event', this.logContext));
13949
14024
  this.debouncedTrackMuteHandler = r(() => __awaiter(this, void 0, void 0, function* () {
13950
14025
  yield this.pauseUpstream();
13951
14026
  }), 5000);
@@ -14016,9 +14091,6 @@ class LocalTrack extends Track {
14016
14091
  this._mediaStreamTrack.removeEventListener('ended', this.handleEnded);
14017
14092
  this._mediaStreamTrack.removeEventListener('mute', this.handleTrackMuteEvent);
14018
14093
  this._mediaStreamTrack.removeEventListener('unmute', this.handleTrackUnmuteEvent);
14019
- if (!this.providedByUser && this._mediaStreamTrack !== newTrack) {
14020
- this._mediaStreamTrack.stop();
14021
- }
14022
14094
  }
14023
14095
  this.mediaStream = new MediaStream([newTrack]);
14024
14096
  if (newTrack) {
@@ -14034,7 +14106,7 @@ class LocalTrack extends Track {
14034
14106
  }
14035
14107
  let processedTrack;
14036
14108
  if (this.processor && newTrack && this.processorElement) {
14037
- livekitLogger.debug('restarting processor');
14109
+ this.log.debug('restarting processor', this.logContext);
14038
14110
  if (this.kind === 'unknown') {
14039
14111
  throw TypeError('cannot set processor on track of unknown kind');
14040
14112
  }
@@ -14051,6 +14123,11 @@ class LocalTrack extends Track {
14051
14123
  if (this.sender) {
14052
14124
  yield this.sender.replaceTrack(processedTrack !== null && processedTrack !== void 0 ? processedTrack : newTrack);
14053
14125
  }
14126
+ // if `newTrack` is different from the existing track, stop the
14127
+ // older track just before replacing it
14128
+ if (!this.providedByUser && this._mediaStreamTrack !== newTrack) {
14129
+ this._mediaStreamTrack.stop();
14130
+ }
14054
14131
  this._mediaStreamTrack = newTrack;
14055
14132
  if (newTrack) {
14056
14133
  // sync muted state with the enabled state of the newly provided track
@@ -14121,7 +14198,7 @@ class LocalTrack extends Track {
14121
14198
  if (!this.sender) {
14122
14199
  throw new TrackInvalidError('unable to replace an unpublished track');
14123
14200
  }
14124
- livekitLogger.debug('replace MediaStreamTrack');
14201
+ this.log.debug('replace MediaStreamTrack', this.logContext);
14125
14202
  yield this.setMediaStreamTrack(track);
14126
14203
  // this must be synced *after* setting mediaStreamTrack above, since it relies
14127
14204
  // on the previous state in order to cleanup
@@ -14137,7 +14214,9 @@ class LocalTrack extends Track {
14137
14214
  if (!constraints) {
14138
14215
  constraints = this._constraints;
14139
14216
  }
14140
- livekitLogger.debug('restarting track with constraints', constraints);
14217
+ this.log.debug('restarting track with constraints', Object.assign(Object.assign({}, this.logContext), {
14218
+ constraints
14219
+ }));
14141
14220
  const streamConstraints = {
14142
14221
  audio: false,
14143
14222
  video: false
@@ -14161,7 +14240,7 @@ class LocalTrack extends Track {
14161
14240
  const mediaStream = yield navigator.mediaDevices.getUserMedia(streamConstraints);
14162
14241
  const newTrack = mediaStream.getTracks()[0];
14163
14242
  newTrack.addEventListener('ended', this.handleEnded);
14164
- livekitLogger.debug('re-acquired MediaStreamTrack');
14243
+ this.log.debug('re-acquired MediaStreamTrack', this.logContext);
14165
14244
  yield this.setMediaStreamTrack(newTrack);
14166
14245
  this._constraints = constraints;
14167
14246
  this.emit(TrackEvent.Restarted, this);
@@ -14169,7 +14248,7 @@ class LocalTrack extends Track {
14169
14248
  });
14170
14249
  }
14171
14250
  setTrackMuted(muted) {
14172
- livekitLogger.debug("setting ".concat(this.kind, " track ").concat(muted ? 'muted' : 'unmuted'));
14251
+ this.log.debug("setting ".concat(this.kind, " track ").concat(muted ? 'muted' : 'unmuted'), this.logContext);
14173
14252
  if (this.isMuted === muted && this._mediaStreamTrack.enabled !== muted) {
14174
14253
  return;
14175
14254
  }
@@ -14189,9 +14268,9 @@ class LocalTrack extends Track {
14189
14268
  return __awaiter(this, void 0, void 0, function* () {
14190
14269
  yield _super.handleAppVisibilityChanged.call(this);
14191
14270
  if (!isMobile()) return;
14192
- livekitLogger.debug("visibility changed, is in Background: ".concat(this.isInBackground));
14271
+ this.log.debug("visibility changed, is in Background: ".concat(this.isInBackground), this.logContext);
14193
14272
  if (!this.isInBackground && this.needsReAcquisition && !this.isUserProvided && !this.isMuted) {
14194
- livekitLogger.debug("track needs to be reacquired, restarting ".concat(this.source));
14273
+ this.log.debug("track needs to be reacquired, restarting ".concat(this.source), this.logContext);
14195
14274
  yield this.restart();
14196
14275
  this.reacquireTrack = false;
14197
14276
  }
@@ -14220,7 +14299,7 @@ class LocalTrack extends Track {
14220
14299
  return;
14221
14300
  }
14222
14301
  if (!this.sender) {
14223
- livekitLogger.warn('unable to pause upstream for an unpublished track');
14302
+ this.log.warn('unable to pause upstream for an unpublished track', this.logContext);
14224
14303
  return;
14225
14304
  }
14226
14305
  this._isUpstreamPaused = true;
@@ -14244,7 +14323,7 @@ class LocalTrack extends Track {
14244
14323
  return;
14245
14324
  }
14246
14325
  if (!this.sender) {
14247
- livekitLogger.warn('unable to resume upstream for an unpublished track');
14326
+ this.log.warn('unable to resume upstream for an unpublished track', this.logContext);
14248
14327
  return;
14249
14328
  }
14250
14329
  this._isUpstreamPaused = false;
@@ -14288,7 +14367,7 @@ class LocalTrack extends Track {
14288
14367
  return __awaiter(this, void 0, void 0, function* () {
14289
14368
  const unlock = yield this.processorLock.lock();
14290
14369
  try {
14291
- livekitLogger.debug('setting up processor');
14370
+ this.log.debug('setting up processor', this.logContext);
14292
14371
  if (this.processor) {
14293
14372
  yield this.stopProcessor();
14294
14373
  }
@@ -14298,9 +14377,9 @@ class LocalTrack extends Track {
14298
14377
  this.processorElement = (_a = this.processorElement) !== null && _a !== void 0 ? _a : document.createElement(this.kind);
14299
14378
  attachToElement(this._mediaStreamTrack, this.processorElement);
14300
14379
  this.processorElement.muted = true;
14301
- this.processorElement.play().catch(error => livekitLogger.error('failed to play processor element', {
14380
+ this.processorElement.play().catch(error => this.log.error('failed to play processor element', Object.assign(Object.assign({}, this.logContext), {
14302
14381
  error
14303
- }));
14382
+ })));
14304
14383
  const processorOptions = {
14305
14384
  kind: this.kind,
14306
14385
  track: this._mediaStreamTrack,
@@ -14336,7 +14415,7 @@ class LocalTrack extends Track {
14336
14415
  var _a, _b;
14337
14416
  return __awaiter(this, void 0, void 0, function* () {
14338
14417
  if (!this.processor) return;
14339
- livekitLogger.debug('stopping processor');
14418
+ this.log.debug('stopping processor', this.logContext);
14340
14419
  (_a = this.processor.processedTrack) === null || _a === void 0 ? void 0 : _a.stop();
14341
14420
  yield this.processor.destroy();
14342
14421
  this.processor = undefined;
@@ -14758,9 +14837,12 @@ class SignalClient {
14758
14837
  }
14759
14838
  constructor() {
14760
14839
  let useJSON = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
14840
+ let loggerOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
14841
+ var _a;
14761
14842
  /** signal rtt in milliseconds */
14762
14843
  this.rtt = 0;
14763
14844
  this.state = SignalConnectionState.DISCONNECTED;
14845
+ this.log = livekitLogger;
14764
14846
  /** @internal */
14765
14847
  this.resetCallbacks = () => {
14766
14848
  this.onAnswer = undefined;
@@ -14775,6 +14857,8 @@ class SignalClient {
14775
14857
  this.onTrickle = undefined;
14776
14858
  this.onClose = undefined;
14777
14859
  };
14860
+ this.log = getLogger((_a = loggerOptions.loggerName) !== null && _a !== void 0 ? _a : LoggerNames.Signal);
14861
+ this.loggerContextCb = loggerOptions.loggerContextCb;
14778
14862
  this.useJSON = useJSON;
14779
14863
  this.requestQueue = new AsyncQueue();
14780
14864
  this.queuedRequests = [];
@@ -14782,6 +14866,10 @@ class SignalClient {
14782
14866
  this.connectionLock = new Mutex();
14783
14867
  this.state = SignalConnectionState.DISCONNECTED;
14784
14868
  }
14869
+ get logContext() {
14870
+ var _a, _b;
14871
+ return (_b = (_a = this.loggerContextCb) === null || _a === void 0 ? void 0 : _a.call(this)) !== null && _b !== void 0 ? _b : {};
14872
+ }
14785
14873
  join(url, token, opts, abortSignal) {
14786
14874
  return __awaiter(this, void 0, void 0, function* () {
14787
14875
  // during a full reconnect, we'd want to start the sequence even if currently
@@ -14795,7 +14883,7 @@ class SignalClient {
14795
14883
  reconnect(url, token, sid, reason) {
14796
14884
  return __awaiter(this, void 0, void 0, function* () {
14797
14885
  if (!this.options) {
14798
- livekitLogger.warn('attempted to reconnect without signal options being set, ignoring');
14886
+ this.log.warn('attempted to reconnect without signal options being set, ignoring', this.logContext);
14799
14887
  return;
14800
14888
  }
14801
14889
  this.state = SignalConnectionState.RECONNECTING;
@@ -14833,7 +14921,7 @@ class SignalClient {
14833
14921
  abortHandler();
14834
14922
  }
14835
14923
  abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.addEventListener('abort', abortHandler);
14836
- livekitLogger.debug("connecting to ".concat(url + params));
14924
+ this.log.debug("connecting to ".concat(url + params), this.logContext);
14837
14925
  if (this.ws) {
14838
14926
  yield this.close();
14839
14927
  }
@@ -14871,7 +14959,7 @@ class SignalClient {
14871
14959
  } else if (ev.data instanceof ArrayBuffer) {
14872
14960
  resp = SignalResponse.fromBinary(new Uint8Array(ev.data));
14873
14961
  } else {
14874
- livekitLogger.error("could not decode websocket message: ".concat(typeof ev.data));
14962
+ this.log.error("could not decode websocket message: ".concat(typeof ev.data), this.logContext);
14875
14963
  return;
14876
14964
  }
14877
14965
  if (this.state !== SignalConnectionState.CONNECTED) {
@@ -14883,10 +14971,10 @@ class SignalClient {
14883
14971
  this.pingTimeoutDuration = resp.message.value.pingTimeout;
14884
14972
  this.pingIntervalDuration = resp.message.value.pingInterval;
14885
14973
  if (this.pingTimeoutDuration && this.pingTimeoutDuration > 0) {
14886
- livekitLogger.debug('ping config', {
14974
+ this.log.debug('ping config', Object.assign(Object.assign({}, this.logContext), {
14887
14975
  timeout: this.pingTimeoutDuration,
14888
14976
  interval: this.pingIntervalDuration
14889
- });
14977
+ }));
14890
14978
  this.startPingInterval();
14891
14979
  }
14892
14980
  resolve(resp.message.value);
@@ -14915,9 +15003,9 @@ class SignalClient {
14915
15003
  this.handleSignalResponse(resp);
14916
15004
  });
14917
15005
  this.ws.onclose = ev => {
14918
- livekitLogger.warn("websocket closed", {
14919
- ev
14920
- });
15006
+ this.log.warn("websocket closed", Object.assign(Object.assign({}, this.logContext), {
15007
+ reason: ev.reason
15008
+ }));
14921
15009
  this.handleOnClose(ev.reason);
14922
15010
  };
14923
15011
  } finally {
@@ -14960,7 +15048,9 @@ class SignalClient {
14960
15048
  }
14961
15049
  // initial offer after joining
14962
15050
  sendOffer(offer) {
14963
- livekitLogger.debug('sending offer', offer);
15051
+ this.log.debug('sending offer', Object.assign(Object.assign({}, this.logContext), {
15052
+ offerSdp: offer.sdp
15053
+ }));
14964
15054
  this.sendRequest({
14965
15055
  case: 'offer',
14966
15056
  value: toProtoSessionDescription(offer)
@@ -14968,14 +15058,18 @@ class SignalClient {
14968
15058
  }
14969
15059
  // answer a server-initiated offer
14970
15060
  sendAnswer(answer) {
14971
- livekitLogger.debug('sending answer');
15061
+ this.log.debug('sending answer', Object.assign(Object.assign({}, this.logContext), {
15062
+ answerSdp: answer.sdp
15063
+ }));
14972
15064
  return this.sendRequest({
14973
15065
  case: 'answer',
14974
15066
  value: toProtoSessionDescription(answer)
14975
15067
  });
14976
15068
  }
14977
15069
  sendIceCandidate(candidate, target) {
14978
- livekitLogger.trace('sending ice candidate', candidate);
15070
+ this.log.trace('sending ice candidate', Object.assign(Object.assign({}, this.logContext), {
15071
+ candidate
15072
+ }));
14979
15073
  return this.sendRequest({
14980
15074
  case: 'trickle',
14981
15075
  value: new TrickleRequest({
@@ -15092,7 +15186,7 @@ class SignalClient {
15092
15186
  yield sleep(this.signalLatency);
15093
15187
  }
15094
15188
  if (!this.ws || this.ws.readyState !== this.ws.OPEN) {
15095
- livekitLogger.error("cannot send signal request before connected, type: ".concat(message === null || message === void 0 ? void 0 : message.case));
15189
+ this.log.error("cannot send signal request before connected, type: ".concat(message === null || message === void 0 ? void 0 : message.case), this.logContext);
15096
15190
  return;
15097
15191
  }
15098
15192
  const req = new SignalRequest({
@@ -15105,9 +15199,9 @@ class SignalClient {
15105
15199
  this.ws.send(req.toBinary());
15106
15200
  }
15107
15201
  } catch (e) {
15108
- livekitLogger.error('error sending signal message', {
15202
+ this.log.error('error sending signal message', Object.assign(Object.assign({}, this.logContext), {
15109
15203
  error: e
15110
- });
15204
+ }));
15111
15205
  }
15112
15206
  });
15113
15207
  }
@@ -15115,7 +15209,7 @@ class SignalClient {
15115
15209
  var _a, _b;
15116
15210
  const msg = res.message;
15117
15211
  if (msg == undefined) {
15118
- livekitLogger.debug('received unsupported message');
15212
+ this.log.debug('received unsupported message', this.logContext);
15119
15213
  return;
15120
15214
  }
15121
15215
  let pingHandled = false;
@@ -15191,7 +15285,9 @@ class SignalClient {
15191
15285
  this.resetPingTimeout();
15192
15286
  pingHandled = true;
15193
15287
  } else {
15194
- livekitLogger.debug('unsupported message', msg);
15288
+ this.log.debug('unsupported message', Object.assign(Object.assign({}, this.logContext), {
15289
+ msgCase: msg.case
15290
+ }));
15195
15291
  }
15196
15292
  if (!pingHandled) {
15197
15293
  this.resetPingTimeout();
@@ -15210,14 +15306,18 @@ class SignalClient {
15210
15306
  if (this.state === SignalConnectionState.DISCONNECTED) return;
15211
15307
  const onCloseCallback = this.onClose;
15212
15308
  yield this.close();
15213
- livekitLogger.debug("websocket connection closed: ".concat(reason));
15309
+ this.log.debug("websocket connection closed: ".concat(reason), Object.assign(Object.assign({}, this.logContext), {
15310
+ reason
15311
+ }));
15214
15312
  if (onCloseCallback) {
15215
15313
  onCloseCallback(reason);
15216
15314
  }
15217
15315
  });
15218
15316
  }
15219
15317
  handleWSError(ev) {
15220
- livekitLogger.error('websocket error', ev);
15318
+ this.log.error('websocket error', Object.assign(Object.assign({}, this.logContext), {
15319
+ error: ev
15320
+ }));
15221
15321
  }
15222
15322
  /**
15223
15323
  * Resets the ping timeout and starts a new timeout.
@@ -15226,11 +15326,11 @@ class SignalClient {
15226
15326
  resetPingTimeout() {
15227
15327
  this.clearPingTimeout();
15228
15328
  if (!this.pingTimeoutDuration) {
15229
- livekitLogger.warn('ping timeout duration not set');
15329
+ this.log.warn('ping timeout duration not set', this.logContext);
15230
15330
  return;
15231
15331
  }
15232
15332
  this.pingTimeout = CriticalTimers.setTimeout(() => {
15233
- livekitLogger.warn("ping timeout triggered. last pong received at: ".concat(new Date(Date.now() - this.pingTimeoutDuration * 1000).toUTCString()));
15333
+ this.log.warn("ping timeout triggered. last pong received at: ".concat(new Date(Date.now() - this.pingTimeoutDuration * 1000).toUTCString()), this.logContext);
15234
15334
  this.handleOnClose('ping timeout');
15235
15335
  }, this.pingTimeoutDuration * 1000);
15236
15336
  }
@@ -15246,16 +15346,16 @@ class SignalClient {
15246
15346
  this.clearPingInterval();
15247
15347
  this.resetPingTimeout();
15248
15348
  if (!this.pingIntervalDuration) {
15249
- livekitLogger.warn('ping interval duration not set');
15349
+ this.log.warn('ping interval duration not set', this.logContext);
15250
15350
  return;
15251
15351
  }
15252
- livekitLogger.debug('start ping interval');
15352
+ this.log.debug('start ping interval', this.logContext);
15253
15353
  this.pingInterval = CriticalTimers.setInterval(() => {
15254
15354
  this.sendPing();
15255
15355
  }, this.pingIntervalDuration * 1000);
15256
15356
  }
15257
15357
  clearPingInterval() {
15258
- livekitLogger.debug('clearing ping interval');
15358
+ this.log.debug('clearing ping interval', this.logContext);
15259
15359
  this.clearPingTimeout();
15260
15360
  if (this.pingInterval) {
15261
15361
  CriticalTimers.clearInterval(this.pingInterval);
@@ -16020,7 +16120,10 @@ class PCTransport extends eventsExports.EventEmitter {
16020
16120
  }
16021
16121
  constructor(config) {
16022
16122
  let mediaConstraints = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
16123
+ let loggerOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
16124
+ var _a;
16023
16125
  super();
16126
+ this.log = livekitLogger;
16024
16127
  this.pendingCandidates = [];
16025
16128
  this.restartingIce = false;
16026
16129
  this.renegotiate = false;
@@ -16058,6 +16161,8 @@ class PCTransport extends eventsExports.EventEmitter {
16058
16161
  this._pc.oniceconnectionstatechange = null;
16059
16162
  this._pc = null;
16060
16163
  };
16164
+ this.log = getLogger((_a = loggerOptions.loggerName) !== null && _a !== void 0 ? _a : LoggerNames.PCTransport);
16165
+ this.loggerOptions = loggerOptions;
16061
16166
  this.config = config;
16062
16167
  this.mediaConstraints = mediaConstraints;
16063
16168
  this._pc = this.createPC();
@@ -16097,6 +16202,10 @@ class PCTransport extends eventsExports.EventEmitter {
16097
16202
  };
16098
16203
  return pc;
16099
16204
  }
16205
+ get logContext() {
16206
+ var _a, _b;
16207
+ return Object.assign({}, (_b = (_a = this.loggerOptions).loggerContextCb) === null || _b === void 0 ? void 0 : _b.call(_a));
16208
+ }
16100
16209
  get isICEConnected() {
16101
16210
  return this._pc !== null && (this.pc.iceConnectionState === 'connected' || this.pc.iceConnectionState === 'completed');
16102
16211
  }
@@ -16193,7 +16302,7 @@ class PCTransport extends eventsExports.EventEmitter {
16193
16302
  return;
16194
16303
  }
16195
16304
  if (options === null || options === void 0 ? void 0 : options.iceRestart) {
16196
- livekitLogger.debug('restarting ICE');
16305
+ this.log.debug('restarting ICE', this.logContext);
16197
16306
  this.restartingIce = true;
16198
16307
  }
16199
16308
  if (this._pc && this._pc.signalingState === 'have-local-offer') {
@@ -16209,11 +16318,11 @@ class PCTransport extends eventsExports.EventEmitter {
16209
16318
  return;
16210
16319
  }
16211
16320
  } else if (!this._pc || this._pc.signalingState === 'closed') {
16212
- livekitLogger.warn('could not createOffer with closed peer connection');
16321
+ this.log.warn('could not createOffer with closed peer connection', this.logContext);
16213
16322
  return;
16214
16323
  }
16215
16324
  // actually negotiate
16216
- livekitLogger.debug('starting to negotiate');
16325
+ this.log.debug('starting to negotiate', this.logContext);
16217
16326
  const offer = yield this.pc.createOffer(options);
16218
16327
  const sdpParsed = parse((_a = offer.sdp) !== null && _a !== void 0 ? _a : '');
16219
16328
  sdpParsed.media.forEach(media => {
@@ -16382,7 +16491,7 @@ class PCTransport extends eventsExports.EventEmitter {
16382
16491
  const originalSdp = sd.sdp;
16383
16492
  sd.sdp = munged;
16384
16493
  try {
16385
- livekitLogger.debug("setting munged ".concat(remote ? 'remote' : 'local', " description"));
16494
+ this.log.debug("setting munged ".concat(remote ? 'remote' : 'local', " description"), this.logContext);
16386
16495
  if (remote) {
16387
16496
  yield this.pc.setRemoteDescription(sd);
16388
16497
  } else {
@@ -16390,10 +16499,10 @@ class PCTransport extends eventsExports.EventEmitter {
16390
16499
  }
16391
16500
  return;
16392
16501
  } catch (e) {
16393
- livekitLogger.warn("not able to set ".concat(sd.type, ", falling back to unmodified sdp"), {
16502
+ this.log.warn("not able to set ".concat(sd.type, ", falling back to unmodified sdp"), Object.assign(Object.assign({}, this.logContext), {
16394
16503
  error: e,
16395
16504
  sdp: munged
16396
- });
16505
+ }));
16397
16506
  sd.sdp = originalSdp;
16398
16507
  }
16399
16508
  }
@@ -16419,7 +16528,9 @@ class PCTransport extends eventsExports.EventEmitter {
16419
16528
  if (!remote && this.pc.remoteDescription) {
16420
16529
  fields.remoteSdp = this.pc.remoteDescription;
16421
16530
  }
16422
- livekitLogger.error("unable to set ".concat(sd.type), fields);
16531
+ this.log.error("unable to set ".concat(sd.type), Object.assign(Object.assign({}, this.logContext), {
16532
+ fields
16533
+ }));
16423
16534
  throw new NegotiationError(msg);
16424
16535
  }
16425
16536
  });
@@ -16576,8 +16687,10 @@ class PCTransportManager {
16576
16687
  get currentState() {
16577
16688
  return this.state;
16578
16689
  }
16579
- constructor(rtcConfig, subscriberPrimary) {
16690
+ constructor(rtcConfig, subscriberPrimary, loggerOptions) {
16691
+ var _a;
16580
16692
  this.peerConnectionTimeout = roomConnectOptionDefaults.peerConnectionTimeout;
16693
+ this.log = livekitLogger;
16581
16694
  this.updateState = () => {
16582
16695
  var _a;
16583
16696
  const previousState = this.state;
@@ -16596,10 +16709,12 @@ class PCTransportManager {
16596
16709
  this.state = PCTransportState.NEW;
16597
16710
  }
16598
16711
  if (previousState !== this.state) {
16599
- livekitLogger.debug("pc state change: from ".concat(PCTransportState[previousState], " to ").concat(PCTransportState[this.state]));
16712
+ this.log.debug("pc state change: from ".concat(PCTransportState[previousState], " to ").concat(PCTransportState[this.state]), this.logContext);
16600
16713
  (_a = this.onStateChange) === null || _a === void 0 ? void 0 : _a.call(this, this.state, this.publisher.getConnectionState(), this.subscriber.getConnectionState());
16601
16714
  }
16602
16715
  };
16716
+ this.log = getLogger((_a = loggerOptions.loggerName) !== null && _a !== void 0 ? _a : LoggerNames.PCManager);
16717
+ this.loggerOptions = loggerOptions;
16603
16718
  this.isPublisherConnectionRequired = !subscriberPrimary;
16604
16719
  this.isSubscriberConnectionRequired = subscriberPrimary;
16605
16720
  const googConstraints = {
@@ -16607,8 +16722,8 @@ class PCTransportManager {
16607
16722
  googDscp: true
16608
16723
  }]
16609
16724
  };
16610
- this.publisher = new PCTransport(rtcConfig, googConstraints);
16611
- this.subscriber = new PCTransport(rtcConfig);
16725
+ this.publisher = new PCTransport(rtcConfig, googConstraints, loggerOptions);
16726
+ this.subscriber = new PCTransport(rtcConfig, loggerOptions);
16612
16727
  this.publisher.onConnectionStateChange = this.updateState;
16613
16728
  this.subscriber.onConnectionStateChange = this.updateState;
16614
16729
  this.publisher.onIceConnectionStateChange = this.updateState;
@@ -16639,6 +16754,10 @@ class PCTransportManager {
16639
16754
  this.state = PCTransportState.NEW;
16640
16755
  this.connectionLock = new Mutex();
16641
16756
  }
16757
+ get logContext() {
16758
+ var _a, _b;
16759
+ return Object.assign({}, (_b = (_a = this.loggerOptions).loggerContextCb) === null || _b === void 0 ? void 0 : _b.call(_a));
16760
+ }
16642
16761
  requirePublisher() {
16643
16762
  let require = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
16644
16763
  this.isPublisherConnectionRequired = require;
@@ -16669,9 +16788,9 @@ class PCTransportManager {
16669
16788
  publisher.removeTrack(sender);
16670
16789
  }
16671
16790
  } catch (e) {
16672
- livekitLogger.warn('could not removeTrack', {
16791
+ this.log.warn('could not removeTrack', Object.assign(Object.assign({}, this.logContext), {
16673
16792
  error: e
16674
- });
16793
+ }));
16675
16794
  }
16676
16795
  }
16677
16796
  }
@@ -16701,10 +16820,10 @@ class PCTransportManager {
16701
16820
  }
16702
16821
  createSubscriberAnswerFromOffer(sd) {
16703
16822
  return __awaiter(this, void 0, void 0, function* () {
16704
- livekitLogger.debug('received server offer', {
16823
+ this.log.debug('received server offer', Object.assign(Object.assign({}, this.logContext), {
16705
16824
  RTCSdpType: sd.type,
16706
16825
  signalingState: this.subscriber.getSignallingState().toString()
16707
- });
16826
+ }));
16708
16827
  yield this.subscriber.setRemoteDescription(sd);
16709
16828
  // answer the offer
16710
16829
  const answer = yield this.subscriber.createAndSetAnswer();
@@ -16724,7 +16843,7 @@ class PCTransportManager {
16724
16843
  const unlock = yield this.connectionLock.lock();
16725
16844
  try {
16726
16845
  if (this.isPublisherConnectionRequired && this.publisher.getConnectionState() !== 'connected' && this.publisher.getConnectionState() !== 'connecting') {
16727
- livekitLogger.debug('negotiation required, start negotiating');
16846
+ this.log.debug('negotiation required, start negotiating', this.logContext);
16728
16847
  this.publisher.negotiate();
16729
16848
  }
16730
16849
  yield Promise.all((_a = this.requiredTransports) === null || _a === void 0 ? void 0 : _a.map(transport => this.ensureTransportConnected(transport, abortController, timeout)));
@@ -16799,7 +16918,7 @@ class PCTransportManager {
16799
16918
  }
16800
16919
  return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
16801
16920
  const abortHandler = () => {
16802
- livekitLogger.warn('abort transport connection');
16921
+ this.log.warn('abort transport connection', this.logContext);
16803
16922
  CriticalTimers.clearTimeout(connectTimeout);
16804
16923
  reject(new ConnectionError('room connection has been cancelled', 3 /* ConnectionErrorReason.Cancelled */));
16805
16924
  };
@@ -16844,6 +16963,7 @@ class RTCEngine extends eventsExports.EventEmitter {
16844
16963
  return this._isClosed;
16845
16964
  }
16846
16965
  constructor(options) {
16966
+ var _a;
16847
16967
  super();
16848
16968
  this.options = options;
16849
16969
  this.rtcConfig = {};
@@ -16861,6 +16981,7 @@ class RTCEngine extends eventsExports.EventEmitter {
16861
16981
  /** specifies how often an initial join connection is allowed to retry */
16862
16982
  this.maxJoinAttempts = 1;
16863
16983
  this.shouldFailNext = false;
16984
+ this.log = livekitLogger;
16864
16985
  this.handleDataChannel = _ref => {
16865
16986
  let {
16866
16987
  channel
@@ -16876,12 +16997,12 @@ class RTCEngine extends eventsExports.EventEmitter {
16876
16997
  } else {
16877
16998
  return;
16878
16999
  }
16879
- livekitLogger.debug("on data channel ".concat(channel.id, ", ").concat(channel.label));
17000
+ this.log.debug("on data channel ".concat(channel.id, ", ").concat(channel.label), this.logContext);
16880
17001
  channel.onmessage = this.handleDataMessage;
16881
17002
  });
16882
17003
  };
16883
17004
  this.handleDataMessage = message => __awaiter(this, void 0, void 0, function* () {
16884
- var _a, _b;
17005
+ var _b, _c;
16885
17006
  // make sure to respect incoming data message order by processing message events one after the other
16886
17007
  const unlock = yield this.dataProcessLock.lock();
16887
17008
  try {
@@ -16892,14 +17013,16 @@ class RTCEngine extends eventsExports.EventEmitter {
16892
17013
  } else if (message.data instanceof Blob) {
16893
17014
  buffer = yield message.data.arrayBuffer();
16894
17015
  } else {
16895
- livekitLogger.error('unsupported data type', message.data);
17016
+ this.log.error('unsupported data type', Object.assign(Object.assign({}, this.logContext), {
17017
+ data: message.data
17018
+ }));
16896
17019
  return;
16897
17020
  }
16898
17021
  const dp = DataPacket.fromBinary(new Uint8Array(buffer));
16899
- if (((_a = dp.value) === null || _a === void 0 ? void 0 : _a.case) === 'speaker') {
17022
+ if (((_b = dp.value) === null || _b === void 0 ? void 0 : _b.case) === 'speaker') {
16900
17023
  // dispatch speaker updates
16901
17024
  this.emit(EngineEvent.ActiveSpeakersUpdate, dp.value.value.speakers);
16902
- } else if (((_b = dp.value) === null || _b === void 0 ? void 0 : _b.case) === 'user') {
17025
+ } else if (((_c = dp.value) === null || _c === void 0 ? void 0 : _c.case) === 'user') {
16903
17026
  this.emit(EngineEvent.DataPacketReceived, dp.value.value, dp.kind);
16904
17027
  }
16905
17028
  } finally {
@@ -16913,9 +17036,13 @@ class RTCEngine extends eventsExports.EventEmitter {
16913
17036
  const {
16914
17037
  error
16915
17038
  } = event.error;
16916
- livekitLogger.error("DataChannel error on ".concat(channelKind, ": ").concat(event.message), error);
17039
+ this.log.error("DataChannel error on ".concat(channelKind, ": ").concat(event.message), Object.assign(Object.assign({}, this.logContext), {
17040
+ error
17041
+ }));
16917
17042
  } else {
16918
- livekitLogger.error("Unknown DataChannel error on ".concat(channelKind), event);
17043
+ this.log.error("Unknown DataChannel error on ".concat(channelKind), Object.assign(Object.assign({}, this.logContext), {
17044
+ event
17045
+ }));
16919
17046
  }
16920
17047
  };
16921
17048
  this.handleBufferedAmountLow = event => {
@@ -16930,13 +17057,13 @@ class RTCEngine extends eventsExports.EventEmitter {
16930
17057
  if (this._isClosed) {
16931
17058
  return;
16932
17059
  }
16933
- livekitLogger.warn("".concat(connection, " disconnected"));
17060
+ this.log.warn("".concat(connection, " disconnected"), this.logContext);
16934
17061
  if (this.reconnectAttempts === 0) {
16935
17062
  // only reset start time on the first try
16936
17063
  this.reconnectStart = Date.now();
16937
17064
  }
16938
17065
  const disconnect = duration => {
16939
- livekitLogger.warn("could not recover connection after ".concat(this.reconnectAttempts, " attempts, ").concat(duration, "ms. giving up"));
17066
+ this.log.warn("could not recover connection after ".concat(this.reconnectAttempts, " attempts, ").concat(duration, "ms. giving up"), this.logContext);
16940
17067
  this.emit(EngineEvent.Disconnected);
16941
17068
  this.close();
16942
17069
  };
@@ -16952,7 +17079,7 @@ class RTCEngine extends eventsExports.EventEmitter {
16952
17079
  if (connection === leaveReconnect) {
16953
17080
  delay = 0;
16954
17081
  }
16955
- livekitLogger.debug("reconnecting in ".concat(delay, "ms"));
17082
+ this.log.debug("reconnecting in ".concat(delay, "ms"), this.logContext);
16956
17083
  this.clearReconnectTimeout();
16957
17084
  if (this.token && this.regionUrlProvider) {
16958
17085
  // token may have been refreshed, we do not want to recreate the regionUrlProvider
@@ -16998,7 +17125,12 @@ class RTCEngine extends eventsExports.EventEmitter {
16998
17125
  this.attemptReconnect(ReconnectReason.RR_SIGNAL_DISCONNECTED);
16999
17126
  }
17000
17127
  };
17001
- this.client = new SignalClient();
17128
+ this.log = getLogger((_a = options.loggerName) !== null && _a !== void 0 ? _a : LoggerNames.Engine);
17129
+ this.loggerOptions = {
17130
+ loggerName: options.loggerName,
17131
+ loggerContextCb: () => this.logContext
17132
+ };
17133
+ this.client = new SignalClient(undefined, this.loggerOptions);
17002
17134
  this.client.signalLatency = this.options.expSignalLatency;
17003
17135
  this.reconnectPolicy = this.options.reconnectPolicy;
17004
17136
  this.registerOnLineListener();
@@ -17013,6 +17145,15 @@ class RTCEngine extends eventsExports.EventEmitter {
17013
17145
  this.client.onSpeakersChanged = update => this.emit(EngineEvent.SpeakersChanged, update);
17014
17146
  this.client.onStreamStateUpdate = update => this.emit(EngineEvent.StreamStateChanged, update);
17015
17147
  }
17148
+ /** @internal */
17149
+ get logContext() {
17150
+ var _a, _b, _c, _d, _e, _f;
17151
+ return {
17152
+ room: (_b = (_a = this.latestJoinResponse) === null || _a === void 0 ? void 0 : _a.room) === null || _b === void 0 ? void 0 : _b.name,
17153
+ roomSid: (_d = (_c = this.latestJoinResponse) === null || _c === void 0 ? void 0 : _c.room) === null || _d === void 0 ? void 0 : _d.sid,
17154
+ identity: (_f = (_e = this.latestJoinResponse) === null || _e === void 0 ? void 0 : _e.participant) === null || _f === void 0 ? void 0 : _f.identity
17155
+ };
17156
+ }
17016
17157
  join(url, token, opts, abortSignal) {
17017
17158
  return __awaiter(this, void 0, void 0, function* () {
17018
17159
  this.url = url;
@@ -17038,7 +17179,7 @@ class RTCEngine extends eventsExports.EventEmitter {
17038
17179
  } catch (e) {
17039
17180
  if (e instanceof ConnectionError) {
17040
17181
  if (e.reason === 1 /* ConnectionErrorReason.ServerUnreachable */) {
17041
- livekitLogger.warn("Couldn't connect to server, attempt ".concat(this.joinAttempts, " of ").concat(this.maxJoinAttempts));
17182
+ this.log.warn("Couldn't connect to server, attempt ".concat(this.joinAttempts, " of ").concat(this.maxJoinAttempts), this.logContext);
17042
17183
  if (this.joinAttempts < this.maxJoinAttempts) {
17043
17184
  return this.join(url, token, opts, abortSignal);
17044
17185
  }
@@ -17141,10 +17282,9 @@ class RTCEngine extends eventsExports.EventEmitter {
17141
17282
  this.pcManager.removeTrack(sender);
17142
17283
  return true;
17143
17284
  } catch (e) {
17144
- livekitLogger.warn('failed to remove track', {
17145
- error: e,
17146
- method: 'removeTrack'
17147
- });
17285
+ this.log.warn('failed to remove track', Object.assign(Object.assign({}, this.logContext), {
17286
+ error: e
17287
+ }));
17148
17288
  }
17149
17289
  return false;
17150
17290
  }
@@ -17174,7 +17314,7 @@ class RTCEngine extends eventsExports.EventEmitter {
17174
17314
  }
17175
17315
  this.participantSid = (_a = joinResponse.participant) === null || _a === void 0 ? void 0 : _a.sid;
17176
17316
  const rtcConfig = this.makeRTCConfiguration(joinResponse);
17177
- this.pcManager = new PCTransportManager(rtcConfig, joinResponse.subscriberPrimary);
17317
+ this.pcManager = new PCTransportManager(rtcConfig, joinResponse.subscriberPrimary, this.loggerOptions);
17178
17318
  this.emit(EngineEvent.TransportsCreated, this.pcManager.publisher, this.pcManager.subscriber);
17179
17319
  this.pcManager.onIceCandidate = (candidate, target) => {
17180
17320
  this.client.sendIceCandidate(candidate, target);
@@ -17184,7 +17324,7 @@ class RTCEngine extends eventsExports.EventEmitter {
17184
17324
  };
17185
17325
  this.pcManager.onDataChannel = this.handleDataChannel;
17186
17326
  this.pcManager.onStateChange = (connectionState, publisherState, subscriberState) => __awaiter(this, void 0, void 0, function* () {
17187
- livekitLogger.debug("primary PC state changed ".concat(connectionState));
17327
+ this.log.debug("primary PC state changed ".concat(connectionState), this.logContext);
17188
17328
  if (connectionState === PCTransportState.CONNECTED) {
17189
17329
  const shouldEmit = this.pcState === PCState.New;
17190
17330
  this.pcState = PCState.Connected;
@@ -17211,9 +17351,9 @@ class RTCEngine extends eventsExports.EventEmitter {
17211
17351
  if (!this.pcManager) {
17212
17352
  return;
17213
17353
  }
17214
- livekitLogger.debug('received server answer', {
17354
+ this.log.debug('received server answer', Object.assign(Object.assign({}, this.logContext), {
17215
17355
  RTCSdpType: sd.type
17216
- });
17356
+ }));
17217
17357
  yield this.pcManager.setPublisherAnswer(sd);
17218
17358
  });
17219
17359
  // add candidate on trickle
@@ -17221,10 +17361,10 @@ class RTCEngine extends eventsExports.EventEmitter {
17221
17361
  if (!this.pcManager) {
17222
17362
  return;
17223
17363
  }
17224
- livekitLogger.trace('got ICE candidate from peer', {
17364
+ this.log.trace('got ICE candidate from peer', Object.assign(Object.assign({}, this.logContext), {
17225
17365
  candidate,
17226
17366
  target
17227
- });
17367
+ }));
17228
17368
  this.pcManager.addIceCandidate(candidate, target);
17229
17369
  };
17230
17370
  // when server creates an offer for the client
@@ -17236,9 +17376,15 @@ class RTCEngine extends eventsExports.EventEmitter {
17236
17376
  this.client.sendAnswer(answer);
17237
17377
  });
17238
17378
  this.client.onLocalTrackPublished = res => {
17239
- livekitLogger.debug('received trackPublishedResponse', res);
17379
+ var _a;
17380
+ this.log.debug('received trackPublishedResponse', Object.assign(Object.assign({}, this.logContext), {
17381
+ cid: res.cid,
17382
+ track: (_a = res.track) === null || _a === void 0 ? void 0 : _a.sid
17383
+ }));
17240
17384
  if (!this.pendingTrackResolvers[res.cid]) {
17241
- livekitLogger.error("missing track resolver for ".concat(res.cid));
17385
+ this.log.error("missing track resolver for ".concat(res.cid), Object.assign(Object.assign({}, this.logContext), {
17386
+ cid: res.cid
17387
+ }));
17242
17388
  return;
17243
17389
  }
17244
17390
  const {
@@ -17268,16 +17414,16 @@ class RTCEngine extends eventsExports.EventEmitter {
17268
17414
  this.emit(EngineEvent.Disconnected, leave === null || leave === void 0 ? void 0 : leave.reason);
17269
17415
  this.close();
17270
17416
  }
17271
- livekitLogger.trace('leave request', {
17272
- leave
17273
- });
17417
+ this.log.debug('client leave request', Object.assign(Object.assign({}, this.logContext), {
17418
+ reason: leave === null || leave === void 0 ? void 0 : leave.reason
17419
+ }));
17274
17420
  };
17275
17421
  }
17276
17422
  makeRTCConfiguration(serverResponse) {
17277
17423
  var _a;
17278
17424
  const rtcConfig = Object.assign({}, this.rtcConfig);
17279
17425
  if ((_a = this.signalOpts) === null || _a === void 0 ? void 0 : _a.e2eeEnabled) {
17280
- livekitLogger.debug('E2EE - setting up transports with insertable streams');
17426
+ this.log.debug('E2EE - setting up transports with insertable streams', this.logContext);
17281
17427
  // this makes sure that no data is sent before the transforms are ready
17282
17428
  // @ts-ignore
17283
17429
  rtcConfig.encodedInsertableStreams = true;
@@ -17347,7 +17493,9 @@ class RTCEngine extends eventsExports.EventEmitter {
17347
17493
  }
17348
17494
  const cap = RTCRtpSender.getCapabilities(kind);
17349
17495
  if (!cap) return;
17350
- livekitLogger.debug('get capabilities', cap);
17496
+ this.log.debug('get sender capabilities', Object.assign(Object.assign({}, this.logContext), {
17497
+ cap
17498
+ }));
17351
17499
  const matched = [];
17352
17500
  const partialMatched = [];
17353
17501
  const unmatched = [];
@@ -17385,7 +17533,7 @@ class RTCEngine extends eventsExports.EventEmitter {
17385
17533
  return sender;
17386
17534
  }
17387
17535
  if (supportsAddTrack()) {
17388
- livekitLogger.warn('using add-track fallback');
17536
+ this.log.warn('using add-track fallback', this.logContext);
17389
17537
  const sender = yield this.createRTCRtpSender(track.mediaStreamTrack);
17390
17538
  return sender;
17391
17539
  }
@@ -17399,7 +17547,7 @@ class RTCEngine extends eventsExports.EventEmitter {
17399
17547
  return this.createSimulcastTransceiverSender(track, simulcastTrack, opts, encodings);
17400
17548
  }
17401
17549
  if (supportsAddTrack()) {
17402
- livekitLogger.debug('using add-track fallback');
17550
+ this.log.debug('using add-track fallback', this.logContext);
17403
17551
  return this.createRTCRtpSender(track.mediaStreamTrack);
17404
17552
  }
17405
17553
  throw new UnexpectedConnectionState('Cannot stream on this device');
@@ -17488,9 +17636,9 @@ class RTCEngine extends eventsExports.EventEmitter {
17488
17636
  this.reconnectAttempts += 1;
17489
17637
  let recoverable = true;
17490
17638
  if (e instanceof UnexpectedConnectionState) {
17491
- livekitLogger.debug('received unrecoverable error', {
17639
+ this.log.debug('received unrecoverable error', Object.assign(Object.assign({}, this.logContext), {
17492
17640
  error: e
17493
- });
17641
+ }));
17494
17642
  // unrecoverable
17495
17643
  recoverable = false;
17496
17644
  } else if (!(e instanceof SignalReconnectError)) {
@@ -17500,7 +17648,7 @@ class RTCEngine extends eventsExports.EventEmitter {
17500
17648
  if (recoverable) {
17501
17649
  this.handleDisconnect('reconnect', ReconnectReason.RR_UNKNOWN);
17502
17650
  } else {
17503
- livekitLogger.info("could not recover connection after ".concat(this.reconnectAttempts, " attempts, ").concat(Date.now() - this.reconnectStart, "ms. giving up"));
17651
+ this.log.info("could not recover connection after ".concat(this.reconnectAttempts, " attempts, ").concat(Date.now() - this.reconnectStart, "ms. giving up"), this.logContext);
17504
17652
  this.emit(EngineEvent.Disconnected);
17505
17653
  yield this.close();
17506
17654
  }
@@ -17513,9 +17661,9 @@ class RTCEngine extends eventsExports.EventEmitter {
17513
17661
  try {
17514
17662
  return this.reconnectPolicy.nextRetryDelayInMs(context);
17515
17663
  } catch (e) {
17516
- livekitLogger.warn('encountered error in reconnect policy', {
17664
+ this.log.warn('encountered error in reconnect policy', Object.assign(Object.assign({}, this.logContext), {
17517
17665
  error: e
17518
- });
17666
+ }));
17519
17667
  }
17520
17668
  // error in user code with provided reconnect policy, stop reconnecting
17521
17669
  return null;
@@ -17528,7 +17676,7 @@ class RTCEngine extends eventsExports.EventEmitter {
17528
17676
  // permanent failure, don't attempt reconnection
17529
17677
  throw new UnexpectedConnectionState('could not reconnect, url or token not saved');
17530
17678
  }
17531
- livekitLogger.info("reconnecting, attempt: ".concat(this.reconnectAttempts));
17679
+ this.log.info("reconnecting, attempt: ".concat(this.reconnectAttempts), this.logContext);
17532
17680
  this.emit(EngineEvent.Restarting);
17533
17681
  if (!this.client.isDisconnected) {
17534
17682
  yield this.client.sendLeave();
@@ -17538,7 +17686,7 @@ class RTCEngine extends eventsExports.EventEmitter {
17538
17686
  let joinResponse;
17539
17687
  try {
17540
17688
  if (!this.signalOpts) {
17541
- livekitLogger.warn('attempted connection restart, without signal options present');
17689
+ this.log.warn('attempted connection restart, without signal options present', this.logContext);
17542
17690
  throw new SignalReconnectError();
17543
17691
  }
17544
17692
  // in case a regionUrl is passed, the region URL takes precedence
@@ -17583,7 +17731,7 @@ class RTCEngine extends eventsExports.EventEmitter {
17583
17731
  if (!this.pcManager) {
17584
17732
  throw new UnexpectedConnectionState('publisher and subscriber connections unset');
17585
17733
  }
17586
- livekitLogger.info("resuming signal connection, attempt ".concat(this.reconnectAttempts));
17734
+ this.log.info("resuming signal connection, attempt ".concat(this.reconnectAttempts), this.logContext);
17587
17735
  this.emit(EngineEvent.Resuming);
17588
17736
  try {
17589
17737
  this.setupSignalClientCallbacks();
@@ -17596,7 +17744,7 @@ class RTCEngine extends eventsExports.EventEmitter {
17596
17744
  let message = '';
17597
17745
  if (e instanceof Error) {
17598
17746
  message = e.message;
17599
- livekitLogger.error(e.message);
17747
+ this.log.error(e.message, this.logContext);
17600
17748
  }
17601
17749
  if (e instanceof ConnectionError && e.reason === 0 /* ConnectionErrorReason.NotAllowed */) {
17602
17750
  throw new UnexpectedConnectionState('could not reconnect, token might be expired');
@@ -17631,7 +17779,7 @@ class RTCEngine extends eventsExports.EventEmitter {
17631
17779
  waitForPCReconnected() {
17632
17780
  return __awaiter(this, void 0, void 0, function* () {
17633
17781
  this.pcState = PCState.Reconnecting;
17634
- livekitLogger.debug('waiting for peer connection to reconnect');
17782
+ this.log.debug('waiting for peer connection to reconnect', this.logContext);
17635
17783
  try {
17636
17784
  yield sleep(minReconnectWait); // FIXME setTimeout again not ideal for a connection critical path
17637
17785
  if (!this.pcManager) {
@@ -17726,7 +17874,7 @@ class RTCEngine extends eventsExports.EventEmitter {
17726
17874
  const abortController = new AbortController();
17727
17875
  const handleClosed = () => {
17728
17876
  abortController.abort();
17729
- livekitLogger.debug('engine disconnected while negotiation was ongoing');
17877
+ this.log.debug('engine disconnected while negotiation was ongoing', this.logContext);
17730
17878
  resolve();
17731
17879
  return;
17732
17880
  };
@@ -17780,7 +17928,7 @@ class RTCEngine extends eventsExports.EventEmitter {
17780
17928
  sendSyncState(remoteTracks, localTracks) {
17781
17929
  var _a, _b;
17782
17930
  if (!this.pcManager) {
17783
- livekitLogger.warn('sync state cannot be sent without peer connection setup');
17931
+ this.log.warn('sync state cannot be sent without peer connection setup', this.logContext);
17784
17932
  return;
17785
17933
  }
17786
17934
  const previousAnswer = this.pcManager.subscriber.getLocalDescription();
@@ -17951,7 +18099,8 @@ class LocalAudioTrack extends LocalTrack {
17951
18099
  constructor(mediaTrack, constraints) {
17952
18100
  let userProvidedTrack = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
17953
18101
  let audioContext = arguments.length > 3 ? arguments[3] : undefined;
17954
- super(mediaTrack, Track.Kind.Audio, constraints, userProvidedTrack);
18102
+ let loggerOptions = arguments.length > 4 ? arguments[4] : undefined;
18103
+ super(mediaTrack, Track.Kind.Audio, constraints, userProvidedTrack, loggerOptions);
17955
18104
  /** @internal */
17956
18105
  this.stopOnMute = false;
17957
18106
  this.monitorSender = () => __awaiter(this, void 0, void 0, function* () {
@@ -17963,9 +18112,9 @@ class LocalAudioTrack extends LocalTrack {
17963
18112
  try {
17964
18113
  stats = yield this.getSenderStats();
17965
18114
  } catch (e) {
17966
- livekitLogger.error('could not get audio sender stats', {
18115
+ this.log.error('could not get audio sender stats', Object.assign(Object.assign({}, this.logContext), {
17967
18116
  error: e
17968
- });
18117
+ }));
17969
18118
  return;
17970
18119
  }
17971
18120
  if (stats && this.prevStats) {
@@ -17999,7 +18148,7 @@ class LocalAudioTrack extends LocalTrack {
17999
18148
  try {
18000
18149
  // disabled special handling as it will cause BT headsets to switch communication modes
18001
18150
  if (this.source === Track.Source.Microphone && this.stopOnMute && !this.isUserProvided) {
18002
- livekitLogger.debug('stopping mic track');
18151
+ this.log.debug('stopping mic track', this.logContext);
18003
18152
  // also stop the track, so that microphone indicator is turned off
18004
18153
  this._mediaStreamTrack.stop();
18005
18154
  }
@@ -18021,7 +18170,7 @@ class LocalAudioTrack extends LocalTrack {
18021
18170
  try {
18022
18171
  const deviceHasChanged = this._constraints.deviceId && this._mediaStreamTrack.getSettings().deviceId !== unwrapConstraint(this._constraints.deviceId);
18023
18172
  if (this.source === Track.Source.Microphone && (this.stopOnMute || this._mediaStreamTrack.readyState === 'ended' || deviceHasChanged) && !this.isUserProvided) {
18024
- livekitLogger.debug('reacquiring mic track');
18173
+ this.log.debug('reacquiring mic track', this.logContext);
18025
18174
  yield this.restartTrack();
18026
18175
  }
18027
18176
  yield _super.unmute.call(this);
@@ -18088,7 +18237,7 @@ class LocalAudioTrack extends LocalTrack {
18088
18237
  track: this._mediaStreamTrack,
18089
18238
  audioContext: this.audioContext
18090
18239
  };
18091
- livekitLogger.debug("setting up audio processor ".concat(processor.name));
18240
+ this.log.debug("setting up audio processor ".concat(processor.name), this.logContext);
18092
18241
  yield processor.init(processorOptions);
18093
18242
  this.processor = processor;
18094
18243
  if (this.processor.processedTrack) {
@@ -18136,7 +18285,7 @@ class LocalAudioTrack extends LocalTrack {
18136
18285
  const trackIsSilent = yield detectSilence(this);
18137
18286
  if (trackIsSilent) {
18138
18287
  if (!this.isMuted) {
18139
- livekitLogger.warn('silence detected on local audio track');
18288
+ this.log.warn('silence detected on local audio track', this.logContext);
18140
18289
  }
18141
18290
  this.emit(TrackEvent.AudioSilenceDetected);
18142
18291
  }
@@ -18146,12 +18295,12 @@ class LocalAudioTrack extends LocalTrack {
18146
18295
  }
18147
18296
 
18148
18297
  /** @internal */
18149
- function mediaTrackToLocalTrack(mediaStreamTrack, constraints) {
18298
+ function mediaTrackToLocalTrack(mediaStreamTrack, constraints, loggerOptions) {
18150
18299
  switch (mediaStreamTrack.kind) {
18151
18300
  case 'audio':
18152
- return new LocalAudioTrack(mediaStreamTrack, constraints, false);
18301
+ return new LocalAudioTrack(mediaStreamTrack, constraints, false, undefined, loggerOptions);
18153
18302
  case 'video':
18154
- return new LocalVideoTrack(mediaStreamTrack, constraints, false);
18303
+ return new LocalVideoTrack(mediaStreamTrack, constraints, false, loggerOptions);
18155
18304
  default:
18156
18305
  throw new TrackInvalidError("unsupported track type: ".concat(mediaStreamTrack.kind));
18157
18306
  }
@@ -18170,11 +18319,11 @@ const defaultSimulcastPresets43 = [VideoPresets43.h180, VideoPresets43.h360];
18170
18319
  const computeDefaultScreenShareSimulcastPresets = fromPreset => {
18171
18320
  const layers = [{
18172
18321
  scaleResolutionDownBy: 2,
18173
- fps: 3
18322
+ fps: fromPreset.encoding.maxFramerate
18174
18323
  }];
18175
18324
  return layers.map(t => {
18176
- var _a;
18177
- return new VideoPreset(Math.floor(fromPreset.width / t.scaleResolutionDownBy), Math.floor(fromPreset.height / t.scaleResolutionDownBy), Math.max(150000, Math.floor(fromPreset.encoding.maxBitrate / (Math.pow(t.scaleResolutionDownBy, 2) * (((_a = fromPreset.encoding.maxFramerate) !== null && _a !== void 0 ? _a : 30) / t.fps)))), t.fps, fromPreset.encoding.priority);
18325
+ var _a, _b;
18326
+ return new VideoPreset(Math.floor(fromPreset.width / t.scaleResolutionDownBy), Math.floor(fromPreset.height / t.scaleResolutionDownBy), Math.max(150000, Math.floor(fromPreset.encoding.maxBitrate / (Math.pow(t.scaleResolutionDownBy, 2) * (((_a = fromPreset.encoding.maxFramerate) !== null && _a !== void 0 ? _a : 30) / ((_b = t.fps) !== null && _b !== void 0 ? _b : 30))))), t.fps, fromPreset.encoding.priority);
18178
18327
  });
18179
18328
  };
18180
18329
  // /**
@@ -18456,7 +18605,8 @@ class LocalVideoTrack extends LocalTrack {
18456
18605
  */
18457
18606
  constructor(mediaTrack, constraints) {
18458
18607
  let userProvidedTrack = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
18459
- super(mediaTrack, Track.Kind.Video, constraints, userProvidedTrack);
18608
+ let loggerOptions = arguments.length > 3 ? arguments[3] : undefined;
18609
+ super(mediaTrack, Track.Kind.Video, constraints, userProvidedTrack, loggerOptions);
18460
18610
  /* @internal */
18461
18611
  this.simulcastCodecs = new Map();
18462
18612
  this.monitorSender = () => __awaiter(this, void 0, void 0, function* () {
@@ -18468,9 +18618,9 @@ class LocalVideoTrack extends LocalTrack {
18468
18618
  try {
18469
18619
  stats = yield this.getSenderStats();
18470
18620
  } catch (e) {
18471
- livekitLogger.error('could not get audio sender stats', {
18621
+ this.log.error('could not get audio sender stats', Object.assign(Object.assign({}, this.logContext), {
18472
18622
  error: e
18473
- });
18623
+ }));
18474
18624
  return;
18475
18625
  }
18476
18626
  const statsMap = new Map(stats.map(s => [s.rid, s]));
@@ -18590,7 +18740,7 @@ class LocalVideoTrack extends LocalTrack {
18590
18740
  const unlock = yield this.muteLock.lock();
18591
18741
  try {
18592
18742
  if (this.source === Track.Source.Camera && !this.isUserProvided) {
18593
- livekitLogger.debug('stopping camera track');
18743
+ this.log.debug('stopping camera track', this.logContext);
18594
18744
  // also stop the track, so that camera indicator is turned off
18595
18745
  this._mediaStreamTrack.stop();
18596
18746
  }
@@ -18611,7 +18761,7 @@ class LocalVideoTrack extends LocalTrack {
18611
18761
  const unlock = yield this.muteLock.lock();
18612
18762
  try {
18613
18763
  if (this.source === Track.Source.Camera && !this.isUserProvided) {
18614
- livekitLogger.debug('reacquiring camera track');
18764
+ this.log.debug('reacquiring camera track', this.logContext);
18615
18765
  yield this.restartTrack();
18616
18766
  }
18617
18767
  yield _super.unmute.call(this);
@@ -18676,7 +18826,7 @@ class LocalVideoTrack extends LocalTrack {
18676
18826
  enabled: q <= maxQuality
18677
18827
  }));
18678
18828
  }
18679
- livekitLogger.debug("setting publishing quality. max quality ".concat(maxQuality));
18829
+ this.log.debug("setting publishing quality. max quality ".concat(maxQuality), this.logContext);
18680
18830
  this.setPublishingLayers(qualities);
18681
18831
  }
18682
18832
  setDeviceId(deviceId) {
@@ -18798,10 +18948,10 @@ class LocalVideoTrack extends LocalTrack {
18798
18948
  var _a, codecs_1, codecs_1_1;
18799
18949
  var _b, e_5, _c, _d;
18800
18950
  return __awaiter(this, void 0, void 0, function* () {
18801
- livekitLogger.debug('setting publishing codecs', {
18951
+ this.log.debug('setting publishing codecs', Object.assign(Object.assign({}, this.logContext), {
18802
18952
  codecs,
18803
18953
  currentCodec: this.codec
18804
- });
18954
+ }));
18805
18955
  // only enable simulcast codec for preference codec setted
18806
18956
  if (!this.codec && codecs.length > 0) {
18807
18957
  yield this.setPublishingLayers(codecs[0].qualities);
@@ -18818,7 +18968,9 @@ class LocalVideoTrack extends LocalTrack {
18818
18968
  yield this.setPublishingLayers(codec.qualities);
18819
18969
  } else {
18820
18970
  const simulcastCodecInfo = this.simulcastCodecs.get(codec.codec);
18821
- livekitLogger.debug("try setPublishingCodec for ".concat(codec.codec), simulcastCodecInfo);
18971
+ this.log.debug("try setPublishingCodec for ".concat(codec.codec), Object.assign(Object.assign({}, this.logContext), {
18972
+ simulcastCodecInfo
18973
+ }));
18822
18974
  if (!simulcastCodecInfo || !simulcastCodecInfo.sender) {
18823
18975
  for (const q of codec.qualities) {
18824
18976
  if (q.enabled) {
@@ -18827,8 +18979,8 @@ class LocalVideoTrack extends LocalTrack {
18827
18979
  }
18828
18980
  }
18829
18981
  } else if (simulcastCodecInfo.encodings) {
18830
- livekitLogger.debug("try setPublishingLayersForSender ".concat(codec.codec));
18831
- yield setPublishingLayersForSender(simulcastCodecInfo.sender, simulcastCodecInfo.encodings, codec.qualities, this.senderLock);
18982
+ this.log.debug("try setPublishingLayersForSender ".concat(codec.codec), this.logContext);
18983
+ yield setPublishingLayersForSender(simulcastCodecInfo.sender, simulcastCodecInfo.encodings, codec.qualities, this.senderLock, this.log, this.logContext);
18832
18984
  }
18833
18985
  }
18834
18986
  }
@@ -18852,11 +19004,13 @@ class LocalVideoTrack extends LocalTrack {
18852
19004
  */
18853
19005
  setPublishingLayers(qualities) {
18854
19006
  return __awaiter(this, void 0, void 0, function* () {
18855
- livekitLogger.debug('setting publishing layers', qualities);
19007
+ this.log.debug('setting publishing layers', Object.assign(Object.assign({}, this.logContext), {
19008
+ qualities
19009
+ }));
18856
19010
  if (!this.sender || !this.encodings) {
18857
19011
  return;
18858
19012
  }
18859
- yield setPublishingLayersForSender(this.sender, this.encodings, qualities, this.senderLock);
19013
+ yield setPublishingLayersForSender(this.sender, this.encodings, qualities, this.senderLock, this.log, this.logContext);
18860
19014
  });
18861
19015
  }
18862
19016
  handleAppVisibilityChanged() {
@@ -18874,14 +19028,14 @@ class LocalVideoTrack extends LocalTrack {
18874
19028
  });
18875
19029
  }
18876
19030
  }
18877
- function setPublishingLayersForSender(sender, senderEncodings, qualities, senderLock) {
19031
+ function setPublishingLayersForSender(sender, senderEncodings, qualities, senderLock, log, logContext) {
18878
19032
  return __awaiter(this, void 0, void 0, function* () {
18879
19033
  const unlock = yield senderLock.lock();
18880
- livekitLogger.debug('setPublishingLayersForSender', {
19034
+ log.debug('setPublishingLayersForSender', Object.assign(Object.assign({}, logContext), {
18881
19035
  sender,
18882
19036
  qualities,
18883
19037
  senderEncodings
18884
- });
19038
+ }));
18885
19039
  try {
18886
19040
  const params = sender.getParameters();
18887
19041
  const {
@@ -18891,7 +19045,7 @@ function setPublishingLayersForSender(sender, senderEncodings, qualities, sender
18891
19045
  return;
18892
19046
  }
18893
19047
  if (encodings.length !== senderEncodings.length) {
18894
- livekitLogger.warn('cannot set publishing layers, encodings mismatch');
19048
+ log.warn('cannot set publishing layers, encodings mismatch');
18895
19049
  return;
18896
19050
  }
18897
19051
  let hasChanged = false;
@@ -18917,7 +19071,7 @@ function setPublishingLayersForSender(sender, senderEncodings, qualities, sender
18917
19071
  if (encoding.active !== subscribedQuality.enabled) {
18918
19072
  hasChanged = true;
18919
19073
  encoding.active = subscribedQuality.enabled;
18920
- livekitLogger.debug("setting layer ".concat(subscribedQuality.quality, " to ").concat(encoding.active ? 'enabled' : 'disabled'));
19074
+ log.debug("setting layer ".concat(subscribedQuality.quality, " to ").concat(encoding.active ? 'enabled' : 'disabled'), logContext);
18921
19075
  // FireFox does not support setting encoding.active to false, so we
18922
19076
  // have a workaround of lowering its bitrate and resolution to the min.
18923
19077
  if (isFireFox()) {
@@ -18938,7 +19092,9 @@ function setPublishingLayersForSender(sender, senderEncodings, qualities, sender
18938
19092
  }
18939
19093
  if (hasChanged) {
18940
19094
  params.encodings = encodings;
18941
- livekitLogger.debug("setting encodings", params.encodings);
19095
+ log.debug("setting encodings", Object.assign(Object.assign({}, logContext), {
19096
+ encodings: params.encodings
19097
+ }));
18942
19098
  yield sender.setParameters(params);
18943
19099
  }
18944
19100
  } finally {
@@ -19001,8 +19157,8 @@ function videoLayersFromEncodings(width, height, encodings, svc) {
19001
19157
  }
19002
19158
 
19003
19159
  class RemoteTrack extends Track {
19004
- constructor(mediaTrack, sid, kind, receiver) {
19005
- super(mediaTrack, kind);
19160
+ constructor(mediaTrack, sid, kind, receiver, loggerOptions) {
19161
+ super(mediaTrack, kind, loggerOptions);
19006
19162
  this.sid = sid;
19007
19163
  this.receiver = receiver;
19008
19164
  }
@@ -19063,8 +19219,8 @@ class RemoteTrack extends Track {
19063
19219
  }
19064
19220
 
19065
19221
  class RemoteAudioTrack extends RemoteTrack {
19066
- constructor(mediaTrack, sid, receiver, audioContext, audioOutput) {
19067
- super(mediaTrack, sid, Track.Kind.Audio, receiver);
19222
+ constructor(mediaTrack, sid, receiver, audioContext, audioOutput, loggerOptions) {
19223
+ super(mediaTrack, sid, Track.Kind.Audio, receiver, loggerOptions);
19068
19224
  this.monitorReceiver = () => __awaiter(this, void 0, void 0, function* () {
19069
19225
  if (!this.receiver) {
19070
19226
  this._currentBitrate = 0;
@@ -19147,7 +19303,7 @@ class RemoteAudioTrack extends RemoteTrack {
19147
19303
  element.setSinkId(this.sinkId);
19148
19304
  }
19149
19305
  if (this.audioContext && needsNewWebAudioConnection) {
19150
- livekitLogger.debug('using audio context mapping');
19306
+ this.log.debug('using audio context mapping', this.logContext);
19151
19307
  this.connectWebAudio(this.audioContext, element);
19152
19308
  element.volume = 0;
19153
19309
  element.muted = true;
@@ -19263,8 +19419,8 @@ class RemoteAudioTrack extends RemoteTrack {
19263
19419
 
19264
19420
  const REACTION_DELAY = 100;
19265
19421
  class RemoteVideoTrack extends RemoteTrack {
19266
- constructor(mediaTrack, sid, receiver, adaptiveStreamSettings) {
19267
- super(mediaTrack, sid, Track.Kind.Video, receiver);
19422
+ constructor(mediaTrack, sid, receiver, adaptiveStreamSettings, loggerOptions) {
19423
+ super(mediaTrack, sid, Track.Kind.Video, receiver, loggerOptions);
19268
19424
  this.elementInfos = [];
19269
19425
  this.monitorReceiver = () => __awaiter(this, void 0, void 0, function* () {
19270
19426
  if (!this.receiver) {
@@ -19338,7 +19494,7 @@ class RemoteVideoTrack extends RemoteTrack {
19338
19494
  this.debouncedHandleResize();
19339
19495
  this.updateVisibility();
19340
19496
  } else {
19341
- livekitLogger.warn('visibility resize observer not triggered');
19497
+ this.log.warn('visibility resize observer not triggered', this.logContext);
19342
19498
  }
19343
19499
  }
19344
19500
  /**
@@ -19348,7 +19504,7 @@ class RemoteVideoTrack extends RemoteTrack {
19348
19504
  */
19349
19505
  stopObservingElementInfo(elementInfo) {
19350
19506
  if (!this.isAdaptiveStream) {
19351
- livekitLogger.warn('stopObservingElementInfo ignored');
19507
+ this.log.warn('stopObservingElementInfo ignored', this.logContext);
19352
19508
  return;
19353
19509
  }
19354
19510
  const stopElementInfos = this.elementInfos.filter(info => info === elementInfo);
@@ -19579,16 +19735,20 @@ function isElementInViewport(el) {
19579
19735
  }
19580
19736
 
19581
19737
  class TrackPublication extends eventsExports.EventEmitter {
19582
- constructor(kind, id, name) {
19738
+ constructor(kind, id, name, loggerOptions) {
19739
+ var _a;
19583
19740
  super();
19584
19741
  this.metadataMuted = false;
19585
19742
  this.encryption = Encryption_Type.NONE;
19743
+ this.log = livekitLogger;
19586
19744
  this.handleMuted = () => {
19587
19745
  this.emit(TrackEvent.Muted);
19588
19746
  };
19589
19747
  this.handleUnmuted = () => {
19590
19748
  this.emit(TrackEvent.Unmuted);
19591
19749
  };
19750
+ this.log = getLogger((_a = loggerOptions === null || loggerOptions === void 0 ? void 0 : loggerOptions.loggerName) !== null && _a !== void 0 ? _a : LoggerNames.Publication);
19751
+ this.loggerContextCb = this.loggerContextCb;
19592
19752
  this.setMaxListeners(100);
19593
19753
  this.kind = kind;
19594
19754
  this.trackSid = id;
@@ -19608,6 +19768,10 @@ class TrackPublication extends eventsExports.EventEmitter {
19608
19768
  track.on(TrackEvent.Unmuted, this.handleUnmuted);
19609
19769
  }
19610
19770
  }
19771
+ get logContext() {
19772
+ var _a;
19773
+ return Object.assign(Object.assign({}, (_a = this.loggerContextCb) === null || _a === void 0 ? void 0 : _a.call(this)), getLogContextFromTrack(this));
19774
+ }
19611
19775
  get isMuted() {
19612
19776
  return this.metadataMuted;
19613
19777
  }
@@ -19651,9 +19815,9 @@ class TrackPublication extends eventsExports.EventEmitter {
19651
19815
  }
19652
19816
  this.encryption = info.encryption;
19653
19817
  this.trackInfo = info;
19654
- livekitLogger.debug('update publication info', {
19818
+ this.log.debug('update publication info', Object.assign(Object.assign({}, this.logContext), {
19655
19819
  info
19656
- });
19820
+ }));
19657
19821
  }
19658
19822
  }
19659
19823
  (function (TrackPublication) {
@@ -19673,8 +19837,8 @@ class LocalTrackPublication extends TrackPublication {
19673
19837
  var _a;
19674
19838
  return (_a = this.track) === null || _a === void 0 ? void 0 : _a.isUpstreamPaused;
19675
19839
  }
19676
- constructor(kind, ti, track) {
19677
- super(kind, ti.sid, ti.name);
19840
+ constructor(kind, ti, track, loggerOptions) {
19841
+ super(kind, ti.sid, ti.name, loggerOptions);
19678
19842
  this.track = undefined;
19679
19843
  this.handleTrackEnded = () => {
19680
19844
  this.emit(TrackEvent.Ended);
@@ -19771,6 +19935,13 @@ function qualityFromProto(q) {
19771
19935
  }
19772
19936
  }
19773
19937
  class Participant extends eventsExports.EventEmitter {
19938
+ get logContext() {
19939
+ var _a, _b;
19940
+ return Object.assign(Object.assign({}, (_b = (_a = this.loggerOptions) === null || _a === void 0 ? void 0 : _a.loggerContextCb) === null || _b === void 0 ? void 0 : _b.call(_a)), {
19941
+ participantSid: this.sid,
19942
+ participantId: this.identity
19943
+ });
19944
+ }
19774
19945
  get isEncrypted() {
19775
19946
  return this.tracks.size > 0 && Array.from(this.tracks.values()).every(tr => tr.isEncrypted);
19776
19947
  }
@@ -19779,13 +19950,17 @@ class Participant extends eventsExports.EventEmitter {
19779
19950
  return (_b = (_a = this.permissions) === null || _a === void 0 ? void 0 : _a.agent) !== null && _b !== void 0 ? _b : false;
19780
19951
  }
19781
19952
  /** @internal */
19782
- constructor(sid, identity, name, metadata) {
19953
+ constructor(sid, identity, name, metadata, loggerOptions) {
19954
+ var _a;
19783
19955
  super();
19784
19956
  /** audio level between 0-1.0, 1 being loudest, 0 being softest */
19785
19957
  this.audioLevel = 0;
19786
19958
  /** if participant is currently speaking */
19787
19959
  this.isSpeaking = false;
19788
19960
  this._connectionQuality = ConnectionQuality.Unknown;
19961
+ this.log = livekitLogger;
19962
+ this.log = getLogger((_a = loggerOptions === null || loggerOptions === void 0 ? void 0 : loggerOptions.loggerName) !== null && _a !== void 0 ? _a : LoggerNames.Participant);
19963
+ this.loggerOptions = loggerOptions;
19789
19964
  this.setMaxListeners(100);
19790
19965
  this.sid = sid;
19791
19966
  this.identity = identity;
@@ -19870,9 +20045,9 @@ class Participant extends eventsExports.EventEmitter {
19870
20045
  }
19871
20046
  // set this last so setMetadata can detect changes
19872
20047
  this.participantInfo = info;
19873
- livekitLogger.trace('update participant info', {
20048
+ this.log.trace('update participant info', Object.assign(Object.assign({}, this.logContext), {
19874
20049
  info
19875
- });
20050
+ }));
19876
20051
  return true;
19877
20052
  }
19878
20053
  /**
@@ -19971,8 +20146,8 @@ function trackPermissionToProto(perms) {
19971
20146
  }
19972
20147
 
19973
20148
  class RemoteTrackPublication extends TrackPublication {
19974
- constructor(kind, ti, autoSubscribe) {
19975
- super(kind, ti.sid, ti.name);
20149
+ constructor(kind, ti, autoSubscribe, loggerOptions) {
20150
+ super(kind, ti.sid, ti.name, loggerOptions);
19976
20151
  this.track = undefined;
19977
20152
  /** @internal */
19978
20153
  this.allowed = true;
@@ -19983,16 +20158,12 @@ class RemoteTrackPublication extends TrackPublication {
19983
20158
  this.emit(TrackEvent.Ended, track);
19984
20159
  };
19985
20160
  this.handleVisibilityChange = visible => {
19986
- livekitLogger.debug("adaptivestream video visibility ".concat(this.trackSid, ", visible=").concat(visible), {
19987
- trackSid: this.trackSid
19988
- });
20161
+ this.log.debug("adaptivestream video visibility ".concat(this.trackSid, ", visible=").concat(visible), this.logContext);
19989
20162
  this.disabled = !visible;
19990
20163
  this.emitTrackUpdate();
19991
20164
  };
19992
20165
  this.handleVideoDimensionsChange = dimensions => {
19993
- livekitLogger.debug("adaptivestream video dimensions ".concat(dimensions.width, "x").concat(dimensions.height), {
19994
- trackSid: this.trackSid
19995
- });
20166
+ this.log.debug("adaptivestream video dimensions ".concat(dimensions.width, "x").concat(dimensions.height), this.logContext);
19996
20167
  this.videoDimensions = dimensions;
19997
20168
  this.emitTrackUpdate();
19998
20169
  };
@@ -20178,15 +20349,11 @@ class RemoteTrackPublication extends TrackPublication {
20178
20349
  }
20179
20350
  isManualOperationAllowed() {
20180
20351
  if (this.kind === Track.Kind.Video && this.isAdaptiveStream) {
20181
- livekitLogger.warn('adaptive stream is enabled, cannot change video track settings', {
20182
- trackSid: this.trackSid
20183
- });
20352
+ this.log.warn('adaptive stream is enabled, cannot change video track settings', this.logContext);
20184
20353
  return false;
20185
20354
  }
20186
20355
  if (!this.isDesired) {
20187
- livekitLogger.warn('cannot update track settings when not subscribed', {
20188
- trackSid: this.trackSid
20189
- });
20356
+ this.log.warn('cannot update track settings when not subscribed', this.logContext);
20190
20357
  return false;
20191
20358
  }
20192
20359
  return true;
@@ -20220,8 +20387,8 @@ class RemoteParticipant extends Participant {
20220
20387
  return new RemoteParticipant(signalClient, pi.sid, pi.identity, pi.name, pi.metadata);
20221
20388
  }
20222
20389
  /** @internal */
20223
- constructor(signalClient, sid, identity, name, metadata) {
20224
- super(sid, identity || '', name, metadata);
20390
+ constructor(signalClient, sid, identity, name, metadata, loggerOptions) {
20391
+ super(sid, identity || '', name, metadata, loggerOptions);
20225
20392
  this.signalClient = signalClient;
20226
20393
  this.tracks = new Map();
20227
20394
  this.audioTracks = new Map();
@@ -20232,7 +20399,7 @@ class RemoteParticipant extends Participant {
20232
20399
  super.addTrackPublication(publication);
20233
20400
  // register action events
20234
20401
  publication.on(TrackEvent.UpdateSettings, settings => {
20235
- livekitLogger.debug('send update settings', settings);
20402
+ this.log.debug('send update settings', Object.assign(Object.assign({}, this.logContext), getLogContextFromTrack(publication)));
20236
20403
  this.signalClient.sendUpdateTrackSettings(settings);
20237
20404
  });
20238
20405
  publication.on(TrackEvent.UpdateSubscription, sub => {
@@ -20315,10 +20482,9 @@ class RemoteParticipant extends Participant {
20315
20482
  // yet arrived. Wait a bit longer for it to arrive, or fire an error
20316
20483
  if (!publication) {
20317
20484
  if (triesLeft === 0) {
20318
- livekitLogger.error('could not find published track', {
20319
- participant: this.sid,
20485
+ this.log.error('could not find published track', Object.assign(Object.assign({}, this.logContext), {
20320
20486
  trackSid: sid
20321
- });
20487
+ }));
20322
20488
  this.emit(ParticipantEvent.TrackSubscriptionFailed, sid);
20323
20489
  return;
20324
20490
  }
@@ -20329,10 +20495,7 @@ class RemoteParticipant extends Participant {
20329
20495
  return;
20330
20496
  }
20331
20497
  if (mediaTrack.readyState === 'ended') {
20332
- livekitLogger.error('unable to subscribe because MediaStreamTrack is ended. Do not call MediaStreamTrack.stop()', {
20333
- participant: this.sid,
20334
- trackSid: sid
20335
- });
20498
+ this.log.error('unable to subscribe because MediaStreamTrack is ended. Do not call MediaStreamTrack.stop()', Object.assign(Object.assign({}, this.logContext), getLogContextFromTrack(publication)));
20336
20499
  this.emit(ParticipantEvent.TrackSubscriptionFailed, sid);
20337
20500
  return;
20338
20501
  }
@@ -20375,7 +20538,7 @@ class RemoteParticipant extends Participant {
20375
20538
  const validTracks = new Map();
20376
20539
  const newTracks = new Map();
20377
20540
  info.tracks.forEach(ti => {
20378
- var _a;
20541
+ var _a, _b;
20379
20542
  let publication = this.getTrackPublication(ti.sid);
20380
20543
  if (!publication) {
20381
20544
  // new publication
@@ -20383,17 +20546,18 @@ class RemoteParticipant extends Participant {
20383
20546
  if (!kind) {
20384
20547
  return;
20385
20548
  }
20386
- publication = new RemoteTrackPublication(kind, ti, (_a = this.signalClient.connectOptions) === null || _a === void 0 ? void 0 : _a.autoSubscribe);
20549
+ publication = new RemoteTrackPublication(kind, ti, (_a = this.signalClient.connectOptions) === null || _a === void 0 ? void 0 : _a.autoSubscribe, {
20550
+ loggerContextCb: () => this.logContext,
20551
+ loggerName: (_b = this.loggerOptions) === null || _b === void 0 ? void 0 : _b.loggerName
20552
+ });
20387
20553
  publication.updateInfo(ti);
20388
20554
  newTracks.set(ti.sid, publication);
20389
20555
  const existingTrackOfSource = Array.from(this.tracks.values()).find(publishedTrack => publishedTrack.source === (publication === null || publication === void 0 ? void 0 : publication.source));
20390
20556
  if (existingTrackOfSource && publication.source !== Track.Source.Unknown) {
20391
- livekitLogger.debug("received a second track publication for ".concat(this.identity, " with the same source: ").concat(publication.source), {
20392
- oldTrack: existingTrackOfSource,
20393
- newTrack: publication,
20394
- participant: this,
20395
- participantInfo: info
20396
- });
20557
+ this.log.debug("received a second track publication for ".concat(this.identity, " with the same source: ").concat(publication.source), Object.assign(Object.assign({}, this.logContext), {
20558
+ oldTrack: getLogContextFromTrack(existingTrackOfSource),
20559
+ newTrack: getLogContextFromTrack(publication)
20560
+ }));
20397
20561
  }
20398
20562
  this.addTrackPublication(publication);
20399
20563
  } else {
@@ -20404,10 +20568,7 @@ class RemoteParticipant extends Participant {
20404
20568
  // detect removed tracks
20405
20569
  this.tracks.forEach(publication => {
20406
20570
  if (!validTracks.has(publication.trackSid)) {
20407
- livekitLogger.trace('detected removed track on remote participant, unpublishing', {
20408
- publication,
20409
- participantSid: this.sid
20410
- });
20571
+ this.log.trace('detected removed track on remote participant, unpublishing', Object.assign(Object.assign({}, this.logContext), getLogContextFromTrack(publication)));
20411
20572
  this.unpublishTrack(publication.trackSid, true);
20412
20573
  }
20413
20574
  });
@@ -20467,11 +20628,10 @@ class RemoteParticipant extends Participant {
20467
20628
  for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
20468
20629
  args[_key - 1] = arguments[_key];
20469
20630
  }
20470
- livekitLogger.trace('participant event', {
20471
- participant: this.sid,
20631
+ this.log.trace('participant event', Object.assign(Object.assign({}, this.logContext), {
20472
20632
  event,
20473
20633
  args
20474
- });
20634
+ }));
20475
20635
  return super.emit(event, ...args);
20476
20636
  }
20477
20637
  }
@@ -20479,7 +20639,10 @@ class RemoteParticipant extends Participant {
20479
20639
  class LocalParticipant extends Participant {
20480
20640
  /** @internal */
20481
20641
  constructor(sid, identity, engine, options) {
20482
- super(sid, identity);
20642
+ super(sid, identity, undefined, undefined, {
20643
+ loggerName: options.loggerName,
20644
+ loggerContextCb: () => this.engine.logContext
20645
+ });
20483
20646
  this.pendingPublishing = new Set();
20484
20647
  this.pendingPublishPromises = new Map();
20485
20648
  this.participantTrackPermissions = [];
@@ -20499,16 +20662,16 @@ class LocalParticipant extends Participant {
20499
20662
  this.handleDisconnected = () => {
20500
20663
  var _a, _b;
20501
20664
  if (this.reconnectFuture) {
20502
- this.reconnectFuture.promise.catch(e => livekitLogger.warn(e));
20665
+ this.reconnectFuture.promise.catch(e => this.log.warn(e.message, this.logContext));
20503
20666
  (_b = (_a = this.reconnectFuture) === null || _a === void 0 ? void 0 : _a.reject) === null || _b === void 0 ? void 0 : _b.call(_a, 'Got disconnected during reconnection attempt');
20504
20667
  this.reconnectFuture = undefined;
20505
20668
  }
20506
20669
  };
20507
20670
  this.updateTrackSubscriptionPermissions = () => {
20508
- livekitLogger.debug('updating track subscription permissions', {
20671
+ this.log.debug('updating track subscription permissions', Object.assign(Object.assign({}, this.logContext), {
20509
20672
  allParticipantsAllowed: this.allParticipantsAllowedToSubscribe,
20510
20673
  participantTrackPermissions: this.participantTrackPermissions
20511
- });
20674
+ }));
20512
20675
  this.engine.client.sendUpdateSubscriptionPermissions(this.allParticipantsAllowedToSubscribe, this.participantTrackPermissions.map(p => trackPermissionToProto(p)));
20513
20676
  };
20514
20677
  /** @internal */
@@ -20522,17 +20685,17 @@ class LocalParticipant extends Participant {
20522
20685
  muted = true;
20523
20686
  }
20524
20687
  if (!track.sid) {
20525
- livekitLogger.error('could not update mute status for unpublished track', track);
20688
+ this.log.error('could not update mute status for unpublished track', Object.assign(Object.assign({}, this.logContext), getLogContextFromTrack(track)));
20526
20689
  return;
20527
20690
  }
20528
20691
  this.engine.updateMuteStatus(track.sid, muted);
20529
20692
  };
20530
20693
  this.onTrackUpstreamPaused = track => {
20531
- livekitLogger.debug('upstream paused');
20694
+ this.log.debug('upstream paused', Object.assign(Object.assign({}, this.logContext), getLogContextFromTrack(track)));
20532
20695
  this.onTrackMuted(track, true);
20533
20696
  };
20534
20697
  this.onTrackUpstreamResumed = track => {
20535
- livekitLogger.debug('upstream resumed');
20698
+ this.log.debug('upstream resumed', Object.assign(Object.assign({}, this.logContext), getLogContextFromTrack(track)));
20536
20699
  this.onTrackMuted(track, track.isMuted);
20537
20700
  };
20538
20701
  this.handleSubscribedQualityUpdate = update => __awaiter(this, void 0, void 0, function* () {
@@ -20543,10 +20706,9 @@ class LocalParticipant extends Participant {
20543
20706
  }
20544
20707
  const pub = this.videoTracks.get(update.trackSid);
20545
20708
  if (!pub) {
20546
- livekitLogger.warn('received subscribed quality update for unknown track', {
20547
- method: 'handleSubscribedQualityUpdate',
20548
- sid: update.trackSid
20549
- });
20709
+ this.log.warn('received subscribed quality update for unknown track', Object.assign(Object.assign({}, this.logContext), {
20710
+ trackSid: update.trackSid
20711
+ }));
20550
20712
  return;
20551
20713
  }
20552
20714
  if (update.subscribedCodecs.length > 0) {
@@ -20560,7 +20722,7 @@ class LocalParticipant extends Participant {
20560
20722
  _f = false;
20561
20723
  const codec = _c;
20562
20724
  if (isBackupCodec(codec)) {
20563
- livekitLogger.debug("publish ".concat(codec, " for ").concat(pub.videoTrack.sid));
20725
+ this.log.debug("publish ".concat(codec, " for ").concat(pub.videoTrack.sid), Object.assign(Object.assign({}, this.logContext), getLogContextFromTrack(pub)));
20564
20726
  yield this.publishAdditionalCodecForTrack(pub.videoTrack, codec, pub.options);
20565
20727
  }
20566
20728
  }
@@ -20582,19 +20744,16 @@ class LocalParticipant extends Participant {
20582
20744
  this.handleLocalTrackUnpublished = unpublished => {
20583
20745
  const track = this.tracks.get(unpublished.trackSid);
20584
20746
  if (!track) {
20585
- livekitLogger.warn('received unpublished event for unknown track', {
20586
- method: 'handleLocalTrackUnpublished',
20747
+ this.log.warn('received unpublished event for unknown track', Object.assign(Object.assign({}, this.logContext), {
20587
20748
  trackSid: unpublished.trackSid
20588
- });
20749
+ }));
20589
20750
  return;
20590
20751
  }
20591
20752
  this.unpublishTrack(track.track);
20592
20753
  };
20593
20754
  this.handleTrackEnded = track => __awaiter(this, void 0, void 0, function* () {
20594
20755
  if (track.source === Track.Source.ScreenShare || track.source === Track.Source.ScreenShareAudio) {
20595
- livekitLogger.debug('unpublishing local track due to TrackEnded', {
20596
- track: track.sid
20597
- });
20756
+ this.log.debug('unpublishing local track due to TrackEnded', Object.assign(Object.assign({}, this.logContext), getLogContextFromTrack(track)));
20598
20757
  this.unpublishTrack(track);
20599
20758
  } else if (track.isUserProvided) {
20600
20759
  yield track.mute();
@@ -20608,7 +20767,7 @@ class LocalParticipant extends Participant {
20608
20767
  name: track.source === Track.Source.Camera ? 'camera' : 'microphone'
20609
20768
  });
20610
20769
  if (currentPermissions && currentPermissions.state === 'denied') {
20611
- livekitLogger.warn("user has revoked access to ".concat(track.source));
20770
+ this.log.warn("user has revoked access to ".concat(track.source), Object.assign(Object.assign({}, this.logContext), getLogContextFromTrack(track)));
20612
20771
  // detect granted change after permissions were denied to try and resume then
20613
20772
  currentPermissions.onchange = () => {
20614
20773
  if (currentPermissions.state !== 'denied') {
@@ -20625,11 +20784,11 @@ class LocalParticipant extends Participant {
20625
20784
  }
20626
20785
  }
20627
20786
  if (!track.isMuted) {
20628
- livekitLogger.debug('track ended, attempting to use a different device');
20787
+ this.log.debug('track ended, attempting to use a different device', Object.assign(Object.assign({}, this.logContext), getLogContextFromTrack(track)));
20629
20788
  yield track.restartTrack();
20630
20789
  }
20631
20790
  } catch (e) {
20632
- livekitLogger.warn("could not restart track, muting instead");
20791
+ this.log.warn("could not restart track, muting instead", Object.assign(Object.assign({}, this.logContext), getLogContextFromTrack(track)));
20633
20792
  yield track.mute();
20634
20793
  }
20635
20794
  }
@@ -20747,10 +20906,10 @@ class LocalParticipant extends Participant {
20747
20906
  setTrackEnabled(source, enabled, options, publishOptions) {
20748
20907
  var _a, _b;
20749
20908
  return __awaiter(this, void 0, void 0, function* () {
20750
- livekitLogger.debug('setTrackEnabled', {
20909
+ this.log.debug('setTrackEnabled', Object.assign(Object.assign({}, this.logContext), {
20751
20910
  source,
20752
20911
  enabled
20753
- });
20912
+ }));
20754
20913
  let track = this.getTrack(source);
20755
20914
  if (enabled) {
20756
20915
  if (track) {
@@ -20758,9 +20917,9 @@ class LocalParticipant extends Participant {
20758
20917
  } else {
20759
20918
  let localTracks;
20760
20919
  if (this.pendingPublishing.has(source)) {
20761
- livekitLogger.info('skipping duplicate published source', {
20920
+ this.log.info('skipping duplicate published source', Object.assign(Object.assign({}, this.logContext), {
20762
20921
  source
20763
- });
20922
+ }));
20764
20923
  // no-op it's already been requested
20765
20924
  return;
20766
20925
  }
@@ -20785,9 +20944,7 @@ class LocalParticipant extends Participant {
20785
20944
  }
20786
20945
  const publishPromises = [];
20787
20946
  for (const localTrack of localTracks) {
20788
- livekitLogger.info('publishing track', {
20789
- localTrack
20790
- });
20947
+ this.log.info('publishing track', Object.assign(Object.assign({}, this.logContext), getLogContextFromTrack(localTrack)));
20791
20948
  publishPromises.push(this.publishTrack(localTrack, publishOptions));
20792
20949
  }
20793
20950
  const publishedTracks = yield Promise.all(publishPromises);
@@ -20884,7 +21041,10 @@ class LocalParticipant extends Participant {
20884
21041
  if (typeof conOrBool !== 'boolean') {
20885
21042
  trackConstraints = conOrBool;
20886
21043
  }
20887
- const track = mediaTrackToLocalTrack(mediaStreamTrack, trackConstraints);
21044
+ const track = mediaTrackToLocalTrack(mediaStreamTrack, trackConstraints, {
21045
+ loggerName: this.roomOptions.loggerName,
21046
+ loggerContextCb: () => this.logContext
21047
+ });
20888
21048
  if (track.kind === Track.Kind.Video) {
20889
21049
  track.source = Track.Source.Camera;
20890
21050
  } else if (track.kind === Track.Kind.Audio) {
@@ -20908,18 +21068,33 @@ class LocalParticipant extends Participant {
20908
21068
  if (navigator.mediaDevices.getDisplayMedia === undefined) {
20909
21069
  throw new DeviceUnsupportedError('getDisplayMedia not supported');
20910
21070
  }
21071
+ if (options.resolution === undefined && !isSafari17()) {
21072
+ // we need to constrain the dimensions, otherwise it could lead to low bitrate
21073
+ // due to encoding a huge video. Encoding such large surfaces is really expensive
21074
+ // unfortunately Safari 17 has a but and cannot be constrained by default
21075
+ options.resolution = ScreenSharePresets.h1080fps30.resolution;
21076
+ }
20911
21077
  const constraints = screenCaptureToDisplayMediaStreamOptions(options);
20912
21078
  const stream = yield navigator.mediaDevices.getDisplayMedia(constraints);
20913
21079
  const tracks = stream.getVideoTracks();
20914
21080
  if (tracks.length === 0) {
20915
21081
  throw new TrackInvalidError('no video track found');
20916
21082
  }
20917
- const screenVideo = new LocalVideoTrack(tracks[0], undefined, false);
21083
+ const screenVideo = new LocalVideoTrack(tracks[0], undefined, false, {
21084
+ loggerName: this.roomOptions.loggerName,
21085
+ loggerContextCb: () => this.logContext
21086
+ });
20918
21087
  screenVideo.source = Track.Source.ScreenShare;
21088
+ if (options.contentHint) {
21089
+ screenVideo.mediaStreamTrack.contentHint = options.contentHint;
21090
+ }
20919
21091
  const localTracks = [screenVideo];
20920
21092
  if (stream.getAudioTracks().length > 0) {
20921
21093
  this.emit(ParticipantEvent.AudioStreamAcquired);
20922
- const screenAudio = new LocalAudioTrack(stream.getAudioTracks()[0], undefined, false, this.audioContext);
21094
+ const screenAudio = new LocalAudioTrack(stream.getAudioTracks()[0], undefined, false, this.audioContext, {
21095
+ loggerName: this.roomOptions.loggerName,
21096
+ loggerContextCb: () => this.logContext
21097
+ });
20923
21098
  screenAudio.source = Track.Source.ScreenShareAudio;
20924
21099
  localTracks.push(screenAudio);
20925
21100
  }
@@ -20963,14 +21138,25 @@ class LocalParticipant extends Participant {
20963
21138
  if (track instanceof MediaStreamTrack) {
20964
21139
  switch (track.kind) {
20965
21140
  case 'audio':
20966
- track = new LocalAudioTrack(track, defaultConstraints, true, this.audioContext);
21141
+ track = new LocalAudioTrack(track, defaultConstraints, true, this.audioContext, {
21142
+ loggerName: this.roomOptions.loggerName,
21143
+ loggerContextCb: () => this.logContext
21144
+ });
20967
21145
  break;
20968
21146
  case 'video':
20969
- track = new LocalVideoTrack(track, defaultConstraints, true);
21147
+ track = new LocalVideoTrack(track, defaultConstraints, true, {
21148
+ loggerName: this.roomOptions.loggerName,
21149
+ loggerContextCb: () => this.logContext
21150
+ });
20970
21151
  break;
20971
21152
  default:
20972
21153
  throw new TrackInvalidError("unsupported MediaStreamTrack kind ".concat(track.kind));
20973
21154
  }
21155
+ } else {
21156
+ track.updateLoggerOptions({
21157
+ loggerName: this.roomOptions.loggerName,
21158
+ loggerContextCb: () => this.logContext
21159
+ });
20974
21160
  }
20975
21161
  if (track instanceof LocalAudioTrack) {
20976
21162
  track.setAudioContext(this.audioContext);
@@ -20986,7 +21172,7 @@ class LocalParticipant extends Participant {
20986
21172
  }
20987
21173
  });
20988
21174
  if (existingPublication) {
20989
- livekitLogger.warn('track has already been published, skipping');
21175
+ this.log.warn('track has already been published, skipping', Object.assign(Object.assign({}, this.logContext), getLogContextFromTrack(existingPublication)));
20990
21176
  return existingPublication;
20991
21177
  }
20992
21178
  const isStereoInput = 'channelCount' in track.mediaStreamTrack.getSettings() &&
@@ -20999,10 +21185,10 @@ class LocalParticipant extends Participant {
20999
21185
  options = {};
21000
21186
  }
21001
21187
  if (options.dtx === undefined) {
21002
- livekitLogger.info("Opus DTX will be disabled for stereo tracks by default. Enable them explicitly to make it work.");
21188
+ this.log.info("Opus DTX will be disabled for stereo tracks by default. Enable them explicitly to make it work.", Object.assign(Object.assign({}, this.logContext), getLogContextFromTrack(track)));
21003
21189
  }
21004
21190
  if (options.red === undefined) {
21005
- livekitLogger.info("Opus RED will be disabled for stereo tracks by default. Enable them explicitly to make it work.");
21191
+ this.log.info("Opus RED will be disabled for stereo tracks by default. Enable them explicitly to make it work.");
21006
21192
  }
21007
21193
  (_c = options.dtx) !== null && _c !== void 0 ? _c : options.dtx = false;
21008
21194
  (_d = options.red) !== null && _d !== void 0 ? _d : options.red = false;
@@ -21010,7 +21196,7 @@ class LocalParticipant extends Participant {
21010
21196
  const opts = Object.assign(Object.assign({}, this.roomOptions.publishDefaults), options);
21011
21197
  // disable simulcast if e2ee is set on safari
21012
21198
  if (isSafari() && this.roomOptions.e2ee) {
21013
- livekitLogger.info("End-to-end encryption is set up, simulcast publishing will be disabled on Safari");
21199
+ this.log.info("End-to-end encryption is set up, simulcast publishing will be disabled on Safari", Object.assign({}, this.logContext));
21014
21200
  opts.simulcast = false;
21015
21201
  }
21016
21202
  if (opts.source) {
@@ -21033,7 +21219,7 @@ class LocalParticipant extends Participant {
21033
21219
  return __awaiter(this, void 0, void 0, function* () {
21034
21220
  const existingTrackOfSource = Array.from(this.tracks.values()).find(publishedTrack => track instanceof LocalTrack && publishedTrack.source === track.source);
21035
21221
  if (existingTrackOfSource && track.source !== Track.Source.Unknown) {
21036
- livekitLogger.info("publishing a second track with the same source: ".concat(track.source));
21222
+ this.log.info("publishing a second track with the same source: ".concat(track.source), Object.assign(Object.assign({}, this.logContext), getLogContextFromTrack(track)));
21037
21223
  }
21038
21224
  if (opts.stopMicTrackOnMute && track instanceof LocalAudioTrack) {
21039
21225
  track.stopOnMute = true;
@@ -21092,7 +21278,9 @@ class LocalParticipant extends Participant {
21092
21278
  height: defaultRes.height
21093
21279
  };
21094
21280
  // log failure
21095
- livekitLogger.error('could not determine track dimensions, using defaults', dims);
21281
+ this.log.error('could not determine track dimensions, using defaults', Object.assign(Object.assign(Object.assign({}, this.logContext), getLogContextFromTrack(track)), {
21282
+ dims
21283
+ }));
21096
21284
  }
21097
21285
  // width and height should be defined for video
21098
21286
  req.width = dims.width;
@@ -21154,26 +21342,29 @@ class LocalParticipant extends Participant {
21154
21342
  if (primaryCodecMime && track.kind === Track.Kind.Video) {
21155
21343
  const updatedCodec = mimeTypeToVideoCodecString(primaryCodecMime);
21156
21344
  if (updatedCodec !== videoCodec) {
21157
- livekitLogger.debug('falling back to server selected codec', {
21345
+ this.log.debug('falling back to server selected codec', Object.assign(Object.assign(Object.assign({}, this.logContext), getLogContextFromTrack(track)), {
21158
21346
  codec: updatedCodec
21159
- });
21347
+ }));
21160
21348
  /* @ts-ignore */
21161
21349
  opts.videoCodec = updatedCodec;
21162
21350
  // recompute encodings since bitrates/etc could have changed
21163
21351
  encodings = computeVideoEncodings(track.source === Track.Source.ScreenShare, req.width, req.height, opts);
21164
21352
  }
21165
21353
  }
21166
- const publication = new LocalTrackPublication(track.kind, ti, track);
21354
+ const publication = new LocalTrackPublication(track.kind, ti, track, {
21355
+ loggerName: this.roomOptions.loggerName,
21356
+ loggerContextCb: () => this.logContext
21357
+ });
21167
21358
  // save options for when it needs to be republished again
21168
21359
  publication.options = opts;
21169
21360
  track.sid = ti.sid;
21170
21361
  if (!this.engine.pcManager) {
21171
21362
  throw new UnexpectedConnectionState('pcManager is not ready');
21172
21363
  }
21173
- livekitLogger.debug("publishing ".concat(track.kind, " with encodings"), {
21364
+ this.log.debug("publishing ".concat(track.kind, " with encodings"), Object.assign(Object.assign({}, this.logContext), {
21174
21365
  encodings,
21175
21366
  trackInfo: ti
21176
- });
21367
+ }));
21177
21368
  track.sender = yield this.engine.createSender(track, opts, encodings);
21178
21369
  if (encodings) {
21179
21370
  if (isFireFox() && track.kind === Track.Kind.Audio) {
@@ -21250,7 +21441,7 @@ class LocalParticipant extends Participant {
21250
21441
  const opts = Object.assign(Object.assign({}, (_a = this.roomOptions) === null || _a === void 0 ? void 0 : _a.publishDefaults), options);
21251
21442
  const encodings = computeTrackBackupEncodings(track, videoCodec, opts);
21252
21443
  if (!encodings) {
21253
- livekitLogger.info("backup codec has been disabled, ignoring request to add additional codec for track");
21444
+ this.log.info("backup codec has been disabled, ignoring request to add additional codec for track", Object.assign(Object.assign({}, this.logContext), getLogContextFromTrack(track)));
21254
21445
  return;
21255
21446
  }
21256
21447
  const simulcastTrack = track.addSimulcastTrack(videoCodec, encodings);
@@ -21272,10 +21463,10 @@ class LocalParticipant extends Participant {
21272
21463
  const ti = yield this.engine.addTrack(req);
21273
21464
  yield this.engine.createSimulcastSender(track, simulcastTrack, opts, encodings);
21274
21465
  yield this.engine.negotiate();
21275
- livekitLogger.debug("published ".concat(videoCodec, " for track ").concat(track.sid), {
21466
+ this.log.debug("published ".concat(videoCodec, " for track ").concat(track.sid), Object.assign(Object.assign({}, this.logContext), {
21276
21467
  encodings,
21277
21468
  trackInfo: ti
21278
- });
21469
+ }));
21279
21470
  });
21280
21471
  }
21281
21472
  unpublishTrack(track, stopOnUnpublish) {
@@ -21283,15 +21474,10 @@ class LocalParticipant extends Participant {
21283
21474
  return __awaiter(this, void 0, void 0, function* () {
21284
21475
  // look through all published tracks to find the right ones
21285
21476
  const publication = this.getPublicationForTrack(track);
21286
- livekitLogger.debug('unpublishing track', {
21287
- track,
21288
- method: 'unpublishTrack'
21289
- });
21477
+ const pubLogContext = publication ? getLogContextFromTrack(publication) : undefined;
21478
+ this.log.debug('unpublishing track', Object.assign(Object.assign({}, this.logContext), pubLogContext));
21290
21479
  if (!publication || !publication.track) {
21291
- livekitLogger.warn('track was not unpublished because no publication was found', {
21292
- track,
21293
- method: 'unpublishTrack'
21294
- });
21480
+ this.log.warn('track was not unpublished because no publication was found', Object.assign(Object.assign({}, this.logContext), pubLogContext));
21295
21481
  return undefined;
21296
21482
  }
21297
21483
  track = publication.track;
@@ -21336,10 +21522,9 @@ class LocalParticipant extends Participant {
21336
21522
  track.simulcastCodecs.clear();
21337
21523
  }
21338
21524
  } catch (e) {
21339
- livekitLogger.warn('failed to unpublish track', {
21340
- error: e,
21341
- method: 'unpublishTrack'
21342
- });
21525
+ this.log.warn('failed to unpublish track', Object.assign(Object.assign(Object.assign({}, this.logContext), pubLogContext), {
21526
+ error: e
21527
+ }));
21343
21528
  }
21344
21529
  }
21345
21530
  // remove from our maps
@@ -21381,12 +21566,12 @@ class LocalParticipant extends Participant {
21381
21566
  yield Promise.all(localPubs.map(pub => __awaiter(this, void 0, void 0, function* () {
21382
21567
  const track = pub.track;
21383
21568
  yield this.unpublishTrack(track, false);
21384
- if (restartTracks && !track.isMuted && (track instanceof LocalAudioTrack || track instanceof LocalVideoTrack) && !track.isUserProvided) {
21569
+ if (restartTracks && !track.isMuted && track.source !== Track.Source.ScreenShare && track.source !== Track.Source.ScreenShareAudio && (track instanceof LocalAudioTrack || track instanceof LocalVideoTrack) && !track.isUserProvided) {
21385
21570
  // generally we need to restart the track before publishing, often a full reconnect
21386
21571
  // is necessary because computer had gone to sleep.
21387
- livekitLogger.debug('restarting existing track', {
21572
+ this.log.debug('restarting existing track', Object.assign(Object.assign({}, this.logContext), {
21388
21573
  track: pub.trackSid
21389
- });
21574
+ }));
21390
21575
  yield track.restartTrack();
21391
21576
  }
21392
21577
  yield this.publishTrack(track, pub.options);
@@ -21467,10 +21652,9 @@ class LocalParticipant extends Participant {
21467
21652
  if (pub) {
21468
21653
  const mutedOnServer = pub.isMuted || ((_b = (_a = pub.track) === null || _a === void 0 ? void 0 : _a.isUpstreamPaused) !== null && _b !== void 0 ? _b : false);
21469
21654
  if (mutedOnServer !== ti.muted) {
21470
- livekitLogger.debug('updating server mute state after reconcile', {
21471
- sid: ti.sid,
21472
- muted: mutedOnServer
21473
- });
21655
+ this.log.debug('updating server mute state after reconcile', Object.assign(Object.assign(Object.assign({}, this.logContext), getLogContextFromTrack(pub)), {
21656
+ mutedOnServer
21657
+ }));
21474
21658
  this.engine.client.sendMuteTrack(ti.sid, mutedOnServer);
21475
21659
  }
21476
21660
  }
@@ -21524,7 +21708,7 @@ class Room extends eventsExports.EventEmitter {
21524
21708
  */
21525
21709
  constructor(options) {
21526
21710
  var _this;
21527
- var _a;
21711
+ var _a, _b;
21528
21712
  super();
21529
21713
  _this = this;
21530
21714
  this.state = ConnectionState.Disconnected;
@@ -21537,13 +21721,14 @@ class Room extends eventsExports.EventEmitter {
21537
21721
  this.isE2EEEnabled = false;
21538
21722
  this.audioEnabled = true;
21539
21723
  this.isVideoPlaybackBlocked = false;
21724
+ this.log = livekitLogger;
21540
21725
  this.connect = (url, token, opts) => __awaiter(this, void 0, void 0, function* () {
21541
- var _b;
21726
+ var _c;
21542
21727
  // In case a disconnect called happened right before the connect call, make sure the disconnect is completed first by awaiting its lock
21543
21728
  const unlockDisconnect = yield this.disconnectLock.lock();
21544
21729
  if (this.state === ConnectionState.Connected) {
21545
21730
  // when the state is reconnecting or connected, this function returns immediately
21546
- livekitLogger.info("already connected to room ".concat(this.name));
21731
+ this.log.info("already connected to room ".concat(this.name), this.logContext);
21547
21732
  unlockDisconnect();
21548
21733
  return Promise.resolve();
21549
21734
  }
@@ -21552,7 +21737,7 @@ class Room extends eventsExports.EventEmitter {
21552
21737
  return this.connectFuture.promise;
21553
21738
  }
21554
21739
  this.setAndEmitConnectionState(ConnectionState.Connecting);
21555
- if (((_b = this.regionUrlProvider) === null || _b === void 0 ? void 0 : _b.getServerUrl().toString()) !== url) {
21740
+ if (((_c = this.regionUrlProvider) === null || _c === void 0 ? void 0 : _c.getServerUrl().toString()) !== url) {
21556
21741
  this.regionUrl = undefined;
21557
21742
  this.regionUrlProvider = undefined;
21558
21743
  }
@@ -21566,13 +21751,13 @@ class Room extends eventsExports.EventEmitter {
21566
21751
  // if initial connection fails, this will speed up picking regional url
21567
21752
  // on subsequent runs
21568
21753
  this.regionUrlProvider.fetchRegionSettings().catch(e => {
21569
- livekitLogger.warn('could not fetch region settings', {
21754
+ this.log.warn('could not fetch region settings', Object.assign(Object.assign({}, this.logContext), {
21570
21755
  error: e
21571
- });
21756
+ }));
21572
21757
  });
21573
21758
  }
21574
21759
  const connectFn = (resolve, reject, regionUrl) => __awaiter(this, void 0, void 0, function* () {
21575
- var _c;
21760
+ var _d;
21576
21761
  if (this.abortController) {
21577
21762
  this.abortController.abort();
21578
21763
  }
@@ -21589,7 +21774,7 @@ class Room extends eventsExports.EventEmitter {
21589
21774
  if (this.regionUrlProvider && e instanceof ConnectionError && e.reason !== 3 /* ConnectionErrorReason.Cancelled */ && e.reason !== 0 /* ConnectionErrorReason.NotAllowed */) {
21590
21775
  let nextUrl = null;
21591
21776
  try {
21592
- nextUrl = yield this.regionUrlProvider.getNextBestRegionUrl((_c = this.abortController) === null || _c === void 0 ? void 0 : _c.signal);
21777
+ nextUrl = yield this.regionUrlProvider.getNextBestRegionUrl((_d = this.abortController) === null || _d === void 0 ? void 0 : _d.signal);
21593
21778
  } catch (error) {
21594
21779
  if (error instanceof ConnectionError && (error.status === 401 || error.reason === 3 /* ConnectionErrorReason.Cancelled */)) {
21595
21780
  this.handleDisconnect(this.options.stopLocalTrackOnUnpublish);
@@ -21598,7 +21783,7 @@ class Room extends eventsExports.EventEmitter {
21598
21783
  }
21599
21784
  }
21600
21785
  if (nextUrl) {
21601
- livekitLogger.info("Initial connection failed with ConnectionError: ".concat(e.message, ". Retrying with another region: ").concat(nextUrl));
21786
+ this.log.info("Initial connection failed with ConnectionError: ".concat(e.message, ". Retrying with another region: ").concat(nextUrl), this.logContext);
21602
21787
  yield connectFn(resolve, reject, nextUrl);
21603
21788
  } else {
21604
21789
  this.handleDisconnect(this.options.stopLocalTrackOnUnpublish);
@@ -21620,6 +21805,7 @@ class Room extends eventsExports.EventEmitter {
21620
21805
  return this.connectFuture.promise;
21621
21806
  });
21622
21807
  this.connectSignal = (url, token, engine, connectOptions, roomOptions, abortController) => __awaiter(this, void 0, void 0, function* () {
21808
+ var _e, _f, _g;
21623
21809
  const joinResponse = yield engine.join(url, token, {
21624
21810
  autoSubscribe: connectOptions.autoSubscribe,
21625
21811
  publishOnly: connectOptions.publishOnly,
@@ -21635,15 +21821,19 @@ class Room extends eventsExports.EventEmitter {
21635
21821
  region: joinResponse.serverRegion
21636
21822
  };
21637
21823
  }
21638
- livekitLogger.debug("connected to Livekit Server ".concat(Object.entries(serverInfo).map(_ref => {
21824
+ this.log.debug("connected to Livekit Server ".concat(Object.entries(serverInfo).map(_ref => {
21639
21825
  let [key, value] = _ref;
21640
21826
  return "".concat(key, ": ").concat(value);
21641
- }).join(', ')));
21827
+ }).join(', ')), {
21828
+ room: (_e = joinResponse.room) === null || _e === void 0 ? void 0 : _e.name,
21829
+ roomSid: (_f = joinResponse.room) === null || _f === void 0 ? void 0 : _f.sid,
21830
+ identity: (_g = joinResponse.participant) === null || _g === void 0 ? void 0 : _g.identity
21831
+ });
21642
21832
  if (!joinResponse.serverVersion) {
21643
21833
  throw new UnsupportedServer('unknown server version');
21644
21834
  }
21645
21835
  if (joinResponse.serverVersion === '0.15.1' && this.options.dynacast) {
21646
- livekitLogger.debug('disabling dynacast due to server version');
21836
+ this.log.debug('disabling dynacast due to server version', this.logContext);
21647
21837
  // dynacast has a bug in 0.15.1, so we cannot use it then
21648
21838
  roomOptions.dynacast = false;
21649
21839
  }
@@ -21663,16 +21853,16 @@ class Room extends eventsExports.EventEmitter {
21663
21853
  }
21664
21854
  };
21665
21855
  this.attemptConnection = (url, token, opts, abortController) => __awaiter(this, void 0, void 0, function* () {
21666
- var _d, _e;
21856
+ var _h, _j;
21667
21857
  if (this.state === ConnectionState.Reconnecting) {
21668
- livekitLogger.info('Reconnection attempt replaced by new connection attempt');
21858
+ this.log.info('Reconnection attempt replaced by new connection attempt', this.logContext);
21669
21859
  // make sure we close and recreate the existing engine in order to get rid of any potentially ongoing reconnection attempts
21670
21860
  this.recreateEngine();
21671
21861
  } else {
21672
21862
  // create engine if previously disconnected
21673
21863
  this.maybeCreateEngine();
21674
21864
  }
21675
- if ((_d = this.regionUrlProvider) === null || _d === void 0 ? void 0 : _d.isCloud()) {
21865
+ if ((_h = this.regionUrlProvider) === null || _h === void 0 ? void 0 : _h.isCloud()) {
21676
21866
  this.engine.setRegionUrlProvider(this.regionUrlProvider);
21677
21867
  }
21678
21868
  this.acquireAudioContext();
@@ -21700,9 +21890,9 @@ class Room extends eventsExports.EventEmitter {
21700
21890
  resultingError.reason = err.reason;
21701
21891
  resultingError.status = err.status;
21702
21892
  }
21703
- livekitLogger.debug("error trying to establish signal connection", {
21893
+ this.log.debug("error trying to establish signal connection", Object.assign(Object.assign({}, this.logContext), {
21704
21894
  error: err
21705
- });
21895
+ }));
21706
21896
  throw resultingError;
21707
21897
  }
21708
21898
  if (abortController.signal.aborted) {
@@ -21725,7 +21915,7 @@ class Room extends eventsExports.EventEmitter {
21725
21915
  }
21726
21916
  if (isWeb()) {
21727
21917
  document.addEventListener('freeze', this.onPageLeave);
21728
- (_e = navigator.mediaDevices) === null || _e === void 0 ? void 0 : _e.addEventListener('devicechange', this.handleDeviceChange);
21918
+ (_j = navigator.mediaDevices) === null || _j === void 0 ? void 0 : _j.addEventListener('devicechange', this.handleDeviceChange);
21729
21919
  }
21730
21920
  this.setAndEmitConnectionState(ConnectionState.Connected);
21731
21921
  this.emit(RoomEvent.Connected);
@@ -21737,26 +21927,24 @@ class Room extends eventsExports.EventEmitter {
21737
21927
  this.disconnect = function () {
21738
21928
  let stopTracks = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
21739
21929
  return __awaiter(_this, void 0, void 0, function* () {
21740
- var _f, _g, _h, _j;
21930
+ var _k, _l, _m, _o;
21741
21931
  const unlock = yield this.disconnectLock.lock();
21742
21932
  try {
21743
21933
  if (this.state === ConnectionState.Disconnected) {
21744
- livekitLogger.debug('already disconnected');
21934
+ this.log.debug('already disconnected', this.logContext);
21745
21935
  return;
21746
21936
  }
21747
- livekitLogger.info('disconnect from room', {
21748
- identity: this.localParticipant.identity
21749
- });
21937
+ this.log.info('disconnect from room', Object.assign({}, this.logContext));
21750
21938
  if (this.state === ConnectionState.Connecting || this.state === ConnectionState.Reconnecting) {
21751
21939
  // try aborting pending connection attempt
21752
- livekitLogger.warn('abort connection attempt');
21753
- (_f = this.abortController) === null || _f === void 0 ? void 0 : _f.abort();
21940
+ this.log.warn('abort connection attempt', this.logContext);
21941
+ (_k = this.abortController) === null || _k === void 0 ? void 0 : _k.abort();
21754
21942
  // in case the abort controller didn't manage to cancel the connection attempt, reject the connect promise explicitly
21755
- (_h = (_g = this.connectFuture) === null || _g === void 0 ? void 0 : _g.reject) === null || _h === void 0 ? void 0 : _h.call(_g, new ConnectionError('Client initiated disconnect'));
21943
+ (_m = (_l = this.connectFuture) === null || _l === void 0 ? void 0 : _l.reject) === null || _m === void 0 ? void 0 : _m.call(_l, new ConnectionError('Client initiated disconnect'));
21756
21944
  this.connectFuture = undefined;
21757
21945
  }
21758
21946
  // send leave
21759
- if (!((_j = this.engine) === null || _j === void 0 ? void 0 : _j.client.isDisconnected)) {
21947
+ if (!((_o = this.engine) === null || _o === void 0 ? void 0 : _o.client.isDisconnected)) {
21760
21948
  yield this.engine.client.sendLeave();
21761
21949
  }
21762
21950
  // close engine (also closes client)
@@ -21856,7 +22044,7 @@ class Room extends eventsExports.EventEmitter {
21856
22044
  if (e.name === 'NotAllowedError') {
21857
22045
  this.handleVideoPlaybackFailed();
21858
22046
  } else {
21859
- livekitLogger.warn('Resuming video playback failed, make sure you call `startVideo` directly in a user gesture handler');
22047
+ this.log.warn('Resuming video playback failed, make sure you call `startVideo` directly in a user gesture handler', this.logContext);
21860
22048
  }
21861
22049
  });
21862
22050
  });
@@ -21871,48 +22059,25 @@ class Room extends eventsExports.EventEmitter {
21871
22059
  }
21872
22060
  };
21873
22061
  this.handleSignalRestarted = joinResponse => __awaiter(this, void 0, void 0, function* () {
21874
- livekitLogger.debug("signal reconnected to server", {
22062
+ this.log.debug("signal reconnected to server, region ".concat(joinResponse.serverRegion), Object.assign(Object.assign({}, this.logContext), {
21875
22063
  region: joinResponse.serverRegion
21876
- });
22064
+ }));
21877
22065
  this.cachedParticipantSids = [];
21878
22066
  this.applyJoinResponse(joinResponse);
21879
22067
  try {
21880
22068
  // unpublish & republish tracks
21881
- const localPubs = [];
21882
- this.localParticipant.tracks.forEach(pub => {
21883
- if (pub.track) {
21884
- localPubs.push(pub);
21885
- }
21886
- });
21887
- yield Promise.all(localPubs.map(pub => __awaiter(this, void 0, void 0, function* () {
21888
- const track = pub.track;
21889
- this.localParticipant.unpublishTrack(track, false);
21890
- if (!track.isMuted) {
21891
- if ((track instanceof LocalAudioTrack || track instanceof LocalVideoTrack) && track.source !== Track.Source.ScreenShare && track.source !== Track.Source.ScreenShareAudio && !track.isUserProvided) {
21892
- // we need to restart the track before publishing, often a full reconnect
21893
- // is necessary because computer had gone to sleep.
21894
- livekitLogger.debug('restarting existing track', {
21895
- track: pub.trackSid
21896
- });
21897
- yield track.restartTrack();
21898
- }
21899
- livekitLogger.debug('publishing new track', {
21900
- track: pub.trackSid
21901
- });
21902
- yield this.localParticipant.publishTrack(track, pub.options);
21903
- }
21904
- })));
22069
+ yield this.localParticipant.republishAllTracks(undefined, true);
21905
22070
  } catch (error) {
21906
- livekitLogger.error('error trying to re-publish tracks after reconnection', {
22071
+ this.log.error('error trying to re-publish tracks after reconnection', Object.assign(Object.assign({}, this.logContext), {
21907
22072
  error
21908
- });
22073
+ }));
21909
22074
  }
21910
22075
  try {
21911
22076
  yield this.engine.waitForRestarted();
21912
- livekitLogger.debug("fully reconnected to server", {
22077
+ this.log.debug("fully reconnected to server", Object.assign(Object.assign({}, this.logContext), {
21913
22078
  region: joinResponse.serverRegion
21914
- });
21915
- } catch (_k) {
22079
+ }));
22080
+ } catch (_p) {
21916
22081
  // reconnection failed, handleDisconnect is being invoked already, just return here
21917
22082
  return;
21918
22083
  }
@@ -22063,7 +22228,9 @@ class Room extends eventsExports.EventEmitter {
22063
22228
  this.emit(RoomEvent.AudioPlaybackStatusChanged, true);
22064
22229
  };
22065
22230
  this.handleAudioPlaybackFailed = e => {
22066
- livekitLogger.warn('could not playback audio', e);
22231
+ this.log.warn('could not playback audio', Object.assign(Object.assign({}, this.logContext), {
22232
+ error: e
22233
+ }));
22067
22234
  if (!this.canPlaybackAudio) {
22068
22235
  return;
22069
22236
  }
@@ -22120,7 +22287,7 @@ class Room extends eventsExports.EventEmitter {
22120
22287
  this.emit(RoomEvent.TrackUnmuted, pub, this.localParticipant);
22121
22288
  };
22122
22289
  this.onLocalTrackPublished = pub => __awaiter(this, void 0, void 0, function* () {
22123
- var _l;
22290
+ var _q;
22124
22291
  this.emit(RoomEvent.LocalTrackPublished, pub, this.localParticipant);
22125
22292
  if (pub.track instanceof LocalAudioTrack) {
22126
22293
  const trackIsSilent = yield pub.track.checkForSilence();
@@ -22128,7 +22295,7 @@ class Room extends eventsExports.EventEmitter {
22128
22295
  this.emit(RoomEvent.LocalAudioSilenceDetected, pub);
22129
22296
  }
22130
22297
  }
22131
- const deviceId = yield (_l = pub.track) === null || _l === void 0 ? void 0 : _l.getDeviceId();
22298
+ const deviceId = yield (_q = pub.track) === null || _q === void 0 ? void 0 : _q.getDeviceId();
22132
22299
  const deviceKind = sourceToKind(pub.source);
22133
22300
  if (deviceKind && deviceId && deviceId !== this.localParticipant.activeDeviceMap.get(deviceKind)) {
22134
22301
  this.localParticipant.activeDeviceMap.set(deviceKind, deviceId);
@@ -22152,6 +22319,7 @@ class Room extends eventsExports.EventEmitter {
22152
22319
  this.cachedParticipantSids = [];
22153
22320
  this.identityToSid = new Map();
22154
22321
  this.options = Object.assign(Object.assign({}, roomOptionDefaults), options);
22322
+ this.log = getLogger((_a = this.options.loggerName) !== null && _a !== void 0 ? _a : LoggerNames.Room);
22155
22323
  this.options.audioCaptureDefaults = Object.assign(Object.assign({}, audioDefaults), options === null || options === void 0 ? void 0 : options.audioCaptureDefaults);
22156
22324
  this.options.videoCaptureDefaults = Object.assign(Object.assign({}, videoDefaults), options === null || options === void 0 ? void 0 : options.videoCaptureDefaults);
22157
22325
  this.options.publishDefaults = Object.assign(Object.assign({}, publishDefaults), options === null || options === void 0 ? void 0 : options.publishDefaults);
@@ -22164,8 +22332,8 @@ class Room extends eventsExports.EventEmitter {
22164
22332
  if (this.options.audioCaptureDefaults.deviceId) {
22165
22333
  this.localParticipant.activeDeviceMap.set('audioinput', unwrapConstraint(this.options.audioCaptureDefaults.deviceId));
22166
22334
  }
22167
- if ((_a = this.options.audioOutput) === null || _a === void 0 ? void 0 : _a.deviceId) {
22168
- this.switchActiveDevice('audiooutput', unwrapConstraint(this.options.audioOutput.deviceId)).catch(e => livekitLogger.warn("Could not set audio output: ".concat(e.message)));
22335
+ if ((_b = this.options.audioOutput) === null || _b === void 0 ? void 0 : _b.deviceId) {
22336
+ this.switchActiveDevice('audiooutput', unwrapConstraint(this.options.audioOutput.deviceId)).catch(e => this.log.warn("Could not set audio output: ".concat(e.message), this.logContext));
22169
22337
  }
22170
22338
  if (this.options.e2ee) {
22171
22339
  this.setupE2EE();
@@ -22200,6 +22368,13 @@ class Room extends eventsExports.EventEmitter {
22200
22368
  (_a = this.e2eeManager) === null || _a === void 0 ? void 0 : _a.setup(this);
22201
22369
  }
22202
22370
  }
22371
+ get logContext() {
22372
+ return {
22373
+ room: this.name,
22374
+ roomSid: this.sid,
22375
+ identity: this.localParticipant.identity
22376
+ };
22377
+ }
22203
22378
  /**
22204
22379
  * if the current room has a participant with `recorder: true` in its JWT grant
22205
22380
  **/
@@ -22294,7 +22469,7 @@ class Room extends eventsExports.EventEmitter {
22294
22469
  if (this.state !== ConnectionState.Disconnected) {
22295
22470
  return;
22296
22471
  }
22297
- livekitLogger.debug("prepareConnection to ".concat(url));
22472
+ this.log.debug("prepareConnection to ".concat(url), this.logContext);
22298
22473
  try {
22299
22474
  if (isCloud(new URL(url)) && token) {
22300
22475
  this.regionUrlProvider = new RegionUrlProvider(url, token);
@@ -22306,7 +22481,7 @@ class Room extends eventsExports.EventEmitter {
22306
22481
  yield fetch(toHttpUrl(regionUrl), {
22307
22482
  method: 'HEAD'
22308
22483
  });
22309
- livekitLogger.debug("prepared connection to ".concat(regionUrl));
22484
+ this.log.debug("prepared connection to ".concat(regionUrl), this.logContext);
22310
22485
  }
22311
22486
  } else {
22312
22487
  yield fetch(toHttpUrl(url), {
@@ -22314,9 +22489,9 @@ class Room extends eventsExports.EventEmitter {
22314
22489
  });
22315
22490
  }
22316
22491
  } catch (e) {
22317
- livekitLogger.warn('could not prepare connection', {
22492
+ this.log.warn('could not prepare connection', Object.assign(Object.assign({}, this.logContext), {
22318
22493
  error: e
22319
- });
22494
+ }));
22320
22495
  }
22321
22496
  });
22322
22497
  }
@@ -22563,7 +22738,7 @@ class Room extends eventsExports.EventEmitter {
22563
22738
  return;
22564
22739
  }
22565
22740
  if (this.state === ConnectionState.Disconnected) {
22566
- livekitLogger.warn('skipping incoming track after Room disconnected');
22741
+ this.log.warn('skipping incoming track after Room disconnected', this.logContext);
22567
22742
  return;
22568
22743
  }
22569
22744
  const parts = unpackStreamId(stream.id);
@@ -22574,12 +22749,12 @@ class Room extends eventsExports.EventEmitter {
22574
22749
  // and generates its own track id instead of infer from sdp track id.
22575
22750
  if (streamId && streamId.startsWith('TR')) trackId = streamId;
22576
22751
  if (participantId === this.localParticipant.sid) {
22577
- livekitLogger.warn('tried to create RemoteParticipant for local participant');
22752
+ this.log.warn('tried to create RemoteParticipant for local participant', this.logContext);
22578
22753
  return;
22579
22754
  }
22580
22755
  const participant = this.participants.get(participantId);
22581
22756
  if (!participant) {
22582
- livekitLogger.error("Tried to add a track for a participant, that's not present. Sid: ".concat(participantId));
22757
+ this.log.error("Tried to add a track for a participant, that's not present. Sid: ".concat(participantId), this.logContext);
22583
22758
  return;
22584
22759
  }
22585
22760
  let adaptiveStreamSettings;
@@ -22667,7 +22842,9 @@ class Room extends eventsExports.EventEmitter {
22667
22842
  try {
22668
22843
  yield this.audioContext.resume();
22669
22844
  } catch (e) {
22670
- livekitLogger.warn(e);
22845
+ this.log.warn('Could not resume audio context', Object.assign(Object.assign({}, this.logContext), {
22846
+ error: e
22847
+ }));
22671
22848
  }
22672
22849
  }
22673
22850
  if (this.options.expWebAudioMix) {
@@ -22687,13 +22864,16 @@ class Room extends eventsExports.EventEmitter {
22687
22864
  if (info) {
22688
22865
  participant = RemoteParticipant.fromParticipantInfo(this.engine.client, info);
22689
22866
  } else {
22690
- participant = new RemoteParticipant(this.engine.client, id, '', undefined, undefined);
22867
+ participant = new RemoteParticipant(this.engine.client, id, '', undefined, undefined, {
22868
+ loggerContextCb: () => this.logContext,
22869
+ loggerName: this.options.loggerName
22870
+ });
22691
22871
  }
22692
22872
  if (this.options.expWebAudioMix) {
22693
22873
  participant.setAudioContext(this.audioContext);
22694
22874
  }
22695
22875
  if ((_a = this.options.audioOutput) === null || _a === void 0 ? void 0 : _a.deviceId) {
22696
- participant.setAudioOutput(this.options.audioOutput).catch(e => livekitLogger.warn("Could not set audio output: ".concat(e.message)));
22876
+ participant.setAudioOutput(this.options.audioOutput).catch(e => this.log.warn("Could not set audio output: ".concat(e.message), this.logContext));
22697
22877
  }
22698
22878
  return participant;
22699
22879
  }
@@ -22786,9 +22966,9 @@ class Room extends eventsExports.EventEmitter {
22786
22966
  // transports failed without notifying engine
22787
22967
  !this.engine.verifyTransport()) {
22788
22968
  consecutiveFailures++;
22789
- livekitLogger.warn('detected connection state mismatch', {
22969
+ this.log.warn('detected connection state mismatch', Object.assign(Object.assign({}, this.logContext), {
22790
22970
  numFailures: consecutiveFailures
22791
- });
22971
+ }));
22792
22972
  if (consecutiveFailures >= 3) {
22793
22973
  this.recreateEngine();
22794
22974
  this.handleDisconnect(this.options.stopLocalTrackOnUnpublish, DisconnectReason.STATE_MISMATCH);
@@ -22870,7 +23050,13 @@ class Room extends eventsExports.EventEmitter {
22870
23050
  name: 'video-dummy'
22871
23051
  }), new LocalVideoTrack(publishOptions.useRealTracks ? (yield window.navigator.mediaDevices.getUserMedia({
22872
23052
  video: true
22873
- })).getVideoTracks()[0] : createDummyVideoStreamTrack((_a = 160 * participantOptions.aspectRatios[0]) !== null && _a !== void 0 ? _a : 1, 160, true, true)));
23053
+ })).getVideoTracks()[0] : createDummyVideoStreamTrack((_a = 160 * participantOptions.aspectRatios[0]) !== null && _a !== void 0 ? _a : 1, 160, true, true), undefined, false, {
23054
+ loggerName: this.options.loggerName,
23055
+ loggerContextCb: () => this.logContext
23056
+ }), {
23057
+ loggerName: this.options.loggerName,
23058
+ loggerContextCb: () => this.logContext
23059
+ });
22874
23060
  // @ts-ignore
22875
23061
  this.localParticipant.addTrackPublication(camPub);
22876
23062
  this.localParticipant.emit(ParticipantEvent.LocalTrackPublished, camPub);
@@ -22882,7 +23068,13 @@ class Room extends eventsExports.EventEmitter {
22882
23068
  type: TrackType.AUDIO
22883
23069
  }), new LocalAudioTrack(publishOptions.useRealTracks ? (yield navigator.mediaDevices.getUserMedia({
22884
23070
  audio: true
22885
- })).getAudioTracks()[0] : getEmptyAudioStreamTrack()));
23071
+ })).getAudioTracks()[0] : getEmptyAudioStreamTrack(), undefined, false, this.audioContext, {
23072
+ loggerName: this.options.loggerName,
23073
+ loggerContextCb: () => this.logContext
23074
+ }), {
23075
+ loggerName: this.options.loggerName,
23076
+ loggerContextCb: () => this.logContext
23077
+ });
22886
23078
  // @ts-ignore
22887
23079
  this.localParticipant.addTrackPublication(audioPub);
22888
23080
  this.localParticipant.emit(ParticipantEvent.LocalTrackPublished, audioPub);
@@ -22927,14 +23119,30 @@ class Room extends eventsExports.EventEmitter {
22927
23119
  }
22928
23120
  // active speaker updates are too spammy
22929
23121
  if (event !== RoomEvent.ActiveSpeakersChanged) {
22930
- livekitLogger.debug("room event ".concat(event), {
23122
+ // only extract logContext from arguments in order to avoid logging the whole object tree
23123
+ const minimizedArgs = mapArgs(args).filter(arg => arg !== undefined);
23124
+ this.log.debug("room event ".concat(event), Object.assign(Object.assign({}, this.logContext), {
22931
23125
  event,
22932
- args
22933
- });
23126
+ args: minimizedArgs
23127
+ }));
22934
23128
  }
22935
23129
  return super.emit(event, ...args);
22936
23130
  }
22937
23131
  }
23132
+ function mapArgs(args) {
23133
+ return args.map(arg => {
23134
+ if (!arg) {
23135
+ return;
23136
+ }
23137
+ if (Array.isArray(arg)) {
23138
+ return mapArgs(arg);
23139
+ }
23140
+ if (typeof arg === 'object') {
23141
+ return 'logContext' in arg && arg.logContext;
23142
+ }
23143
+ return arg;
23144
+ });
23145
+ }
22938
23146
 
22939
23147
  var CheckStatus;
22940
23148
  (function (CheckStatus) {
@@ -23140,8 +23348,8 @@ function createLocalScreenTracks(options) {
23140
23348
  if (options === undefined) {
23141
23349
  options = {};
23142
23350
  }
23143
- if (options.resolution === undefined) {
23144
- options.resolution = ScreenSharePresets.h1080fps15.resolution;
23351
+ if (options.resolution === undefined && !isSafari17()) {
23352
+ options.resolution = ScreenSharePresets.h1080fps30.resolution;
23145
23353
  }
23146
23354
  if (navigator.mediaDevices.getDisplayMedia === undefined) {
23147
23355
  throw new DeviceUnsupportedError('getDisplayMedia not supported');
@@ -23568,5 +23776,5 @@ function isFacingModeValue(item) {
23568
23776
  return item === undefined || allowedValues.includes(item);
23569
23777
  }
23570
23778
 
23571
- export { AudioPresets, BaseKeyProvider, ConnectionCheck, ConnectionError, ConnectionQuality, ConnectionState, CriticalTimers, CryptorEvent, DataPacket_Kind, DefaultReconnectPolicy, DeviceUnsupportedError, DisconnectReason, EncryptionEvent, EngineEvent, ExternalE2EEKeyProvider, KeyHandlerEvent, KeyProviderEvent, LivekitError, LocalAudioTrack, LocalParticipant, LocalTrack, LocalTrackPublication, LocalVideoTrack, LogLevel, MediaDeviceFailure, NegotiationError, Participant, ParticipantEvent, PublishDataError, RemoteAudioTrack, RemoteParticipant, RemoteTrack, RemoteTrackPublication, RemoteVideoTrack, Room, RoomEvent, RoomState, ScreenSharePresets, Track, TrackEvent, TrackInvalidError, TrackPublication, UnexpectedConnectionState, UnsupportedServer, VideoPreset, VideoPresets, VideoPresets43, VideoQuality, attachToElement, createAudioAnalyser, createE2EEKey, createKeyMaterialFromBuffer, createKeyMaterialFromString, createLocalAudioTrack, createLocalScreenTracks, createLocalTracks, createLocalVideoTrack, deriveKeys, detachTrack, facingModeFromDeviceLabel, facingModeFromLocalTrack, getEmptyAudioStreamTrack, getEmptyVideoStreamTrack, importKey, isBackupCodec, isBrowserSupported, isE2EESupported, isInsertableStreamSupported, isScriptTransformSupported, isVideoFrame, needsRbspUnescaping, parseRbsp, protocolVersion, ratchet, setLogExtension, setLogLevel, supportsAV1, supportsAdaptiveStream, supportsDynacast, supportsVP9, version, videoCodecs, writeRbsp };
23779
+ export { AudioPresets, BaseKeyProvider, ConnectionCheck, ConnectionError, ConnectionQuality, ConnectionState, CriticalTimers, CryptorEvent, DataPacket_Kind, DefaultReconnectPolicy, DeviceUnsupportedError, DisconnectReason, EncryptionEvent, EngineEvent, ExternalE2EEKeyProvider, KeyHandlerEvent, KeyProviderEvent, LivekitError, LocalAudioTrack, LocalParticipant, LocalTrack, LocalTrackPublication, LocalVideoTrack, LogLevel, MediaDeviceFailure, NegotiationError, Participant, ParticipantEvent, PublishDataError, RemoteAudioTrack, RemoteParticipant, RemoteTrack, RemoteTrackPublication, RemoteVideoTrack, Room, RoomEvent, RoomState, ScreenSharePresets, Track, TrackEvent, TrackInvalidError, TrackPublication, UnexpectedConnectionState, UnsupportedServer, VideoPreset, VideoPresets, VideoPresets43, VideoQuality, attachToElement, createAudioAnalyser, createE2EEKey, createKeyMaterialFromBuffer, createKeyMaterialFromString, createLocalAudioTrack, createLocalScreenTracks, createLocalTracks, createLocalVideoTrack, deriveKeys, detachTrack, facingModeFromDeviceLabel, facingModeFromLocalTrack, getEmptyAudioStreamTrack, getEmptyVideoStreamTrack, getLogger, importKey, isBackupCodec, isBrowserSupported, isE2EESupported, isInsertableStreamSupported, isScriptTransformSupported, isVideoFrame, needsRbspUnescaping, parseRbsp, protocolVersion, ratchet, setLogExtension, setLogLevel, supportsAV1, supportsAdaptiveStream, supportsDynacast, supportsVP9, version, videoCodecs, writeRbsp };
23572
23780
  //# sourceMappingURL=livekit-client.esm.mjs.map