@coventia/softphone 0.2.1 → 0.3.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/{call-VKq1I8yP.d.cts → call-CaPDWVk3.d.cts} +44 -1
- package/dist/{call-VKq1I8yP.d.ts → call-CaPDWVk3.d.ts} +44 -1
- package/dist/{chunk-LMJXX4YM.js → chunk-UHNLEBBO.js} +4 -2
- package/dist/chunk-UHNLEBBO.js.map +1 -0
- package/dist/element/index.d.ts +68 -9
- package/dist/element/index.js +962 -114
- package/dist/element/index.js.map +1 -1
- package/dist/{engine-C0BOkIcW.d.ts → engine-BgBsIcEa.d.ts} +1 -1
- package/dist/{engine-BlQBo2Ys.d.cts → engine-CU2rEo3g.d.cts} +1 -1
- package/dist/index.cjs +120 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +69 -10
- package/dist/index.js.map +1 -1
- package/dist/react/index.cjs +2 -0
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +2 -2
- package/dist/react/index.d.ts +2 -2
- package/dist/react/index.js +1 -1
- package/dist/{softphone-Cyq3hiIM.d.ts → softphone-DEt0TtQw.d.ts} +26 -10
- package/dist/{softphone-DlGV12Xp.d.cts → softphone-dZMkW8V1.d.cts} +26 -10
- package/dist/softphone.css +110 -12
- package/dist/{sources-IRKNQPWW.js → sources-M3GYMS6V.js} +54 -3
- package/dist/sources-M3GYMS6V.js.map +1 -0
- package/dist/testing/index.d.cts +2 -2
- package/dist/testing/index.d.ts +2 -2
- package/dist/ui/index.cjs +885 -28
- package/dist/ui/index.cjs.map +1 -1
- package/dist/ui/index.d.cts +25 -3
- package/dist/ui/index.d.ts +25 -3
- package/dist/ui/index.js +885 -31
- package/dist/ui/index.js.map +1 -1
- package/dist/zadarma/index.d.cts +2 -2
- package/dist/zadarma/index.d.ts +2 -2
- package/package.json +1 -1
- package/dist/chunk-LMJXX4YM.js.map +0 -1
- package/dist/sources-IRKNQPWW.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { e as CallOptions, b as CallDirection, H as HangupReason, i as HoldOriginator,
|
|
1
|
+
import { e as CallOptions, b as CallDirection, H as HangupReason, i as HoldOriginator, r as SoftphoneState, n as SoftphoneError } from './call-CaPDWVk3.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* The `CallEngine` seam — INTERNAL, not exported from src/index.ts.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { e as CallOptions, b as CallDirection, H as HangupReason, i as HoldOriginator,
|
|
1
|
+
import { e as CallOptions, b as CallDirection, H as HangupReason, i as HoldOriginator, r as SoftphoneState, n as SoftphoneError } from './call-CaPDWVk3.cjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* The `CallEngine` seam — INTERNAL, not exported from src/index.ts.
|
package/dist/index.cjs
CHANGED
|
@@ -331,6 +331,56 @@ function coventiaSources(config) {
|
|
|
331
331
|
})();
|
|
332
332
|
});
|
|
333
333
|
};
|
|
334
|
+
const fileBase = config.baseUrl.replace(/\/+$/, "");
|
|
335
|
+
const toLoop = (l) => l && Number.isFinite(l.start) && Number.isFinite(l.end) && l.start >= 0 && l.end > l.start ? { start: l.start, end: l.end } : null;
|
|
336
|
+
const toRingtoneSettings = (body) => {
|
|
337
|
+
const catalogue = (body.catalogue ?? []).map((r) => ({
|
|
338
|
+
id: r.id,
|
|
339
|
+
name: r.name,
|
|
340
|
+
url: r.path ? `${fileBase}${r.path}` : null,
|
|
341
|
+
loop: r.path ? toLoop(r.loop) : null
|
|
342
|
+
}));
|
|
343
|
+
const builtIn = catalogue.find((r) => r.url === null)?.id ?? "clasico";
|
|
344
|
+
const effective = catalogue.some((r) => r.id === body.effective) ? body.effective : builtIn;
|
|
345
|
+
return { catalogue, orgDefault: body.orgDefault ?? null, mine: body.user ?? null, effective };
|
|
346
|
+
};
|
|
347
|
+
const CACHE_PREFIX = "coventia-softphone:ringtones:";
|
|
348
|
+
const cacheKey = async () => {
|
|
349
|
+
try {
|
|
350
|
+
const { identity } = await config.tokenSource.getToken();
|
|
351
|
+
return `${CACHE_PREFIX}${fileBase}|${config.organizationId ?? "-"}|${identity}`;
|
|
352
|
+
} catch {
|
|
353
|
+
return null;
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
const remember = async (settings) => {
|
|
357
|
+
const key = await cacheKey();
|
|
358
|
+
try {
|
|
359
|
+
if (key) globalThis.localStorage?.setItem(key, JSON.stringify(settings));
|
|
360
|
+
} catch {
|
|
361
|
+
}
|
|
362
|
+
return settings;
|
|
363
|
+
};
|
|
364
|
+
const recall = async () => {
|
|
365
|
+
const key = await cacheKey();
|
|
366
|
+
try {
|
|
367
|
+
const raw = key ? globalThis.localStorage?.getItem(key) : null;
|
|
368
|
+
const s = raw ? JSON.parse(raw) : null;
|
|
369
|
+
const ok = s && Array.isArray(s.catalogue) && s.catalogue.every((r) => typeof r?.id === "string" && typeof r.name === "string" && (r.url === null || typeof r.url === "string")) && s.catalogue.some((r) => r.id === s.effective);
|
|
370
|
+
return ok ? { ...s, catalogue: s.catalogue.map((r) => ({ ...r, loop: toLoop(r.loop) })) } : null;
|
|
371
|
+
} catch {
|
|
372
|
+
return null;
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
const ringtones = {
|
|
376
|
+
get: async (signal) => remember(toRingtoneSettings(await get(`${base}/ringtones`, org, signal))),
|
|
377
|
+
// `null` clears: the empty id is dropped from the query by the request helper, and the backend reads a
|
|
378
|
+
// missing `ringtone_id` as "clear".
|
|
379
|
+
setMine: async (id) => remember(
|
|
380
|
+
toRingtoneSettings(await post(`${base}/ringtones/user`, { ...org, ringtone_id: id ?? "" }))
|
|
381
|
+
),
|
|
382
|
+
cached: recall
|
|
383
|
+
};
|
|
334
384
|
const contacts = config.contacts ?? coventiaContacts;
|
|
335
385
|
const resolve = config.resolveContact ?? (config.contacts ? resolverFromContacts(config.contacts) : coventiaResolve);
|
|
336
386
|
const history = withNameResolution(rawHistory, resolve);
|
|
@@ -342,7 +392,8 @@ function coventiaSources(config) {
|
|
|
342
392
|
resolveContact: resolve,
|
|
343
393
|
listAgents: coventiaListAgents,
|
|
344
394
|
transferOutcomes,
|
|
345
|
-
presence
|
|
395
|
+
presence,
|
|
396
|
+
ringtones
|
|
346
397
|
};
|
|
347
398
|
}
|
|
348
399
|
var toContact, toDirection, otherParty, isMissed, toOutcome, toDate, toTransferOutcome, toPresenceState, toPresenceEntry, toWebSocketUrl;
|
|
@@ -2006,7 +2057,12 @@ function coventiaBackend(config, tokenSource, fallbackBaseUrl) {
|
|
|
2006
2057
|
resolveContact: async (number) => (await load()).resolveContact(number),
|
|
2007
2058
|
listAgents: async () => (await load()).listAgents(),
|
|
2008
2059
|
transferOutcomes: async (params) => (await load()).transferOutcomes(params),
|
|
2009
|
-
presence: async (callbacks) => (await load()).presence(callbacks)
|
|
2060
|
+
presence: async (callbacks) => (await load()).presence(callbacks),
|
|
2061
|
+
ringtones: {
|
|
2062
|
+
get: async (signal) => (await load()).ringtones.get(signal),
|
|
2063
|
+
setMine: async (id) => (await load()).ringtones.setMine(id),
|
|
2064
|
+
cached: async () => (await load()).ringtones.cached?.() ?? null
|
|
2065
|
+
}
|
|
2010
2066
|
};
|
|
2011
2067
|
}
|
|
2012
2068
|
|
|
@@ -2229,13 +2285,30 @@ var BrowserAudioDevices = class {
|
|
|
2229
2285
|
outputs = [];
|
|
2230
2286
|
currentInputId = null;
|
|
2231
2287
|
currentOutputId = null;
|
|
2288
|
+
currentRingtoneOutputId = null;
|
|
2232
2289
|
canSelectOutput;
|
|
2290
|
+
canSelectRingtoneOutput;
|
|
2233
2291
|
#engine;
|
|
2234
2292
|
#onChange;
|
|
2293
|
+
/**
|
|
2294
|
+
* What the user CHOSE, remembered across reloads — distinct from the `current*` fields, which are
|
|
2295
|
+
* what is usable right now. Keeping them apart is what stops a fresh page load from wiping a saved
|
|
2296
|
+
* choice: until the microphone has been granted, Chrome enumerates every device with a blank id, so
|
|
2297
|
+
* "is the saved device in the list?" is no on every first enumeration. The preference survives
|
|
2298
|
+
* that; `current*` simply reads `null` until the device is really there.
|
|
2299
|
+
*/
|
|
2300
|
+
#preferred;
|
|
2301
|
+
/** The input the engine was last told about — it starts on the system default (`null`). */
|
|
2302
|
+
#engineInputId = null;
|
|
2235
2303
|
constructor(engine, onChange) {
|
|
2236
2304
|
this.#engine = engine;
|
|
2237
2305
|
this.#onChange = onChange;
|
|
2238
2306
|
this.canSelectOutput = isBrowser() && typeof HTMLMediaElement !== "undefined" && "setSinkId" in HTMLMediaElement.prototype;
|
|
2307
|
+
this.canSelectRingtoneOutput = this.canSelectOutput;
|
|
2308
|
+
this.#preferred = readStoredDevices();
|
|
2309
|
+
this.currentInputId = this.#preferred.input;
|
|
2310
|
+
this.currentOutputId = this.#preferred.output;
|
|
2311
|
+
this.currentRingtoneOutputId = this.#preferred.ringtone;
|
|
2239
2312
|
if (isBrowser() && navigator.mediaDevices) {
|
|
2240
2313
|
void this.refresh();
|
|
2241
2314
|
navigator.mediaDevices.addEventListener?.("devicechange", () => void this.refresh());
|
|
@@ -2251,26 +2324,63 @@ var BrowserAudioDevices = class {
|
|
|
2251
2324
|
}
|
|
2252
2325
|
this.inputs = all.filter((d) => d.kind === "audioinput");
|
|
2253
2326
|
this.outputs = all.filter((d) => d.kind === "audiooutput");
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
if (this.currentOutputId && !this.outputs.some((d) => d.deviceId === this.currentOutputId)) {
|
|
2258
|
-
this.currentOutputId = null;
|
|
2259
|
-
}
|
|
2327
|
+
this.currentInputId = usable(this.#preferred.input, this.inputs);
|
|
2328
|
+
this.currentOutputId = usable(this.#preferred.output, this.outputs);
|
|
2329
|
+
this.currentRingtoneOutputId = usable(this.#preferred.ringtone, this.outputs);
|
|
2260
2330
|
this.#onChange();
|
|
2331
|
+
if (this.currentInputId && this.currentInputId !== this.#engineInputId) {
|
|
2332
|
+
await this.#tellEngine(this.currentInputId);
|
|
2333
|
+
}
|
|
2261
2334
|
}
|
|
2262
2335
|
async setInput(deviceId) {
|
|
2263
2336
|
this.currentInputId = deviceId;
|
|
2337
|
+
this.#remember({ input: deviceId });
|
|
2264
2338
|
this.#onChange();
|
|
2339
|
+
await this.#tellEngine(deviceId);
|
|
2340
|
+
}
|
|
2341
|
+
async #tellEngine(deviceId) {
|
|
2342
|
+
this.#engineInputId = deviceId;
|
|
2265
2343
|
await this.#engine.setInputDevice?.(deviceId);
|
|
2266
2344
|
}
|
|
2267
2345
|
async setOutput(deviceId) {
|
|
2268
2346
|
this.currentOutputId = deviceId;
|
|
2347
|
+
this.#remember({ output: deviceId });
|
|
2348
|
+
this.#onChange();
|
|
2349
|
+
}
|
|
2350
|
+
async setRingtoneOutput(deviceId) {
|
|
2351
|
+
this.currentRingtoneOutputId = deviceId;
|
|
2352
|
+
this.#remember({ ringtone: deviceId });
|
|
2269
2353
|
this.#onChange();
|
|
2270
2354
|
}
|
|
2271
|
-
|
|
2355
|
+
#remember(patch) {
|
|
2356
|
+
this.#preferred = { ...this.#preferred, ...patch };
|
|
2357
|
+
writeStoredDevices(this.#preferred);
|
|
2272
2358
|
}
|
|
2273
2359
|
};
|
|
2360
|
+
var DEVICES_KEY = "coventia-softphone:devices";
|
|
2361
|
+
var NO_DEVICES = { input: null, output: null, ringtone: null };
|
|
2362
|
+
function usable(id, list) {
|
|
2363
|
+
return id && list.some((d) => d.deviceId === id) ? id : null;
|
|
2364
|
+
}
|
|
2365
|
+
function readStoredDevices() {
|
|
2366
|
+
if (!isBrowser()) return NO_DEVICES;
|
|
2367
|
+
try {
|
|
2368
|
+
const raw = JSON.parse(globalThis.localStorage?.getItem(DEVICES_KEY) ?? "null");
|
|
2369
|
+
if (!raw || typeof raw !== "object") return NO_DEVICES;
|
|
2370
|
+
const pick = (v) => typeof v === "string" && v ? v : null;
|
|
2371
|
+
const r = raw;
|
|
2372
|
+
return { input: pick(r.input), output: pick(r.output), ringtone: pick(r.ringtone) };
|
|
2373
|
+
} catch {
|
|
2374
|
+
return NO_DEVICES;
|
|
2375
|
+
}
|
|
2376
|
+
}
|
|
2377
|
+
function writeStoredDevices(devices) {
|
|
2378
|
+
if (!isBrowser()) return;
|
|
2379
|
+
try {
|
|
2380
|
+
globalThis.localStorage?.setItem(DEVICES_KEY, JSON.stringify(devices));
|
|
2381
|
+
} catch {
|
|
2382
|
+
}
|
|
2383
|
+
}
|
|
2274
2384
|
var SoftphoneImpl = class extends Emitter {
|
|
2275
2385
|
#state = "stopped";
|
|
2276
2386
|
#lastError = null;
|
|
@@ -2674,7 +2784,7 @@ function isCallEngine(value) {
|
|
|
2674
2784
|
|
|
2675
2785
|
// src/index.ts
|
|
2676
2786
|
init_errors();
|
|
2677
|
-
var VERSION = "0.
|
|
2787
|
+
var VERSION = "0.3.0";
|
|
2678
2788
|
|
|
2679
2789
|
exports.CALL_TRANSITIONS = CALL_TRANSITIONS;
|
|
2680
2790
|
exports.CallEvent = CallEvent;
|