@dora-cell/sdk 4.1.1 → 4.1.2

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/index.js CHANGED
@@ -23037,7 +23037,7 @@ var ApiTokenAuthProvider = class {
23037
23037
  errorData = { message: authResponse.statusText };
23038
23038
  }
23039
23039
  throw new AuthenticationError(
23040
- errorData.message || errorData.error || `Key verification failed: ${authResponse.status}`,
23040
+ errorData.message || errorData.error || authResponse.statusText || `HTTP ${authResponse.status}`,
23041
23041
  { status: authResponse.status, data: errorData }
23042
23042
  );
23043
23043
  }
@@ -23064,7 +23064,7 @@ var ApiTokenAuthProvider = class {
23064
23064
  errorData = { message: validateResponse.statusText };
23065
23065
  }
23066
23066
  throw new AuthenticationError(
23067
- errorData.message || errorData.error || `Secondary validation failed: ${validateResponse.status}`,
23067
+ errorData.message || errorData.error || validateResponse.statusText || `HTTP ${validateResponse.status}`,
23068
23068
  { status: validateResponse.status, data: errorData }
23069
23069
  );
23070
23070
  }
@@ -23077,11 +23077,12 @@ var ApiTokenAuthProvider = class {
23077
23077
  this.credentials = this.parseCredentials(actualResponseData);
23078
23078
  return this.credentials;
23079
23079
  } catch (error) {
23080
+ console.error("Dora Cell SDK: Authentication error:", error);
23080
23081
  if (error instanceof AuthenticationError) {
23081
23082
  throw error;
23082
23083
  }
23083
23084
  throw new AuthenticationError(
23084
- `Authentication failed: ${error instanceof Error ? error.message : "Unknown error"}`,
23085
+ error instanceof Error ? error.message : "Unknown error",
23085
23086
  { originalError: error }
23086
23087
  );
23087
23088
  }
@@ -23103,9 +23104,9 @@ var ApiTokenAuthProvider = class {
23103
23104
  const DEFAULT_WSS_URL = "wss://cell.usedora.com:8089/ws";
23104
23105
  const DEFAULT_SIP_IP = "64.227.10.164";
23105
23106
  const DEFAULT_PASSWORD = "1234";
23106
- const wsUrl = data.ws_url || data.wsUrl || DEFAULT_WSS_URL;
23107
- const sipDomain = data.sip_domain || data.sipDomain || DEFAULT_SIP_IP;
23108
- const password = data.password || DEFAULT_PASSWORD;
23107
+ const wsUrl = DEFAULT_WSS_URL;
23108
+ const sipDomain = DEFAULT_SIP_IP;
23109
+ const password = DEFAULT_PASSWORD;
23109
23110
  const extensions = data.extensions || [];
23110
23111
  const expiresIn = data.expires_in || data.expiresIn;
23111
23112
  let sipUri = data.sip_uri || data.sipUri;
@@ -23608,9 +23609,14 @@ var DoraCell = class {
23608
23609
  await this.waitForRegistration();
23609
23610
  }
23610
23611
  } catch (error) {
23612
+ if (error instanceof DoraCellError) {
23613
+ this.emitError(error);
23614
+ throw error;
23615
+ }
23611
23616
  const errorMessage = error instanceof Error ? error.message : "Unknown error";
23612
- this.emitError(new ConnectionError(`Initialization failed: ${errorMessage}`));
23613
- throw error;
23617
+ const connError = new ConnectionError(errorMessage, { originalError: error });
23618
+ this.emitError(connError);
23619
+ throw connError;
23614
23620
  }
23615
23621
  }
23616
23622
  waitForRegistration(timeoutMs = 1e4) {
@@ -23620,17 +23626,19 @@ var DoraCell = class {
23620
23626
  return new Promise((resolve, reject) => {
23621
23627
  const timeout = setTimeout(() => {
23622
23628
  this.off("connection:status", handler);
23623
- reject(new ConnectionError(`Registration timed out after ${timeoutMs}ms`));
23629
+ const statusInfo = this.connectionStatus !== "connecting" ? ` (Last status: ${this.connectionStatus})` : "";
23630
+ reject(new ConnectionError(`Registration timed out after ${timeoutMs}ms${statusInfo}`));
23624
23631
  }, timeoutMs);
23625
23632
  const handler = (state) => {
23626
23633
  if (state.status === "registered") {
23627
23634
  clearTimeout(timeout);
23628
23635
  this.off("connection:status", handler);
23629
23636
  resolve();
23630
- } else if (state.status === "registrationFailed") {
23637
+ } else if (state.status === "registrationFailed" || state.status === "disconnected") {
23631
23638
  clearTimeout(timeout);
23632
23639
  this.off("connection:status", handler);
23633
- reject(new ConnectionError(`Registration failed: ${state.error || "Unknown cause"}`));
23640
+ const cause = state.error || (state.status === "disconnected" ? "WebSocket disconnected" : "Registration failed");
23641
+ reject(new ConnectionError(cause));
23634
23642
  }
23635
23643
  };
23636
23644
  this.on("connection:status", handler);
@@ -23644,6 +23652,7 @@ var DoraCell = class {
23644
23652
  this.emitConnectionStatus();
23645
23653
  if (this.ua) {
23646
23654
  try {
23655
+ this.ua.removeAllListeners();
23647
23656
  this.ua.stop();
23648
23657
  } catch (e) {
23649
23658
  }
@@ -23675,7 +23684,8 @@ var DoraCell = class {
23675
23684
  }
23676
23685
  } catch (error) {
23677
23686
  throw new ConnectionError(
23678
- `Failed to initialize User Agent: ${error instanceof Error ? error.message : "Unknown error"}`
23687
+ error instanceof Error ? error.message : "Failed to initialize User Agent",
23688
+ { originalError: error }
23679
23689
  );
23680
23690
  }
23681
23691
  }
@@ -23685,9 +23695,25 @@ var DoraCell = class {
23685
23695
  this.connectionStatus = "connected";
23686
23696
  this.emitConnectionStatus();
23687
23697
  });
23688
- this.ua.on("disconnected", () => {
23698
+ this.ua.on("disconnected", (e) => {
23699
+ if (this.config.debug) {
23700
+ console.error("Dora Cell SDK: WebSocket disconnected:", e);
23701
+ }
23689
23702
  this.connectionStatus = "disconnected";
23690
- this.emitConnectionStatus();
23703
+ let reason = e.reason || (e.error ? `WebSocket error` : void 0);
23704
+ if (reason && e.code) {
23705
+ reason = `${reason} (Code: ${e.code})`;
23706
+ }
23707
+ this.emitConnectionStatus(reason);
23708
+ if (e.error && this.retryCount < this.maxRetries) {
23709
+ this.retryCount++;
23710
+ setTimeout(() => {
23711
+ if (this.connectionStatus !== "registered" && this.connectionStatus !== "connected") {
23712
+ this.initializeUserAgent().catch(() => {
23713
+ });
23714
+ }
23715
+ }, 5e3);
23716
+ }
23691
23717
  });
23692
23718
  this.ua.on("registered", () => {
23693
23719
  this.connectionStatus = "registered";
@@ -23696,8 +23722,15 @@ var DoraCell = class {
23696
23722
  this.emitConnectionStatus();
23697
23723
  });
23698
23724
  this.ua.on("registrationFailed", (e) => {
23725
+ if (this.config.debug) {
23726
+ console.error("Dora Cell SDK: Registration failed:", e);
23727
+ }
23699
23728
  this.connectionStatus = "registrationFailed";
23700
- this.emitConnectionStatus(e.cause);
23729
+ let error = e.cause;
23730
+ if (e.response) {
23731
+ error = `${e.response.status_code} ${e.response.reason_phrase} (${e.cause})`;
23732
+ }
23733
+ this.emitConnectionStatus(error);
23701
23734
  if (this.retryCount < this.maxRetries) {
23702
23735
  this.retryCount++;
23703
23736
  setTimeout(() => {
@@ -23835,7 +23868,7 @@ var DoraCell = class {
23835
23868
  this.credentials.sipUri = `sip:${extension}@${domain}`;
23836
23869
  await this.initializeUserAgent();
23837
23870
  await this.waitForRegistration();
23838
- this.emitConnectionStatus(this.connectionStatus);
23871
+ this.emitConnectionStatus();
23839
23872
  }
23840
23873
  }
23841
23874
  /**
@@ -23884,14 +23917,9 @@ var DoraCell = class {
23884
23917
  this.events.emit("error", error);
23885
23918
  }
23886
23919
  getDefaultTurnServers() {
23887
- let turnUri = "turn:64.227.10.164:3478";
23888
- let turnUser = "02018890089";
23889
- let turnPass = "dora12345";
23890
- if (typeof process !== "undefined" && process.env) {
23891
- turnUri = turnUri;
23892
- turnUser = turnUser;
23893
- turnPass = turnPass;
23894
- }
23920
+ const turnUri = "turn:64.227.10.164:3478";
23921
+ const turnUser = "02018890089";
23922
+ const turnPass = "dora12345";
23895
23923
  return [
23896
23924
  {
23897
23925
  urls: turnUri,
@@ -23933,9 +23961,6 @@ var DoraCell = class {
23933
23961
  return "https://api.cell.usedora.com/api";
23934
23962
  }
23935
23963
  }
23936
- if (typeof process !== "undefined" && process.env?.NEXT_PUBLIC_BASE_API_URL) {
23937
- return process.env.NEXT_PUBLIC_BASE_API_URL;
23938
- }
23939
23964
  return "https://api.cell.usedora.com/api";
23940
23965
  }
23941
23966
  };