@16x/webphone-sdk 3.0.1

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.
Files changed (75) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/LICENSE +2 -0
  3. package/README.md +113 -0
  4. package/dist/CCBarClient-BdbynNBi.js +2515 -0
  5. package/dist/CCBarClient-DKWdvgf5.cjs +1 -0
  6. package/dist/CCBarError-CIqJE8zK.cjs +1 -0
  7. package/dist/CCBarError-DSbPw2dA.js +14 -0
  8. package/dist/Diagnostics-BYVvmxil.cjs +1 -0
  9. package/dist/Diagnostics-Cw2HVrCD.js +123 -0
  10. package/dist/JsSipAdapter-GHzVSCDh.js +304 -0
  11. package/dist/JsSipAdapter-jtGdoXrm.cjs +1 -0
  12. package/dist/SharedWorkerProtocol-BqUafs8d.js +73 -0
  13. package/dist/SharedWorkerProtocol-CYN0AprP.cjs +1 -0
  14. package/dist/api/WebPhoneApi.d.ts +28 -0
  15. package/dist/api/contracts.d.ts +94 -0
  16. package/dist/auth/TokenManager.d.ts +22 -0
  17. package/dist/core/CCBarCall.d.ts +94 -0
  18. package/dist/core/CCBarClient.d.ts +113 -0
  19. package/dist/core/CallManager.d.ts +93 -0
  20. package/dist/core/callId.d.ts +1 -0
  21. package/dist/core/mediaBridge.d.ts +17 -0
  22. package/dist/createJsSipFactory-2X4FBIU2.cjs +75 -0
  23. package/dist/createJsSipFactory-yttVU3d6.js +9662 -0
  24. package/dist/diagnostics/Diagnostics.d.ts +74 -0
  25. package/dist/diagnostics/RingBuffer.d.ts +7 -0
  26. package/dist/diagnostics/index.cjs +1 -0
  27. package/dist/diagnostics/index.d.ts +4 -0
  28. package/dist/diagnostics/index.js +6 -0
  29. package/dist/diagnostics/redact.d.ts +5 -0
  30. package/dist/errors/CCBarError.d.ts +15 -0
  31. package/dist/events/TypedEventBus.d.ts +9 -0
  32. package/dist/index.cjs +1 -0
  33. package/dist/index.d.ts +21 -0
  34. package/dist/index.js +152 -0
  35. package/dist/index.umd.js +75 -0
  36. package/dist/legacy/CCBarSDK.d.ts +29 -0
  37. package/dist/legacy/index.cjs +1 -0
  38. package/dist/legacy/index.d.ts +8 -0
  39. package/dist/legacy/index.js +108 -0
  40. package/dist/redact-Bq26pObO.cjs +1 -0
  41. package/dist/redact-DB3CMbsK.js +21 -0
  42. package/dist/shared/SharedCallTransport.d.ts +55 -0
  43. package/dist/shared/SharedWorkerClient.d.ts +20 -0
  44. package/dist/shared/SharedWorkerEntry.d.ts +3 -0
  45. package/dist/shared/SharedWorkerFactory.d.ts +29 -0
  46. package/dist/shared/SharedWorkerProtocol.d.ts +47 -0
  47. package/dist/shared/SharedWorkerRuntime.d.ts +35 -0
  48. package/dist/shared-worker.cjs +1 -0
  49. package/dist/shared-worker.d.ts +1 -0
  50. package/dist/shared-worker.js +185 -0
  51. package/dist/state/callStateMachine.d.ts +9 -0
  52. package/dist/styles.css +7 -0
  53. package/dist/types.d.ts +134 -0
  54. package/dist/ui/XCallCCBarElement.d.ts +23 -0
  55. package/dist/ui/controllers/mobileLifecycle.d.ts +18 -0
  56. package/dist/ui/controllers/phoneActions.d.ts +27 -0
  57. package/dist/ui/i18n/en-US.d.ts +2 -0
  58. package/dist/ui/i18n/index.d.ts +6 -0
  59. package/dist/ui/i18n/types.d.ts +53 -0
  60. package/dist/ui/i18n/zh-CN.d.ts +2 -0
  61. package/dist/ui/icons/index.d.ts +5 -0
  62. package/dist/ui/index.cjs +1 -0
  63. package/dist/ui/index.d.ts +3 -0
  64. package/dist/ui/index.js +1044 -0
  65. package/dist/ui/state/toPhoneViewModel.d.ts +54 -0
  66. package/dist/ui/views/dom.d.ts +11 -0
  67. package/dist/ui/views/messages.d.ts +5 -0
  68. package/dist/ui/views/renderActiveCall.d.ts +8 -0
  69. package/dist/ui/views/renderDesktop.d.ts +24 -0
  70. package/dist/ui/views/renderDialpad.d.ts +4 -0
  71. package/dist/ui/views/renderError.d.ts +6 -0
  72. package/dist/ui/views/renderIncoming.d.ts +8 -0
  73. package/dist/ui/views/renderMobile.d.ts +15 -0
  74. package/dist/ui/views/renderSetup.d.ts +6 -0
  75. package/package.json +107 -0
@@ -0,0 +1,29 @@
1
+ import { CCBarClientOptions } from '../core/CCBarClient.js';
2
+ import { CCBarCall } from '../core/CCBarCall.js';
3
+ export declare class DeprecatedError extends Error {
4
+ readonly code = "LEGACY_METHOD_DEPRECATED";
5
+ constructor(method: string, replacement: string);
6
+ }
7
+ export declare class CCBarSDK {
8
+ private readonly client;
9
+ private readonly warnedMethods;
10
+ private readonly unsubscribeIncoming;
11
+ private currentCall?;
12
+ constructor(options: CCBarClientOptions);
13
+ getToken(..._legacyArguments: readonly unknown[]): Promise<void>;
14
+ getAccount(..._legacyArguments: readonly unknown[]): Promise<void>;
15
+ login(..._legacyArguments: readonly unknown[]): Promise<void>;
16
+ call(number: string | number, ..._legacyArguments: readonly unknown[]): Promise<CCBarCall>;
17
+ insideCall(number: string | number, ..._legacyArguments: readonly unknown[]): Promise<CCBarCall>;
18
+ answer(..._legacyArguments: readonly unknown[]): Promise<void>;
19
+ hangup(..._legacyArguments: readonly unknown[]): Promise<void>;
20
+ holdCall(..._legacyArguments: readonly unknown[]): Promise<void>;
21
+ unholdCall(..._legacyArguments: readonly unknown[]): Promise<void>;
22
+ transSo(number: string | number, ..._legacyArguments: readonly unknown[]): Promise<void>;
23
+ signOut(..._legacyArguments: readonly unknown[]): Promise<void>;
24
+ setId(..._legacyArguments: readonly unknown[]): Promise<void>;
25
+ setBu(..._legacyArguments: readonly unknown[]): never;
26
+ setRe(..._legacyArguments: readonly unknown[]): Promise<void>;
27
+ private requireCurrentCall;
28
+ private warn;
29
+ }
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../CCBarError-CIqJE8zK.cjs"),t=require("../CCBarClient-DKWdvgf5.cjs");require("../createJsSipFactory-2X4FBIU2.cjs");var n=class extends Error{code=`LEGACY_METHOD_DEPRECATED`;constructor(e,t){super(`${e} 已废弃:${t}`),this.name=`DeprecatedError`}},r=class{client;warnedMethods=new Set;unsubscribeIncoming;currentCall;constructor(e){this.client=new t.t(e),this.unsubscribeIncoming=this.client.on(`call.incoming`,({callId:e})=>{this.currentCall=this.client.getCalls().find(t=>t.id===e)})}getToken(...e){return this.warn(`getToken`,`请改用 client.connect()`),this.client.connect()}getAccount(...e){return this.warn(`getAccount`,`请改用 client.connect()`),this.client.connect()}login(...e){return this.warn(`login`,`请改用 client.connect()`),this.client.connect()}async call(e,...t){this.warn(`call`,`请改用 client.dial({ destination })`);let n=await this.client.dial({destination:String(e)});return this.currentCall=n,n}async insideCall(e,...t){this.warn(`insideCall`,`请改用 client.dial({ destination, type: 'extension' })`);let n=await this.client.dial({destination:String(e),type:`extension`});return this.currentCall=n,n}answer(...e){this.warn(`answer`,`请改用 call.answer()`);let t=this.requireCurrentCall();return this.client.answer(t.id)}async hangup(...e){this.warn(`hangup`,`请改用 call.hangup()`);let t=this.requireCurrentCall();try{await t.hangup()}finally{this.currentCall===t&&(this.currentCall=void 0)}}holdCall(...e){return this.warn(`holdCall`,`请改用 call.hold()`),this.requireCurrentCall().hold()}unholdCall(...e){return this.warn(`unholdCall`,`请改用 call.resume()`),this.requireCurrentCall().resume()}transSo(e,...t){return this.warn(`transSo`,`请改用 call.transfer({ target, type: 'blind' })`),this.requireCurrentCall().transfer({target:String(e),type:`blind`})}async signOut(...e){this.warn(`signOut`,`请改用 client.disconnect() 和 client.dispose()`);let t;try{await this.client.disconnect()}catch(e){t=e}try{await this.client.dispose()}catch(e){t??=e}if(this.unsubscribeIncoming(),this.currentCall=void 0,t!==void 0)throw t}setId(...e){return this.warn(`setId`,`请改用 client.setAgentStatus('available')`),this.client.setAgentStatus(`available`)}setBu(...e){throw this.warn(`setBu`,`busy由通话状态或服务端状态策略控制,浏览器不得伪造`),new n(`setBu()`,`busy由通话状态或服务端状态策略控制,浏览器不得伪造`)}setRe(...e){return this.warn(`setRe`,`请改用 client.setAgentStatus('break')`),this.client.setAgentStatus(`break`)}requireCurrentCall(){let t=this.client.getActiveCall();if(t!==void 0&&(this.currentCall=t),this.currentCall===void 0)throw new e.t(`CALL_NOT_CONNECTED`,`call`,!1);return this.currentCall}warn(e,t){i()&&!this.warnedMethods.has(e)&&(this.warnedMethods.add(e),console.warn(`[CCBarSDK] ${e}() 已废弃。${t}`))}};function i(){return!1}var a=`0.1.0`;typeof window<`u`&&(window.CCBarSDK=r),exports.CCBarSDK=r,exports.DeprecatedError=n,exports.legacyVersion=a;
@@ -0,0 +1,8 @@
1
+ import { CCBarSDK } from './CCBarSDK.js';
2
+ export { CCBarSDK, DeprecatedError } from './CCBarSDK.js';
3
+ export declare const legacyVersion = "0.1.0";
4
+ declare global {
5
+ interface Window {
6
+ CCBarSDK: typeof CCBarSDK;
7
+ }
8
+ }
@@ -0,0 +1,108 @@
1
+ import { t as e } from "../CCBarError-DSbPw2dA.js";
2
+ import { t } from "../CCBarClient-BdbynNBi.js";
3
+ //#region src/legacy/CCBarSDK.ts
4
+ var n = class extends Error {
5
+ code = "LEGACY_METHOD_DEPRECATED";
6
+ constructor(e, t) {
7
+ super(`${e} 已废弃:${t}`), this.name = "DeprecatedError";
8
+ }
9
+ }, r = class {
10
+ client;
11
+ warnedMethods = /* @__PURE__ */ new Set();
12
+ unsubscribeIncoming;
13
+ currentCall;
14
+ constructor(e) {
15
+ this.client = new t(e), this.unsubscribeIncoming = this.client.on("call.incoming", ({ callId: e }) => {
16
+ this.currentCall = this.client.getCalls().find((t) => t.id === e);
17
+ });
18
+ }
19
+ getToken(...e) {
20
+ return this.warn("getToken", "请改用 client.connect()"), this.client.connect();
21
+ }
22
+ getAccount(...e) {
23
+ return this.warn("getAccount", "请改用 client.connect()"), this.client.connect();
24
+ }
25
+ login(...e) {
26
+ return this.warn("login", "请改用 client.connect()"), this.client.connect();
27
+ }
28
+ async call(e, ...t) {
29
+ this.warn("call", "请改用 client.dial({ destination })");
30
+ let n = await this.client.dial({ destination: String(e) });
31
+ return this.currentCall = n, n;
32
+ }
33
+ async insideCall(e, ...t) {
34
+ this.warn("insideCall", "请改用 client.dial({ destination, type: 'extension' })");
35
+ let n = await this.client.dial({
36
+ destination: String(e),
37
+ type: "extension"
38
+ });
39
+ return this.currentCall = n, n;
40
+ }
41
+ answer(...e) {
42
+ this.warn("answer", "请改用 call.answer()");
43
+ let t = this.requireCurrentCall();
44
+ return this.client.answer(t.id);
45
+ }
46
+ async hangup(...e) {
47
+ this.warn("hangup", "请改用 call.hangup()");
48
+ let t = this.requireCurrentCall();
49
+ try {
50
+ await t.hangup();
51
+ } finally {
52
+ this.currentCall === t && (this.currentCall = void 0);
53
+ }
54
+ }
55
+ holdCall(...e) {
56
+ return this.warn("holdCall", "请改用 call.hold()"), this.requireCurrentCall().hold();
57
+ }
58
+ unholdCall(...e) {
59
+ return this.warn("unholdCall", "请改用 call.resume()"), this.requireCurrentCall().resume();
60
+ }
61
+ transSo(e, ...t) {
62
+ return this.warn("transSo", "请改用 call.transfer({ target, type: 'blind' })"), this.requireCurrentCall().transfer({
63
+ target: String(e),
64
+ type: "blind"
65
+ });
66
+ }
67
+ async signOut(...e) {
68
+ this.warn("signOut", "请改用 client.disconnect() 和 client.dispose()");
69
+ let t;
70
+ try {
71
+ await this.client.disconnect();
72
+ } catch (e) {
73
+ t = e;
74
+ }
75
+ try {
76
+ await this.client.dispose();
77
+ } catch (e) {
78
+ t ??= e;
79
+ }
80
+ if (this.unsubscribeIncoming(), this.currentCall = void 0, t !== void 0) throw t;
81
+ }
82
+ setId(...e) {
83
+ return this.warn("setId", "请改用 client.setAgentStatus('available')"), this.client.setAgentStatus("available");
84
+ }
85
+ setBu(...e) {
86
+ throw this.warn("setBu", "busy由通话状态或服务端状态策略控制,浏览器不得伪造"), new n("setBu()", "busy由通话状态或服务端状态策略控制,浏览器不得伪造");
87
+ }
88
+ setRe(...e) {
89
+ return this.warn("setRe", "请改用 client.setAgentStatus('break')"), this.client.setAgentStatus("break");
90
+ }
91
+ requireCurrentCall() {
92
+ let t = this.client.getActiveCall();
93
+ if (t !== void 0 && (this.currentCall = t), this.currentCall === void 0) throw new e("CALL_NOT_CONNECTED", "call", !1);
94
+ return this.currentCall;
95
+ }
96
+ warn(e, t) {
97
+ i() && !this.warnedMethods.has(e) && (this.warnedMethods.add(e), console.warn(`[CCBarSDK] ${e}() 已废弃。${t}`));
98
+ }
99
+ };
100
+ function i() {
101
+ return !1;
102
+ }
103
+ //#endregion
104
+ //#region src/legacy/index.ts
105
+ var a = "0.1.0";
106
+ typeof window < "u" && (window.CCBarSDK = r);
107
+ //#endregion
108
+ export { r as CCBarSDK, n as DeprecatedError, a as legacyVersion };
@@ -0,0 +1 @@
1
+ var e=`[REDACTED]`,t=/\bBearer\s+[^\s,;"'}]+/gi,n=/(\bAuthorization\s*[:=]\s*)Digest\s+[^\r\n]*/gi,r=/(\bAuthorization\s*[:=]\s*)(?:(Bearer|Basic|Digest|Token)\s+)?[^\s,;"'}]+/gi,i=/\beyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\b/g,a=/\b((?:sip|sips|turn|turns|ws|wss):(?:\/\/)?)[^/?#@\s:]+:[^/?#@\s]+@/gi,o=/(\b(?:sip(?:Register)?Ticket|registerTicket|wssTicket|turnCredential|credential|accessToken|refreshToken|appSecret|password|jwt|ticket)\b\s*[:=]\s*)(["']?)([^\s,;&}"']+)(["']?)/gi,s=/(?<!\d)(1[3-9]\d)\d{4}(\d{4})(?!\d)/g,c=/(?:authorization|token|ticket|credential|password|secret)$/i;function l(c,l={}){let u=c.replace(t,`Bearer ${e}`).replace(n,(t,n)=>`${n}Digest ${e}`).replace(r,(t,n,r)=>`${n}${r===void 0?``:`${r} `}${e}`).replace(i,e).replace(a,(t,n)=>`${n}${e}@`).replace(o,(t,n)=>`${n}${e}`);return l.maskPhoneNumbers!==!1&&(u=u.replace(s,`$1****$2`)),u}function u(e,t={}){return d(e,t,new WeakSet)}function d(t,n,r){if(typeof t==`string`)return l(t,n);if(typeof t!=`object`||!t)return t;if(r.has(t))return`[Circular]`;if(r.add(t),Array.isArray(t))return t.map(e=>d(e,n,r));let i={};return Object.entries(t).forEach(([t,a])=>{i[t]=c.test(t)?e:d(a,n,r)}),i}Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return l}});
@@ -0,0 +1,21 @@
1
+ //#region src/diagnostics/redact.ts
2
+ var e = "[REDACTED]", t = /\bBearer\s+[^\s,;"'}]+/gi, n = /(\bAuthorization\s*[:=]\s*)Digest\s+[^\r\n]*/gi, r = /(\bAuthorization\s*[:=]\s*)(?:(Bearer|Basic|Digest|Token)\s+)?[^\s,;"'}]+/gi, i = /\beyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\b/g, a = /\b((?:sip|sips|turn|turns|ws|wss):(?:\/\/)?)[^/?#@\s:]+:[^/?#@\s]+@/gi, o = /(\b(?:sip(?:Register)?Ticket|registerTicket|wssTicket|turnCredential|credential|accessToken|refreshToken|appSecret|password|jwt|ticket)\b\s*[:=]\s*)(["']?)([^\s,;&}"']+)(["']?)/gi, s = /(?<!\d)(1[3-9]\d)\d{4}(\d{4})(?!\d)/g, c = /(?:authorization|token|ticket|credential|password|secret)$/i;
3
+ function l(c, l = {}) {
4
+ let u = c.replace(t, `Bearer ${e}`).replace(n, (t, n) => `${n}Digest ${e}`).replace(r, (t, n, r) => `${n}${r === void 0 ? "" : `${r} `}${e}`).replace(i, e).replace(a, (t, n) => `${n}${e}@`).replace(o, (t, n) => `${n}${e}`);
5
+ return l.maskPhoneNumbers !== !1 && (u = u.replace(s, "$1****$2")), u;
6
+ }
7
+ function u(e, t = {}) {
8
+ return d(e, t, /* @__PURE__ */ new WeakSet());
9
+ }
10
+ function d(t, n, r) {
11
+ if (typeof t == "string") return l(t, n);
12
+ if (typeof t != "object" || !t) return t;
13
+ if (r.has(t)) return "[Circular]";
14
+ if (r.add(t), Array.isArray(t)) return t.map((e) => d(e, n, r));
15
+ let i = {};
16
+ return Object.entries(t).forEach(([t, a]) => {
17
+ i[t] = c.test(t) ? e : d(a, n, r);
18
+ }), i;
19
+ }
20
+ //#endregion
21
+ export { u as n, l as t };
@@ -0,0 +1,55 @@
1
+ import { CallDialOptions, CallSessionEvent, CreateSessionRequest, WebPhoneSession } from '../api/contracts.js';
2
+ import { CallSnapshot as PublicCallSnapshot } from '../types.js';
3
+ import { SipAdapter, SipSessionHandle } from '../sip/SipAdapter.js';
4
+ export interface SharedSessionApi {
5
+ createSession(request: CreateSessionRequest): Promise<WebPhoneSession>;
6
+ refreshSession(sessionId: string): Promise<WebPhoneSession>;
7
+ deleteSession(sessionId: string): Promise<void>;
8
+ }
9
+ export interface SharedSipCoreOptions {
10
+ readonly api: SharedSessionApi;
11
+ readonly sip: SipAdapter;
12
+ readonly request: CreateSessionRequest;
13
+ readonly onCallTerminal?: (callId: string) => void | Promise<void>;
14
+ }
15
+ export declare class SharedSipCore {
16
+ private readonly api;
17
+ private readonly sip;
18
+ private readonly request;
19
+ private readonly onCallTerminal?;
20
+ private readonly calls;
21
+ private session?;
22
+ private connected;
23
+ private connectOperation?;
24
+ private refreshOperation?;
25
+ private disconnectOperation?;
26
+ constructor(options: SharedSipCoreOptions);
27
+ connect(): Promise<void>;
28
+ disconnect(): Promise<void>;
29
+ dispose(): Promise<void>;
30
+ refreshAndReconnect(): Promise<void>;
31
+ dial(target: string, options: CallDialOptions): Promise<PublicCallSnapshot>;
32
+ getSession(): WebPhoneSession | undefined;
33
+ getCall(callId: string): SharedCallTransport | undefined;
34
+ private performConnect;
35
+ private performRefreshAndReconnect;
36
+ private performDisconnect;
37
+ private removeCall;
38
+ }
39
+ export declare class SharedCallTransport {
40
+ private readonly session;
41
+ private snapshot;
42
+ constructor(session: SipSessionHandle, destination: string, incoming: boolean);
43
+ get id(): string;
44
+ getSnapshot(): PublicCallSnapshot;
45
+ answer(options: Parameters<SipSessionHandle['answer']>[0]): void;
46
+ terminate(): void;
47
+ hold(): Promise<void>;
48
+ unhold(): Promise<void>;
49
+ mute(): void;
50
+ unmute(): void;
51
+ sendDtmf(tone: string): void;
52
+ refer(target: string): void;
53
+ on(event: CallSessionEvent, handler: (payload: unknown) => void): () => void;
54
+ private updateSnapshot;
55
+ }
@@ -0,0 +1,20 @@
1
+ import { SharedWorkerLifecycleState } from '../types.js';
2
+ import { PROTOCOL_VERSION, WorkerEvent, WorkerRequest } from './SharedWorkerProtocol.js';
3
+ export interface SharedWorkerClientOptions {
4
+ readonly timeoutMs?: number;
5
+ }
6
+ export declare class SharedWorkerClient {
7
+ private readonly port;
8
+ private readonly timeoutMs;
9
+ private readonly pending;
10
+ private readonly eventHandlers;
11
+ private closed;
12
+ private lifecycleState;
13
+ constructor(port: MessagePort, options?: SharedWorkerClientOptions);
14
+ request<T>(request: WorkerRequest): Promise<T>;
15
+ onEvent(handler: (event: WorkerEvent) => void): () => void;
16
+ getLifecycleState(): SharedWorkerLifecycleState;
17
+ close(): void;
18
+ private handleMessage;
19
+ }
20
+ export { PROTOCOL_VERSION };
@@ -0,0 +1,3 @@
1
+ import { installSharedWorker, SharedWorkerScope } from './SharedWorkerRuntime.js';
2
+ export declare function createSharedWorkerRuntime(scope: SharedWorkerScope): ReturnType<typeof installSharedWorker>;
3
+ export declare const sharedWorkerRuntime: import('./SharedWorkerRuntime.js').SharedWorkerRuntime | undefined;
@@ -0,0 +1,29 @@
1
+ import { SharedWorkerMode, SharedWorkerOptions } from '../types.js';
2
+ import { SharedWorkerClient } from './SharedWorkerClient.js';
3
+ export interface SharedWorkerLike {
4
+ readonly port: MessagePort;
5
+ }
6
+ export type SharedWorkerConstructor = new (scriptURL: string, options?: {
7
+ readonly name?: string;
8
+ }) => SharedWorkerLike;
9
+ export interface SharedWorkerFactoryOptions extends SharedWorkerOptions {
10
+ readonly tabId?: string;
11
+ readonly workerCtor?: SharedWorkerConstructor;
12
+ readonly locationHref?: string;
13
+ }
14
+ export interface SharedWorkerConnection {
15
+ readonly mode: 'shared';
16
+ readonly worker: SharedWorkerLike;
17
+ readonly client: SharedWorkerClient;
18
+ readonly tabId: string;
19
+ readonly workerUrl: string;
20
+ readonly ready: Promise<void>;
21
+ }
22
+ export interface SingleTabFallback {
23
+ readonly mode: 'single-tab';
24
+ readonly reason: string;
25
+ }
26
+ export type SharedWorkerSelection = SharedWorkerConnection | SingleTabFallback;
27
+ export declare function createSharedWorkerSelection(options?: SharedWorkerFactoryOptions): SharedWorkerSelection;
28
+ export declare function resolveWorkerUrl(url: string | undefined, locationHref?: string | undefined): string | undefined;
29
+ export type { SharedWorkerMode };
@@ -0,0 +1,47 @@
1
+ import { CallSnapshot, SharedTabInfo, SharedWorkerOptions } from '../types.js';
2
+ export declare const PROTOCOL_VERSION: 1;
3
+ export type { CallSnapshot, SharedTabInfo, SharedWorkerOptions };
4
+ export interface SerializedCCBarError {
5
+ readonly code: string;
6
+ readonly category: string;
7
+ readonly retryable: boolean;
8
+ readonly requestId?: string;
9
+ readonly callId?: string;
10
+ readonly message: string;
11
+ }
12
+ export type WorkerRequest = {
13
+ readonly version: typeof PROTOCOL_VERSION;
14
+ readonly type: 'attach';
15
+ readonly requestId: string;
16
+ readonly tabId: string;
17
+ } | {
18
+ readonly version: typeof PROTOCOL_VERSION;
19
+ readonly type: 'detach';
20
+ readonly requestId: string;
21
+ readonly tabId: string;
22
+ } | {
23
+ readonly version: typeof PROTOCOL_VERSION;
24
+ readonly type: 'command';
25
+ readonly requestId: string;
26
+ readonly tabId: string;
27
+ readonly command: string;
28
+ readonly payload?: Record<string, unknown>;
29
+ };
30
+ export interface WorkerResponse {
31
+ readonly version: typeof PROTOCOL_VERSION;
32
+ readonly type: 'response';
33
+ readonly requestId: string;
34
+ readonly ok: boolean;
35
+ readonly result?: unknown;
36
+ readonly error?: SerializedCCBarError;
37
+ }
38
+ export interface WorkerEvent {
39
+ readonly version: typeof PROTOCOL_VERSION;
40
+ readonly type: 'event';
41
+ readonly event: 'connection.stateChanged' | 'call.created' | 'call.incoming' | 'call.stateChanged' | 'call.snapshot' | 'call.ownershipChanged' | 'call.ended' | 'call.failed' | 'tabs.changed' | 'error';
42
+ readonly payload: unknown;
43
+ }
44
+ export type WorkerMessage = WorkerRequest | WorkerResponse | WorkerEvent;
45
+ export declare function serializeCallSnapshot(value: CallSnapshot | Record<string, unknown>): CallSnapshot;
46
+ export declare function serializeError(error: unknown): SerializedCCBarError;
47
+ export declare function parseWorkerMessage(value: unknown): WorkerMessage;
@@ -0,0 +1,35 @@
1
+ import { WorkerEvent, WorkerRequest, WorkerResponse } from './SharedWorkerProtocol.js';
2
+ import { CallSnapshot, SharedWorkerLifecycleState } from '../types.js';
3
+ export interface SharedWorkerRuntimeOptions {
4
+ readonly handleRequest?: (request: WorkerRequest) => Promise<unknown>;
5
+ readonly timeoutMs?: number;
6
+ readonly onPortDetached?: (tabId: string) => void | Promise<void>;
7
+ }
8
+ export declare class SharedWorkerRuntime {
9
+ private readonly ports;
10
+ private readonly requestResults;
11
+ private lifecycleState;
12
+ private bootstrapOwner?;
13
+ private readonly options;
14
+ constructor(options?: SharedWorkerRuntimeOptions);
15
+ attach(port: MessagePort, tabId: string): () => void;
16
+ handle(request: WorkerRequest): Promise<WorkerResponse>;
17
+ broadcast(event: WorkerEvent): void;
18
+ getTabIds(): string[];
19
+ getLifecycleState(): SharedWorkerLifecycleState;
20
+ /** @internal Called by the Worker connection supervisor after a Worker/SIP restart. */
21
+ restart(): void;
22
+ /** @internal Marks recovery complete and replays serializable call state to every tab. */
23
+ markReady(snapshots?: readonly CallSnapshot[]): void;
24
+ private execute;
25
+ private assertCommandAllowed;
26
+ private claimBootstrap;
27
+ private handlePortMessage;
28
+ private detachPort;
29
+ }
30
+ export interface SharedWorkerScope {
31
+ onconnect: ((event: {
32
+ readonly ports: readonly MessagePort[];
33
+ }) => void) | null;
34
+ }
35
+ export declare function installSharedWorker(scope: SharedWorkerScope, runtime?: SharedWorkerRuntime): SharedWorkerRuntime;
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./CCBarError-CIqJE8zK.cjs"),t=require("./SharedWorkerProtocol-CYN0AprP.cjs");require("./createJsSipFactory-2X4FBIU2.cjs");var n=class{ports=new Map;requestResults=new Map;lifecycleState=`connected`;bootstrapOwner;options;constructor(e={}){this.options={timeoutMs:e.timeoutMs??15e3,...e}}attach(e,t){let n=e;s(t);let r=this.ports.get(t);r!==void 0&&r!==n&&this.detachPort(t,r),this.ports.set(t,n),n.onmessage=e=>{this.handlePortMessage(n,t,e.data)},n.start();let i=!1;return()=>{i||(i=!0,this.ports.get(t)===n&&this.detachPort(t,n))}}async handle(n){let r=t.t(n);if(!o(r))return a(n.requestId,new e.t(`SDK_INTERNAL_ERROR`,`internal`,!1));let i=`${r.tabId}:${r.requestId}`,s=this.requestResults.get(i);if(s!==void 0)return s;let c=this.execute(r);return this.requestResults.set(i,c),c}broadcast(e){let t=i(e);this.ports.forEach(e=>e.postMessage(t))}getTabIds(){return[...this.ports.keys()]}getLifecycleState(){return this.lifecycleState}restart(){this.lifecycleState=`reconnecting`,this.bootstrapOwner=void 0,this.broadcast({version:1,type:`event`,event:`connection.stateChanged`,payload:{state:`reconnecting`}})}markReady(e=[]){this.lifecycleState=`connected`,this.bootstrapOwner=void 0,this.broadcast({version:1,type:`event`,event:`connection.stateChanged`,payload:{state:`connected`}}),e.forEach(e=>{this.broadcast({version:1,type:`event`,event:`call.snapshot`,payload:t.n(e)})})}async execute(t){try{this.assertCommandAllowed(t),t.type===`command`&&t.command===`bootstrap`&&this.claimBootstrap(t.tabId);let e=await c(this.options.handleRequest?.(t)??Promise.resolve({attached:t.tabId}),this.options.timeoutMs);return{version:1,type:`response`,requestId:t.requestId,ok:!0,result:e}}catch(n){let r=n instanceof e.t?n:n instanceof l?new e.t(`NETWORK_TIMEOUT`,`network`,!0,{requestId:t.requestId}):new e.t(`SDK_INTERNAL_ERROR`,`internal`,!1,{requestId:t.requestId,cause:n});return a(t.requestId,r)}}assertCommandAllowed(t){if(t.type===`command`&&this.lifecycleState===`reconnecting`&&(t.command===`dial`||t.command===`answer`))throw new e.t(`CALL_OPERATION_NOT_ALLOWED`,`call`,!0,{callId:t.payload?.callId})}claimBootstrap(t){if(this.bootstrapOwner===void 0){this.bootstrapOwner=t;return}if(this.bootstrapOwner!==t)throw new e.t(`CALL_OPERATION_NOT_ALLOWED`,`call`,!0)}async handlePortMessage(n,r,i){try{let s=t.t(i);if(!o(s)||s.tabId!==r){n.postMessage(a(typeof i==`object`&&i&&`requestId`in i&&typeof i.requestId==`string`?i.requestId:``,new e.t(`SDK_INTERNAL_ERROR`,`internal`,!1)));return}n.postMessage(await this.handle(s))}catch(e){let t=typeof i==`object`&&i&&`requestId`in i&&typeof i.requestId==`string`?i.requestId:``;n.postMessage(a(t,e))}}detachPort(e,t){t.onmessage=null,this.ports.delete(e),this.options.onPortDetached?.(e)}};function r(r,i=new n){return r.onconnect=n=>{let r=n.ports[0];if(r===void 0)return;let s=!0;r.onmessage=n=>{try{let a=t.t(n.data);if(!o(a)||a.type!==`attach`)throw new e.t(`SDK_INTERNAL_ERROR`,`internal`,!1);s=!1,i.attach(r,a.tabId),i.handle(a).then(e=>r.postMessage(e))}catch(e){let t=typeof n.data==`object`&&n.data!==null&&`requestId`in n.data&&typeof n.data.requestId==`string`?n.data.requestId:``;r.postMessage(a(t,e))}},r.start(),s||(r.onmessage=null)},i}function i(e){if((e.event===`call.snapshot`||e.event===`call.created`)&&typeof e.payload==`object`&&e.payload!==null)return{...e,payload:t.n(e.payload)};if(e.event===`call.failed`&&typeof e.payload==`object`&&e.payload!==null&&`error`in e.payload){let n=e.payload;return{...e,payload:{...typeof n.callId==`string`?{callId:n.callId}:{},error:t.r(n.error)}}}return e.event===`error`?{...e,payload:t.r(e.payload)}:structuredClone(e)}function a(e,n){return{version:1,type:`response`,requestId:e,ok:!1,error:t.r(n)}}function o(e){return typeof e==`object`&&!!e&&`requestId`in e&&`tabId`in e&&`type`in e&&(e.type===`attach`||e.type===`detach`||e.type===`command`)}function s(t){if(!/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/.test(t))throw new e.t(`SDK_INTERNAL_ERROR`,`internal`,!1)}async function c(e,t){let n;try{return await Promise.race([e,new Promise((e,r)=>{n=setTimeout(()=>r(new l),t)})])}finally{n!==void 0&&clearTimeout(n)}}var l=class extends Error{};function u(e){return r(e)}var d=typeof globalThis==`object`&&`onconnect`in globalThis?r(globalThis):void 0;exports.createSharedWorkerRuntime=u,exports.sharedWorkerRuntime=d;
@@ -0,0 +1 @@
1
+ export * from './shared/SharedWorkerEntry.js';
@@ -0,0 +1,185 @@
1
+ import { t as e } from "./CCBarError-DSbPw2dA.js";
2
+ import { n as t, r as n, t as r } from "./SharedWorkerProtocol-BqUafs8d.js";
3
+ //#region src/shared/SharedWorkerRuntime.ts
4
+ var i = class {
5
+ ports = /* @__PURE__ */ new Map();
6
+ requestResults = /* @__PURE__ */ new Map();
7
+ lifecycleState = "connected";
8
+ bootstrapOwner;
9
+ options;
10
+ constructor(e = {}) {
11
+ this.options = {
12
+ timeoutMs: e.timeoutMs ?? 15e3,
13
+ ...e
14
+ };
15
+ }
16
+ attach(e, t) {
17
+ let n = e;
18
+ l(t);
19
+ let r = this.ports.get(t);
20
+ r !== void 0 && r !== n && this.detachPort(t, r), this.ports.set(t, n), n.onmessage = (e) => {
21
+ this.handlePortMessage(n, t, e.data);
22
+ }, n.start();
23
+ let i = !1;
24
+ return () => {
25
+ i || (i = !0, this.ports.get(t) === n && this.detachPort(t, n));
26
+ };
27
+ }
28
+ async handle(t) {
29
+ let n = r(t);
30
+ if (!c(n)) return s(t.requestId, new e("SDK_INTERNAL_ERROR", "internal", !1));
31
+ let i = `${n.tabId}:${n.requestId}`, a = this.requestResults.get(i);
32
+ if (a !== void 0) return a;
33
+ let o = this.execute(n);
34
+ return this.requestResults.set(i, o), o;
35
+ }
36
+ broadcast(e) {
37
+ let t = o(e);
38
+ this.ports.forEach((e) => e.postMessage(t));
39
+ }
40
+ getTabIds() {
41
+ return [...this.ports.keys()];
42
+ }
43
+ getLifecycleState() {
44
+ return this.lifecycleState;
45
+ }
46
+ restart() {
47
+ this.lifecycleState = "reconnecting", this.bootstrapOwner = void 0, this.broadcast({
48
+ version: 1,
49
+ type: "event",
50
+ event: "connection.stateChanged",
51
+ payload: { state: "reconnecting" }
52
+ });
53
+ }
54
+ markReady(e = []) {
55
+ this.lifecycleState = "connected", this.bootstrapOwner = void 0, this.broadcast({
56
+ version: 1,
57
+ type: "event",
58
+ event: "connection.stateChanged",
59
+ payload: { state: "connected" }
60
+ }), e.forEach((e) => {
61
+ this.broadcast({
62
+ version: 1,
63
+ type: "event",
64
+ event: "call.snapshot",
65
+ payload: t(e)
66
+ });
67
+ });
68
+ }
69
+ async execute(t) {
70
+ try {
71
+ this.assertCommandAllowed(t), t.type === "command" && t.command === "bootstrap" && this.claimBootstrap(t.tabId);
72
+ let e = await u(this.options.handleRequest?.(t) ?? Promise.resolve({ attached: t.tabId }), this.options.timeoutMs);
73
+ return {
74
+ version: 1,
75
+ type: "response",
76
+ requestId: t.requestId,
77
+ ok: !0,
78
+ result: e
79
+ };
80
+ } catch (n) {
81
+ let r = n instanceof e ? n : n instanceof d ? new e("NETWORK_TIMEOUT", "network", !0, { requestId: t.requestId }) : new e("SDK_INTERNAL_ERROR", "internal", !1, {
82
+ requestId: t.requestId,
83
+ cause: n
84
+ });
85
+ return s(t.requestId, r);
86
+ }
87
+ }
88
+ assertCommandAllowed(t) {
89
+ if (t.type === "command" && this.lifecycleState === "reconnecting" && (t.command === "dial" || t.command === "answer")) throw new e("CALL_OPERATION_NOT_ALLOWED", "call", !0, { callId: t.payload?.callId });
90
+ }
91
+ claimBootstrap(t) {
92
+ if (this.bootstrapOwner === void 0) {
93
+ this.bootstrapOwner = t;
94
+ return;
95
+ }
96
+ if (this.bootstrapOwner !== t) throw new e("CALL_OPERATION_NOT_ALLOWED", "call", !0);
97
+ }
98
+ async handlePortMessage(t, n, i) {
99
+ try {
100
+ let a = r(i);
101
+ if (!c(a) || a.tabId !== n) {
102
+ t.postMessage(s(typeof i == "object" && i && "requestId" in i && typeof i.requestId == "string" ? i.requestId : "", new e("SDK_INTERNAL_ERROR", "internal", !1)));
103
+ return;
104
+ }
105
+ t.postMessage(await this.handle(a));
106
+ } catch (e) {
107
+ let n = typeof i == "object" && i && "requestId" in i && typeof i.requestId == "string" ? i.requestId : "";
108
+ t.postMessage(s(n, e));
109
+ }
110
+ }
111
+ detachPort(e, t) {
112
+ t.onmessage = null, this.ports.delete(e), this.options.onPortDetached?.(e);
113
+ }
114
+ };
115
+ function a(t, n = new i()) {
116
+ return t.onconnect = (t) => {
117
+ let i = t.ports[0];
118
+ if (i === void 0) return;
119
+ let a = !0;
120
+ i.onmessage = (t) => {
121
+ try {
122
+ let o = r(t.data);
123
+ if (!c(o) || o.type !== "attach") throw new e("SDK_INTERNAL_ERROR", "internal", !1);
124
+ a = !1, n.attach(i, o.tabId), n.handle(o).then((e) => i.postMessage(e));
125
+ } catch (e) {
126
+ let n = typeof t.data == "object" && t.data !== null && "requestId" in t.data && typeof t.data.requestId == "string" ? t.data.requestId : "";
127
+ i.postMessage(s(n, e));
128
+ }
129
+ }, i.start(), a || (i.onmessage = null);
130
+ }, n;
131
+ }
132
+ function o(e) {
133
+ if ((e.event === "call.snapshot" || e.event === "call.created") && typeof e.payload == "object" && e.payload !== null) return {
134
+ ...e,
135
+ payload: t(e.payload)
136
+ };
137
+ if (e.event === "call.failed" && typeof e.payload == "object" && e.payload !== null && "error" in e.payload) {
138
+ let t = e.payload;
139
+ return {
140
+ ...e,
141
+ payload: {
142
+ ...typeof t.callId == "string" ? { callId: t.callId } : {},
143
+ error: n(t.error)
144
+ }
145
+ };
146
+ }
147
+ return e.event === "error" ? {
148
+ ...e,
149
+ payload: n(e.payload)
150
+ } : structuredClone(e);
151
+ }
152
+ function s(e, t) {
153
+ return {
154
+ version: 1,
155
+ type: "response",
156
+ requestId: e,
157
+ ok: !1,
158
+ error: n(t)
159
+ };
160
+ }
161
+ function c(e) {
162
+ return typeof e == "object" && !!e && "requestId" in e && "tabId" in e && "type" in e && (e.type === "attach" || e.type === "detach" || e.type === "command");
163
+ }
164
+ function l(t) {
165
+ if (!/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/.test(t)) throw new e("SDK_INTERNAL_ERROR", "internal", !1);
166
+ }
167
+ async function u(e, t) {
168
+ let n;
169
+ try {
170
+ return await Promise.race([e, new Promise((e, r) => {
171
+ n = setTimeout(() => r(new d()), t);
172
+ })]);
173
+ } finally {
174
+ n !== void 0 && clearTimeout(n);
175
+ }
176
+ }
177
+ var d = class extends Error {};
178
+ //#endregion
179
+ //#region src/shared/SharedWorkerEntry.ts
180
+ function f(e) {
181
+ return a(e);
182
+ }
183
+ var p = typeof globalThis == "object" && "onconnect" in globalThis ? a(globalThis) : void 0;
184
+ //#endregion
185
+ export { f as createSharedWorkerRuntime, p as sharedWorkerRuntime };
@@ -0,0 +1,9 @@
1
+ import { CCBarError } from '../errors/CCBarError.js';
2
+ import { CallState } from '../types.js';
3
+ export declare const transitions: Record<CallState, ReadonlySet<CallState>>;
4
+ export declare const canTransition: (from: CallState, to: CallState) => boolean;
5
+ export declare function assertCallTransition(from: CallState, to: CallState): CallState;
6
+ export declare class CallStateError extends CCBarError {
7
+ constructor(from: CallState, to: CallState);
8
+ }
9
+ export declare const transition: typeof assertCallTransition;
@@ -0,0 +1,7 @@
1
+ @import './tokens.css';
2
+ @import './base.css';
3
+ @import './compact.css';
4
+ @import './panel.css';
5
+ @import './mobile.css';
6
+ @import './dark.css';
7
+ @import './reduced-motion.css';