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