@signalwire/js 4.0.0-dev-20260416142417 → 4.0.0-dev-20260416174405

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/browser.mjs CHANGED
@@ -9492,33 +9492,70 @@ const originalFactory = defaultLogger.methodFactory;
9492
9492
  defaultLogger.methodFactory = (methodName, logLevel, loggerName) => {
9493
9493
  const rawMethod = originalFactory(methodName, logLevel, loggerName);
9494
9494
  return function(...args) {
9495
- args.unshift(datetime(), "-");
9496
- rawMethod.apply(void 0, args);
9495
+ const prefixed = [
9496
+ datetime(),
9497
+ "-",
9498
+ ...args
9499
+ ];
9500
+ rawMethod.apply(void 0, prefixed);
9497
9501
  };
9498
9502
  };
9499
- const defaultLoggerLevel = defaultLogger.levels.DEBUG;
9503
+ const defaultLoggerLevel = defaultLogger.levels.WARN;
9500
9504
  defaultLogger.setLevel(defaultLoggerLevel);
9501
- let userLogger;
9505
+ let userLogger = null;
9506
+ /** Replace the built-in logger with a custom implementation. Pass `null` to restore defaults. */
9507
+ const setLogger = (logger$30) => {
9508
+ userLogger = logger$30;
9509
+ };
9502
9510
  let debugOptions = {};
9511
+ /** Configure debug options (e.g., `{ logWsTraffic: true }`). */
9512
+ const setDebugOptions = (options) => {
9513
+ if (options == null) {
9514
+ debugOptions = {};
9515
+ return;
9516
+ }
9517
+ debugOptions = {
9518
+ ...debugOptions,
9519
+ ...options
9520
+ };
9521
+ };
9522
+ /**
9523
+ * Set the log level for the built-in logger.
9524
+ * Has no effect when a custom logger is set via `setLogger()`.
9525
+ */
9526
+ const setLogLevel = (level) => {
9527
+ defaultLogger.setLevel(level);
9528
+ };
9503
9529
  const getLoggerInstance = () => {
9504
9530
  return userLogger ?? defaultLogger;
9505
9531
  };
9506
9532
  const shouldStringify = (payload) => {
9507
- if ("method" in payload && payload.method === "signalwire.ping") return false;
9533
+ if (payload != null && typeof payload === "object" && "method" in payload) return payload.method !== "signalwire.ping";
9508
9534
  return true;
9509
9535
  };
9510
- const wsTraffic = ({ type, payload }) => {
9511
- const logger$30 = getLoggerInstance();
9512
- const { logWsTraffic } = debugOptions ?? {};
9536
+ const wsTraffic = (options) => {
9537
+ const { logWsTraffic } = debugOptions;
9513
9538
  if (!logWsTraffic) return;
9539
+ const loggerInstance = getLoggerInstance();
9540
+ let payload;
9541
+ if ("raw" in options) try {
9542
+ payload = JSON.parse(options.raw);
9543
+ } catch {
9544
+ loggerInstance.debug(`[WebSocket] ${options.type.toUpperCase()}: non-JSON message`);
9545
+ return;
9546
+ }
9547
+ else payload = options.payload;
9514
9548
  const msg = shouldStringify(payload) ? JSON.stringify(payload, null, 2) : payload;
9515
- return logger$30.debug(`${type.toUpperCase()}: \n`, msg, "\n");
9549
+ loggerInstance.debug(`${options.type.toUpperCase()}: \n`, msg, "\n");
9516
9550
  };
9517
9551
  const getLogger = () => {
9518
9552
  const logger$30 = getLoggerInstance();
9519
- return new Proxy(logger$30, { get(target, prop, receiver) {
9553
+ return new Proxy(logger$30, { get(_target, prop, _receiver) {
9520
9554
  if (prop === "wsTraffic") return wsTraffic;
9521
- return Reflect.get(target, prop, receiver);
9555
+ const instance = getLoggerInstance();
9556
+ const value = Reflect.get(instance, prop);
9557
+ if (typeof value === "function") return value.bind(instance);
9558
+ return value;
9522
9559
  } });
9523
9560
  };
9524
9561
 
@@ -20112,11 +20149,10 @@ var WebSocketController = class WebSocketController extends Destroyable {
20112
20149
  }
20113
20150
  send(data) {
20114
20151
  if (this._status$.value === "connected" && this.socket?.readyState === 1) {
20115
- try {
20116
- logger$3.debug(`[WebSocketConnectionManager] Sending message:\n${JSON.stringify(JSON.parse(data), null, 2)}`);
20117
- } catch {
20118
- logger$3.warn(`[WebSocketConnectionManager] Sending non-JSON message:\n${data}`);
20119
- }
20152
+ logger$3.wsTraffic({
20153
+ type: "send",
20154
+ raw: data
20155
+ });
20120
20156
  this.socket.send(data);
20121
20157
  } else this.messageQueue.push(data);
20122
20158
  }
@@ -20179,11 +20215,10 @@ var WebSocketController = class WebSocketController extends Destroyable {
20179
20215
  this.handleConnectionError();
20180
20216
  }
20181
20217
  handleMessage(event) {
20182
- try {
20183
- logger$3.debug(`[WebSocketConnectionManager] Received message:\n${JSON.stringify(JSON.parse(event.data), null, 2)}`);
20184
- } catch {
20185
- logger$3.warn(`[WebSocketConnectionManager] Received non-JSON message:\n${event.data}`);
20186
- }
20218
+ logger$3.wsTraffic({
20219
+ type: "recv",
20220
+ raw: event.data
20221
+ });
20187
20222
  this._incomingMessages$.next(event);
20188
20223
  }
20189
20224
  handleConnectionError() {
@@ -20486,6 +20521,9 @@ var SignalWire = class extends Destroyable {
20486
20521
  if (this._options.webSocketConstructor) this._deps.WebSocket = this._options.webSocketConstructor;
20487
20522
  if (this._options.savePreferences) this.preferences.enableSavePreferences(this._deps.storage);
20488
20523
  if (this._options.webRTCApiProvider) this._deps.webRTCApiProvider = this._options.webRTCApiProvider;
20524
+ if (this._options.logger !== void 0) setLogger(this._options.logger);
20525
+ if (this._options.logLevel) setLogLevel(this._options.logLevel);
20526
+ if (this._options.debug) setDebugOptions(this._options.debug);
20489
20527
  this._deviceController = this._deps.deviceController;
20490
20528
  if (!this._options.skipDeviceMonitoring) this._deviceController.enableDeviceMonitoring();
20491
20529
  this.subscribeTo(this._deviceController.errors$, (error) => {
@@ -20562,7 +20600,7 @@ var SignalWire = class extends Destroyable {
20562
20600
  if (_credentials.expiry_at && credentialProvider?.refresh) this.scheduleCredentialRefresh(credentialProvider, _credentials.expiry_at);
20563
20601
  this._deps.credential = _credentials;
20564
20602
  this.persistCredential(_credentials);
20565
- if (this.isConnected && this._clientSession?.authenticated && _credentials.token) try {
20603
+ if (this.isConnected && this._clientSession.authenticated && _credentials.token) try {
20566
20604
  await this._clientSession.reauthenticate(_credentials.token);
20567
20605
  logger$1.info("[SignalWire] Session refreshed with new credentials.");
20568
20606
  } catch (error) {
@@ -20640,9 +20678,9 @@ var SignalWire = class extends Destroyable {
20640
20678
  * unexpectedly (e.g. network change, server restart). Reconnection uses an
20641
20679
  * **exponential back-off** strategy:
20642
20680
  *
20643
- * - First retry after `reconnectDelayMin` (default **1 s**).
20681
+ * - First retry after `reconnectDelayMin` (default **0.1 s**).
20644
20682
  * - Each subsequent retry doubles the delay up to `reconnectDelayMax`
20645
- * (default **30 s**).
20683
+ * (default **3 s**).
20646
20684
  * - The delay resets to `reconnectDelayMin` once a connection succeeds.
20647
20685
  * - A per-attempt `connectionTimeout` (default **10 s**) aborts the
20648
20686
  * attempt and schedules the next retry if the server does not respond.
@@ -21397,5 +21435,5 @@ emitReadyEvent();
21397
21435
  if (typeof process === "undefined") globalThis.process = { env: { NODE_ENV: "production" } };
21398
21436
 
21399
21437
  //#endregion
21400
- export { Address, CallCreateError, ClientPreferences, CollectionFetchError, DPoPInitError, DeviceTokenError, InvalidCredentialsError, MediaTrackError, MessageParseError, OverconstrainedFallbackError, Participant, PreflightError, RecoveryError, SelfCapabilities, SelfParticipant, SignalWire, StaticCredentialProvider, Subscriber, TokenRefreshError, UnexpectedError, VertoPongError, WebRTCCall, embeddableCall, isSelfParticipant, ready, version };
21438
+ export { Address, CallCreateError, ClientPreferences, CollectionFetchError, DPoPInitError, DeviceTokenError, InvalidCredentialsError, MediaTrackError, MessageParseError, OverconstrainedFallbackError, Participant, PreflightError, RecoveryError, SelfCapabilities, SelfParticipant, SignalWire, StaticCredentialProvider, Subscriber, TokenRefreshError, UnexpectedError, VertoPongError, WebRTCCall, embeddableCall, isSelfParticipant, ready, setDebugOptions, setLogLevel, setLogger, version };
21401
21439
  //# sourceMappingURL=browser.mjs.map