@dora-cell/sdk 4.1.0 → 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
@@ -23030,9 +23030,15 @@ var ApiTokenAuthProvider = class {
23030
23030
  })
23031
23031
  });
23032
23032
  if (!authResponse.ok) {
23033
+ let errorData;
23034
+ try {
23035
+ errorData = await authResponse.json();
23036
+ } catch (e) {
23037
+ errorData = { message: authResponse.statusText };
23038
+ }
23033
23039
  throw new AuthenticationError(
23034
- `Key verification failed: ${authResponse.status}`,
23035
- { status: authResponse.status }
23040
+ errorData.message || errorData.error || authResponse.statusText || `HTTP ${authResponse.status}`,
23041
+ { status: authResponse.status, data: errorData }
23036
23042
  );
23037
23043
  }
23038
23044
  const authData = await authResponse.json();
@@ -23051,9 +23057,15 @@ var ApiTokenAuthProvider = class {
23051
23057
  }
23052
23058
  });
23053
23059
  if (!validateResponse.ok) {
23060
+ let errorData;
23061
+ try {
23062
+ errorData = await validateResponse.json();
23063
+ } catch (e) {
23064
+ errorData = { message: validateResponse.statusText };
23065
+ }
23054
23066
  throw new AuthenticationError(
23055
- `Secondary validation failed: ${validateResponse.status}`,
23056
- { status: validateResponse.status }
23067
+ errorData.message || errorData.error || validateResponse.statusText || `HTTP ${validateResponse.status}`,
23068
+ { status: validateResponse.status, data: errorData }
23057
23069
  );
23058
23070
  }
23059
23071
  const validateData = await validateResponse.json();
@@ -23065,11 +23077,12 @@ var ApiTokenAuthProvider = class {
23065
23077
  this.credentials = this.parseCredentials(actualResponseData);
23066
23078
  return this.credentials;
23067
23079
  } catch (error) {
23080
+ console.error("Dora Cell SDK: Authentication error:", error);
23068
23081
  if (error instanceof AuthenticationError) {
23069
23082
  throw error;
23070
23083
  }
23071
23084
  throw new AuthenticationError(
23072
- `Authentication failed: ${error instanceof Error ? error.message : "Unknown error"}`,
23085
+ error instanceof Error ? error.message : "Unknown error",
23073
23086
  { originalError: error }
23074
23087
  );
23075
23088
  }
@@ -23091,9 +23104,9 @@ var ApiTokenAuthProvider = class {
23091
23104
  const DEFAULT_WSS_URL = "wss://cell.usedora.com:8089/ws";
23092
23105
  const DEFAULT_SIP_IP = "64.227.10.164";
23093
23106
  const DEFAULT_PASSWORD = "1234";
23094
- const wsUrl = data.ws_url || data.wsUrl || DEFAULT_WSS_URL;
23095
- const sipDomain = data.sip_domain || data.sipDomain || DEFAULT_SIP_IP;
23096
- const password = data.password || DEFAULT_PASSWORD;
23107
+ const wsUrl = DEFAULT_WSS_URL;
23108
+ const sipDomain = DEFAULT_SIP_IP;
23109
+ const password = DEFAULT_PASSWORD;
23097
23110
  const extensions = data.extensions || [];
23098
23111
  const expiresIn = data.expires_in || data.expiresIn;
23099
23112
  let sipUri = data.sip_uri || data.sipUri;
@@ -23596,9 +23609,14 @@ var DoraCell = class {
23596
23609
  await this.waitForRegistration();
23597
23610
  }
23598
23611
  } catch (error) {
23612
+ if (error instanceof DoraCellError) {
23613
+ this.emitError(error);
23614
+ throw error;
23615
+ }
23599
23616
  const errorMessage = error instanceof Error ? error.message : "Unknown error";
23600
- this.emitError(new ConnectionError(`Initialization failed: ${errorMessage}`));
23601
- throw error;
23617
+ const connError = new ConnectionError(errorMessage, { originalError: error });
23618
+ this.emitError(connError);
23619
+ throw connError;
23602
23620
  }
23603
23621
  }
23604
23622
  waitForRegistration(timeoutMs = 1e4) {
@@ -23608,17 +23626,19 @@ var DoraCell = class {
23608
23626
  return new Promise((resolve, reject) => {
23609
23627
  const timeout = setTimeout(() => {
23610
23628
  this.off("connection:status", handler);
23611
- 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}`));
23612
23631
  }, timeoutMs);
23613
23632
  const handler = (state) => {
23614
23633
  if (state.status === "registered") {
23615
23634
  clearTimeout(timeout);
23616
23635
  this.off("connection:status", handler);
23617
23636
  resolve();
23618
- } else if (state.status === "registrationFailed") {
23637
+ } else if (state.status === "registrationFailed" || state.status === "disconnected") {
23619
23638
  clearTimeout(timeout);
23620
23639
  this.off("connection:status", handler);
23621
- 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));
23622
23642
  }
23623
23643
  };
23624
23644
  this.on("connection:status", handler);
@@ -23632,6 +23652,7 @@ var DoraCell = class {
23632
23652
  this.emitConnectionStatus();
23633
23653
  if (this.ua) {
23634
23654
  try {
23655
+ this.ua.removeAllListeners();
23635
23656
  this.ua.stop();
23636
23657
  } catch (e) {
23637
23658
  }
@@ -23663,7 +23684,8 @@ var DoraCell = class {
23663
23684
  }
23664
23685
  } catch (error) {
23665
23686
  throw new ConnectionError(
23666
- `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 }
23667
23689
  );
23668
23690
  }
23669
23691
  }
@@ -23673,9 +23695,25 @@ var DoraCell = class {
23673
23695
  this.connectionStatus = "connected";
23674
23696
  this.emitConnectionStatus();
23675
23697
  });
23676
- 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
+ }
23677
23702
  this.connectionStatus = "disconnected";
23678
- 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
+ }
23679
23717
  });
23680
23718
  this.ua.on("registered", () => {
23681
23719
  this.connectionStatus = "registered";
@@ -23684,8 +23722,15 @@ var DoraCell = class {
23684
23722
  this.emitConnectionStatus();
23685
23723
  });
23686
23724
  this.ua.on("registrationFailed", (e) => {
23725
+ if (this.config.debug) {
23726
+ console.error("Dora Cell SDK: Registration failed:", e);
23727
+ }
23687
23728
  this.connectionStatus = "registrationFailed";
23688
- 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);
23689
23734
  if (this.retryCount < this.maxRetries) {
23690
23735
  this.retryCount++;
23691
23736
  setTimeout(() => {
@@ -23823,7 +23868,7 @@ var DoraCell = class {
23823
23868
  this.credentials.sipUri = `sip:${extension}@${domain}`;
23824
23869
  await this.initializeUserAgent();
23825
23870
  await this.waitForRegistration();
23826
- this.emitConnectionStatus(this.connectionStatus);
23871
+ this.emitConnectionStatus();
23827
23872
  }
23828
23873
  }
23829
23874
  /**
@@ -23872,14 +23917,9 @@ var DoraCell = class {
23872
23917
  this.events.emit("error", error);
23873
23918
  }
23874
23919
  getDefaultTurnServers() {
23875
- let turnUri = "turn:64.227.10.164:3478";
23876
- let turnUser = "02018890089";
23877
- let turnPass = "dora12345";
23878
- if (typeof process !== "undefined" && process.env) {
23879
- turnUri = turnUri;
23880
- turnUser = turnUser;
23881
- turnPass = turnPass;
23882
- }
23920
+ const turnUri = "turn:64.227.10.164:3478";
23921
+ const turnUser = "02018890089";
23922
+ const turnPass = "dora12345";
23883
23923
  return [
23884
23924
  {
23885
23925
  urls: turnUri,
@@ -23921,9 +23961,6 @@ var DoraCell = class {
23921
23961
  return "https://api.cell.usedora.com/api";
23922
23962
  }
23923
23963
  }
23924
- if (typeof process !== "undefined" && process.env?.NEXT_PUBLIC_BASE_API_URL) {
23925
- return process.env.NEXT_PUBLIC_BASE_API_URL;
23926
- }
23927
23964
  return "https://api.cell.usedora.com/api";
23928
23965
  }
23929
23966
  };