@signalwire/js 4.0.0-dev-20260304194027 → 4.0.0-dev-20260309151622

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
@@ -9122,6 +9122,15 @@ var JSONRPCError = class extends Error {
9122
9122
  this.name = "JSONRPCError";
9123
9123
  }
9124
9124
  };
9125
+ var RPCError = class extends Error {
9126
+ constructor(code, requestId, message, data, options) {
9127
+ super(message, options);
9128
+ this.code = code;
9129
+ this.requestId = requestId;
9130
+ this.data = data;
9131
+ this.name = "RPCError";
9132
+ }
9133
+ };
9125
9134
  var InvalidParams = class extends Error {
9126
9135
  constructor(message, options) {
9127
9136
  super(message, options);
@@ -15292,9 +15301,15 @@ var PendingRPC = class PendingRPC {
15292
15301
  return () => signal.removeEventListener("abort", abortHandler);
15293
15302
  }) : import_cjs$6.NEVER).subscribe({
15294
15303
  next: (response) => {
15295
- logger$7.debug(`[PendingRPC(${this.id}) request:${request.id}] Resolving promise with response:`, response);
15296
15304
  isSettled = true;
15297
- resolve(response);
15305
+ if (response.error) {
15306
+ const rpcError = new RPCError(response.error.code, request.id, response.error.message, response.error.data);
15307
+ logger$7.debug(`[PendingRPC(${this.id}) request:${request.id}] Rejecting promise with RPC error:`, rpcError);
15308
+ reject(rpcError);
15309
+ } else {
15310
+ logger$7.debug(`[PendingRPC(${this.id}) request:${request.id}] Resolving promise with response:`, response);
15311
+ resolve(response);
15312
+ }
15298
15313
  subscription.unsubscribe();
15299
15314
  },
15300
15315
  error: (error) => {
@@ -16310,7 +16325,10 @@ var SignalWire = class extends Destroyable {
16310
16325
  throw new InvalidCredentialsError("Provided credentials have expired.");
16311
16326
  }
16312
16327
  if (_credentials.expiry_at && credentialProvider.refresh) {
16313
- const refreshFn = credentialProvider.refresh;
16328
+ const refreshFn = async () => {
16329
+ if (!credentialProvider.refresh) throw new InvalidCredentialsError("Credential provider does not support refresh");
16330
+ return credentialProvider.refresh();
16331
+ };
16314
16332
  const refreshInterval = Math.max(_credentials.expiry_at - Date.now() - 5e3, 1e3);
16315
16333
  this._refreshTimerId = setTimeout(async () => {
16316
16334
  try {
@@ -16340,7 +16358,12 @@ var SignalWire = class extends Destroyable {
16340
16358
  this._subscriber$.next(new Subscriber(this._deps.http));
16341
16359
  if (!this._options.skipConnection) await this.connect();
16342
16360
  if (!this._options.reconnectAttachedCalls && this._attachManager) await this._attachManager.flush();
16343
- if (!this._options.skipRegister) this.register();
16361
+ if (!this._options.skipRegister) try {
16362
+ await this.register();
16363
+ } catch (error) {
16364
+ logger$1.error("[SignalWire] Registration failed:", error);
16365
+ this._errors$.next(error instanceof Error ? error : new Error(String(error), { cause: error }));
16366
+ }
16344
16367
  this.handleAttachments();
16345
16368
  }
16346
16369
  async handleAttachments() {
@@ -16503,8 +16526,22 @@ var SignalWire = class extends Destroyable {
16503
16526
  }));
16504
16527
  this._isRegistered$.next(true);
16505
16528
  } catch (error) {
16506
- logger$1.error("[SignalWire] Failed to register subscriber:", error);
16529
+ logger$1.debug("[SignalWire] Failed to register subscriber, trying reauthentication...");
16530
+ if (this._deps.credential.token) this._clientSession.reauthenticate(this._deps.credential.token).then(async () => {
16531
+ logger$1.debug("[SignalWire] Reauthentication successful, retrying register()");
16532
+ await this._transport.execute(RPCExecute({
16533
+ method: "subscriber.online",
16534
+ params: {}
16535
+ }));
16536
+ this._isRegistered$.next(true);
16537
+ }).catch((reauthError) => {
16538
+ logger$1.error("[SignalWire] Reauthentication failed during register():", reauthError);
16539
+ const registerError = new InvalidCredentialsError("Failed to register subscriber, and reauthentication attempt also failed. Please check your credentials.", { cause: reauthError instanceof Error ? reauthError : new Error(String(reauthError), { cause: reauthError }) });
16540
+ this._errors$.next(registerError);
16541
+ throw registerError;
16542
+ });
16507
16543
  this._errors$.next(error instanceof Error ? error : new Error(String(error), { cause: error }));
16544
+ throw error;
16508
16545
  }
16509
16546
  }
16510
16547
  /** Unregisters the subscriber, going offline for inbound calls. */