livekit-client 1.15.5 → 1.15.7

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 +561 -328
  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 +4 -5
  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 +4 -5
  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 +15 -15
  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 +94 -30
  98. package/src/room/participant/LocalParticipant.ts +163 -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 +27 -20
  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.5";
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,11 +14106,13 @@ 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
  }
14041
14113
  attachToElement(newTrack, this.processorElement);
14114
+ // ensure the processorElement itself stays muted
14115
+ this.processorElement.muted = true;
14042
14116
  yield this.processor.restart({
14043
14117
  track: newTrack,
14044
14118
  kind: this.kind,
@@ -14049,6 +14123,11 @@ class LocalTrack extends Track {
14049
14123
  if (this.sender) {
14050
14124
  yield this.sender.replaceTrack(processedTrack !== null && processedTrack !== void 0 ? processedTrack : newTrack);
14051
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
+ }
14052
14131
  this._mediaStreamTrack = newTrack;
14053
14132
  if (newTrack) {
14054
14133
  // sync muted state with the enabled state of the newly provided track
@@ -14119,7 +14198,7 @@ class LocalTrack extends Track {
14119
14198
  if (!this.sender) {
14120
14199
  throw new TrackInvalidError('unable to replace an unpublished track');
14121
14200
  }
14122
- livekitLogger.debug('replace MediaStreamTrack');
14201
+ this.log.debug('replace MediaStreamTrack', this.logContext);
14123
14202
  yield this.setMediaStreamTrack(track);
14124
14203
  // this must be synced *after* setting mediaStreamTrack above, since it relies
14125
14204
  // on the previous state in order to cleanup
@@ -14135,7 +14214,9 @@ class LocalTrack extends Track {
14135
14214
  if (!constraints) {
14136
14215
  constraints = this._constraints;
14137
14216
  }
14138
- livekitLogger.debug('restarting track with constraints', constraints);
14217
+ this.log.debug('restarting track with constraints', Object.assign(Object.assign({}, this.logContext), {
14218
+ constraints
14219
+ }));
14139
14220
  const streamConstraints = {
14140
14221
  audio: false,
14141
14222
  video: false
@@ -14159,7 +14240,7 @@ class LocalTrack extends Track {
14159
14240
  const mediaStream = yield navigator.mediaDevices.getUserMedia(streamConstraints);
14160
14241
  const newTrack = mediaStream.getTracks()[0];
14161
14242
  newTrack.addEventListener('ended', this.handleEnded);
14162
- livekitLogger.debug('re-acquired MediaStreamTrack');
14243
+ this.log.debug('re-acquired MediaStreamTrack', this.logContext);
14163
14244
  yield this.setMediaStreamTrack(newTrack);
14164
14245
  this._constraints = constraints;
14165
14246
  this.emit(TrackEvent.Restarted, this);
@@ -14167,7 +14248,7 @@ class LocalTrack extends Track {
14167
14248
  });
14168
14249
  }
14169
14250
  setTrackMuted(muted) {
14170
- 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);
14171
14252
  if (this.isMuted === muted && this._mediaStreamTrack.enabled !== muted) {
14172
14253
  return;
14173
14254
  }
@@ -14187,9 +14268,9 @@ class LocalTrack extends Track {
14187
14268
  return __awaiter(this, void 0, void 0, function* () {
14188
14269
  yield _super.handleAppVisibilityChanged.call(this);
14189
14270
  if (!isMobile()) return;
14190
- livekitLogger.debug("visibility changed, is in Background: ".concat(this.isInBackground));
14271
+ this.log.debug("visibility changed, is in Background: ".concat(this.isInBackground), this.logContext);
14191
14272
  if (!this.isInBackground && this.needsReAcquisition && !this.isUserProvided && !this.isMuted) {
14192
- 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);
14193
14274
  yield this.restart();
14194
14275
  this.reacquireTrack = false;
14195
14276
  }
@@ -14218,7 +14299,7 @@ class LocalTrack extends Track {
14218
14299
  return;
14219
14300
  }
14220
14301
  if (!this.sender) {
14221
- livekitLogger.warn('unable to pause upstream for an unpublished track');
14302
+ this.log.warn('unable to pause upstream for an unpublished track', this.logContext);
14222
14303
  return;
14223
14304
  }
14224
14305
  this._isUpstreamPaused = true;
@@ -14242,7 +14323,7 @@ class LocalTrack extends Track {
14242
14323
  return;
14243
14324
  }
14244
14325
  if (!this.sender) {
14245
- livekitLogger.warn('unable to resume upstream for an unpublished track');
14326
+ this.log.warn('unable to resume upstream for an unpublished track', this.logContext);
14246
14327
  return;
14247
14328
  }
14248
14329
  this._isUpstreamPaused = false;
@@ -14286,7 +14367,7 @@ class LocalTrack extends Track {
14286
14367
  return __awaiter(this, void 0, void 0, function* () {
14287
14368
  const unlock = yield this.processorLock.lock();
14288
14369
  try {
14289
- livekitLogger.debug('setting up processor');
14370
+ this.log.debug('setting up processor', this.logContext);
14290
14371
  if (this.processor) {
14291
14372
  yield this.stopProcessor();
14292
14373
  }
@@ -14294,11 +14375,11 @@ class LocalTrack extends Track {
14294
14375
  throw TypeError('cannot set processor on track of unknown kind');
14295
14376
  }
14296
14377
  this.processorElement = (_a = this.processorElement) !== null && _a !== void 0 ? _a : document.createElement(this.kind);
14297
- this.processorElement.muted = true;
14298
14378
  attachToElement(this._mediaStreamTrack, this.processorElement);
14299
- this.processorElement.play().catch(error => livekitLogger.error('failed to play processor element', {
14379
+ this.processorElement.muted = true;
14380
+ this.processorElement.play().catch(error => this.log.error('failed to play processor element', Object.assign(Object.assign({}, this.logContext), {
14300
14381
  error
14301
- }));
14382
+ })));
14302
14383
  const processorOptions = {
14303
14384
  kind: this.kind,
14304
14385
  track: this._mediaStreamTrack,
@@ -14334,7 +14415,7 @@ class LocalTrack extends Track {
14334
14415
  var _a, _b;
14335
14416
  return __awaiter(this, void 0, void 0, function* () {
14336
14417
  if (!this.processor) return;
14337
- livekitLogger.debug('stopping processor');
14418
+ this.log.debug('stopping processor', this.logContext);
14338
14419
  (_a = this.processor.processedTrack) === null || _a === void 0 ? void 0 : _a.stop();
14339
14420
  yield this.processor.destroy();
14340
14421
  this.processor = undefined;
@@ -14756,9 +14837,12 @@ class SignalClient {
14756
14837
  }
14757
14838
  constructor() {
14758
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;
14759
14842
  /** signal rtt in milliseconds */
14760
14843
  this.rtt = 0;
14761
14844
  this.state = SignalConnectionState.DISCONNECTED;
14845
+ this.log = livekitLogger;
14762
14846
  /** @internal */
14763
14847
  this.resetCallbacks = () => {
14764
14848
  this.onAnswer = undefined;
@@ -14773,6 +14857,8 @@ class SignalClient {
14773
14857
  this.onTrickle = undefined;
14774
14858
  this.onClose = undefined;
14775
14859
  };
14860
+ this.log = getLogger((_a = loggerOptions.loggerName) !== null && _a !== void 0 ? _a : LoggerNames.Signal);
14861
+ this.loggerContextCb = loggerOptions.loggerContextCb;
14776
14862
  this.useJSON = useJSON;
14777
14863
  this.requestQueue = new AsyncQueue();
14778
14864
  this.queuedRequests = [];
@@ -14780,6 +14866,10 @@ class SignalClient {
14780
14866
  this.connectionLock = new Mutex();
14781
14867
  this.state = SignalConnectionState.DISCONNECTED;
14782
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
+ }
14783
14873
  join(url, token, opts, abortSignal) {
14784
14874
  return __awaiter(this, void 0, void 0, function* () {
14785
14875
  // during a full reconnect, we'd want to start the sequence even if currently
@@ -14793,7 +14883,7 @@ class SignalClient {
14793
14883
  reconnect(url, token, sid, reason) {
14794
14884
  return __awaiter(this, void 0, void 0, function* () {
14795
14885
  if (!this.options) {
14796
- 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);
14797
14887
  return;
14798
14888
  }
14799
14889
  this.state = SignalConnectionState.RECONNECTING;
@@ -14831,7 +14921,7 @@ class SignalClient {
14831
14921
  abortHandler();
14832
14922
  }
14833
14923
  abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.addEventListener('abort', abortHandler);
14834
- livekitLogger.debug("connecting to ".concat(url + params));
14924
+ this.log.debug("connecting to ".concat(url + params), this.logContext);
14835
14925
  if (this.ws) {
14836
14926
  yield this.close();
14837
14927
  }
@@ -14869,7 +14959,7 @@ class SignalClient {
14869
14959
  } else if (ev.data instanceof ArrayBuffer) {
14870
14960
  resp = SignalResponse.fromBinary(new Uint8Array(ev.data));
14871
14961
  } else {
14872
- 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);
14873
14963
  return;
14874
14964
  }
14875
14965
  if (this.state !== SignalConnectionState.CONNECTED) {
@@ -14881,10 +14971,10 @@ class SignalClient {
14881
14971
  this.pingTimeoutDuration = resp.message.value.pingTimeout;
14882
14972
  this.pingIntervalDuration = resp.message.value.pingInterval;
14883
14973
  if (this.pingTimeoutDuration && this.pingTimeoutDuration > 0) {
14884
- livekitLogger.debug('ping config', {
14974
+ this.log.debug('ping config', Object.assign(Object.assign({}, this.logContext), {
14885
14975
  timeout: this.pingTimeoutDuration,
14886
14976
  interval: this.pingIntervalDuration
14887
- });
14977
+ }));
14888
14978
  this.startPingInterval();
14889
14979
  }
14890
14980
  resolve(resp.message.value);
@@ -14913,9 +15003,9 @@ class SignalClient {
14913
15003
  this.handleSignalResponse(resp);
14914
15004
  });
14915
15005
  this.ws.onclose = ev => {
14916
- livekitLogger.warn("websocket closed", {
14917
- ev
14918
- });
15006
+ this.log.warn("websocket closed", Object.assign(Object.assign({}, this.logContext), {
15007
+ reason: ev.reason
15008
+ }));
14919
15009
  this.handleOnClose(ev.reason);
14920
15010
  };
14921
15011
  } finally {
@@ -14958,7 +15048,9 @@ class SignalClient {
14958
15048
  }
14959
15049
  // initial offer after joining
14960
15050
  sendOffer(offer) {
14961
- livekitLogger.debug('sending offer', offer);
15051
+ this.log.debug('sending offer', Object.assign(Object.assign({}, this.logContext), {
15052
+ offerSdp: offer.sdp
15053
+ }));
14962
15054
  this.sendRequest({
14963
15055
  case: 'offer',
14964
15056
  value: toProtoSessionDescription(offer)
@@ -14966,14 +15058,18 @@ class SignalClient {
14966
15058
  }
14967
15059
  // answer a server-initiated offer
14968
15060
  sendAnswer(answer) {
14969
- livekitLogger.debug('sending answer');
15061
+ this.log.debug('sending answer', Object.assign(Object.assign({}, this.logContext), {
15062
+ answerSdp: answer.sdp
15063
+ }));
14970
15064
  return this.sendRequest({
14971
15065
  case: 'answer',
14972
15066
  value: toProtoSessionDescription(answer)
14973
15067
  });
14974
15068
  }
14975
15069
  sendIceCandidate(candidate, target) {
14976
- livekitLogger.trace('sending ice candidate', candidate);
15070
+ this.log.trace('sending ice candidate', Object.assign(Object.assign({}, this.logContext), {
15071
+ candidate
15072
+ }));
14977
15073
  return this.sendRequest({
14978
15074
  case: 'trickle',
14979
15075
  value: new TrickleRequest({
@@ -15090,7 +15186,7 @@ class SignalClient {
15090
15186
  yield sleep(this.signalLatency);
15091
15187
  }
15092
15188
  if (!this.ws || this.ws.readyState !== this.ws.OPEN) {
15093
- 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);
15094
15190
  return;
15095
15191
  }
15096
15192
  const req = new SignalRequest({
@@ -15103,9 +15199,9 @@ class SignalClient {
15103
15199
  this.ws.send(req.toBinary());
15104
15200
  }
15105
15201
  } catch (e) {
15106
- livekitLogger.error('error sending signal message', {
15202
+ this.log.error('error sending signal message', Object.assign(Object.assign({}, this.logContext), {
15107
15203
  error: e
15108
- });
15204
+ }));
15109
15205
  }
15110
15206
  });
15111
15207
  }
@@ -15113,7 +15209,7 @@ class SignalClient {
15113
15209
  var _a, _b;
15114
15210
  const msg = res.message;
15115
15211
  if (msg == undefined) {
15116
- livekitLogger.debug('received unsupported message');
15212
+ this.log.debug('received unsupported message', this.logContext);
15117
15213
  return;
15118
15214
  }
15119
15215
  let pingHandled = false;
@@ -15189,7 +15285,9 @@ class SignalClient {
15189
15285
  this.resetPingTimeout();
15190
15286
  pingHandled = true;
15191
15287
  } else {
15192
- livekitLogger.debug('unsupported message', msg);
15288
+ this.log.debug('unsupported message', Object.assign(Object.assign({}, this.logContext), {
15289
+ msgCase: msg.case
15290
+ }));
15193
15291
  }
15194
15292
  if (!pingHandled) {
15195
15293
  this.resetPingTimeout();
@@ -15208,14 +15306,18 @@ class SignalClient {
15208
15306
  if (this.state === SignalConnectionState.DISCONNECTED) return;
15209
15307
  const onCloseCallback = this.onClose;
15210
15308
  yield this.close();
15211
- 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
+ }));
15212
15312
  if (onCloseCallback) {
15213
15313
  onCloseCallback(reason);
15214
15314
  }
15215
15315
  });
15216
15316
  }
15217
15317
  handleWSError(ev) {
15218
- livekitLogger.error('websocket error', ev);
15318
+ this.log.error('websocket error', Object.assign(Object.assign({}, this.logContext), {
15319
+ error: ev
15320
+ }));
15219
15321
  }
15220
15322
  /**
15221
15323
  * Resets the ping timeout and starts a new timeout.
@@ -15224,11 +15326,11 @@ class SignalClient {
15224
15326
  resetPingTimeout() {
15225
15327
  this.clearPingTimeout();
15226
15328
  if (!this.pingTimeoutDuration) {
15227
- livekitLogger.warn('ping timeout duration not set');
15329
+ this.log.warn('ping timeout duration not set', this.logContext);
15228
15330
  return;
15229
15331
  }
15230
15332
  this.pingTimeout = CriticalTimers.setTimeout(() => {
15231
- 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);
15232
15334
  this.handleOnClose('ping timeout');
15233
15335
  }, this.pingTimeoutDuration * 1000);
15234
15336
  }
@@ -15244,16 +15346,16 @@ class SignalClient {
15244
15346
  this.clearPingInterval();
15245
15347
  this.resetPingTimeout();
15246
15348
  if (!this.pingIntervalDuration) {
15247
- livekitLogger.warn('ping interval duration not set');
15349
+ this.log.warn('ping interval duration not set', this.logContext);
15248
15350
  return;
15249
15351
  }
15250
- livekitLogger.debug('start ping interval');
15352
+ this.log.debug('start ping interval', this.logContext);
15251
15353
  this.pingInterval = CriticalTimers.setInterval(() => {
15252
15354
  this.sendPing();
15253
15355
  }, this.pingIntervalDuration * 1000);
15254
15356
  }
15255
15357
  clearPingInterval() {
15256
- livekitLogger.debug('clearing ping interval');
15358
+ this.log.debug('clearing ping interval', this.logContext);
15257
15359
  this.clearPingTimeout();
15258
15360
  if (this.pingInterval) {
15259
15361
  CriticalTimers.clearInterval(this.pingInterval);
@@ -16018,7 +16120,10 @@ class PCTransport extends eventsExports.EventEmitter {
16018
16120
  }
16019
16121
  constructor(config) {
16020
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;
16021
16125
  super();
16126
+ this.log = livekitLogger;
16022
16127
  this.pendingCandidates = [];
16023
16128
  this.restartingIce = false;
16024
16129
  this.renegotiate = false;
@@ -16056,6 +16161,8 @@ class PCTransport extends eventsExports.EventEmitter {
16056
16161
  this._pc.oniceconnectionstatechange = null;
16057
16162
  this._pc = null;
16058
16163
  };
16164
+ this.log = getLogger((_a = loggerOptions.loggerName) !== null && _a !== void 0 ? _a : LoggerNames.PCTransport);
16165
+ this.loggerOptions = loggerOptions;
16059
16166
  this.config = config;
16060
16167
  this.mediaConstraints = mediaConstraints;
16061
16168
  this._pc = this.createPC();
@@ -16095,6 +16202,10 @@ class PCTransport extends eventsExports.EventEmitter {
16095
16202
  };
16096
16203
  return pc;
16097
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
+ }
16098
16209
  get isICEConnected() {
16099
16210
  return this._pc !== null && (this.pc.iceConnectionState === 'connected' || this.pc.iceConnectionState === 'completed');
16100
16211
  }
@@ -16191,7 +16302,7 @@ class PCTransport extends eventsExports.EventEmitter {
16191
16302
  return;
16192
16303
  }
16193
16304
  if (options === null || options === void 0 ? void 0 : options.iceRestart) {
16194
- livekitLogger.debug('restarting ICE');
16305
+ this.log.debug('restarting ICE', this.logContext);
16195
16306
  this.restartingIce = true;
16196
16307
  }
16197
16308
  if (this._pc && this._pc.signalingState === 'have-local-offer') {
@@ -16207,11 +16318,11 @@ class PCTransport extends eventsExports.EventEmitter {
16207
16318
  return;
16208
16319
  }
16209
16320
  } else if (!this._pc || this._pc.signalingState === 'closed') {
16210
- livekitLogger.warn('could not createOffer with closed peer connection');
16321
+ this.log.warn('could not createOffer with closed peer connection', this.logContext);
16211
16322
  return;
16212
16323
  }
16213
16324
  // actually negotiate
16214
- livekitLogger.debug('starting to negotiate');
16325
+ this.log.debug('starting to negotiate', this.logContext);
16215
16326
  const offer = yield this.pc.createOffer(options);
16216
16327
  const sdpParsed = parse((_a = offer.sdp) !== null && _a !== void 0 ? _a : '');
16217
16328
  sdpParsed.media.forEach(media => {
@@ -16380,7 +16491,7 @@ class PCTransport extends eventsExports.EventEmitter {
16380
16491
  const originalSdp = sd.sdp;
16381
16492
  sd.sdp = munged;
16382
16493
  try {
16383
- livekitLogger.debug("setting munged ".concat(remote ? 'remote' : 'local', " description"));
16494
+ this.log.debug("setting munged ".concat(remote ? 'remote' : 'local', " description"), this.logContext);
16384
16495
  if (remote) {
16385
16496
  yield this.pc.setRemoteDescription(sd);
16386
16497
  } else {
@@ -16388,10 +16499,10 @@ class PCTransport extends eventsExports.EventEmitter {
16388
16499
  }
16389
16500
  return;
16390
16501
  } catch (e) {
16391
- 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), {
16392
16503
  error: e,
16393
16504
  sdp: munged
16394
- });
16505
+ }));
16395
16506
  sd.sdp = originalSdp;
16396
16507
  }
16397
16508
  }
@@ -16417,7 +16528,9 @@ class PCTransport extends eventsExports.EventEmitter {
16417
16528
  if (!remote && this.pc.remoteDescription) {
16418
16529
  fields.remoteSdp = this.pc.remoteDescription;
16419
16530
  }
16420
- 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
+ }));
16421
16534
  throw new NegotiationError(msg);
16422
16535
  }
16423
16536
  });
@@ -16574,8 +16687,10 @@ class PCTransportManager {
16574
16687
  get currentState() {
16575
16688
  return this.state;
16576
16689
  }
16577
- constructor(rtcConfig, subscriberPrimary) {
16690
+ constructor(rtcConfig, subscriberPrimary, loggerOptions) {
16691
+ var _a;
16578
16692
  this.peerConnectionTimeout = roomConnectOptionDefaults.peerConnectionTimeout;
16693
+ this.log = livekitLogger;
16579
16694
  this.updateState = () => {
16580
16695
  var _a;
16581
16696
  const previousState = this.state;
@@ -16594,10 +16709,12 @@ class PCTransportManager {
16594
16709
  this.state = PCTransportState.NEW;
16595
16710
  }
16596
16711
  if (previousState !== this.state) {
16597
- 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);
16598
16713
  (_a = this.onStateChange) === null || _a === void 0 ? void 0 : _a.call(this, this.state, this.publisher.getConnectionState(), this.subscriber.getConnectionState());
16599
16714
  }
16600
16715
  };
16716
+ this.log = getLogger((_a = loggerOptions.loggerName) !== null && _a !== void 0 ? _a : LoggerNames.PCManager);
16717
+ this.loggerOptions = loggerOptions;
16601
16718
  this.isPublisherConnectionRequired = !subscriberPrimary;
16602
16719
  this.isSubscriberConnectionRequired = subscriberPrimary;
16603
16720
  const googConstraints = {
@@ -16605,8 +16722,8 @@ class PCTransportManager {
16605
16722
  googDscp: true
16606
16723
  }]
16607
16724
  };
16608
- this.publisher = new PCTransport(rtcConfig, googConstraints);
16609
- this.subscriber = new PCTransport(rtcConfig);
16725
+ this.publisher = new PCTransport(rtcConfig, googConstraints, loggerOptions);
16726
+ this.subscriber = new PCTransport(rtcConfig, loggerOptions);
16610
16727
  this.publisher.onConnectionStateChange = this.updateState;
16611
16728
  this.subscriber.onConnectionStateChange = this.updateState;
16612
16729
  this.publisher.onIceConnectionStateChange = this.updateState;
@@ -16637,6 +16754,10 @@ class PCTransportManager {
16637
16754
  this.state = PCTransportState.NEW;
16638
16755
  this.connectionLock = new Mutex();
16639
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
+ }
16640
16761
  requirePublisher() {
16641
16762
  let require = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
16642
16763
  this.isPublisherConnectionRequired = require;
@@ -16667,9 +16788,9 @@ class PCTransportManager {
16667
16788
  publisher.removeTrack(sender);
16668
16789
  }
16669
16790
  } catch (e) {
16670
- livekitLogger.warn('could not removeTrack', {
16791
+ this.log.warn('could not removeTrack', Object.assign(Object.assign({}, this.logContext), {
16671
16792
  error: e
16672
- });
16793
+ }));
16673
16794
  }
16674
16795
  }
16675
16796
  }
@@ -16699,10 +16820,10 @@ class PCTransportManager {
16699
16820
  }
16700
16821
  createSubscriberAnswerFromOffer(sd) {
16701
16822
  return __awaiter(this, void 0, void 0, function* () {
16702
- livekitLogger.debug('received server offer', {
16823
+ this.log.debug('received server offer', Object.assign(Object.assign({}, this.logContext), {
16703
16824
  RTCSdpType: sd.type,
16704
16825
  signalingState: this.subscriber.getSignallingState().toString()
16705
- });
16826
+ }));
16706
16827
  yield this.subscriber.setRemoteDescription(sd);
16707
16828
  // answer the offer
16708
16829
  const answer = yield this.subscriber.createAndSetAnswer();
@@ -16722,7 +16843,7 @@ class PCTransportManager {
16722
16843
  const unlock = yield this.connectionLock.lock();
16723
16844
  try {
16724
16845
  if (this.isPublisherConnectionRequired && this.publisher.getConnectionState() !== 'connected' && this.publisher.getConnectionState() !== 'connecting') {
16725
- livekitLogger.debug('negotiation required, start negotiating');
16846
+ this.log.debug('negotiation required, start negotiating', this.logContext);
16726
16847
  this.publisher.negotiate();
16727
16848
  }
16728
16849
  yield Promise.all((_a = this.requiredTransports) === null || _a === void 0 ? void 0 : _a.map(transport => this.ensureTransportConnected(transport, abortController, timeout)));
@@ -16797,7 +16918,7 @@ class PCTransportManager {
16797
16918
  }
16798
16919
  return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
16799
16920
  const abortHandler = () => {
16800
- livekitLogger.warn('abort transport connection');
16921
+ this.log.warn('abort transport connection', this.logContext);
16801
16922
  CriticalTimers.clearTimeout(connectTimeout);
16802
16923
  reject(new ConnectionError('room connection has been cancelled', 3 /* ConnectionErrorReason.Cancelled */));
16803
16924
  };
@@ -16842,6 +16963,7 @@ class RTCEngine extends eventsExports.EventEmitter {
16842
16963
  return this._isClosed;
16843
16964
  }
16844
16965
  constructor(options) {
16966
+ var _a;
16845
16967
  super();
16846
16968
  this.options = options;
16847
16969
  this.rtcConfig = {};
@@ -16859,6 +16981,7 @@ class RTCEngine extends eventsExports.EventEmitter {
16859
16981
  /** specifies how often an initial join connection is allowed to retry */
16860
16982
  this.maxJoinAttempts = 1;
16861
16983
  this.shouldFailNext = false;
16984
+ this.log = livekitLogger;
16862
16985
  this.handleDataChannel = _ref => {
16863
16986
  let {
16864
16987
  channel
@@ -16874,12 +16997,12 @@ class RTCEngine extends eventsExports.EventEmitter {
16874
16997
  } else {
16875
16998
  return;
16876
16999
  }
16877
- 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);
16878
17001
  channel.onmessage = this.handleDataMessage;
16879
17002
  });
16880
17003
  };
16881
17004
  this.handleDataMessage = message => __awaiter(this, void 0, void 0, function* () {
16882
- var _a, _b;
17005
+ var _b, _c;
16883
17006
  // make sure to respect incoming data message order by processing message events one after the other
16884
17007
  const unlock = yield this.dataProcessLock.lock();
16885
17008
  try {
@@ -16890,14 +17013,16 @@ class RTCEngine extends eventsExports.EventEmitter {
16890
17013
  } else if (message.data instanceof Blob) {
16891
17014
  buffer = yield message.data.arrayBuffer();
16892
17015
  } else {
16893
- 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
+ }));
16894
17019
  return;
16895
17020
  }
16896
17021
  const dp = DataPacket.fromBinary(new Uint8Array(buffer));
16897
- 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') {
16898
17023
  // dispatch speaker updates
16899
17024
  this.emit(EngineEvent.ActiveSpeakersUpdate, dp.value.value.speakers);
16900
- } 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') {
16901
17026
  this.emit(EngineEvent.DataPacketReceived, dp.value.value, dp.kind);
16902
17027
  }
16903
17028
  } finally {
@@ -16911,9 +17036,13 @@ class RTCEngine extends eventsExports.EventEmitter {
16911
17036
  const {
16912
17037
  error
16913
17038
  } = event.error;
16914
- 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
+ }));
16915
17042
  } else {
16916
- 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
+ }));
16917
17046
  }
16918
17047
  };
16919
17048
  this.handleBufferedAmountLow = event => {
@@ -16928,13 +17057,13 @@ class RTCEngine extends eventsExports.EventEmitter {
16928
17057
  if (this._isClosed) {
16929
17058
  return;
16930
17059
  }
16931
- livekitLogger.warn("".concat(connection, " disconnected"));
17060
+ this.log.warn("".concat(connection, " disconnected"), this.logContext);
16932
17061
  if (this.reconnectAttempts === 0) {
16933
17062
  // only reset start time on the first try
16934
17063
  this.reconnectStart = Date.now();
16935
17064
  }
16936
17065
  const disconnect = duration => {
16937
- 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);
16938
17067
  this.emit(EngineEvent.Disconnected);
16939
17068
  this.close();
16940
17069
  };
@@ -16950,7 +17079,7 @@ class RTCEngine extends eventsExports.EventEmitter {
16950
17079
  if (connection === leaveReconnect) {
16951
17080
  delay = 0;
16952
17081
  }
16953
- livekitLogger.debug("reconnecting in ".concat(delay, "ms"));
17082
+ this.log.debug("reconnecting in ".concat(delay, "ms"), this.logContext);
16954
17083
  this.clearReconnectTimeout();
16955
17084
  if (this.token && this.regionUrlProvider) {
16956
17085
  // token may have been refreshed, we do not want to recreate the regionUrlProvider
@@ -16996,7 +17125,12 @@ class RTCEngine extends eventsExports.EventEmitter {
16996
17125
  this.attemptReconnect(ReconnectReason.RR_SIGNAL_DISCONNECTED);
16997
17126
  }
16998
17127
  };
16999
- 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);
17000
17134
  this.client.signalLatency = this.options.expSignalLatency;
17001
17135
  this.reconnectPolicy = this.options.reconnectPolicy;
17002
17136
  this.registerOnLineListener();
@@ -17011,6 +17145,15 @@ class RTCEngine extends eventsExports.EventEmitter {
17011
17145
  this.client.onSpeakersChanged = update => this.emit(EngineEvent.SpeakersChanged, update);
17012
17146
  this.client.onStreamStateUpdate = update => this.emit(EngineEvent.StreamStateChanged, update);
17013
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
+ }
17014
17157
  join(url, token, opts, abortSignal) {
17015
17158
  return __awaiter(this, void 0, void 0, function* () {
17016
17159
  this.url = url;
@@ -17036,7 +17179,7 @@ class RTCEngine extends eventsExports.EventEmitter {
17036
17179
  } catch (e) {
17037
17180
  if (e instanceof ConnectionError) {
17038
17181
  if (e.reason === 1 /* ConnectionErrorReason.ServerUnreachable */) {
17039
- 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);
17040
17183
  if (this.joinAttempts < this.maxJoinAttempts) {
17041
17184
  return this.join(url, token, opts, abortSignal);
17042
17185
  }
@@ -17139,10 +17282,9 @@ class RTCEngine extends eventsExports.EventEmitter {
17139
17282
  this.pcManager.removeTrack(sender);
17140
17283
  return true;
17141
17284
  } catch (e) {
17142
- livekitLogger.warn('failed to remove track', {
17143
- error: e,
17144
- method: 'removeTrack'
17145
- });
17285
+ this.log.warn('failed to remove track', Object.assign(Object.assign({}, this.logContext), {
17286
+ error: e
17287
+ }));
17146
17288
  }
17147
17289
  return false;
17148
17290
  }
@@ -17172,7 +17314,7 @@ class RTCEngine extends eventsExports.EventEmitter {
17172
17314
  }
17173
17315
  this.participantSid = (_a = joinResponse.participant) === null || _a === void 0 ? void 0 : _a.sid;
17174
17316
  const rtcConfig = this.makeRTCConfiguration(joinResponse);
17175
- this.pcManager = new PCTransportManager(rtcConfig, joinResponse.subscriberPrimary);
17317
+ this.pcManager = new PCTransportManager(rtcConfig, joinResponse.subscriberPrimary, this.loggerOptions);
17176
17318
  this.emit(EngineEvent.TransportsCreated, this.pcManager.publisher, this.pcManager.subscriber);
17177
17319
  this.pcManager.onIceCandidate = (candidate, target) => {
17178
17320
  this.client.sendIceCandidate(candidate, target);
@@ -17182,7 +17324,7 @@ class RTCEngine extends eventsExports.EventEmitter {
17182
17324
  };
17183
17325
  this.pcManager.onDataChannel = this.handleDataChannel;
17184
17326
  this.pcManager.onStateChange = (connectionState, publisherState, subscriberState) => __awaiter(this, void 0, void 0, function* () {
17185
- livekitLogger.debug("primary PC state changed ".concat(connectionState));
17327
+ this.log.debug("primary PC state changed ".concat(connectionState), this.logContext);
17186
17328
  if (connectionState === PCTransportState.CONNECTED) {
17187
17329
  const shouldEmit = this.pcState === PCState.New;
17188
17330
  this.pcState = PCState.Connected;
@@ -17209,9 +17351,9 @@ class RTCEngine extends eventsExports.EventEmitter {
17209
17351
  if (!this.pcManager) {
17210
17352
  return;
17211
17353
  }
17212
- livekitLogger.debug('received server answer', {
17354
+ this.log.debug('received server answer', Object.assign(Object.assign({}, this.logContext), {
17213
17355
  RTCSdpType: sd.type
17214
- });
17356
+ }));
17215
17357
  yield this.pcManager.setPublisherAnswer(sd);
17216
17358
  });
17217
17359
  // add candidate on trickle
@@ -17219,10 +17361,10 @@ class RTCEngine extends eventsExports.EventEmitter {
17219
17361
  if (!this.pcManager) {
17220
17362
  return;
17221
17363
  }
17222
- livekitLogger.trace('got ICE candidate from peer', {
17364
+ this.log.trace('got ICE candidate from peer', Object.assign(Object.assign({}, this.logContext), {
17223
17365
  candidate,
17224
17366
  target
17225
- });
17367
+ }));
17226
17368
  this.pcManager.addIceCandidate(candidate, target);
17227
17369
  };
17228
17370
  // when server creates an offer for the client
@@ -17234,9 +17376,15 @@ class RTCEngine extends eventsExports.EventEmitter {
17234
17376
  this.client.sendAnswer(answer);
17235
17377
  });
17236
17378
  this.client.onLocalTrackPublished = res => {
17237
- 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
+ }));
17238
17384
  if (!this.pendingTrackResolvers[res.cid]) {
17239
- 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
+ }));
17240
17388
  return;
17241
17389
  }
17242
17390
  const {
@@ -17266,16 +17414,16 @@ class RTCEngine extends eventsExports.EventEmitter {
17266
17414
  this.emit(EngineEvent.Disconnected, leave === null || leave === void 0 ? void 0 : leave.reason);
17267
17415
  this.close();
17268
17416
  }
17269
- livekitLogger.trace('leave request', {
17270
- leave
17271
- });
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
+ }));
17272
17420
  };
17273
17421
  }
17274
17422
  makeRTCConfiguration(serverResponse) {
17275
17423
  var _a;
17276
17424
  const rtcConfig = Object.assign({}, this.rtcConfig);
17277
17425
  if ((_a = this.signalOpts) === null || _a === void 0 ? void 0 : _a.e2eeEnabled) {
17278
- livekitLogger.debug('E2EE - setting up transports with insertable streams');
17426
+ this.log.debug('E2EE - setting up transports with insertable streams', this.logContext);
17279
17427
  // this makes sure that no data is sent before the transforms are ready
17280
17428
  // @ts-ignore
17281
17429
  rtcConfig.encodedInsertableStreams = true;
@@ -17345,7 +17493,9 @@ class RTCEngine extends eventsExports.EventEmitter {
17345
17493
  }
17346
17494
  const cap = RTCRtpSender.getCapabilities(kind);
17347
17495
  if (!cap) return;
17348
- livekitLogger.debug('get capabilities', cap);
17496
+ this.log.debug('get sender capabilities', Object.assign(Object.assign({}, this.logContext), {
17497
+ cap
17498
+ }));
17349
17499
  const matched = [];
17350
17500
  const partialMatched = [];
17351
17501
  const unmatched = [];
@@ -17383,7 +17533,7 @@ class RTCEngine extends eventsExports.EventEmitter {
17383
17533
  return sender;
17384
17534
  }
17385
17535
  if (supportsAddTrack()) {
17386
- livekitLogger.warn('using add-track fallback');
17536
+ this.log.warn('using add-track fallback', this.logContext);
17387
17537
  const sender = yield this.createRTCRtpSender(track.mediaStreamTrack);
17388
17538
  return sender;
17389
17539
  }
@@ -17397,7 +17547,7 @@ class RTCEngine extends eventsExports.EventEmitter {
17397
17547
  return this.createSimulcastTransceiverSender(track, simulcastTrack, opts, encodings);
17398
17548
  }
17399
17549
  if (supportsAddTrack()) {
17400
- livekitLogger.debug('using add-track fallback');
17550
+ this.log.debug('using add-track fallback', this.logContext);
17401
17551
  return this.createRTCRtpSender(track.mediaStreamTrack);
17402
17552
  }
17403
17553
  throw new UnexpectedConnectionState('Cannot stream on this device');
@@ -17486,9 +17636,9 @@ class RTCEngine extends eventsExports.EventEmitter {
17486
17636
  this.reconnectAttempts += 1;
17487
17637
  let recoverable = true;
17488
17638
  if (e instanceof UnexpectedConnectionState) {
17489
- livekitLogger.debug('received unrecoverable error', {
17639
+ this.log.debug('received unrecoverable error', Object.assign(Object.assign({}, this.logContext), {
17490
17640
  error: e
17491
- });
17641
+ }));
17492
17642
  // unrecoverable
17493
17643
  recoverable = false;
17494
17644
  } else if (!(e instanceof SignalReconnectError)) {
@@ -17498,7 +17648,7 @@ class RTCEngine extends eventsExports.EventEmitter {
17498
17648
  if (recoverable) {
17499
17649
  this.handleDisconnect('reconnect', ReconnectReason.RR_UNKNOWN);
17500
17650
  } else {
17501
- 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);
17502
17652
  this.emit(EngineEvent.Disconnected);
17503
17653
  yield this.close();
17504
17654
  }
@@ -17511,9 +17661,9 @@ class RTCEngine extends eventsExports.EventEmitter {
17511
17661
  try {
17512
17662
  return this.reconnectPolicy.nextRetryDelayInMs(context);
17513
17663
  } catch (e) {
17514
- livekitLogger.warn('encountered error in reconnect policy', {
17664
+ this.log.warn('encountered error in reconnect policy', Object.assign(Object.assign({}, this.logContext), {
17515
17665
  error: e
17516
- });
17666
+ }));
17517
17667
  }
17518
17668
  // error in user code with provided reconnect policy, stop reconnecting
17519
17669
  return null;
@@ -17526,7 +17676,7 @@ class RTCEngine extends eventsExports.EventEmitter {
17526
17676
  // permanent failure, don't attempt reconnection
17527
17677
  throw new UnexpectedConnectionState('could not reconnect, url or token not saved');
17528
17678
  }
17529
- livekitLogger.info("reconnecting, attempt: ".concat(this.reconnectAttempts));
17679
+ this.log.info("reconnecting, attempt: ".concat(this.reconnectAttempts), this.logContext);
17530
17680
  this.emit(EngineEvent.Restarting);
17531
17681
  if (!this.client.isDisconnected) {
17532
17682
  yield this.client.sendLeave();
@@ -17536,7 +17686,7 @@ class RTCEngine extends eventsExports.EventEmitter {
17536
17686
  let joinResponse;
17537
17687
  try {
17538
17688
  if (!this.signalOpts) {
17539
- livekitLogger.warn('attempted connection restart, without signal options present');
17689
+ this.log.warn('attempted connection restart, without signal options present', this.logContext);
17540
17690
  throw new SignalReconnectError();
17541
17691
  }
17542
17692
  // in case a regionUrl is passed, the region URL takes precedence
@@ -17581,7 +17731,7 @@ class RTCEngine extends eventsExports.EventEmitter {
17581
17731
  if (!this.pcManager) {
17582
17732
  throw new UnexpectedConnectionState('publisher and subscriber connections unset');
17583
17733
  }
17584
- livekitLogger.info("resuming signal connection, attempt ".concat(this.reconnectAttempts));
17734
+ this.log.info("resuming signal connection, attempt ".concat(this.reconnectAttempts), this.logContext);
17585
17735
  this.emit(EngineEvent.Resuming);
17586
17736
  try {
17587
17737
  this.setupSignalClientCallbacks();
@@ -17594,7 +17744,7 @@ class RTCEngine extends eventsExports.EventEmitter {
17594
17744
  let message = '';
17595
17745
  if (e instanceof Error) {
17596
17746
  message = e.message;
17597
- livekitLogger.error(e.message);
17747
+ this.log.error(e.message, this.logContext);
17598
17748
  }
17599
17749
  if (e instanceof ConnectionError && e.reason === 0 /* ConnectionErrorReason.NotAllowed */) {
17600
17750
  throw new UnexpectedConnectionState('could not reconnect, token might be expired');
@@ -17629,7 +17779,7 @@ class RTCEngine extends eventsExports.EventEmitter {
17629
17779
  waitForPCReconnected() {
17630
17780
  return __awaiter(this, void 0, void 0, function* () {
17631
17781
  this.pcState = PCState.Reconnecting;
17632
- livekitLogger.debug('waiting for peer connection to reconnect');
17782
+ this.log.debug('waiting for peer connection to reconnect', this.logContext);
17633
17783
  try {
17634
17784
  yield sleep(minReconnectWait); // FIXME setTimeout again not ideal for a connection critical path
17635
17785
  if (!this.pcManager) {
@@ -17724,7 +17874,7 @@ class RTCEngine extends eventsExports.EventEmitter {
17724
17874
  const abortController = new AbortController();
17725
17875
  const handleClosed = () => {
17726
17876
  abortController.abort();
17727
- livekitLogger.debug('engine disconnected while negotiation was ongoing');
17877
+ this.log.debug('engine disconnected while negotiation was ongoing', this.logContext);
17728
17878
  resolve();
17729
17879
  return;
17730
17880
  };
@@ -17778,7 +17928,7 @@ class RTCEngine extends eventsExports.EventEmitter {
17778
17928
  sendSyncState(remoteTracks, localTracks) {
17779
17929
  var _a, _b;
17780
17930
  if (!this.pcManager) {
17781
- 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);
17782
17932
  return;
17783
17933
  }
17784
17934
  const previousAnswer = this.pcManager.subscriber.getLocalDescription();
@@ -17949,7 +18099,8 @@ class LocalAudioTrack extends LocalTrack {
17949
18099
  constructor(mediaTrack, constraints) {
17950
18100
  let userProvidedTrack = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
17951
18101
  let audioContext = arguments.length > 3 ? arguments[3] : undefined;
17952
- 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);
17953
18104
  /** @internal */
17954
18105
  this.stopOnMute = false;
17955
18106
  this.monitorSender = () => __awaiter(this, void 0, void 0, function* () {
@@ -17961,9 +18112,9 @@ class LocalAudioTrack extends LocalTrack {
17961
18112
  try {
17962
18113
  stats = yield this.getSenderStats();
17963
18114
  } catch (e) {
17964
- livekitLogger.error('could not get audio sender stats', {
18115
+ this.log.error('could not get audio sender stats', Object.assign(Object.assign({}, this.logContext), {
17965
18116
  error: e
17966
- });
18117
+ }));
17967
18118
  return;
17968
18119
  }
17969
18120
  if (stats && this.prevStats) {
@@ -17997,7 +18148,7 @@ class LocalAudioTrack extends LocalTrack {
17997
18148
  try {
17998
18149
  // disabled special handling as it will cause BT headsets to switch communication modes
17999
18150
  if (this.source === Track.Source.Microphone && this.stopOnMute && !this.isUserProvided) {
18000
- livekitLogger.debug('stopping mic track');
18151
+ this.log.debug('stopping mic track', this.logContext);
18001
18152
  // also stop the track, so that microphone indicator is turned off
18002
18153
  this._mediaStreamTrack.stop();
18003
18154
  }
@@ -18019,7 +18170,7 @@ class LocalAudioTrack extends LocalTrack {
18019
18170
  try {
18020
18171
  const deviceHasChanged = this._constraints.deviceId && this._mediaStreamTrack.getSettings().deviceId !== unwrapConstraint(this._constraints.deviceId);
18021
18172
  if (this.source === Track.Source.Microphone && (this.stopOnMute || this._mediaStreamTrack.readyState === 'ended' || deviceHasChanged) && !this.isUserProvided) {
18022
- livekitLogger.debug('reacquiring mic track');
18173
+ this.log.debug('reacquiring mic track', this.logContext);
18023
18174
  yield this.restartTrack();
18024
18175
  }
18025
18176
  yield _super.unmute.call(this);
@@ -18086,7 +18237,7 @@ class LocalAudioTrack extends LocalTrack {
18086
18237
  track: this._mediaStreamTrack,
18087
18238
  audioContext: this.audioContext
18088
18239
  };
18089
- livekitLogger.debug("setting up audio processor ".concat(processor.name));
18240
+ this.log.debug("setting up audio processor ".concat(processor.name), this.logContext);
18090
18241
  yield processor.init(processorOptions);
18091
18242
  this.processor = processor;
18092
18243
  if (this.processor.processedTrack) {
@@ -18134,7 +18285,7 @@ class LocalAudioTrack extends LocalTrack {
18134
18285
  const trackIsSilent = yield detectSilence(this);
18135
18286
  if (trackIsSilent) {
18136
18287
  if (!this.isMuted) {
18137
- livekitLogger.warn('silence detected on local audio track');
18288
+ this.log.warn('silence detected on local audio track', this.logContext);
18138
18289
  }
18139
18290
  this.emit(TrackEvent.AudioSilenceDetected);
18140
18291
  }
@@ -18144,12 +18295,12 @@ class LocalAudioTrack extends LocalTrack {
18144
18295
  }
18145
18296
 
18146
18297
  /** @internal */
18147
- function mediaTrackToLocalTrack(mediaStreamTrack, constraints) {
18298
+ function mediaTrackToLocalTrack(mediaStreamTrack, constraints, loggerOptions) {
18148
18299
  switch (mediaStreamTrack.kind) {
18149
18300
  case 'audio':
18150
- return new LocalAudioTrack(mediaStreamTrack, constraints, false);
18301
+ return new LocalAudioTrack(mediaStreamTrack, constraints, false, undefined, loggerOptions);
18151
18302
  case 'video':
18152
- return new LocalVideoTrack(mediaStreamTrack, constraints, false);
18303
+ return new LocalVideoTrack(mediaStreamTrack, constraints, false, loggerOptions);
18153
18304
  default:
18154
18305
  throw new TrackInvalidError("unsupported track type: ".concat(mediaStreamTrack.kind));
18155
18306
  }
@@ -18168,11 +18319,11 @@ const defaultSimulcastPresets43 = [VideoPresets43.h180, VideoPresets43.h360];
18168
18319
  const computeDefaultScreenShareSimulcastPresets = fromPreset => {
18169
18320
  const layers = [{
18170
18321
  scaleResolutionDownBy: 2,
18171
- fps: 3
18322
+ fps: fromPreset.encoding.maxFramerate
18172
18323
  }];
18173
18324
  return layers.map(t => {
18174
- var _a;
18175
- 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);
18176
18327
  });
18177
18328
  };
18178
18329
  // /**
@@ -18454,7 +18605,8 @@ class LocalVideoTrack extends LocalTrack {
18454
18605
  */
18455
18606
  constructor(mediaTrack, constraints) {
18456
18607
  let userProvidedTrack = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
18457
- 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);
18458
18610
  /* @internal */
18459
18611
  this.simulcastCodecs = new Map();
18460
18612
  this.monitorSender = () => __awaiter(this, void 0, void 0, function* () {
@@ -18466,9 +18618,9 @@ class LocalVideoTrack extends LocalTrack {
18466
18618
  try {
18467
18619
  stats = yield this.getSenderStats();
18468
18620
  } catch (e) {
18469
- livekitLogger.error('could not get audio sender stats', {
18621
+ this.log.error('could not get audio sender stats', Object.assign(Object.assign({}, this.logContext), {
18470
18622
  error: e
18471
- });
18623
+ }));
18472
18624
  return;
18473
18625
  }
18474
18626
  const statsMap = new Map(stats.map(s => [s.rid, s]));
@@ -18588,7 +18740,7 @@ class LocalVideoTrack extends LocalTrack {
18588
18740
  const unlock = yield this.muteLock.lock();
18589
18741
  try {
18590
18742
  if (this.source === Track.Source.Camera && !this.isUserProvided) {
18591
- livekitLogger.debug('stopping camera track');
18743
+ this.log.debug('stopping camera track', this.logContext);
18592
18744
  // also stop the track, so that camera indicator is turned off
18593
18745
  this._mediaStreamTrack.stop();
18594
18746
  }
@@ -18609,7 +18761,7 @@ class LocalVideoTrack extends LocalTrack {
18609
18761
  const unlock = yield this.muteLock.lock();
18610
18762
  try {
18611
18763
  if (this.source === Track.Source.Camera && !this.isUserProvided) {
18612
- livekitLogger.debug('reacquiring camera track');
18764
+ this.log.debug('reacquiring camera track', this.logContext);
18613
18765
  yield this.restartTrack();
18614
18766
  }
18615
18767
  yield _super.unmute.call(this);
@@ -18674,7 +18826,7 @@ class LocalVideoTrack extends LocalTrack {
18674
18826
  enabled: q <= maxQuality
18675
18827
  }));
18676
18828
  }
18677
- livekitLogger.debug("setting publishing quality. max quality ".concat(maxQuality));
18829
+ this.log.debug("setting publishing quality. max quality ".concat(maxQuality), this.logContext);
18678
18830
  this.setPublishingLayers(qualities);
18679
18831
  }
18680
18832
  setDeviceId(deviceId) {
@@ -18796,10 +18948,10 @@ class LocalVideoTrack extends LocalTrack {
18796
18948
  var _a, codecs_1, codecs_1_1;
18797
18949
  var _b, e_5, _c, _d;
18798
18950
  return __awaiter(this, void 0, void 0, function* () {
18799
- livekitLogger.debug('setting publishing codecs', {
18951
+ this.log.debug('setting publishing codecs', Object.assign(Object.assign({}, this.logContext), {
18800
18952
  codecs,
18801
18953
  currentCodec: this.codec
18802
- });
18954
+ }));
18803
18955
  // only enable simulcast codec for preference codec setted
18804
18956
  if (!this.codec && codecs.length > 0) {
18805
18957
  yield this.setPublishingLayers(codecs[0].qualities);
@@ -18816,7 +18968,9 @@ class LocalVideoTrack extends LocalTrack {
18816
18968
  yield this.setPublishingLayers(codec.qualities);
18817
18969
  } else {
18818
18970
  const simulcastCodecInfo = this.simulcastCodecs.get(codec.codec);
18819
- 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
+ }));
18820
18974
  if (!simulcastCodecInfo || !simulcastCodecInfo.sender) {
18821
18975
  for (const q of codec.qualities) {
18822
18976
  if (q.enabled) {
@@ -18825,8 +18979,8 @@ class LocalVideoTrack extends LocalTrack {
18825
18979
  }
18826
18980
  }
18827
18981
  } else if (simulcastCodecInfo.encodings) {
18828
- livekitLogger.debug("try setPublishingLayersForSender ".concat(codec.codec));
18829
- 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);
18830
18984
  }
18831
18985
  }
18832
18986
  }
@@ -18850,11 +19004,13 @@ class LocalVideoTrack extends LocalTrack {
18850
19004
  */
18851
19005
  setPublishingLayers(qualities) {
18852
19006
  return __awaiter(this, void 0, void 0, function* () {
18853
- livekitLogger.debug('setting publishing layers', qualities);
19007
+ this.log.debug('setting publishing layers', Object.assign(Object.assign({}, this.logContext), {
19008
+ qualities
19009
+ }));
18854
19010
  if (!this.sender || !this.encodings) {
18855
19011
  return;
18856
19012
  }
18857
- yield setPublishingLayersForSender(this.sender, this.encodings, qualities, this.senderLock);
19013
+ yield setPublishingLayersForSender(this.sender, this.encodings, qualities, this.senderLock, this.log, this.logContext);
18858
19014
  });
18859
19015
  }
18860
19016
  handleAppVisibilityChanged() {
@@ -18872,14 +19028,14 @@ class LocalVideoTrack extends LocalTrack {
18872
19028
  });
18873
19029
  }
18874
19030
  }
18875
- function setPublishingLayersForSender(sender, senderEncodings, qualities, senderLock) {
19031
+ function setPublishingLayersForSender(sender, senderEncodings, qualities, senderLock, log, logContext) {
18876
19032
  return __awaiter(this, void 0, void 0, function* () {
18877
19033
  const unlock = yield senderLock.lock();
18878
- livekitLogger.debug('setPublishingLayersForSender', {
19034
+ log.debug('setPublishingLayersForSender', Object.assign(Object.assign({}, logContext), {
18879
19035
  sender,
18880
19036
  qualities,
18881
19037
  senderEncodings
18882
- });
19038
+ }));
18883
19039
  try {
18884
19040
  const params = sender.getParameters();
18885
19041
  const {
@@ -18889,7 +19045,7 @@ function setPublishingLayersForSender(sender, senderEncodings, qualities, sender
18889
19045
  return;
18890
19046
  }
18891
19047
  if (encodings.length !== senderEncodings.length) {
18892
- livekitLogger.warn('cannot set publishing layers, encodings mismatch');
19048
+ log.warn('cannot set publishing layers, encodings mismatch');
18893
19049
  return;
18894
19050
  }
18895
19051
  let hasChanged = false;
@@ -18915,7 +19071,7 @@ function setPublishingLayersForSender(sender, senderEncodings, qualities, sender
18915
19071
  if (encoding.active !== subscribedQuality.enabled) {
18916
19072
  hasChanged = true;
18917
19073
  encoding.active = subscribedQuality.enabled;
18918
- 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);
18919
19075
  // FireFox does not support setting encoding.active to false, so we
18920
19076
  // have a workaround of lowering its bitrate and resolution to the min.
18921
19077
  if (isFireFox()) {
@@ -18936,7 +19092,9 @@ function setPublishingLayersForSender(sender, senderEncodings, qualities, sender
18936
19092
  }
18937
19093
  if (hasChanged) {
18938
19094
  params.encodings = encodings;
18939
- livekitLogger.debug("setting encodings", params.encodings);
19095
+ log.debug("setting encodings", Object.assign(Object.assign({}, logContext), {
19096
+ encodings: params.encodings
19097
+ }));
18940
19098
  yield sender.setParameters(params);
18941
19099
  }
18942
19100
  } finally {
@@ -18999,8 +19157,8 @@ function videoLayersFromEncodings(width, height, encodings, svc) {
18999
19157
  }
19000
19158
 
19001
19159
  class RemoteTrack extends Track {
19002
- constructor(mediaTrack, sid, kind, receiver) {
19003
- super(mediaTrack, kind);
19160
+ constructor(mediaTrack, sid, kind, receiver, loggerOptions) {
19161
+ super(mediaTrack, kind, loggerOptions);
19004
19162
  this.sid = sid;
19005
19163
  this.receiver = receiver;
19006
19164
  }
@@ -19061,8 +19219,8 @@ class RemoteTrack extends Track {
19061
19219
  }
19062
19220
 
19063
19221
  class RemoteAudioTrack extends RemoteTrack {
19064
- constructor(mediaTrack, sid, receiver, audioContext, audioOutput) {
19065
- super(mediaTrack, sid, Track.Kind.Audio, receiver);
19222
+ constructor(mediaTrack, sid, receiver, audioContext, audioOutput, loggerOptions) {
19223
+ super(mediaTrack, sid, Track.Kind.Audio, receiver, loggerOptions);
19066
19224
  this.monitorReceiver = () => __awaiter(this, void 0, void 0, function* () {
19067
19225
  if (!this.receiver) {
19068
19226
  this._currentBitrate = 0;
@@ -19145,7 +19303,7 @@ class RemoteAudioTrack extends RemoteTrack {
19145
19303
  element.setSinkId(this.sinkId);
19146
19304
  }
19147
19305
  if (this.audioContext && needsNewWebAudioConnection) {
19148
- livekitLogger.debug('using audio context mapping');
19306
+ this.log.debug('using audio context mapping', this.logContext);
19149
19307
  this.connectWebAudio(this.audioContext, element);
19150
19308
  element.volume = 0;
19151
19309
  element.muted = true;
@@ -19261,8 +19419,8 @@ class RemoteAudioTrack extends RemoteTrack {
19261
19419
 
19262
19420
  const REACTION_DELAY = 100;
19263
19421
  class RemoteVideoTrack extends RemoteTrack {
19264
- constructor(mediaTrack, sid, receiver, adaptiveStreamSettings) {
19265
- super(mediaTrack, sid, Track.Kind.Video, receiver);
19422
+ constructor(mediaTrack, sid, receiver, adaptiveStreamSettings, loggerOptions) {
19423
+ super(mediaTrack, sid, Track.Kind.Video, receiver, loggerOptions);
19266
19424
  this.elementInfos = [];
19267
19425
  this.monitorReceiver = () => __awaiter(this, void 0, void 0, function* () {
19268
19426
  if (!this.receiver) {
@@ -19336,7 +19494,7 @@ class RemoteVideoTrack extends RemoteTrack {
19336
19494
  this.debouncedHandleResize();
19337
19495
  this.updateVisibility();
19338
19496
  } else {
19339
- livekitLogger.warn('visibility resize observer not triggered');
19497
+ this.log.warn('visibility resize observer not triggered', this.logContext);
19340
19498
  }
19341
19499
  }
19342
19500
  /**
@@ -19346,7 +19504,7 @@ class RemoteVideoTrack extends RemoteTrack {
19346
19504
  */
19347
19505
  stopObservingElementInfo(elementInfo) {
19348
19506
  if (!this.isAdaptiveStream) {
19349
- livekitLogger.warn('stopObservingElementInfo ignored');
19507
+ this.log.warn('stopObservingElementInfo ignored', this.logContext);
19350
19508
  return;
19351
19509
  }
19352
19510
  const stopElementInfos = this.elementInfos.filter(info => info === elementInfo);
@@ -19577,16 +19735,20 @@ function isElementInViewport(el) {
19577
19735
  }
19578
19736
 
19579
19737
  class TrackPublication extends eventsExports.EventEmitter {
19580
- constructor(kind, id, name) {
19738
+ constructor(kind, id, name, loggerOptions) {
19739
+ var _a;
19581
19740
  super();
19582
19741
  this.metadataMuted = false;
19583
19742
  this.encryption = Encryption_Type.NONE;
19743
+ this.log = livekitLogger;
19584
19744
  this.handleMuted = () => {
19585
19745
  this.emit(TrackEvent.Muted);
19586
19746
  };
19587
19747
  this.handleUnmuted = () => {
19588
19748
  this.emit(TrackEvent.Unmuted);
19589
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;
19590
19752
  this.setMaxListeners(100);
19591
19753
  this.kind = kind;
19592
19754
  this.trackSid = id;
@@ -19606,6 +19768,10 @@ class TrackPublication extends eventsExports.EventEmitter {
19606
19768
  track.on(TrackEvent.Unmuted, this.handleUnmuted);
19607
19769
  }
19608
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
+ }
19609
19775
  get isMuted() {
19610
19776
  return this.metadataMuted;
19611
19777
  }
@@ -19649,9 +19815,9 @@ class TrackPublication extends eventsExports.EventEmitter {
19649
19815
  }
19650
19816
  this.encryption = info.encryption;
19651
19817
  this.trackInfo = info;
19652
- livekitLogger.debug('update publication info', {
19818
+ this.log.debug('update publication info', Object.assign(Object.assign({}, this.logContext), {
19653
19819
  info
19654
- });
19820
+ }));
19655
19821
  }
19656
19822
  }
19657
19823
  (function (TrackPublication) {
@@ -19671,8 +19837,8 @@ class LocalTrackPublication extends TrackPublication {
19671
19837
  var _a;
19672
19838
  return (_a = this.track) === null || _a === void 0 ? void 0 : _a.isUpstreamPaused;
19673
19839
  }
19674
- constructor(kind, ti, track) {
19675
- super(kind, ti.sid, ti.name);
19840
+ constructor(kind, ti, track, loggerOptions) {
19841
+ super(kind, ti.sid, ti.name, loggerOptions);
19676
19842
  this.track = undefined;
19677
19843
  this.handleTrackEnded = () => {
19678
19844
  this.emit(TrackEvent.Ended);
@@ -19769,6 +19935,13 @@ function qualityFromProto(q) {
19769
19935
  }
19770
19936
  }
19771
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
+ }
19772
19945
  get isEncrypted() {
19773
19946
  return this.tracks.size > 0 && Array.from(this.tracks.values()).every(tr => tr.isEncrypted);
19774
19947
  }
@@ -19777,13 +19950,17 @@ class Participant extends eventsExports.EventEmitter {
19777
19950
  return (_b = (_a = this.permissions) === null || _a === void 0 ? void 0 : _a.agent) !== null && _b !== void 0 ? _b : false;
19778
19951
  }
19779
19952
  /** @internal */
19780
- constructor(sid, identity, name, metadata) {
19953
+ constructor(sid, identity, name, metadata, loggerOptions) {
19954
+ var _a;
19781
19955
  super();
19782
19956
  /** audio level between 0-1.0, 1 being loudest, 0 being softest */
19783
19957
  this.audioLevel = 0;
19784
19958
  /** if participant is currently speaking */
19785
19959
  this.isSpeaking = false;
19786
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;
19787
19964
  this.setMaxListeners(100);
19788
19965
  this.sid = sid;
19789
19966
  this.identity = identity;
@@ -19868,9 +20045,9 @@ class Participant extends eventsExports.EventEmitter {
19868
20045
  }
19869
20046
  // set this last so setMetadata can detect changes
19870
20047
  this.participantInfo = info;
19871
- livekitLogger.trace('update participant info', {
20048
+ this.log.trace('update participant info', Object.assign(Object.assign({}, this.logContext), {
19872
20049
  info
19873
- });
20050
+ }));
19874
20051
  return true;
19875
20052
  }
19876
20053
  /**
@@ -19969,8 +20146,8 @@ function trackPermissionToProto(perms) {
19969
20146
  }
19970
20147
 
19971
20148
  class RemoteTrackPublication extends TrackPublication {
19972
- constructor(kind, ti, autoSubscribe) {
19973
- super(kind, ti.sid, ti.name);
20149
+ constructor(kind, ti, autoSubscribe, loggerOptions) {
20150
+ super(kind, ti.sid, ti.name, loggerOptions);
19974
20151
  this.track = undefined;
19975
20152
  /** @internal */
19976
20153
  this.allowed = true;
@@ -19981,16 +20158,12 @@ class RemoteTrackPublication extends TrackPublication {
19981
20158
  this.emit(TrackEvent.Ended, track);
19982
20159
  };
19983
20160
  this.handleVisibilityChange = visible => {
19984
- livekitLogger.debug("adaptivestream video visibility ".concat(this.trackSid, ", visible=").concat(visible), {
19985
- trackSid: this.trackSid
19986
- });
20161
+ this.log.debug("adaptivestream video visibility ".concat(this.trackSid, ", visible=").concat(visible), this.logContext);
19987
20162
  this.disabled = !visible;
19988
20163
  this.emitTrackUpdate();
19989
20164
  };
19990
20165
  this.handleVideoDimensionsChange = dimensions => {
19991
- livekitLogger.debug("adaptivestream video dimensions ".concat(dimensions.width, "x").concat(dimensions.height), {
19992
- trackSid: this.trackSid
19993
- });
20166
+ this.log.debug("adaptivestream video dimensions ".concat(dimensions.width, "x").concat(dimensions.height), this.logContext);
19994
20167
  this.videoDimensions = dimensions;
19995
20168
  this.emitTrackUpdate();
19996
20169
  };
@@ -20176,15 +20349,11 @@ class RemoteTrackPublication extends TrackPublication {
20176
20349
  }
20177
20350
  isManualOperationAllowed() {
20178
20351
  if (this.kind === Track.Kind.Video && this.isAdaptiveStream) {
20179
- livekitLogger.warn('adaptive stream is enabled, cannot change video track settings', {
20180
- trackSid: this.trackSid
20181
- });
20352
+ this.log.warn('adaptive stream is enabled, cannot change video track settings', this.logContext);
20182
20353
  return false;
20183
20354
  }
20184
20355
  if (!this.isDesired) {
20185
- livekitLogger.warn('cannot update track settings when not subscribed', {
20186
- trackSid: this.trackSid
20187
- });
20356
+ this.log.warn('cannot update track settings when not subscribed', this.logContext);
20188
20357
  return false;
20189
20358
  }
20190
20359
  return true;
@@ -20218,8 +20387,8 @@ class RemoteParticipant extends Participant {
20218
20387
  return new RemoteParticipant(signalClient, pi.sid, pi.identity, pi.name, pi.metadata);
20219
20388
  }
20220
20389
  /** @internal */
20221
- constructor(signalClient, sid, identity, name, metadata) {
20222
- super(sid, identity || '', name, metadata);
20390
+ constructor(signalClient, sid, identity, name, metadata, loggerOptions) {
20391
+ super(sid, identity || '', name, metadata, loggerOptions);
20223
20392
  this.signalClient = signalClient;
20224
20393
  this.tracks = new Map();
20225
20394
  this.audioTracks = new Map();
@@ -20230,7 +20399,7 @@ class RemoteParticipant extends Participant {
20230
20399
  super.addTrackPublication(publication);
20231
20400
  // register action events
20232
20401
  publication.on(TrackEvent.UpdateSettings, settings => {
20233
- livekitLogger.debug('send update settings', settings);
20402
+ this.log.debug('send update settings', Object.assign(Object.assign({}, this.logContext), getLogContextFromTrack(publication)));
20234
20403
  this.signalClient.sendUpdateTrackSettings(settings);
20235
20404
  });
20236
20405
  publication.on(TrackEvent.UpdateSubscription, sub => {
@@ -20313,10 +20482,9 @@ class RemoteParticipant extends Participant {
20313
20482
  // yet arrived. Wait a bit longer for it to arrive, or fire an error
20314
20483
  if (!publication) {
20315
20484
  if (triesLeft === 0) {
20316
- livekitLogger.error('could not find published track', {
20317
- participant: this.sid,
20485
+ this.log.error('could not find published track', Object.assign(Object.assign({}, this.logContext), {
20318
20486
  trackSid: sid
20319
- });
20487
+ }));
20320
20488
  this.emit(ParticipantEvent.TrackSubscriptionFailed, sid);
20321
20489
  return;
20322
20490
  }
@@ -20327,10 +20495,7 @@ class RemoteParticipant extends Participant {
20327
20495
  return;
20328
20496
  }
20329
20497
  if (mediaTrack.readyState === 'ended') {
20330
- livekitLogger.error('unable to subscribe because MediaStreamTrack is ended. Do not call MediaStreamTrack.stop()', {
20331
- participant: this.sid,
20332
- trackSid: sid
20333
- });
20498
+ this.log.error('unable to subscribe because MediaStreamTrack is ended. Do not call MediaStreamTrack.stop()', Object.assign(Object.assign({}, this.logContext), getLogContextFromTrack(publication)));
20334
20499
  this.emit(ParticipantEvent.TrackSubscriptionFailed, sid);
20335
20500
  return;
20336
20501
  }
@@ -20373,7 +20538,7 @@ class RemoteParticipant extends Participant {
20373
20538
  const validTracks = new Map();
20374
20539
  const newTracks = new Map();
20375
20540
  info.tracks.forEach(ti => {
20376
- var _a;
20541
+ var _a, _b;
20377
20542
  let publication = this.getTrackPublication(ti.sid);
20378
20543
  if (!publication) {
20379
20544
  // new publication
@@ -20381,17 +20546,18 @@ class RemoteParticipant extends Participant {
20381
20546
  if (!kind) {
20382
20547
  return;
20383
20548
  }
20384
- 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
+ });
20385
20553
  publication.updateInfo(ti);
20386
20554
  newTracks.set(ti.sid, publication);
20387
20555
  const existingTrackOfSource = Array.from(this.tracks.values()).find(publishedTrack => publishedTrack.source === (publication === null || publication === void 0 ? void 0 : publication.source));
20388
20556
  if (existingTrackOfSource && publication.source !== Track.Source.Unknown) {
20389
- livekitLogger.debug("received a second track publication for ".concat(this.identity, " with the same source: ").concat(publication.source), {
20390
- oldTrack: existingTrackOfSource,
20391
- newTrack: publication,
20392
- participant: this,
20393
- participantInfo: info
20394
- });
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
+ }));
20395
20561
  }
20396
20562
  this.addTrackPublication(publication);
20397
20563
  } else {
@@ -20402,10 +20568,7 @@ class RemoteParticipant extends Participant {
20402
20568
  // detect removed tracks
20403
20569
  this.tracks.forEach(publication => {
20404
20570
  if (!validTracks.has(publication.trackSid)) {
20405
- livekitLogger.trace('detected removed track on remote participant, unpublishing', {
20406
- publication,
20407
- participantSid: this.sid
20408
- });
20571
+ this.log.trace('detected removed track on remote participant, unpublishing', Object.assign(Object.assign({}, this.logContext), getLogContextFromTrack(publication)));
20409
20572
  this.unpublishTrack(publication.trackSid, true);
20410
20573
  }
20411
20574
  });
@@ -20465,11 +20628,10 @@ class RemoteParticipant extends Participant {
20465
20628
  for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
20466
20629
  args[_key - 1] = arguments[_key];
20467
20630
  }
20468
- livekitLogger.trace('participant event', {
20469
- participant: this.sid,
20631
+ this.log.trace('participant event', Object.assign(Object.assign({}, this.logContext), {
20470
20632
  event,
20471
20633
  args
20472
- });
20634
+ }));
20473
20635
  return super.emit(event, ...args);
20474
20636
  }
20475
20637
  }
@@ -20477,7 +20639,10 @@ class RemoteParticipant extends Participant {
20477
20639
  class LocalParticipant extends Participant {
20478
20640
  /** @internal */
20479
20641
  constructor(sid, identity, engine, options) {
20480
- super(sid, identity);
20642
+ super(sid, identity, undefined, undefined, {
20643
+ loggerName: options.loggerName,
20644
+ loggerContextCb: () => this.engine.logContext
20645
+ });
20481
20646
  this.pendingPublishing = new Set();
20482
20647
  this.pendingPublishPromises = new Map();
20483
20648
  this.participantTrackPermissions = [];
@@ -20497,16 +20662,16 @@ class LocalParticipant extends Participant {
20497
20662
  this.handleDisconnected = () => {
20498
20663
  var _a, _b;
20499
20664
  if (this.reconnectFuture) {
20500
- this.reconnectFuture.promise.catch(e => livekitLogger.warn(e));
20665
+ this.reconnectFuture.promise.catch(e => this.log.warn(e.message, this.logContext));
20501
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');
20502
20667
  this.reconnectFuture = undefined;
20503
20668
  }
20504
20669
  };
20505
20670
  this.updateTrackSubscriptionPermissions = () => {
20506
- livekitLogger.debug('updating track subscription permissions', {
20671
+ this.log.debug('updating track subscription permissions', Object.assign(Object.assign({}, this.logContext), {
20507
20672
  allParticipantsAllowed: this.allParticipantsAllowedToSubscribe,
20508
20673
  participantTrackPermissions: this.participantTrackPermissions
20509
- });
20674
+ }));
20510
20675
  this.engine.client.sendUpdateSubscriptionPermissions(this.allParticipantsAllowedToSubscribe, this.participantTrackPermissions.map(p => trackPermissionToProto(p)));
20511
20676
  };
20512
20677
  /** @internal */
@@ -20520,17 +20685,17 @@ class LocalParticipant extends Participant {
20520
20685
  muted = true;
20521
20686
  }
20522
20687
  if (!track.sid) {
20523
- 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)));
20524
20689
  return;
20525
20690
  }
20526
20691
  this.engine.updateMuteStatus(track.sid, muted);
20527
20692
  };
20528
20693
  this.onTrackUpstreamPaused = track => {
20529
- livekitLogger.debug('upstream paused');
20694
+ this.log.debug('upstream paused', Object.assign(Object.assign({}, this.logContext), getLogContextFromTrack(track)));
20530
20695
  this.onTrackMuted(track, true);
20531
20696
  };
20532
20697
  this.onTrackUpstreamResumed = track => {
20533
- livekitLogger.debug('upstream resumed');
20698
+ this.log.debug('upstream resumed', Object.assign(Object.assign({}, this.logContext), getLogContextFromTrack(track)));
20534
20699
  this.onTrackMuted(track, track.isMuted);
20535
20700
  };
20536
20701
  this.handleSubscribedQualityUpdate = update => __awaiter(this, void 0, void 0, function* () {
@@ -20541,10 +20706,9 @@ class LocalParticipant extends Participant {
20541
20706
  }
20542
20707
  const pub = this.videoTracks.get(update.trackSid);
20543
20708
  if (!pub) {
20544
- livekitLogger.warn('received subscribed quality update for unknown track', {
20545
- method: 'handleSubscribedQualityUpdate',
20546
- sid: update.trackSid
20547
- });
20709
+ this.log.warn('received subscribed quality update for unknown track', Object.assign(Object.assign({}, this.logContext), {
20710
+ trackSid: update.trackSid
20711
+ }));
20548
20712
  return;
20549
20713
  }
20550
20714
  if (update.subscribedCodecs.length > 0) {
@@ -20558,7 +20722,7 @@ class LocalParticipant extends Participant {
20558
20722
  _f = false;
20559
20723
  const codec = _c;
20560
20724
  if (isBackupCodec(codec)) {
20561
- 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)));
20562
20726
  yield this.publishAdditionalCodecForTrack(pub.videoTrack, codec, pub.options);
20563
20727
  }
20564
20728
  }
@@ -20580,19 +20744,16 @@ class LocalParticipant extends Participant {
20580
20744
  this.handleLocalTrackUnpublished = unpublished => {
20581
20745
  const track = this.tracks.get(unpublished.trackSid);
20582
20746
  if (!track) {
20583
- livekitLogger.warn('received unpublished event for unknown track', {
20584
- method: 'handleLocalTrackUnpublished',
20747
+ this.log.warn('received unpublished event for unknown track', Object.assign(Object.assign({}, this.logContext), {
20585
20748
  trackSid: unpublished.trackSid
20586
- });
20749
+ }));
20587
20750
  return;
20588
20751
  }
20589
20752
  this.unpublishTrack(track.track);
20590
20753
  };
20591
20754
  this.handleTrackEnded = track => __awaiter(this, void 0, void 0, function* () {
20592
20755
  if (track.source === Track.Source.ScreenShare || track.source === Track.Source.ScreenShareAudio) {
20593
- livekitLogger.debug('unpublishing local track due to TrackEnded', {
20594
- track: track.sid
20595
- });
20756
+ this.log.debug('unpublishing local track due to TrackEnded', Object.assign(Object.assign({}, this.logContext), getLogContextFromTrack(track)));
20596
20757
  this.unpublishTrack(track);
20597
20758
  } else if (track.isUserProvided) {
20598
20759
  yield track.mute();
@@ -20606,7 +20767,7 @@ class LocalParticipant extends Participant {
20606
20767
  name: track.source === Track.Source.Camera ? 'camera' : 'microphone'
20607
20768
  });
20608
20769
  if (currentPermissions && currentPermissions.state === 'denied') {
20609
- 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)));
20610
20771
  // detect granted change after permissions were denied to try and resume then
20611
20772
  currentPermissions.onchange = () => {
20612
20773
  if (currentPermissions.state !== 'denied') {
@@ -20623,11 +20784,11 @@ class LocalParticipant extends Participant {
20623
20784
  }
20624
20785
  }
20625
20786
  if (!track.isMuted) {
20626
- 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)));
20627
20788
  yield track.restartTrack();
20628
20789
  }
20629
20790
  } catch (e) {
20630
- 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)));
20631
20792
  yield track.mute();
20632
20793
  }
20633
20794
  }
@@ -20745,10 +20906,10 @@ class LocalParticipant extends Participant {
20745
20906
  setTrackEnabled(source, enabled, options, publishOptions) {
20746
20907
  var _a, _b;
20747
20908
  return __awaiter(this, void 0, void 0, function* () {
20748
- livekitLogger.debug('setTrackEnabled', {
20909
+ this.log.debug('setTrackEnabled', Object.assign(Object.assign({}, this.logContext), {
20749
20910
  source,
20750
20911
  enabled
20751
- });
20912
+ }));
20752
20913
  let track = this.getTrack(source);
20753
20914
  if (enabled) {
20754
20915
  if (track) {
@@ -20756,9 +20917,9 @@ class LocalParticipant extends Participant {
20756
20917
  } else {
20757
20918
  let localTracks;
20758
20919
  if (this.pendingPublishing.has(source)) {
20759
- livekitLogger.info('skipping duplicate published source', {
20920
+ this.log.info('skipping duplicate published source', Object.assign(Object.assign({}, this.logContext), {
20760
20921
  source
20761
- });
20922
+ }));
20762
20923
  // no-op it's already been requested
20763
20924
  return;
20764
20925
  }
@@ -20783,9 +20944,7 @@ class LocalParticipant extends Participant {
20783
20944
  }
20784
20945
  const publishPromises = [];
20785
20946
  for (const localTrack of localTracks) {
20786
- livekitLogger.info('publishing track', {
20787
- localTrack
20788
- });
20947
+ this.log.info('publishing track', Object.assign(Object.assign({}, this.logContext), getLogContextFromTrack(localTrack)));
20789
20948
  publishPromises.push(this.publishTrack(localTrack, publishOptions));
20790
20949
  }
20791
20950
  const publishedTracks = yield Promise.all(publishPromises);
@@ -20882,7 +21041,10 @@ class LocalParticipant extends Participant {
20882
21041
  if (typeof conOrBool !== 'boolean') {
20883
21042
  trackConstraints = conOrBool;
20884
21043
  }
20885
- const track = mediaTrackToLocalTrack(mediaStreamTrack, trackConstraints);
21044
+ const track = mediaTrackToLocalTrack(mediaStreamTrack, trackConstraints, {
21045
+ loggerName: this.roomOptions.loggerName,
21046
+ loggerContextCb: () => this.logContext
21047
+ });
20886
21048
  if (track.kind === Track.Kind.Video) {
20887
21049
  track.source = Track.Source.Camera;
20888
21050
  } else if (track.kind === Track.Kind.Audio) {
@@ -20906,18 +21068,33 @@ class LocalParticipant extends Participant {
20906
21068
  if (navigator.mediaDevices.getDisplayMedia === undefined) {
20907
21069
  throw new DeviceUnsupportedError('getDisplayMedia not supported');
20908
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
+ }
20909
21077
  const constraints = screenCaptureToDisplayMediaStreamOptions(options);
20910
21078
  const stream = yield navigator.mediaDevices.getDisplayMedia(constraints);
20911
21079
  const tracks = stream.getVideoTracks();
20912
21080
  if (tracks.length === 0) {
20913
21081
  throw new TrackInvalidError('no video track found');
20914
21082
  }
20915
- 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
+ });
20916
21087
  screenVideo.source = Track.Source.ScreenShare;
21088
+ if (options.contentHint) {
21089
+ screenVideo.mediaStreamTrack.contentHint = options.contentHint;
21090
+ }
20917
21091
  const localTracks = [screenVideo];
20918
21092
  if (stream.getAudioTracks().length > 0) {
20919
21093
  this.emit(ParticipantEvent.AudioStreamAcquired);
20920
- 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
+ });
20921
21098
  screenAudio.source = Track.Source.ScreenShareAudio;
20922
21099
  localTracks.push(screenAudio);
20923
21100
  }
@@ -20961,14 +21138,25 @@ class LocalParticipant extends Participant {
20961
21138
  if (track instanceof MediaStreamTrack) {
20962
21139
  switch (track.kind) {
20963
21140
  case 'audio':
20964
- 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
+ });
20965
21145
  break;
20966
21146
  case 'video':
20967
- track = new LocalVideoTrack(track, defaultConstraints, true);
21147
+ track = new LocalVideoTrack(track, defaultConstraints, true, {
21148
+ loggerName: this.roomOptions.loggerName,
21149
+ loggerContextCb: () => this.logContext
21150
+ });
20968
21151
  break;
20969
21152
  default:
20970
21153
  throw new TrackInvalidError("unsupported MediaStreamTrack kind ".concat(track.kind));
20971
21154
  }
21155
+ } else {
21156
+ track.updateLoggerOptions({
21157
+ loggerName: this.roomOptions.loggerName,
21158
+ loggerContextCb: () => this.logContext
21159
+ });
20972
21160
  }
20973
21161
  if (track instanceof LocalAudioTrack) {
20974
21162
  track.setAudioContext(this.audioContext);
@@ -20984,7 +21172,7 @@ class LocalParticipant extends Participant {
20984
21172
  }
20985
21173
  });
20986
21174
  if (existingPublication) {
20987
- 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)));
20988
21176
  return existingPublication;
20989
21177
  }
20990
21178
  const isStereoInput = 'channelCount' in track.mediaStreamTrack.getSettings() &&
@@ -20997,10 +21185,10 @@ class LocalParticipant extends Participant {
20997
21185
  options = {};
20998
21186
  }
20999
21187
  if (options.dtx === undefined) {
21000
- 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)));
21001
21189
  }
21002
21190
  if (options.red === undefined) {
21003
- 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.");
21004
21192
  }
21005
21193
  (_c = options.dtx) !== null && _c !== void 0 ? _c : options.dtx = false;
21006
21194
  (_d = options.red) !== null && _d !== void 0 ? _d : options.red = false;
@@ -21008,7 +21196,7 @@ class LocalParticipant extends Participant {
21008
21196
  const opts = Object.assign(Object.assign({}, this.roomOptions.publishDefaults), options);
21009
21197
  // disable simulcast if e2ee is set on safari
21010
21198
  if (isSafari() && this.roomOptions.e2ee) {
21011
- 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));
21012
21200
  opts.simulcast = false;
21013
21201
  }
21014
21202
  if (opts.source) {
@@ -21031,7 +21219,7 @@ class LocalParticipant extends Participant {
21031
21219
  return __awaiter(this, void 0, void 0, function* () {
21032
21220
  const existingTrackOfSource = Array.from(this.tracks.values()).find(publishedTrack => track instanceof LocalTrack && publishedTrack.source === track.source);
21033
21221
  if (existingTrackOfSource && track.source !== Track.Source.Unknown) {
21034
- 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)));
21035
21223
  }
21036
21224
  if (opts.stopMicTrackOnMute && track instanceof LocalAudioTrack) {
21037
21225
  track.stopOnMute = true;
@@ -21090,7 +21278,9 @@ class LocalParticipant extends Participant {
21090
21278
  height: defaultRes.height
21091
21279
  };
21092
21280
  // log failure
21093
- 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
+ }));
21094
21284
  }
21095
21285
  // width and height should be defined for video
21096
21286
  req.width = dims.width;
@@ -21152,26 +21342,29 @@ class LocalParticipant extends Participant {
21152
21342
  if (primaryCodecMime && track.kind === Track.Kind.Video) {
21153
21343
  const updatedCodec = mimeTypeToVideoCodecString(primaryCodecMime);
21154
21344
  if (updatedCodec !== videoCodec) {
21155
- 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)), {
21156
21346
  codec: updatedCodec
21157
- });
21347
+ }));
21158
21348
  /* @ts-ignore */
21159
21349
  opts.videoCodec = updatedCodec;
21160
21350
  // recompute encodings since bitrates/etc could have changed
21161
21351
  encodings = computeVideoEncodings(track.source === Track.Source.ScreenShare, req.width, req.height, opts);
21162
21352
  }
21163
21353
  }
21164
- 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
+ });
21165
21358
  // save options for when it needs to be republished again
21166
21359
  publication.options = opts;
21167
21360
  track.sid = ti.sid;
21168
21361
  if (!this.engine.pcManager) {
21169
21362
  throw new UnexpectedConnectionState('pcManager is not ready');
21170
21363
  }
21171
- livekitLogger.debug("publishing ".concat(track.kind, " with encodings"), {
21364
+ this.log.debug("publishing ".concat(track.kind, " with encodings"), Object.assign(Object.assign({}, this.logContext), {
21172
21365
  encodings,
21173
21366
  trackInfo: ti
21174
- });
21367
+ }));
21175
21368
  track.sender = yield this.engine.createSender(track, opts, encodings);
21176
21369
  if (encodings) {
21177
21370
  if (isFireFox() && track.kind === Track.Kind.Audio) {
@@ -21248,7 +21441,7 @@ class LocalParticipant extends Participant {
21248
21441
  const opts = Object.assign(Object.assign({}, (_a = this.roomOptions) === null || _a === void 0 ? void 0 : _a.publishDefaults), options);
21249
21442
  const encodings = computeTrackBackupEncodings(track, videoCodec, opts);
21250
21443
  if (!encodings) {
21251
- 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)));
21252
21445
  return;
21253
21446
  }
21254
21447
  const simulcastTrack = track.addSimulcastTrack(videoCodec, encodings);
@@ -21270,10 +21463,10 @@ class LocalParticipant extends Participant {
21270
21463
  const ti = yield this.engine.addTrack(req);
21271
21464
  yield this.engine.createSimulcastSender(track, simulcastTrack, opts, encodings);
21272
21465
  yield this.engine.negotiate();
21273
- 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), {
21274
21467
  encodings,
21275
21468
  trackInfo: ti
21276
- });
21469
+ }));
21277
21470
  });
21278
21471
  }
21279
21472
  unpublishTrack(track, stopOnUnpublish) {
@@ -21281,15 +21474,10 @@ class LocalParticipant extends Participant {
21281
21474
  return __awaiter(this, void 0, void 0, function* () {
21282
21475
  // look through all published tracks to find the right ones
21283
21476
  const publication = this.getPublicationForTrack(track);
21284
- livekitLogger.debug('unpublishing track', {
21285
- track,
21286
- method: 'unpublishTrack'
21287
- });
21477
+ const pubLogContext = publication ? getLogContextFromTrack(publication) : undefined;
21478
+ this.log.debug('unpublishing track', Object.assign(Object.assign({}, this.logContext), pubLogContext));
21288
21479
  if (!publication || !publication.track) {
21289
- livekitLogger.warn('track was not unpublished because no publication was found', {
21290
- track,
21291
- method: 'unpublishTrack'
21292
- });
21480
+ this.log.warn('track was not unpublished because no publication was found', Object.assign(Object.assign({}, this.logContext), pubLogContext));
21293
21481
  return undefined;
21294
21482
  }
21295
21483
  track = publication.track;
@@ -21334,10 +21522,9 @@ class LocalParticipant extends Participant {
21334
21522
  track.simulcastCodecs.clear();
21335
21523
  }
21336
21524
  } catch (e) {
21337
- livekitLogger.warn('failed to unpublish track', {
21338
- error: e,
21339
- method: 'unpublishTrack'
21340
- });
21525
+ this.log.warn('failed to unpublish track', Object.assign(Object.assign(Object.assign({}, this.logContext), pubLogContext), {
21526
+ error: e
21527
+ }));
21341
21528
  }
21342
21529
  }
21343
21530
  // remove from our maps
@@ -21382,9 +21569,9 @@ class LocalParticipant extends Participant {
21382
21569
  if (restartTracks && !track.isMuted && (track instanceof LocalAudioTrack || track instanceof LocalVideoTrack) && !track.isUserProvided) {
21383
21570
  // generally we need to restart the track before publishing, often a full reconnect
21384
21571
  // is necessary because computer had gone to sleep.
21385
- livekitLogger.debug('restarting existing track', {
21572
+ this.log.debug('restarting existing track', Object.assign(Object.assign({}, this.logContext), {
21386
21573
  track: pub.trackSid
21387
- });
21574
+ }));
21388
21575
  yield track.restartTrack();
21389
21576
  }
21390
21577
  yield this.publishTrack(track, pub.options);
@@ -21465,10 +21652,9 @@ class LocalParticipant extends Participant {
21465
21652
  if (pub) {
21466
21653
  const mutedOnServer = pub.isMuted || ((_b = (_a = pub.track) === null || _a === void 0 ? void 0 : _a.isUpstreamPaused) !== null && _b !== void 0 ? _b : false);
21467
21654
  if (mutedOnServer !== ti.muted) {
21468
- livekitLogger.debug('updating server mute state after reconcile', {
21469
- sid: ti.sid,
21470
- muted: mutedOnServer
21471
- });
21655
+ this.log.debug('updating server mute state after reconcile', Object.assign(Object.assign(Object.assign({}, this.logContext), getLogContextFromTrack(pub)), {
21656
+ mutedOnServer
21657
+ }));
21472
21658
  this.engine.client.sendMuteTrack(ti.sid, mutedOnServer);
21473
21659
  }
21474
21660
  }
@@ -21522,7 +21708,7 @@ class Room extends eventsExports.EventEmitter {
21522
21708
  */
21523
21709
  constructor(options) {
21524
21710
  var _this;
21525
- var _a;
21711
+ var _a, _b;
21526
21712
  super();
21527
21713
  _this = this;
21528
21714
  this.state = ConnectionState.Disconnected;
@@ -21535,13 +21721,14 @@ class Room extends eventsExports.EventEmitter {
21535
21721
  this.isE2EEEnabled = false;
21536
21722
  this.audioEnabled = true;
21537
21723
  this.isVideoPlaybackBlocked = false;
21724
+ this.log = livekitLogger;
21538
21725
  this.connect = (url, token, opts) => __awaiter(this, void 0, void 0, function* () {
21539
- var _b;
21726
+ var _c;
21540
21727
  // In case a disconnect called happened right before the connect call, make sure the disconnect is completed first by awaiting its lock
21541
21728
  const unlockDisconnect = yield this.disconnectLock.lock();
21542
21729
  if (this.state === ConnectionState.Connected) {
21543
21730
  // when the state is reconnecting or connected, this function returns immediately
21544
- livekitLogger.info("already connected to room ".concat(this.name));
21731
+ this.log.info("already connected to room ".concat(this.name), this.logContext);
21545
21732
  unlockDisconnect();
21546
21733
  return Promise.resolve();
21547
21734
  }
@@ -21550,7 +21737,7 @@ class Room extends eventsExports.EventEmitter {
21550
21737
  return this.connectFuture.promise;
21551
21738
  }
21552
21739
  this.setAndEmitConnectionState(ConnectionState.Connecting);
21553
- 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) {
21554
21741
  this.regionUrl = undefined;
21555
21742
  this.regionUrlProvider = undefined;
21556
21743
  }
@@ -21564,13 +21751,13 @@ class Room extends eventsExports.EventEmitter {
21564
21751
  // if initial connection fails, this will speed up picking regional url
21565
21752
  // on subsequent runs
21566
21753
  this.regionUrlProvider.fetchRegionSettings().catch(e => {
21567
- livekitLogger.warn('could not fetch region settings', {
21754
+ this.log.warn('could not fetch region settings', Object.assign(Object.assign({}, this.logContext), {
21568
21755
  error: e
21569
- });
21756
+ }));
21570
21757
  });
21571
21758
  }
21572
21759
  const connectFn = (resolve, reject, regionUrl) => __awaiter(this, void 0, void 0, function* () {
21573
- var _c;
21760
+ var _d;
21574
21761
  if (this.abortController) {
21575
21762
  this.abortController.abort();
21576
21763
  }
@@ -21587,7 +21774,7 @@ class Room extends eventsExports.EventEmitter {
21587
21774
  if (this.regionUrlProvider && e instanceof ConnectionError && e.reason !== 3 /* ConnectionErrorReason.Cancelled */ && e.reason !== 0 /* ConnectionErrorReason.NotAllowed */) {
21588
21775
  let nextUrl = null;
21589
21776
  try {
21590
- 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);
21591
21778
  } catch (error) {
21592
21779
  if (error instanceof ConnectionError && (error.status === 401 || error.reason === 3 /* ConnectionErrorReason.Cancelled */)) {
21593
21780
  this.handleDisconnect(this.options.stopLocalTrackOnUnpublish);
@@ -21596,7 +21783,7 @@ class Room extends eventsExports.EventEmitter {
21596
21783
  }
21597
21784
  }
21598
21785
  if (nextUrl) {
21599
- 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);
21600
21787
  yield connectFn(resolve, reject, nextUrl);
21601
21788
  } else {
21602
21789
  this.handleDisconnect(this.options.stopLocalTrackOnUnpublish);
@@ -21618,6 +21805,7 @@ class Room extends eventsExports.EventEmitter {
21618
21805
  return this.connectFuture.promise;
21619
21806
  });
21620
21807
  this.connectSignal = (url, token, engine, connectOptions, roomOptions, abortController) => __awaiter(this, void 0, void 0, function* () {
21808
+ var _e, _f, _g;
21621
21809
  const joinResponse = yield engine.join(url, token, {
21622
21810
  autoSubscribe: connectOptions.autoSubscribe,
21623
21811
  publishOnly: connectOptions.publishOnly,
@@ -21633,15 +21821,19 @@ class Room extends eventsExports.EventEmitter {
21633
21821
  region: joinResponse.serverRegion
21634
21822
  };
21635
21823
  }
21636
- 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 => {
21637
21825
  let [key, value] = _ref;
21638
21826
  return "".concat(key, ": ").concat(value);
21639
- }).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
+ });
21640
21832
  if (!joinResponse.serverVersion) {
21641
21833
  throw new UnsupportedServer('unknown server version');
21642
21834
  }
21643
21835
  if (joinResponse.serverVersion === '0.15.1' && this.options.dynacast) {
21644
- livekitLogger.debug('disabling dynacast due to server version');
21836
+ this.log.debug('disabling dynacast due to server version', this.logContext);
21645
21837
  // dynacast has a bug in 0.15.1, so we cannot use it then
21646
21838
  roomOptions.dynacast = false;
21647
21839
  }
@@ -21661,16 +21853,16 @@ class Room extends eventsExports.EventEmitter {
21661
21853
  }
21662
21854
  };
21663
21855
  this.attemptConnection = (url, token, opts, abortController) => __awaiter(this, void 0, void 0, function* () {
21664
- var _d, _e;
21856
+ var _h, _j;
21665
21857
  if (this.state === ConnectionState.Reconnecting) {
21666
- livekitLogger.info('Reconnection attempt replaced by new connection attempt');
21858
+ this.log.info('Reconnection attempt replaced by new connection attempt', this.logContext);
21667
21859
  // make sure we close and recreate the existing engine in order to get rid of any potentially ongoing reconnection attempts
21668
21860
  this.recreateEngine();
21669
21861
  } else {
21670
21862
  // create engine if previously disconnected
21671
21863
  this.maybeCreateEngine();
21672
21864
  }
21673
- 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()) {
21674
21866
  this.engine.setRegionUrlProvider(this.regionUrlProvider);
21675
21867
  }
21676
21868
  this.acquireAudioContext();
@@ -21698,9 +21890,9 @@ class Room extends eventsExports.EventEmitter {
21698
21890
  resultingError.reason = err.reason;
21699
21891
  resultingError.status = err.status;
21700
21892
  }
21701
- livekitLogger.debug("error trying to establish signal connection", {
21893
+ this.log.debug("error trying to establish signal connection", Object.assign(Object.assign({}, this.logContext), {
21702
21894
  error: err
21703
- });
21895
+ }));
21704
21896
  throw resultingError;
21705
21897
  }
21706
21898
  if (abortController.signal.aborted) {
@@ -21723,7 +21915,7 @@ class Room extends eventsExports.EventEmitter {
21723
21915
  }
21724
21916
  if (isWeb()) {
21725
21917
  document.addEventListener('freeze', this.onPageLeave);
21726
- (_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);
21727
21919
  }
21728
21920
  this.setAndEmitConnectionState(ConnectionState.Connected);
21729
21921
  this.emit(RoomEvent.Connected);
@@ -21735,26 +21927,24 @@ class Room extends eventsExports.EventEmitter {
21735
21927
  this.disconnect = function () {
21736
21928
  let stopTracks = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
21737
21929
  return __awaiter(_this, void 0, void 0, function* () {
21738
- var _f, _g, _h, _j;
21930
+ var _k, _l, _m, _o;
21739
21931
  const unlock = yield this.disconnectLock.lock();
21740
21932
  try {
21741
21933
  if (this.state === ConnectionState.Disconnected) {
21742
- livekitLogger.debug('already disconnected');
21934
+ this.log.debug('already disconnected', this.logContext);
21743
21935
  return;
21744
21936
  }
21745
- livekitLogger.info('disconnect from room', {
21746
- identity: this.localParticipant.identity
21747
- });
21937
+ this.log.info('disconnect from room', Object.assign({}, this.logContext));
21748
21938
  if (this.state === ConnectionState.Connecting || this.state === ConnectionState.Reconnecting) {
21749
21939
  // try aborting pending connection attempt
21750
- livekitLogger.warn('abort connection attempt');
21751
- (_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();
21752
21942
  // in case the abort controller didn't manage to cancel the connection attempt, reject the connect promise explicitly
21753
- (_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'));
21754
21944
  this.connectFuture = undefined;
21755
21945
  }
21756
21946
  // send leave
21757
- 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)) {
21758
21948
  yield this.engine.client.sendLeave();
21759
21949
  }
21760
21950
  // close engine (also closes client)
@@ -21854,7 +22044,7 @@ class Room extends eventsExports.EventEmitter {
21854
22044
  if (e.name === 'NotAllowedError') {
21855
22045
  this.handleVideoPlaybackFailed();
21856
22046
  } else {
21857
- 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);
21858
22048
  }
21859
22049
  });
21860
22050
  });
@@ -21869,9 +22059,9 @@ class Room extends eventsExports.EventEmitter {
21869
22059
  }
21870
22060
  };
21871
22061
  this.handleSignalRestarted = joinResponse => __awaiter(this, void 0, void 0, function* () {
21872
- livekitLogger.debug("signal reconnected to server", {
22062
+ this.log.debug("signal reconnected to server, region ".concat(joinResponse.serverRegion), Object.assign(Object.assign({}, this.logContext), {
21873
22063
  region: joinResponse.serverRegion
21874
- });
22064
+ }));
21875
22065
  this.cachedParticipantSids = [];
21876
22066
  this.applyJoinResponse(joinResponse);
21877
22067
  try {
@@ -21889,28 +22079,28 @@ class Room extends eventsExports.EventEmitter {
21889
22079
  if ((track instanceof LocalAudioTrack || track instanceof LocalVideoTrack) && track.source !== Track.Source.ScreenShare && track.source !== Track.Source.ScreenShareAudio && !track.isUserProvided) {
21890
22080
  // we need to restart the track before publishing, often a full reconnect
21891
22081
  // is necessary because computer had gone to sleep.
21892
- livekitLogger.debug('restarting existing track', {
22082
+ this.log.debug('restarting existing track', Object.assign(Object.assign({}, this.logContext), {
21893
22083
  track: pub.trackSid
21894
- });
22084
+ }));
21895
22085
  yield track.restartTrack();
21896
22086
  }
21897
- livekitLogger.debug('publishing new track', {
22087
+ this.log.debug('publishing new track', Object.assign(Object.assign({}, this.logContext), {
21898
22088
  track: pub.trackSid
21899
- });
22089
+ }));
21900
22090
  yield this.localParticipant.publishTrack(track, pub.options);
21901
22091
  }
21902
22092
  })));
21903
22093
  } catch (error) {
21904
- livekitLogger.error('error trying to re-publish tracks after reconnection', {
22094
+ this.log.error('error trying to re-publish tracks after reconnection', Object.assign(Object.assign({}, this.logContext), {
21905
22095
  error
21906
- });
22096
+ }));
21907
22097
  }
21908
22098
  try {
21909
22099
  yield this.engine.waitForRestarted();
21910
- livekitLogger.debug("fully reconnected to server", {
22100
+ this.log.debug("fully reconnected to server", Object.assign(Object.assign({}, this.logContext), {
21911
22101
  region: joinResponse.serverRegion
21912
- });
21913
- } catch (_k) {
22102
+ }));
22103
+ } catch (_p) {
21914
22104
  // reconnection failed, handleDisconnect is being invoked already, just return here
21915
22105
  return;
21916
22106
  }
@@ -22061,7 +22251,9 @@ class Room extends eventsExports.EventEmitter {
22061
22251
  this.emit(RoomEvent.AudioPlaybackStatusChanged, true);
22062
22252
  };
22063
22253
  this.handleAudioPlaybackFailed = e => {
22064
- livekitLogger.warn('could not playback audio', e);
22254
+ this.log.warn('could not playback audio', Object.assign(Object.assign({}, this.logContext), {
22255
+ error: e
22256
+ }));
22065
22257
  if (!this.canPlaybackAudio) {
22066
22258
  return;
22067
22259
  }
@@ -22118,7 +22310,7 @@ class Room extends eventsExports.EventEmitter {
22118
22310
  this.emit(RoomEvent.TrackUnmuted, pub, this.localParticipant);
22119
22311
  };
22120
22312
  this.onLocalTrackPublished = pub => __awaiter(this, void 0, void 0, function* () {
22121
- var _l;
22313
+ var _q;
22122
22314
  this.emit(RoomEvent.LocalTrackPublished, pub, this.localParticipant);
22123
22315
  if (pub.track instanceof LocalAudioTrack) {
22124
22316
  const trackIsSilent = yield pub.track.checkForSilence();
@@ -22126,7 +22318,7 @@ class Room extends eventsExports.EventEmitter {
22126
22318
  this.emit(RoomEvent.LocalAudioSilenceDetected, pub);
22127
22319
  }
22128
22320
  }
22129
- const deviceId = yield (_l = pub.track) === null || _l === void 0 ? void 0 : _l.getDeviceId();
22321
+ const deviceId = yield (_q = pub.track) === null || _q === void 0 ? void 0 : _q.getDeviceId();
22130
22322
  const deviceKind = sourceToKind(pub.source);
22131
22323
  if (deviceKind && deviceId && deviceId !== this.localParticipant.activeDeviceMap.get(deviceKind)) {
22132
22324
  this.localParticipant.activeDeviceMap.set(deviceKind, deviceId);
@@ -22150,6 +22342,7 @@ class Room extends eventsExports.EventEmitter {
22150
22342
  this.cachedParticipantSids = [];
22151
22343
  this.identityToSid = new Map();
22152
22344
  this.options = Object.assign(Object.assign({}, roomOptionDefaults), options);
22345
+ this.log = getLogger((_a = this.options.loggerName) !== null && _a !== void 0 ? _a : LoggerNames.Room);
22153
22346
  this.options.audioCaptureDefaults = Object.assign(Object.assign({}, audioDefaults), options === null || options === void 0 ? void 0 : options.audioCaptureDefaults);
22154
22347
  this.options.videoCaptureDefaults = Object.assign(Object.assign({}, videoDefaults), options === null || options === void 0 ? void 0 : options.videoCaptureDefaults);
22155
22348
  this.options.publishDefaults = Object.assign(Object.assign({}, publishDefaults), options === null || options === void 0 ? void 0 : options.publishDefaults);
@@ -22162,8 +22355,8 @@ class Room extends eventsExports.EventEmitter {
22162
22355
  if (this.options.audioCaptureDefaults.deviceId) {
22163
22356
  this.localParticipant.activeDeviceMap.set('audioinput', unwrapConstraint(this.options.audioCaptureDefaults.deviceId));
22164
22357
  }
22165
- if ((_a = this.options.audioOutput) === null || _a === void 0 ? void 0 : _a.deviceId) {
22166
- this.switchActiveDevice('audiooutput', unwrapConstraint(this.options.audioOutput.deviceId)).catch(e => livekitLogger.warn("Could not set audio output: ".concat(e.message)));
22358
+ if ((_b = this.options.audioOutput) === null || _b === void 0 ? void 0 : _b.deviceId) {
22359
+ this.switchActiveDevice('audiooutput', unwrapConstraint(this.options.audioOutput.deviceId)).catch(e => this.log.warn("Could not set audio output: ".concat(e.message), this.logContext));
22167
22360
  }
22168
22361
  if (this.options.e2ee) {
22169
22362
  this.setupE2EE();
@@ -22198,6 +22391,13 @@ class Room extends eventsExports.EventEmitter {
22198
22391
  (_a = this.e2eeManager) === null || _a === void 0 ? void 0 : _a.setup(this);
22199
22392
  }
22200
22393
  }
22394
+ get logContext() {
22395
+ return {
22396
+ room: this.name,
22397
+ roomSid: this.sid,
22398
+ identity: this.localParticipant.identity
22399
+ };
22400
+ }
22201
22401
  /**
22202
22402
  * if the current room has a participant with `recorder: true` in its JWT grant
22203
22403
  **/
@@ -22292,7 +22492,7 @@ class Room extends eventsExports.EventEmitter {
22292
22492
  if (this.state !== ConnectionState.Disconnected) {
22293
22493
  return;
22294
22494
  }
22295
- livekitLogger.debug("prepareConnection to ".concat(url));
22495
+ this.log.debug("prepareConnection to ".concat(url), this.logContext);
22296
22496
  try {
22297
22497
  if (isCloud(new URL(url)) && token) {
22298
22498
  this.regionUrlProvider = new RegionUrlProvider(url, token);
@@ -22304,7 +22504,7 @@ class Room extends eventsExports.EventEmitter {
22304
22504
  yield fetch(toHttpUrl(regionUrl), {
22305
22505
  method: 'HEAD'
22306
22506
  });
22307
- livekitLogger.debug("prepared connection to ".concat(regionUrl));
22507
+ this.log.debug("prepared connection to ".concat(regionUrl), this.logContext);
22308
22508
  }
22309
22509
  } else {
22310
22510
  yield fetch(toHttpUrl(url), {
@@ -22312,9 +22512,9 @@ class Room extends eventsExports.EventEmitter {
22312
22512
  });
22313
22513
  }
22314
22514
  } catch (e) {
22315
- livekitLogger.warn('could not prepare connection', {
22515
+ this.log.warn('could not prepare connection', Object.assign(Object.assign({}, this.logContext), {
22316
22516
  error: e
22317
- });
22517
+ }));
22318
22518
  }
22319
22519
  });
22320
22520
  }
@@ -22561,7 +22761,7 @@ class Room extends eventsExports.EventEmitter {
22561
22761
  return;
22562
22762
  }
22563
22763
  if (this.state === ConnectionState.Disconnected) {
22564
- livekitLogger.warn('skipping incoming track after Room disconnected');
22764
+ this.log.warn('skipping incoming track after Room disconnected', this.logContext);
22565
22765
  return;
22566
22766
  }
22567
22767
  const parts = unpackStreamId(stream.id);
@@ -22572,12 +22772,12 @@ class Room extends eventsExports.EventEmitter {
22572
22772
  // and generates its own track id instead of infer from sdp track id.
22573
22773
  if (streamId && streamId.startsWith('TR')) trackId = streamId;
22574
22774
  if (participantId === this.localParticipant.sid) {
22575
- livekitLogger.warn('tried to create RemoteParticipant for local participant');
22775
+ this.log.warn('tried to create RemoteParticipant for local participant', this.logContext);
22576
22776
  return;
22577
22777
  }
22578
22778
  const participant = this.participants.get(participantId);
22579
22779
  if (!participant) {
22580
- livekitLogger.error("Tried to add a track for a participant, that's not present. Sid: ".concat(participantId));
22780
+ this.log.error("Tried to add a track for a participant, that's not present. Sid: ".concat(participantId), this.logContext);
22581
22781
  return;
22582
22782
  }
22583
22783
  let adaptiveStreamSettings;
@@ -22665,7 +22865,9 @@ class Room extends eventsExports.EventEmitter {
22665
22865
  try {
22666
22866
  yield this.audioContext.resume();
22667
22867
  } catch (e) {
22668
- livekitLogger.warn(e);
22868
+ this.log.warn('Could not resume audio context', Object.assign(Object.assign({}, this.logContext), {
22869
+ error: e
22870
+ }));
22669
22871
  }
22670
22872
  }
22671
22873
  if (this.options.expWebAudioMix) {
@@ -22685,13 +22887,16 @@ class Room extends eventsExports.EventEmitter {
22685
22887
  if (info) {
22686
22888
  participant = RemoteParticipant.fromParticipantInfo(this.engine.client, info);
22687
22889
  } else {
22688
- participant = new RemoteParticipant(this.engine.client, id, '', undefined, undefined);
22890
+ participant = new RemoteParticipant(this.engine.client, id, '', undefined, undefined, {
22891
+ loggerContextCb: () => this.logContext,
22892
+ loggerName: this.options.loggerName
22893
+ });
22689
22894
  }
22690
22895
  if (this.options.expWebAudioMix) {
22691
22896
  participant.setAudioContext(this.audioContext);
22692
22897
  }
22693
22898
  if ((_a = this.options.audioOutput) === null || _a === void 0 ? void 0 : _a.deviceId) {
22694
- participant.setAudioOutput(this.options.audioOutput).catch(e => livekitLogger.warn("Could not set audio output: ".concat(e.message)));
22899
+ participant.setAudioOutput(this.options.audioOutput).catch(e => this.log.warn("Could not set audio output: ".concat(e.message), this.logContext));
22695
22900
  }
22696
22901
  return participant;
22697
22902
  }
@@ -22784,9 +22989,9 @@ class Room extends eventsExports.EventEmitter {
22784
22989
  // transports failed without notifying engine
22785
22990
  !this.engine.verifyTransport()) {
22786
22991
  consecutiveFailures++;
22787
- livekitLogger.warn('detected connection state mismatch', {
22992
+ this.log.warn('detected connection state mismatch', Object.assign(Object.assign({}, this.logContext), {
22788
22993
  numFailures: consecutiveFailures
22789
- });
22994
+ }));
22790
22995
  if (consecutiveFailures >= 3) {
22791
22996
  this.recreateEngine();
22792
22997
  this.handleDisconnect(this.options.stopLocalTrackOnUnpublish, DisconnectReason.STATE_MISMATCH);
@@ -22868,7 +23073,13 @@ class Room extends eventsExports.EventEmitter {
22868
23073
  name: 'video-dummy'
22869
23074
  }), new LocalVideoTrack(publishOptions.useRealTracks ? (yield window.navigator.mediaDevices.getUserMedia({
22870
23075
  video: true
22871
- })).getVideoTracks()[0] : createDummyVideoStreamTrack((_a = 160 * participantOptions.aspectRatios[0]) !== null && _a !== void 0 ? _a : 1, 160, true, true)));
23076
+ })).getVideoTracks()[0] : createDummyVideoStreamTrack((_a = 160 * participantOptions.aspectRatios[0]) !== null && _a !== void 0 ? _a : 1, 160, true, true), undefined, false, {
23077
+ loggerName: this.options.loggerName,
23078
+ loggerContextCb: () => this.logContext
23079
+ }), {
23080
+ loggerName: this.options.loggerName,
23081
+ loggerContextCb: () => this.logContext
23082
+ });
22872
23083
  // @ts-ignore
22873
23084
  this.localParticipant.addTrackPublication(camPub);
22874
23085
  this.localParticipant.emit(ParticipantEvent.LocalTrackPublished, camPub);
@@ -22880,7 +23091,13 @@ class Room extends eventsExports.EventEmitter {
22880
23091
  type: TrackType.AUDIO
22881
23092
  }), new LocalAudioTrack(publishOptions.useRealTracks ? (yield navigator.mediaDevices.getUserMedia({
22882
23093
  audio: true
22883
- })).getAudioTracks()[0] : getEmptyAudioStreamTrack()));
23094
+ })).getAudioTracks()[0] : getEmptyAudioStreamTrack(), undefined, false, this.audioContext, {
23095
+ loggerName: this.options.loggerName,
23096
+ loggerContextCb: () => this.logContext
23097
+ }), {
23098
+ loggerName: this.options.loggerName,
23099
+ loggerContextCb: () => this.logContext
23100
+ });
22884
23101
  // @ts-ignore
22885
23102
  this.localParticipant.addTrackPublication(audioPub);
22886
23103
  this.localParticipant.emit(ParticipantEvent.LocalTrackPublished, audioPub);
@@ -22925,14 +23142,30 @@ class Room extends eventsExports.EventEmitter {
22925
23142
  }
22926
23143
  // active speaker updates are too spammy
22927
23144
  if (event !== RoomEvent.ActiveSpeakersChanged) {
22928
- livekitLogger.debug("room event ".concat(event), {
23145
+ // only extract logContext from arguments in order to avoid logging the whole object tree
23146
+ const minimizedArgs = mapArgs(args).filter(arg => arg !== undefined);
23147
+ this.log.debug("room event ".concat(event), Object.assign(Object.assign({}, this.logContext), {
22929
23148
  event,
22930
- args
22931
- });
23149
+ args: minimizedArgs
23150
+ }));
22932
23151
  }
22933
23152
  return super.emit(event, ...args);
22934
23153
  }
22935
23154
  }
23155
+ function mapArgs(args) {
23156
+ return args.map(arg => {
23157
+ if (!arg) {
23158
+ return;
23159
+ }
23160
+ if (Array.isArray(arg)) {
23161
+ return mapArgs(arg);
23162
+ }
23163
+ if (typeof arg === 'object') {
23164
+ return 'logContext' in arg && arg.logContext;
23165
+ }
23166
+ return arg;
23167
+ });
23168
+ }
22936
23169
 
22937
23170
  var CheckStatus;
22938
23171
  (function (CheckStatus) {
@@ -23138,8 +23371,8 @@ function createLocalScreenTracks(options) {
23138
23371
  if (options === undefined) {
23139
23372
  options = {};
23140
23373
  }
23141
- if (options.resolution === undefined) {
23142
- options.resolution = ScreenSharePresets.h1080fps15.resolution;
23374
+ if (options.resolution === undefined && !isSafari17()) {
23375
+ options.resolution = ScreenSharePresets.h1080fps30.resolution;
23143
23376
  }
23144
23377
  if (navigator.mediaDevices.getDisplayMedia === undefined) {
23145
23378
  throw new DeviceUnsupportedError('getDisplayMedia not supported');
@@ -23566,5 +23799,5 @@ function isFacingModeValue(item) {
23566
23799
  return item === undefined || allowedValues.includes(item);
23567
23800
  }
23568
23801
 
23569
- 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 };
23802
+ 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 };
23570
23803
  //# sourceMappingURL=livekit-client.esm.mjs.map