@dora-cell/sdk 2.0.0 → 3.0.0

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
@@ -23015,7 +23015,6 @@ var ApiTokenAuthProvider = class {
23015
23015
  }
23016
23016
  const baseUrl = apiBaseUrl?.replace(/\/$/, "") || "https://api.cell.usedora.com/api";
23017
23017
  try {
23018
- console.log("SDK: Verifying keys at:", `${baseUrl}/sdk/v1/auth/session`);
23019
23018
  const authResponse = await fetch(`${baseUrl}/sdk/v1/auth/session`, {
23020
23019
  method: "POST",
23021
23020
  headers: {
@@ -23037,7 +23036,6 @@ var ApiTokenAuthProvider = class {
23037
23036
  if (!this.sessionToken) {
23038
23037
  throw new AuthenticationError("No session token returned after key verification");
23039
23038
  }
23040
- console.log("SDK: Performing secondary validation...");
23041
23039
  const origin = typeof window !== "undefined" ? window.location.origin : "";
23042
23040
  const validateResponse = await fetch(`${baseUrl}/sdk/v1/auth/validate`, {
23043
23041
  method: "GET",
@@ -23055,9 +23053,9 @@ var ApiTokenAuthProvider = class {
23055
23053
  );
23056
23054
  }
23057
23055
  const validateData = await validateResponse.json();
23058
- console.log(`SDK: Secondary validation successful for "${validateData.app_name}"`);
23056
+ console.log(`Dora Cell SDK: Authenticated successfully`);
23059
23057
  if (validateData.features && !validateData.features.includes("voice")) {
23060
- console.warn('SDK: App token does not have the "voice" feature enabled.');
23058
+ console.warn('Dora Cell SDK: App token does not have the "voice" feature enabled.');
23061
23059
  }
23062
23060
  const actualResponseData = authData.data && typeof authData.data === "object" ? authData.data : authData;
23063
23061
  this.credentials = this.parseCredentials(actualResponseData);
@@ -23098,7 +23096,6 @@ var ApiTokenAuthProvider = class {
23098
23096
  if (!sipUri && extensions.length > 0) {
23099
23097
  const ext = extensions[0].extension;
23100
23098
  sipUri = `sip:${ext}@${sipDomain}`;
23101
- console.log(`SDK: Constructed SIP URI from extension: ${sipUri}`);
23102
23099
  } else if (!sipUri) {
23103
23100
  sipUri = "";
23104
23101
  }
@@ -23250,11 +23247,11 @@ var CallSession = class {
23250
23247
  };
23251
23248
  });
23252
23249
  this.session.on("ended", (evt) => {
23253
- console.log(`SDK: Call ended. Cause: ${evt?.cause || "Normal"}`);
23250
+ console.log(`Dora Cell SDK: Call ended (${evt?.cause || "Normal"})`);
23254
23251
  this.handleCallEnd(evt?.cause);
23255
23252
  });
23256
23253
  this.session.on("failed", (evt) => {
23257
- console.warn(`SDK: Call failed. Cause: ${evt?.cause || "Unknown failure"}`);
23254
+ console.warn(`Dora Cell SDK: Call failed (${evt?.cause || "Internal Error"})`);
23258
23255
  this.handleCallEnd(evt?.cause || "Call failed");
23259
23256
  });
23260
23257
  this.session.on("rejected", (evt) => {
@@ -23274,7 +23271,6 @@ var CallSession = class {
23274
23271
  const ssrc = report.ssrc;
23275
23272
  if (ssrc && !this.lastKnownSSRCs.has(ssrc)) {
23276
23273
  this.lastKnownSSRCs.add(ssrc);
23277
- console.log(`SDK: SSRC Switch Detected: ${ssrc}. Re-binding audio...`);
23278
23274
  setTimeout(() => this.reattachFromReceivers(pc), 200);
23279
23275
  }
23280
23276
  }
@@ -23293,7 +23289,6 @@ var CallSession = class {
23293
23289
  if (!pc) return;
23294
23290
  const liveAudioTracks = pc.getReceivers().map((r) => r.track).filter((t) => t && t.kind === "audio" && t.readyState === "live");
23295
23291
  if (liveAudioTracks.length > 0) {
23296
- console.log(`SDK: Audio Fix: Rebuilding stream from ${liveAudioTracks.length} receivers`);
23297
23292
  const newStream = new MediaStream(liveAudioTracks);
23298
23293
  this.remoteStreamValue = newStream;
23299
23294
  this.events.emit("call:stream", this, newStream);
@@ -23384,7 +23379,7 @@ var CallManager = class {
23384
23379
  const extension = options?.extension || this.getDefaultExtension();
23385
23380
  const sipDomain = this.extractDomain(this.credentials.sipUri);
23386
23381
  const sipTarget = formatPhoneToSIP(targetNumber, sipDomain);
23387
- console.log(`SDK: Calling ${sipTarget} using extension ${extension}...`);
23382
+ console.log(`Dora Cell SDK: Initiating call to ${targetNumber}...`);
23388
23383
  const session = this.ua.call(sipTarget, {
23389
23384
  mediaConstraints: options?.mediaConstraints || { audio: true },
23390
23385
  pcConfig: this.callConfig.pcConfig
@@ -23462,10 +23457,13 @@ var CallManager = class {
23462
23457
  this.pendingSession = null;
23463
23458
  }
23464
23459
  getDefaultExtension() {
23460
+ if (this.credentials.sipUri) {
23461
+ return this.extractExtension(this.credentials.sipUri);
23462
+ }
23465
23463
  if (this.credentials.extensions && this.credentials.extensions.length > 0) {
23466
23464
  return this.credentials.extensions[0].extension;
23467
23465
  }
23468
- return this.extractExtension(this.credentials.sipUri);
23466
+ return "unknown";
23469
23467
  }
23470
23468
  extractExtension(sipUri) {
23471
23469
  const match = sipUri.match(/sip:([^@]+)@/);
@@ -23575,30 +23573,23 @@ var DoraCell = class {
23575
23573
  if (this.authProvider instanceof ApiTokenAuthProvider) {
23576
23574
  const token = this.authProvider.getSessionToken();
23577
23575
  if (token) {
23578
- console.log("SDK: Session token acquired and set in API client");
23579
23576
  this.apiClient.setSessionToken(token);
23580
- } else {
23581
- console.warn("SDK: No session token found in auth provider");
23582
23577
  }
23583
23578
  }
23584
23579
  await this.getWallet().catch(() => {
23585
23580
  });
23586
23581
  if (!this.credentials?.extensions || this.credentials.extensions.length === 0) {
23587
- console.log("SDK: No extensions in auth response, fetching from API...");
23588
23582
  await this.fetchExtensions();
23589
23583
  }
23590
23584
  if (this.config.autoSelectExtension && this.credentials?.extensions && this.credentials.extensions.length > 0) {
23591
23585
  const primary = this.credentials.extensions.find((e) => e.isPrimary) || this.credentials.extensions[0];
23592
23586
  const domain = this.credentials.sipDomain || "64.227.10.164";
23593
23587
  this.credentials.sipUri = `sip:${primary.extension}@${domain}`;
23594
- console.log(`SDK: Auto-selected extension ${primary.extension}`);
23595
23588
  }
23596
23589
  if (this.credentials?.sipUri) {
23597
23590
  await this.initializeUserAgent();
23598
23591
  this.initializeCallManager();
23599
23592
  await this.waitForRegistration();
23600
- } else {
23601
- console.warn("SDK: No SIP URI available yet. UA initialization deferred.");
23602
23593
  }
23603
23594
  } catch (error) {
23604
23595
  const errorMessage = error instanceof Error ? error.message : "Unknown error";
@@ -23633,10 +23624,15 @@ var DoraCell = class {
23633
23624
  if (!this.credentials) {
23634
23625
  throw new ConnectionError("No credentials available");
23635
23626
  }
23627
+ this.connectionStatus = "connecting";
23628
+ this.emitConnectionStatus();
23636
23629
  if (this.ua) {
23637
- console.log("SDK: Stopping existing User Agent...");
23638
- this.ua.stop();
23630
+ try {
23631
+ this.ua.stop();
23632
+ } catch (e) {
23633
+ }
23639
23634
  this.ua = null;
23635
+ await new Promise((resolve) => setTimeout(resolve, 500));
23640
23636
  }
23641
23637
  try {
23642
23638
  const socket = new import_jssip.default.WebSocketInterface(this.credentials.wsUrl);
@@ -23655,10 +23651,8 @@ var DoraCell = class {
23655
23651
  pcConfig,
23656
23652
  instance_id: this.generateInstanceId()
23657
23653
  };
23658
- console.log("SDK: Initializing UA with config:", { ...uaConfig, password: "***" });
23659
23654
  this.ua = new import_jssip.default.UA(uaConfig);
23660
23655
  this.setupUserAgentHandlers();
23661
- console.log("SDK: Starting UA...");
23662
23656
  this.ua.start();
23663
23657
  if (this.callManager) {
23664
23658
  this.callManager.setUserAgent(this.ua);
@@ -23682,6 +23676,7 @@ var DoraCell = class {
23682
23676
  this.ua.on("registered", () => {
23683
23677
  this.connectionStatus = "registered";
23684
23678
  this.retryCount = 0;
23679
+ console.log(`Dora Cell SDK: Connected (${this.getDisplayName()})`);
23685
23680
  this.emitConnectionStatus();
23686
23681
  });
23687
23682
  this.ua.on("registrationFailed", (e) => {
@@ -23696,9 +23691,7 @@ var DoraCell = class {
23696
23691
  });
23697
23692
  this.ua.on("newRTCSession", (e) => {
23698
23693
  const session = e.session;
23699
- console.log(`SDK: New session detected (${session.direction}):`, session.remote_identity?.uri?.toString());
23700
23694
  if (session.direction === "incoming") {
23701
- console.log("SDK: Handling incoming call event");
23702
23695
  this.callManager?.handleIncomingCall(session);
23703
23696
  }
23704
23697
  });
@@ -23768,7 +23761,6 @@ var DoraCell = class {
23768
23761
  return { balance: 0, currency: "NGN" };
23769
23762
  }
23770
23763
  try {
23771
- console.log("SDK: Fetching wallet balance...");
23772
23764
  const response = await this.apiClient.get("/wallets");
23773
23765
  const wallets = Array.isArray(response) ? response : response.data || [];
23774
23766
  if (wallets.length === 0) {
@@ -23781,7 +23773,6 @@ var DoraCell = class {
23781
23773
  balance: parseFloat(primary.balance || primary.amount || "0"),
23782
23774
  currency: primary.currency || "NGN"
23783
23775
  };
23784
- console.log("SDK: Wallet balance fetched successfully, userId:", this.userId);
23785
23776
  return result;
23786
23777
  } catch (error) {
23787
23778
  console.error("SDK: Failed to fetch wallet:", error);
@@ -23803,7 +23794,6 @@ var DoraCell = class {
23803
23794
  }
23804
23795
  try {
23805
23796
  const path = this.userId ? `/user/${this.userId}/extensions` : "/extensions";
23806
- console.log(`SDK: Fetching extensions from: ${path}`);
23807
23797
  const response = await this.apiClient.get(path);
23808
23798
  const extensions = response.data || response.extensions || response;
23809
23799
  if (this.credentials && Array.isArray(extensions)) {
@@ -23811,7 +23801,6 @@ var DoraCell = class {
23811
23801
  }
23812
23802
  return Array.isArray(extensions) ? extensions : [];
23813
23803
  } catch (error) {
23814
- console.error("SDK: Failed to fetch extensions:", error);
23815
23804
  return this.credentials?.extensions || [];
23816
23805
  }
23817
23806
  }
@@ -23825,11 +23814,11 @@ var DoraCell = class {
23825
23814
  * Update active extension and re-initialize SIP connection
23826
23815
  */
23827
23816
  async setExtension(extension) {
23828
- console.log(`SDK: Switching to extension ${extension}...`);
23829
23817
  if (this.credentials) {
23830
23818
  const domain = this.credentials.sipDomain || "64.227.10.164";
23831
23819
  this.credentials.sipUri = `sip:${extension}@${domain}`;
23832
23820
  await this.initializeUserAgent();
23821
+ await this.waitForRegistration();
23833
23822
  this.emitConnectionStatus(this.connectionStatus);
23834
23823
  }
23835
23824
  }
@@ -23863,10 +23852,14 @@ var DoraCell = class {
23863
23852
  }
23864
23853
  // Helper methods
23865
23854
  emitConnectionStatus(error) {
23866
- const extension = this.credentials?.extensions?.[0]?.extension || (this.credentials?.sipUri ? extractNumberFromSipUri(this.credentials.sipUri) : void 0);
23855
+ let activeExt = this.credentials?.sipUri ? extractNumberFromSipUri(this.credentials.sipUri) : void 0;
23856
+ if (!activeExt && this.credentials?.extensions && this.credentials.extensions.length > 0) {
23857
+ const primary = this.credentials.extensions.find((e) => e.isPrimary) || this.credentials.extensions[0];
23858
+ activeExt = primary.extension;
23859
+ }
23867
23860
  const state = {
23868
23861
  status: this.connectionStatus,
23869
- extension,
23862
+ extension: activeExt,
23870
23863
  error
23871
23864
  };
23872
23865
  this.events.emit("connection:status", state);
@@ -23892,6 +23885,12 @@ var DoraCell = class {
23892
23885
  ];
23893
23886
  }
23894
23887
  getDisplayName() {
23888
+ const currentExt = this.credentials?.sipUri ? extractNumberFromSipUri(this.credentials.sipUri) : null;
23889
+ if (currentExt && this.credentials?.extensions) {
23890
+ const found = this.credentials.extensions.find((e) => e.extension === currentExt);
23891
+ if (found?.displayName) return found.displayName;
23892
+ if (found?.extension) return `Ext ${found.extension}`;
23893
+ }
23895
23894
  if (this.credentials?.extensions?.[0]?.displayName) {
23896
23895
  return this.credentials.extensions[0].displayName;
23897
23896
  }