@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.mjs
CHANGED
|
@@ -4,13 +4,7 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __getProtoOf = Object.getPrototypeOf;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var
|
|
8
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
9
|
-
}) : x)(function(x) {
|
|
10
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
11
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
12
|
-
});
|
|
13
|
-
var __commonJS = (cb, mod) => function __require2() {
|
|
7
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
14
8
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
15
9
|
};
|
|
16
10
|
var __copyProps = (to, from, except, desc) => {
|
|
@@ -14127,7 +14121,14 @@ var require_browser = __commonJS({
|
|
|
14127
14121
|
// stub-node-builtin:tty-stub
|
|
14128
14122
|
var require_tty_stub = __commonJS({
|
|
14129
14123
|
"stub-node-builtin:tty-stub"(exports$1, module) {
|
|
14130
|
-
module.exports = {};
|
|
14124
|
+
module.exports = { isatty: () => false };
|
|
14125
|
+
}
|
|
14126
|
+
});
|
|
14127
|
+
|
|
14128
|
+
// stub-node-builtin:util-stub
|
|
14129
|
+
var require_util_stub = __commonJS({
|
|
14130
|
+
"stub-node-builtin:util-stub"(exports$1, module) {
|
|
14131
|
+
module.exports = { inspect: { colors: {} } };
|
|
14131
14132
|
}
|
|
14132
14133
|
});
|
|
14133
14134
|
|
|
@@ -14267,7 +14268,7 @@ var require_supports_color = __commonJS({
|
|
|
14267
14268
|
var require_node = __commonJS({
|
|
14268
14269
|
"../../node_modules/.pnpm/debug@4.4.3_supports-color@8.1.1/node_modules/debug/src/node.js"(exports$1, module) {
|
|
14269
14270
|
var tty = require_tty_stub();
|
|
14270
|
-
var util =
|
|
14271
|
+
var util = require_util_stub();
|
|
14271
14272
|
exports$1.init = init;
|
|
14272
14273
|
exports$1.log = log;
|
|
14273
14274
|
exports$1.formatArgs = formatArgs;
|
|
@@ -23011,7 +23012,6 @@ var ApiTokenAuthProvider = class {
|
|
|
23011
23012
|
}
|
|
23012
23013
|
const baseUrl = apiBaseUrl?.replace(/\/$/, "") || "https://api.cell.usedora.com/api";
|
|
23013
23014
|
try {
|
|
23014
|
-
console.log("SDK: Verifying keys at:", `${baseUrl}/sdk/v1/auth/session`);
|
|
23015
23015
|
const authResponse = await fetch(`${baseUrl}/sdk/v1/auth/session`, {
|
|
23016
23016
|
method: "POST",
|
|
23017
23017
|
headers: {
|
|
@@ -23033,7 +23033,6 @@ var ApiTokenAuthProvider = class {
|
|
|
23033
23033
|
if (!this.sessionToken) {
|
|
23034
23034
|
throw new AuthenticationError("No session token returned after key verification");
|
|
23035
23035
|
}
|
|
23036
|
-
console.log("SDK: Performing secondary validation...");
|
|
23037
23036
|
const origin = typeof window !== "undefined" ? window.location.origin : "";
|
|
23038
23037
|
const validateResponse = await fetch(`${baseUrl}/sdk/v1/auth/validate`, {
|
|
23039
23038
|
method: "GET",
|
|
@@ -23051,9 +23050,9 @@ var ApiTokenAuthProvider = class {
|
|
|
23051
23050
|
);
|
|
23052
23051
|
}
|
|
23053
23052
|
const validateData = await validateResponse.json();
|
|
23054
|
-
console.log(`SDK:
|
|
23053
|
+
console.log(`Dora Cell SDK: Authenticated successfully`);
|
|
23055
23054
|
if (validateData.features && !validateData.features.includes("voice")) {
|
|
23056
|
-
console.warn('SDK: App token does not have the "voice" feature enabled.');
|
|
23055
|
+
console.warn('Dora Cell SDK: App token does not have the "voice" feature enabled.');
|
|
23057
23056
|
}
|
|
23058
23057
|
const actualResponseData = authData.data && typeof authData.data === "object" ? authData.data : authData;
|
|
23059
23058
|
this.credentials = this.parseCredentials(actualResponseData);
|
|
@@ -23094,7 +23093,6 @@ var ApiTokenAuthProvider = class {
|
|
|
23094
23093
|
if (!sipUri && extensions.length > 0) {
|
|
23095
23094
|
const ext = extensions[0].extension;
|
|
23096
23095
|
sipUri = `sip:${ext}@${sipDomain}`;
|
|
23097
|
-
console.log(`SDK: Constructed SIP URI from extension: ${sipUri}`);
|
|
23098
23096
|
} else if (!sipUri) {
|
|
23099
23097
|
sipUri = "";
|
|
23100
23098
|
}
|
|
@@ -23246,11 +23244,11 @@ var CallSession = class {
|
|
|
23246
23244
|
};
|
|
23247
23245
|
});
|
|
23248
23246
|
this.session.on("ended", (evt) => {
|
|
23249
|
-
console.log(`SDK: Call ended
|
|
23247
|
+
console.log(`Dora Cell SDK: Call ended (${evt?.cause || "Normal"})`);
|
|
23250
23248
|
this.handleCallEnd(evt?.cause);
|
|
23251
23249
|
});
|
|
23252
23250
|
this.session.on("failed", (evt) => {
|
|
23253
|
-
console.warn(`SDK: Call failed
|
|
23251
|
+
console.warn(`Dora Cell SDK: Call failed (${evt?.cause || "Internal Error"})`);
|
|
23254
23252
|
this.handleCallEnd(evt?.cause || "Call failed");
|
|
23255
23253
|
});
|
|
23256
23254
|
this.session.on("rejected", (evt) => {
|
|
@@ -23270,7 +23268,6 @@ var CallSession = class {
|
|
|
23270
23268
|
const ssrc = report.ssrc;
|
|
23271
23269
|
if (ssrc && !this.lastKnownSSRCs.has(ssrc)) {
|
|
23272
23270
|
this.lastKnownSSRCs.add(ssrc);
|
|
23273
|
-
console.log(`SDK: SSRC Switch Detected: ${ssrc}. Re-binding audio...`);
|
|
23274
23271
|
setTimeout(() => this.reattachFromReceivers(pc), 200);
|
|
23275
23272
|
}
|
|
23276
23273
|
}
|
|
@@ -23289,7 +23286,6 @@ var CallSession = class {
|
|
|
23289
23286
|
if (!pc) return;
|
|
23290
23287
|
const liveAudioTracks = pc.getReceivers().map((r) => r.track).filter((t) => t && t.kind === "audio" && t.readyState === "live");
|
|
23291
23288
|
if (liveAudioTracks.length > 0) {
|
|
23292
|
-
console.log(`SDK: Audio Fix: Rebuilding stream from ${liveAudioTracks.length} receivers`);
|
|
23293
23289
|
const newStream = new MediaStream(liveAudioTracks);
|
|
23294
23290
|
this.remoteStreamValue = newStream;
|
|
23295
23291
|
this.events.emit("call:stream", this, newStream);
|
|
@@ -23380,7 +23376,7 @@ var CallManager = class {
|
|
|
23380
23376
|
const extension = options?.extension || this.getDefaultExtension();
|
|
23381
23377
|
const sipDomain = this.extractDomain(this.credentials.sipUri);
|
|
23382
23378
|
const sipTarget = formatPhoneToSIP(targetNumber, sipDomain);
|
|
23383
|
-
console.log(`SDK:
|
|
23379
|
+
console.log(`Dora Cell SDK: Initiating call to ${targetNumber}...`);
|
|
23384
23380
|
const session = this.ua.call(sipTarget, {
|
|
23385
23381
|
mediaConstraints: options?.mediaConstraints || { audio: true },
|
|
23386
23382
|
pcConfig: this.callConfig.pcConfig
|
|
@@ -23458,10 +23454,13 @@ var CallManager = class {
|
|
|
23458
23454
|
this.pendingSession = null;
|
|
23459
23455
|
}
|
|
23460
23456
|
getDefaultExtension() {
|
|
23457
|
+
if (this.credentials.sipUri) {
|
|
23458
|
+
return this.extractExtension(this.credentials.sipUri);
|
|
23459
|
+
}
|
|
23461
23460
|
if (this.credentials.extensions && this.credentials.extensions.length > 0) {
|
|
23462
23461
|
return this.credentials.extensions[0].extension;
|
|
23463
23462
|
}
|
|
23464
|
-
return
|
|
23463
|
+
return "unknown";
|
|
23465
23464
|
}
|
|
23466
23465
|
extractExtension(sipUri) {
|
|
23467
23466
|
const match = sipUri.match(/sip:([^@]+)@/);
|
|
@@ -23555,7 +23554,7 @@ var DoraCell = class {
|
|
|
23555
23554
|
this.authProvider = createAuthProvider(config.auth);
|
|
23556
23555
|
this.apiBaseUrl = this.resolveApiBaseUrl(config);
|
|
23557
23556
|
this.apiClient = new ApiClient(this.apiBaseUrl);
|
|
23558
|
-
if (this.config.debug) {
|
|
23557
|
+
if (this.config.debug && typeof window !== "undefined") {
|
|
23559
23558
|
import_jssip.default.debug.enable("JsSIP:*");
|
|
23560
23559
|
}
|
|
23561
23560
|
}
|
|
@@ -23571,30 +23570,23 @@ var DoraCell = class {
|
|
|
23571
23570
|
if (this.authProvider instanceof ApiTokenAuthProvider) {
|
|
23572
23571
|
const token = this.authProvider.getSessionToken();
|
|
23573
23572
|
if (token) {
|
|
23574
|
-
console.log("SDK: Session token acquired and set in API client");
|
|
23575
23573
|
this.apiClient.setSessionToken(token);
|
|
23576
|
-
} else {
|
|
23577
|
-
console.warn("SDK: No session token found in auth provider");
|
|
23578
23574
|
}
|
|
23579
23575
|
}
|
|
23580
23576
|
await this.getWallet().catch(() => {
|
|
23581
23577
|
});
|
|
23582
23578
|
if (!this.credentials?.extensions || this.credentials.extensions.length === 0) {
|
|
23583
|
-
console.log("SDK: No extensions in auth response, fetching from API...");
|
|
23584
23579
|
await this.fetchExtensions();
|
|
23585
23580
|
}
|
|
23586
23581
|
if (this.config.autoSelectExtension && this.credentials?.extensions && this.credentials.extensions.length > 0) {
|
|
23587
23582
|
const primary = this.credentials.extensions.find((e) => e.isPrimary) || this.credentials.extensions[0];
|
|
23588
23583
|
const domain = this.credentials.sipDomain || "64.227.10.164";
|
|
23589
23584
|
this.credentials.sipUri = `sip:${primary.extension}@${domain}`;
|
|
23590
|
-
console.log(`SDK: Auto-selected extension ${primary.extension}`);
|
|
23591
23585
|
}
|
|
23592
23586
|
if (this.credentials?.sipUri) {
|
|
23593
23587
|
await this.initializeUserAgent();
|
|
23594
23588
|
this.initializeCallManager();
|
|
23595
23589
|
await this.waitForRegistration();
|
|
23596
|
-
} else {
|
|
23597
|
-
console.warn("SDK: No SIP URI available yet. UA initialization deferred.");
|
|
23598
23590
|
}
|
|
23599
23591
|
} catch (error) {
|
|
23600
23592
|
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
@@ -23629,10 +23621,15 @@ var DoraCell = class {
|
|
|
23629
23621
|
if (!this.credentials) {
|
|
23630
23622
|
throw new ConnectionError("No credentials available");
|
|
23631
23623
|
}
|
|
23624
|
+
this.connectionStatus = "connecting";
|
|
23625
|
+
this.emitConnectionStatus();
|
|
23632
23626
|
if (this.ua) {
|
|
23633
|
-
|
|
23634
|
-
|
|
23627
|
+
try {
|
|
23628
|
+
this.ua.stop();
|
|
23629
|
+
} catch (e) {
|
|
23630
|
+
}
|
|
23635
23631
|
this.ua = null;
|
|
23632
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
23636
23633
|
}
|
|
23637
23634
|
try {
|
|
23638
23635
|
const socket = new import_jssip.default.WebSocketInterface(this.credentials.wsUrl);
|
|
@@ -23651,10 +23648,8 @@ var DoraCell = class {
|
|
|
23651
23648
|
pcConfig,
|
|
23652
23649
|
instance_id: this.generateInstanceId()
|
|
23653
23650
|
};
|
|
23654
|
-
console.log("SDK: Initializing UA with config:", { ...uaConfig, password: "***" });
|
|
23655
23651
|
this.ua = new import_jssip.default.UA(uaConfig);
|
|
23656
23652
|
this.setupUserAgentHandlers();
|
|
23657
|
-
console.log("SDK: Starting UA...");
|
|
23658
23653
|
this.ua.start();
|
|
23659
23654
|
if (this.callManager) {
|
|
23660
23655
|
this.callManager.setUserAgent(this.ua);
|
|
@@ -23678,6 +23673,7 @@ var DoraCell = class {
|
|
|
23678
23673
|
this.ua.on("registered", () => {
|
|
23679
23674
|
this.connectionStatus = "registered";
|
|
23680
23675
|
this.retryCount = 0;
|
|
23676
|
+
console.log(`Dora Cell SDK: Connected (${this.getDisplayName()})`);
|
|
23681
23677
|
this.emitConnectionStatus();
|
|
23682
23678
|
});
|
|
23683
23679
|
this.ua.on("registrationFailed", (e) => {
|
|
@@ -23692,9 +23688,7 @@ var DoraCell = class {
|
|
|
23692
23688
|
});
|
|
23693
23689
|
this.ua.on("newRTCSession", (e) => {
|
|
23694
23690
|
const session = e.session;
|
|
23695
|
-
console.log(`SDK: New session detected (${session.direction}):`, session.remote_identity?.uri?.toString());
|
|
23696
23691
|
if (session.direction === "incoming") {
|
|
23697
|
-
console.log("SDK: Handling incoming call event");
|
|
23698
23692
|
this.callManager?.handleIncomingCall(session);
|
|
23699
23693
|
}
|
|
23700
23694
|
});
|
|
@@ -23764,7 +23758,6 @@ var DoraCell = class {
|
|
|
23764
23758
|
return { balance: 0, currency: "NGN" };
|
|
23765
23759
|
}
|
|
23766
23760
|
try {
|
|
23767
|
-
console.log("SDK: Fetching wallet balance...");
|
|
23768
23761
|
const response = await this.apiClient.get("/wallets");
|
|
23769
23762
|
const wallets = Array.isArray(response) ? response : response.data || [];
|
|
23770
23763
|
if (wallets.length === 0) {
|
|
@@ -23777,7 +23770,6 @@ var DoraCell = class {
|
|
|
23777
23770
|
balance: parseFloat(primary.balance || primary.amount || "0"),
|
|
23778
23771
|
currency: primary.currency || "NGN"
|
|
23779
23772
|
};
|
|
23780
|
-
console.log("SDK: Wallet balance fetched successfully, userId:", this.userId);
|
|
23781
23773
|
return result;
|
|
23782
23774
|
} catch (error) {
|
|
23783
23775
|
console.error("SDK: Failed to fetch wallet:", error);
|
|
@@ -23799,7 +23791,6 @@ var DoraCell = class {
|
|
|
23799
23791
|
}
|
|
23800
23792
|
try {
|
|
23801
23793
|
const path = this.userId ? `/user/${this.userId}/extensions` : "/extensions";
|
|
23802
|
-
console.log(`SDK: Fetching extensions from: ${path}`);
|
|
23803
23794
|
const response = await this.apiClient.get(path);
|
|
23804
23795
|
const extensions = response.data || response.extensions || response;
|
|
23805
23796
|
if (this.credentials && Array.isArray(extensions)) {
|
|
@@ -23807,7 +23798,6 @@ var DoraCell = class {
|
|
|
23807
23798
|
}
|
|
23808
23799
|
return Array.isArray(extensions) ? extensions : [];
|
|
23809
23800
|
} catch (error) {
|
|
23810
|
-
console.error("SDK: Failed to fetch extensions:", error);
|
|
23811
23801
|
return this.credentials?.extensions || [];
|
|
23812
23802
|
}
|
|
23813
23803
|
}
|
|
@@ -23821,11 +23811,11 @@ var DoraCell = class {
|
|
|
23821
23811
|
* Update active extension and re-initialize SIP connection
|
|
23822
23812
|
*/
|
|
23823
23813
|
async setExtension(extension) {
|
|
23824
|
-
console.log(`SDK: Switching to extension ${extension}...`);
|
|
23825
23814
|
if (this.credentials) {
|
|
23826
23815
|
const domain = this.credentials.sipDomain || "64.227.10.164";
|
|
23827
23816
|
this.credentials.sipUri = `sip:${extension}@${domain}`;
|
|
23828
23817
|
await this.initializeUserAgent();
|
|
23818
|
+
await this.waitForRegistration();
|
|
23829
23819
|
this.emitConnectionStatus(this.connectionStatus);
|
|
23830
23820
|
}
|
|
23831
23821
|
}
|
|
@@ -23859,10 +23849,14 @@ var DoraCell = class {
|
|
|
23859
23849
|
}
|
|
23860
23850
|
// Helper methods
|
|
23861
23851
|
emitConnectionStatus(error) {
|
|
23862
|
-
|
|
23852
|
+
let activeExt = this.credentials?.sipUri ? extractNumberFromSipUri(this.credentials.sipUri) : void 0;
|
|
23853
|
+
if (!activeExt && this.credentials?.extensions && this.credentials.extensions.length > 0) {
|
|
23854
|
+
const primary = this.credentials.extensions.find((e) => e.isPrimary) || this.credentials.extensions[0];
|
|
23855
|
+
activeExt = primary.extension;
|
|
23856
|
+
}
|
|
23863
23857
|
const state = {
|
|
23864
23858
|
status: this.connectionStatus,
|
|
23865
|
-
extension,
|
|
23859
|
+
extension: activeExt,
|
|
23866
23860
|
error
|
|
23867
23861
|
};
|
|
23868
23862
|
this.events.emit("connection:status", state);
|
|
@@ -23888,6 +23882,12 @@ var DoraCell = class {
|
|
|
23888
23882
|
];
|
|
23889
23883
|
}
|
|
23890
23884
|
getDisplayName() {
|
|
23885
|
+
const currentExt = this.credentials?.sipUri ? extractNumberFromSipUri(this.credentials.sipUri) : null;
|
|
23886
|
+
if (currentExt && this.credentials?.extensions) {
|
|
23887
|
+
const found = this.credentials.extensions.find((e) => e.extension === currentExt);
|
|
23888
|
+
if (found?.displayName) return found.displayName;
|
|
23889
|
+
if (found?.extension) return `Ext ${found.extension}`;
|
|
23890
|
+
}
|
|
23891
23891
|
if (this.credentials?.extensions?.[0]?.displayName) {
|
|
23892
23892
|
return this.credentials.extensions[0].displayName;
|
|
23893
23893
|
}
|