@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.
- package/CHANGELOG.md +22 -0
- package/LICENSE +2 -0
- package/README.md +113 -0
- package/dist/CCBarClient-BdbynNBi.js +2515 -0
- package/dist/CCBarClient-DKWdvgf5.cjs +1 -0
- package/dist/CCBarError-CIqJE8zK.cjs +1 -0
- package/dist/CCBarError-DSbPw2dA.js +14 -0
- package/dist/Diagnostics-BYVvmxil.cjs +1 -0
- package/dist/Diagnostics-Cw2HVrCD.js +123 -0
- package/dist/JsSipAdapter-GHzVSCDh.js +304 -0
- package/dist/JsSipAdapter-jtGdoXrm.cjs +1 -0
- package/dist/SharedWorkerProtocol-BqUafs8d.js +73 -0
- package/dist/SharedWorkerProtocol-CYN0AprP.cjs +1 -0
- package/dist/api/WebPhoneApi.d.ts +28 -0
- package/dist/api/contracts.d.ts +94 -0
- package/dist/auth/TokenManager.d.ts +22 -0
- package/dist/core/CCBarCall.d.ts +94 -0
- package/dist/core/CCBarClient.d.ts +113 -0
- package/dist/core/CallManager.d.ts +93 -0
- package/dist/core/callId.d.ts +1 -0
- package/dist/core/mediaBridge.d.ts +17 -0
- package/dist/createJsSipFactory-2X4FBIU2.cjs +75 -0
- package/dist/createJsSipFactory-yttVU3d6.js +9662 -0
- package/dist/diagnostics/Diagnostics.d.ts +74 -0
- package/dist/diagnostics/RingBuffer.d.ts +7 -0
- package/dist/diagnostics/index.cjs +1 -0
- package/dist/diagnostics/index.d.ts +4 -0
- package/dist/diagnostics/index.js +6 -0
- package/dist/diagnostics/redact.d.ts +5 -0
- package/dist/errors/CCBarError.d.ts +15 -0
- package/dist/events/TypedEventBus.d.ts +9 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +152 -0
- package/dist/index.umd.js +75 -0
- package/dist/legacy/CCBarSDK.d.ts +29 -0
- package/dist/legacy/index.cjs +1 -0
- package/dist/legacy/index.d.ts +8 -0
- package/dist/legacy/index.js +108 -0
- package/dist/redact-Bq26pObO.cjs +1 -0
- package/dist/redact-DB3CMbsK.js +21 -0
- package/dist/shared/SharedCallTransport.d.ts +55 -0
- package/dist/shared/SharedWorkerClient.d.ts +20 -0
- package/dist/shared/SharedWorkerEntry.d.ts +3 -0
- package/dist/shared/SharedWorkerFactory.d.ts +29 -0
- package/dist/shared/SharedWorkerProtocol.d.ts +47 -0
- package/dist/shared/SharedWorkerRuntime.d.ts +35 -0
- package/dist/shared-worker.cjs +1 -0
- package/dist/shared-worker.d.ts +1 -0
- package/dist/shared-worker.js +185 -0
- package/dist/state/callStateMachine.d.ts +9 -0
- package/dist/styles.css +7 -0
- package/dist/types.d.ts +134 -0
- package/dist/ui/XCallCCBarElement.d.ts +23 -0
- package/dist/ui/controllers/mobileLifecycle.d.ts +18 -0
- package/dist/ui/controllers/phoneActions.d.ts +27 -0
- package/dist/ui/i18n/en-US.d.ts +2 -0
- package/dist/ui/i18n/index.d.ts +6 -0
- package/dist/ui/i18n/types.d.ts +53 -0
- package/dist/ui/i18n/zh-CN.d.ts +2 -0
- package/dist/ui/icons/index.d.ts +5 -0
- package/dist/ui/index.cjs +1 -0
- package/dist/ui/index.d.ts +3 -0
- package/dist/ui/index.js +1044 -0
- package/dist/ui/state/toPhoneViewModel.d.ts +54 -0
- package/dist/ui/views/dom.d.ts +11 -0
- package/dist/ui/views/messages.d.ts +5 -0
- package/dist/ui/views/renderActiveCall.d.ts +8 -0
- package/dist/ui/views/renderDesktop.d.ts +24 -0
- package/dist/ui/views/renderDialpad.d.ts +4 -0
- package/dist/ui/views/renderError.d.ts +6 -0
- package/dist/ui/views/renderIncoming.d.ts +8 -0
- package/dist/ui/views/renderMobile.d.ts +15 -0
- package/dist/ui/views/renderSetup.d.ts +6 -0
- package/package.json +107 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { t as e } from "./CCBarError-DSbPw2dA.js";
|
|
2
|
+
import { t } from "./redact-DB3CMbsK.js";
|
|
3
|
+
var n = [
|
|
4
|
+
"new",
|
|
5
|
+
"dialing",
|
|
6
|
+
"ringing",
|
|
7
|
+
"connecting",
|
|
8
|
+
"active",
|
|
9
|
+
"held",
|
|
10
|
+
"ended",
|
|
11
|
+
"failed"
|
|
12
|
+
];
|
|
13
|
+
function r(e) {
|
|
14
|
+
if (!c(e) || typeof e.id != "string" || typeof e.destination != "string" || typeof e.incoming != "boolean" || !s(e.state)) throw u("Invalid call snapshot");
|
|
15
|
+
return {
|
|
16
|
+
id: e.id,
|
|
17
|
+
...typeof e.from == "string" ? { from: e.from } : {},
|
|
18
|
+
destination: e.destination,
|
|
19
|
+
state: e.state,
|
|
20
|
+
incoming: e.incoming,
|
|
21
|
+
...typeof e.ownerTabId == "string" ? { ownerTabId: e.ownerTabId } : {}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function i(t) {
|
|
25
|
+
return t instanceof e ? {
|
|
26
|
+
code: t.code,
|
|
27
|
+
category: t.category,
|
|
28
|
+
retryable: t.retryable,
|
|
29
|
+
...t.requestId === void 0 ? {} : { requestId: t.requestId },
|
|
30
|
+
...t.callId === void 0 ? {} : { callId: t.callId },
|
|
31
|
+
message: l(t.message)
|
|
32
|
+
} : {
|
|
33
|
+
code: "SDK_INTERNAL_ERROR",
|
|
34
|
+
category: "internal",
|
|
35
|
+
retryable: !1,
|
|
36
|
+
message: l(t instanceof Error ? t.message : String(t))
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function a(e) {
|
|
40
|
+
if (!c(e)) throw u("Invalid worker message");
|
|
41
|
+
if (e.version !== 1) throw u("Unsupported worker protocol version");
|
|
42
|
+
if (e.type === "attach" || e.type === "detach") return o(e), e;
|
|
43
|
+
if (e.type === "command") {
|
|
44
|
+
if (o(e), typeof e.command != "string" || e.payload !== void 0 && !c(e.payload)) throw u("Invalid worker command");
|
|
45
|
+
return e;
|
|
46
|
+
}
|
|
47
|
+
if (e.type === "response") {
|
|
48
|
+
if (typeof e.requestId != "string" || typeof e.ok != "boolean") throw u("Invalid worker response");
|
|
49
|
+
return e;
|
|
50
|
+
}
|
|
51
|
+
if (e.type === "event") {
|
|
52
|
+
if (typeof e.event != "string" || !("payload" in e)) throw u("Invalid worker event");
|
|
53
|
+
return e;
|
|
54
|
+
}
|
|
55
|
+
throw u("Unknown worker message type");
|
|
56
|
+
}
|
|
57
|
+
function o(e) {
|
|
58
|
+
if (typeof e.requestId != "string" || typeof e.tabId != "string") throw u("Worker request requires requestId and tabId");
|
|
59
|
+
}
|
|
60
|
+
function s(e) {
|
|
61
|
+
return typeof e == "string" && n.includes(e);
|
|
62
|
+
}
|
|
63
|
+
function c(e) {
|
|
64
|
+
return typeof e == "object" && !!e && !Array.isArray(e);
|
|
65
|
+
}
|
|
66
|
+
function l(e) {
|
|
67
|
+
return t(e).replace(/(?:authorization|token|ticket|credential|password|secret)/gi, "[REDACTED]");
|
|
68
|
+
}
|
|
69
|
+
function u(t) {
|
|
70
|
+
return new e("SDK_INTERNAL_ERROR", "internal", !1, { cause: t });
|
|
71
|
+
}
|
|
72
|
+
//#endregion
|
|
73
|
+
export { r as n, i as r, a as t };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require("./CCBarError-CIqJE8zK.cjs"),t=require("./redact-Bq26pObO.cjs");var n=[`new`,`dialing`,`ringing`,`connecting`,`active`,`held`,`ended`,`failed`];function r(e){if(!c(e)||typeof e.id!=`string`||typeof e.destination!=`string`||typeof e.incoming!=`boolean`||!s(e.state))throw u(`Invalid call snapshot`);return{id:e.id,...typeof e.from==`string`?{from:e.from}:{},destination:e.destination,state:e.state,incoming:e.incoming,...typeof e.ownerTabId==`string`?{ownerTabId:e.ownerTabId}:{}}}function i(t){return t instanceof e.t?{code:t.code,category:t.category,retryable:t.retryable,...t.requestId===void 0?{}:{requestId:t.requestId},...t.callId===void 0?{}:{callId:t.callId},message:l(t.message)}:{code:`SDK_INTERNAL_ERROR`,category:`internal`,retryable:!1,message:l(t instanceof Error?t.message:String(t))}}function a(e){if(!c(e))throw u(`Invalid worker message`);if(e.version!==1)throw u(`Unsupported worker protocol version`);if(e.type===`attach`||e.type===`detach`)return o(e),e;if(e.type===`command`){if(o(e),typeof e.command!=`string`||e.payload!==void 0&&!c(e.payload))throw u(`Invalid worker command`);return e}if(e.type===`response`){if(typeof e.requestId!=`string`||typeof e.ok!=`boolean`)throw u(`Invalid worker response`);return e}if(e.type===`event`){if(typeof e.event!=`string`||!(`payload`in e))throw u(`Invalid worker event`);return e}throw u(`Unknown worker message type`)}function o(e){if(typeof e.requestId!=`string`||typeof e.tabId!=`string`)throw u(`Worker request requires requestId and tabId`)}function s(e){return typeof e==`string`&&n.includes(e)}function c(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function l(e){return t.t(e).replace(/(?:authorization|token|ticket|credential|password|secret)/gi,`[REDACTED]`)}function u(t){return new e.t(`SDK_INTERNAL_ERROR`,`internal`,!1,{cause:t})}Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return a}});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { TokenProvider } from '../auth/TokenManager.js';
|
|
2
|
+
import { AgentStatusRequest, CapabilitiesResponse, CreateSessionRequest, RefreshSessionRequest, WebPhoneSession } from './contracts.js';
|
|
3
|
+
type Fetcher = typeof fetch;
|
|
4
|
+
export interface WebPhoneApiOptions {
|
|
5
|
+
baseUrl: string;
|
|
6
|
+
tokenProvider: TokenProvider;
|
|
7
|
+
fetcher?: Fetcher;
|
|
8
|
+
timeoutMs?: number;
|
|
9
|
+
}
|
|
10
|
+
export declare class WebPhoneApi {
|
|
11
|
+
private readonly tokenManager;
|
|
12
|
+
private readonly fetcher;
|
|
13
|
+
private readonly baseUrl;
|
|
14
|
+
private readonly timeoutMs;
|
|
15
|
+
constructor(options: WebPhoneApiOptions);
|
|
16
|
+
invalidateToken(): void;
|
|
17
|
+
createSession(request: CreateSessionRequest): Promise<WebPhoneSession>;
|
|
18
|
+
refreshSession(sessionId: string, request?: RefreshSessionRequest): Promise<WebPhoneSession>;
|
|
19
|
+
deleteSession(sessionId: string): Promise<void>;
|
|
20
|
+
setAgentStatus(request: AgentStatusRequest): Promise<void>;
|
|
21
|
+
getCapabilities(): Promise<CapabilitiesResponse>;
|
|
22
|
+
private request;
|
|
23
|
+
private requireData;
|
|
24
|
+
private parseResponse;
|
|
25
|
+
private toCCBarError;
|
|
26
|
+
private mapStatus;
|
|
27
|
+
}
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
export interface WebPhoneEnvelope<T> {
|
|
2
|
+
code: string;
|
|
3
|
+
message?: string;
|
|
4
|
+
requestId?: string;
|
|
5
|
+
data?: T | null;
|
|
6
|
+
}
|
|
7
|
+
export interface CreateSessionRequest {
|
|
8
|
+
sdkVersion: string;
|
|
9
|
+
platform: 'web' | 'mobile_web';
|
|
10
|
+
locale?: string;
|
|
11
|
+
requestedCapabilities?: string[];
|
|
12
|
+
}
|
|
13
|
+
export interface AgentStatusRequest {
|
|
14
|
+
status: 'available' | 'offline' | 'break';
|
|
15
|
+
reason: string;
|
|
16
|
+
}
|
|
17
|
+
export interface IceServer {
|
|
18
|
+
urls: string[];
|
|
19
|
+
username?: string;
|
|
20
|
+
credential?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface WebPhoneSession {
|
|
23
|
+
sessionId: string;
|
|
24
|
+
expiresAt: number;
|
|
25
|
+
agent: {
|
|
26
|
+
id: string;
|
|
27
|
+
externalUserId: string;
|
|
28
|
+
displayName: string;
|
|
29
|
+
extension: string;
|
|
30
|
+
status: string;
|
|
31
|
+
};
|
|
32
|
+
sip: {
|
|
33
|
+
uri: string;
|
|
34
|
+
registrar: string;
|
|
35
|
+
registerTicket: string;
|
|
36
|
+
registerExpires: number;
|
|
37
|
+
ticketExpiresIn: number;
|
|
38
|
+
};
|
|
39
|
+
transport: {
|
|
40
|
+
wssUrl: string;
|
|
41
|
+
ticket: string;
|
|
42
|
+
ticketExpiresIn: number;
|
|
43
|
+
};
|
|
44
|
+
iceServers: IceServer[];
|
|
45
|
+
policy: {
|
|
46
|
+
maxConcurrentCalls: number;
|
|
47
|
+
incomingEnabled: boolean;
|
|
48
|
+
mobileIncomingEnabled: boolean;
|
|
49
|
+
backgroundCallingSupported: boolean;
|
|
50
|
+
};
|
|
51
|
+
capabilities: string[];
|
|
52
|
+
}
|
|
53
|
+
export type CallSessionEvent = 'progress' | 'accepted' | 'confirmed' | 'ended' | 'failed' | 'hold' | 'unhold';
|
|
54
|
+
export interface CallAnswerOptions {
|
|
55
|
+
readonly iceServers: readonly IceServer[];
|
|
56
|
+
readonly pcConfig: {
|
|
57
|
+
readonly iceServers: readonly IceServer[];
|
|
58
|
+
};
|
|
59
|
+
readonly mediaConstraints?: MediaConstraints;
|
|
60
|
+
}
|
|
61
|
+
/** Public, serializable subset of media constraints; native media objects stay inside adapters. */
|
|
62
|
+
export interface MediaConstraints {
|
|
63
|
+
readonly audio?: boolean | Record<string, unknown>;
|
|
64
|
+
readonly video?: boolean | Record<string, unknown>;
|
|
65
|
+
}
|
|
66
|
+
export type CallDestinationType = 'external' | 'extension';
|
|
67
|
+
export interface CallDialOptions {
|
|
68
|
+
readonly iceServers: readonly IceServer[];
|
|
69
|
+
readonly extraHeaders: readonly string[];
|
|
70
|
+
readonly type?: CallDestinationType;
|
|
71
|
+
}
|
|
72
|
+
export interface CallTransportSession {
|
|
73
|
+
readonly id: string;
|
|
74
|
+
readonly from?: string;
|
|
75
|
+
answer(options: CallAnswerOptions): void;
|
|
76
|
+
terminate(): void;
|
|
77
|
+
hold(): Promise<void>;
|
|
78
|
+
unhold(): Promise<void>;
|
|
79
|
+
mute(): void;
|
|
80
|
+
unmute(): void;
|
|
81
|
+
sendDtmf(tone: string): void;
|
|
82
|
+
refer(target: string): void;
|
|
83
|
+
on(event: CallSessionEvent, handler: (payload: unknown) => void): () => void;
|
|
84
|
+
}
|
|
85
|
+
export interface CallTransport {
|
|
86
|
+
dial(target: string, options?: CallDialOptions): CallTransportSession;
|
|
87
|
+
}
|
|
88
|
+
export interface RefreshSessionRequest {
|
|
89
|
+
refresh?: Array<'sip_register_ticket' | 'wss_ticket' | 'turn_credentials'>;
|
|
90
|
+
}
|
|
91
|
+
export interface CapabilitiesResponse {
|
|
92
|
+
capabilities: string[];
|
|
93
|
+
}
|
|
94
|
+
export declare function parseSessionResponse(response: WebPhoneEnvelope<WebPhoneSession>): WebPhoneSession;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface TokenRequest {
|
|
2
|
+
readonly extension?: string;
|
|
3
|
+
}
|
|
4
|
+
export type TokenProviderResult = string | {
|
|
5
|
+
accessToken: string;
|
|
6
|
+
expiresAt?: number;
|
|
7
|
+
extension?: string;
|
|
8
|
+
};
|
|
9
|
+
export type TokenProvider = (request?: TokenRequest) => Promise<TokenProviderResult>;
|
|
10
|
+
export declare class TokenManager {
|
|
11
|
+
private readonly tokenProvider;
|
|
12
|
+
private cachedToken?;
|
|
13
|
+
private cachedRequestKey;
|
|
14
|
+
private refreshing?;
|
|
15
|
+
private generation;
|
|
16
|
+
constructor(tokenProvider: TokenProvider);
|
|
17
|
+
getValidToken(request?: TokenRequest): Promise<string>;
|
|
18
|
+
invalidate(): void;
|
|
19
|
+
private needsRefresh;
|
|
20
|
+
private refresh;
|
|
21
|
+
private clearRefresh;
|
|
22
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { CallAnswerOptions, CallTransportSession } from '../api/contracts.js';
|
|
2
|
+
import { CCBarError } from '../errors/CCBarError.js';
|
|
3
|
+
import { CallState, CallStateEvent } from '../types.js';
|
|
4
|
+
export type CallPlatform = 'web' | 'mobile-web';
|
|
5
|
+
export type CallCapability = 'outbound' | 'inbound' | 'mute' | 'dtmf' | 'hold' | 'blind_transfer';
|
|
6
|
+
export interface BlindTransferOptions {
|
|
7
|
+
readonly type: 'blind';
|
|
8
|
+
readonly target: string;
|
|
9
|
+
}
|
|
10
|
+
export type TransferOptions = BlindTransferOptions;
|
|
11
|
+
export interface RejectOptions {
|
|
12
|
+
readonly reason?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface CCBarCallOptions {
|
|
15
|
+
readonly id: string;
|
|
16
|
+
readonly destination: string;
|
|
17
|
+
readonly platform: CallPlatform;
|
|
18
|
+
readonly incoming?: boolean;
|
|
19
|
+
readonly capabilities?: ReadonlySet<string>;
|
|
20
|
+
readonly session: CallTransportSession;
|
|
21
|
+
readonly onStateChanged?: (event: CallStateEvent, payload?: unknown) => void;
|
|
22
|
+
readonly onError?: (error: CCBarError) => void;
|
|
23
|
+
readonly onDisposed?: () => void;
|
|
24
|
+
}
|
|
25
|
+
export declare class CCBarCall {
|
|
26
|
+
private readonly options;
|
|
27
|
+
private currentState;
|
|
28
|
+
private readonly sessionUnsubscribers;
|
|
29
|
+
private readonly capabilities;
|
|
30
|
+
private disposed;
|
|
31
|
+
private pendingOperation?;
|
|
32
|
+
private incomingOperation?;
|
|
33
|
+
private ownerTabId?;
|
|
34
|
+
private ownerLost;
|
|
35
|
+
readonly id: string;
|
|
36
|
+
readonly destination: string;
|
|
37
|
+
readonly platform: CallPlatform;
|
|
38
|
+
constructor(options: CCBarCallOptions);
|
|
39
|
+
get state(): CallState;
|
|
40
|
+
/** @internal Diagnostics exposes counts only; transport objects remain private. */
|
|
41
|
+
getResourceCounts(): {
|
|
42
|
+
readonly timers: number;
|
|
43
|
+
readonly listeners: number;
|
|
44
|
+
};
|
|
45
|
+
mute(tabId?: string): Promise<void>;
|
|
46
|
+
unmute(tabId?: string): Promise<void>;
|
|
47
|
+
answer(options: CallAnswerOptions, tabId?: string): Promise<void>;
|
|
48
|
+
reject(options?: RejectOptions, tabId?: string): Promise<void>;
|
|
49
|
+
hold(tabId?: string): Promise<void>;
|
|
50
|
+
resume(tabId?: string): Promise<void>;
|
|
51
|
+
sendDtmf(tone: string, tabId?: string): Promise<void>;
|
|
52
|
+
transfer(options: TransferOptions, tabId?: string): Promise<void>;
|
|
53
|
+
hangup(tabId?: string): Promise<void>;
|
|
54
|
+
beginOutbound(): void;
|
|
55
|
+
beginIncoming(): void;
|
|
56
|
+
/** @internal SharedWorker ownership is coordinated by CallManager. */
|
|
57
|
+
setOwnerTabId(tabId: string): void;
|
|
58
|
+
/** @internal SharedWorker ownership is coordinated by CallManager. */
|
|
59
|
+
clearOwnerTabId(options?: {
|
|
60
|
+
readonly lost?: boolean;
|
|
61
|
+
}): void;
|
|
62
|
+
getOwnerTabId(): string | undefined;
|
|
63
|
+
/** @internal CallManager validates tab-scoped active-call operations. */
|
|
64
|
+
assertOwnerForManager(tabId?: string): void;
|
|
65
|
+
/** @internal Only unconnected calls may be reclaimed after a port disconnect. */
|
|
66
|
+
canBeReclaimed(): boolean;
|
|
67
|
+
dispose(): void;
|
|
68
|
+
private handleSessionEvent;
|
|
69
|
+
private transitionToActive;
|
|
70
|
+
private transitionIfAllowed;
|
|
71
|
+
private transitionIfStillRinging;
|
|
72
|
+
private transitionTo;
|
|
73
|
+
private startPendingOperation;
|
|
74
|
+
private resolvePendingOperation;
|
|
75
|
+
private rejectPendingOperation;
|
|
76
|
+
private timeoutPendingOperation;
|
|
77
|
+
private clearPendingTimer;
|
|
78
|
+
private reportIllegalTransition;
|
|
79
|
+
private reportOperationError;
|
|
80
|
+
private finishFailedIncomingOperation;
|
|
81
|
+
private cleanupSessionListeners;
|
|
82
|
+
private assertState;
|
|
83
|
+
private assertMediaControlAllowed;
|
|
84
|
+
private assertHoldCapability;
|
|
85
|
+
private assertTransferCapability;
|
|
86
|
+
private assertIncomingCall;
|
|
87
|
+
private assertIncomingOperationAvailable;
|
|
88
|
+
private assertCapability;
|
|
89
|
+
private invoke;
|
|
90
|
+
private assertNotDisposed;
|
|
91
|
+
private assertOwner;
|
|
92
|
+
private capabilityError;
|
|
93
|
+
private operationError;
|
|
94
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { MediaConstraints, WebPhoneSession } from '../api/contracts.js';
|
|
2
|
+
import { TokenProvider } from '../auth/TokenManager.js';
|
|
3
|
+
import { CCBarEvents, MediaManager as PublicMedia, SharedWorkerOptions } from '../types.js';
|
|
4
|
+
import { DialOptions } from './CallManager.js';
|
|
5
|
+
import { CCBarCall, CallPlatform } from './CCBarCall.js';
|
|
6
|
+
import { DiagnosticsOptions, DiagnosticsReport } from '../diagnostics/Diagnostics.js';
|
|
7
|
+
export interface CCBarClientOptions {
|
|
8
|
+
readonly baseUrl?: string;
|
|
9
|
+
readonly tokenProvider: TokenProvider;
|
|
10
|
+
readonly locale?: string;
|
|
11
|
+
readonly platform?: CallPlatform;
|
|
12
|
+
readonly requestedCapabilities?: readonly string[];
|
|
13
|
+
readonly maxConcurrentCalls?: number;
|
|
14
|
+
readonly autoHoldPreviousCall?: boolean;
|
|
15
|
+
/** SharedWorker is attempted by the multi-tab integration when enabled is omitted or 'auto'. */
|
|
16
|
+
readonly sharedWorker?: SharedWorkerOptions;
|
|
17
|
+
/** @internal Test/integration dependency injection; not required by consumers. */
|
|
18
|
+
readonly api?: unknown;
|
|
19
|
+
/** @internal Test/integration dependency injection; not required by consumers. */
|
|
20
|
+
readonly sip?: unknown;
|
|
21
|
+
}
|
|
22
|
+
export declare class CCBarClient {
|
|
23
|
+
readonly media: PublicMedia;
|
|
24
|
+
private readonly options;
|
|
25
|
+
private readonly api;
|
|
26
|
+
private readonly suppliedSip?;
|
|
27
|
+
private sip?;
|
|
28
|
+
private readonly events;
|
|
29
|
+
private readonly mediaBridge;
|
|
30
|
+
private readonly reconnect;
|
|
31
|
+
private readonly diagnostics;
|
|
32
|
+
private callManager?;
|
|
33
|
+
private session?;
|
|
34
|
+
private state;
|
|
35
|
+
private initialized;
|
|
36
|
+
private disposed;
|
|
37
|
+
private intentionalDisconnect;
|
|
38
|
+
private deferredRebuild;
|
|
39
|
+
private detectedPlatform?;
|
|
40
|
+
private support?;
|
|
41
|
+
private acceptingEvents;
|
|
42
|
+
private connectOperation?;
|
|
43
|
+
private disconnectOperation?;
|
|
44
|
+
private refreshOperation?;
|
|
45
|
+
private disposeOperation?;
|
|
46
|
+
private refreshTimer?;
|
|
47
|
+
private lifecycleGeneration;
|
|
48
|
+
private managerUnsubscribers;
|
|
49
|
+
private sipUnsubscribe?;
|
|
50
|
+
private networkUnsubscribers;
|
|
51
|
+
private readonly sessionDeleteOperations;
|
|
52
|
+
private readonly deletedSessions;
|
|
53
|
+
private readonly ownedSessionIds;
|
|
54
|
+
private readonly terminalReleaseOperations;
|
|
55
|
+
private tokenRequest;
|
|
56
|
+
constructor(options: CCBarClientOptions);
|
|
57
|
+
static checkSupport(): Promise<import('../types.js').PlatformSupport>;
|
|
58
|
+
initialize(): Promise<void>;
|
|
59
|
+
connect(options?: {
|
|
60
|
+
readonly extension?: string;
|
|
61
|
+
}): Promise<void>;
|
|
62
|
+
disconnect(): Promise<void>;
|
|
63
|
+
dispose(): Promise<void>;
|
|
64
|
+
recover(): Promise<void>;
|
|
65
|
+
dial(options: DialOptions): Promise<CCBarCall>;
|
|
66
|
+
answer(callId: string, mediaConstraints?: MediaConstraints): Promise<void>;
|
|
67
|
+
setActiveCall(callId: string): Promise<void>;
|
|
68
|
+
getCalls(): readonly CCBarCall[];
|
|
69
|
+
getActiveCall(): CCBarCall | undefined;
|
|
70
|
+
getAgent(): WebPhoneSession['agent'] | undefined;
|
|
71
|
+
getDiagnostics(options?: DiagnosticsOptions): Promise<DiagnosticsReport>;
|
|
72
|
+
setAgentStatus(status: 'available' | 'offline' | 'break'): Promise<void>;
|
|
73
|
+
on<K extends keyof CCBarEvents>(event: K, handler: (payload: CCBarEvents[K]) => void): () => void;
|
|
74
|
+
off<K extends keyof CCBarEvents>(event: K, handler: (payload: CCBarEvents[K]) => void): void;
|
|
75
|
+
private performConnect;
|
|
76
|
+
private performDisconnect;
|
|
77
|
+
private createCallManager;
|
|
78
|
+
private rollbackConnect;
|
|
79
|
+
private performDispose;
|
|
80
|
+
private awaitMediaReleaseBarriers;
|
|
81
|
+
private detachSipListener;
|
|
82
|
+
private detachManagerListeners;
|
|
83
|
+
private bindManagerEvents;
|
|
84
|
+
private handleCallCreated;
|
|
85
|
+
private handleCallStateChanged;
|
|
86
|
+
private handleCallTerminal;
|
|
87
|
+
private startTerminalRelease;
|
|
88
|
+
private startDeferredRecovery;
|
|
89
|
+
private refreshAndRebuild;
|
|
90
|
+
private performRefreshAndRebuild;
|
|
91
|
+
private handleRefreshFailure;
|
|
92
|
+
private scheduleRefresh;
|
|
93
|
+
private recoverConnection;
|
|
94
|
+
private getSip;
|
|
95
|
+
private attachSipListener;
|
|
96
|
+
private attachNetworkListeners;
|
|
97
|
+
private detachNetworkListeners;
|
|
98
|
+
private getActiveMediaContext;
|
|
99
|
+
private hasNonTerminalCalls;
|
|
100
|
+
private clearRefreshTimer;
|
|
101
|
+
private createDiagnosticsSnapshot;
|
|
102
|
+
private getDiagnosticsResourceCounts;
|
|
103
|
+
private readMicrophonePermission;
|
|
104
|
+
private deleteSession;
|
|
105
|
+
private deleteOwnedSessions;
|
|
106
|
+
private resolvePlatform;
|
|
107
|
+
private setConnectionState;
|
|
108
|
+
private assertConnected;
|
|
109
|
+
private assertGeneration;
|
|
110
|
+
private isCurrentGeneration;
|
|
111
|
+
private assertNotDisposed;
|
|
112
|
+
private disposedError;
|
|
113
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { CallDestinationType, CallTransport, CallTransportSession, MediaConstraints, WebPhoneSession } from '../api/contracts.js';
|
|
2
|
+
import { CCBarEvents } from '../types.js';
|
|
3
|
+
import { CCBarCall, CallPlatform, RejectOptions } from './CCBarCall.js';
|
|
4
|
+
export interface DialOptions {
|
|
5
|
+
readonly destination: string;
|
|
6
|
+
readonly type?: CallDestinationType;
|
|
7
|
+
}
|
|
8
|
+
export type CallManagerEvents = Pick<CCBarEvents, 'call.created' | 'call.incoming' | 'call.stateChanged' | 'call.activeChanged' | 'call.ownershipChanged' | 'call.ended' | 'call.failed' | 'error'>;
|
|
9
|
+
type IncomingCallTransport = CallTransport & {
|
|
10
|
+
onIncoming(handler: (session: CallTransportSession) => void): () => void;
|
|
11
|
+
};
|
|
12
|
+
export interface CallManagerOptions {
|
|
13
|
+
readonly sip: IncomingCallTransport;
|
|
14
|
+
readonly platform: CallPlatform;
|
|
15
|
+
readonly session?: WebPhoneSession;
|
|
16
|
+
readonly maxConcurrentCalls?: number;
|
|
17
|
+
readonly autoHoldPreviousCall?: boolean;
|
|
18
|
+
/** @internal Client lifecycle hook for production media ownership. */
|
|
19
|
+
readonly onCallCreated?: (callId: string, session: CallTransportSession) => void;
|
|
20
|
+
/** @internal Called whenever a call state changes so adapters can become ready. */
|
|
21
|
+
readonly onCallStateChanged?: (callId: string, session: CallTransportSession) => void;
|
|
22
|
+
/** @internal Called exactly once for each call terminal/dispose path. */
|
|
23
|
+
readonly onCallTerminal?: (callId: string) => void | Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
export declare class CallManager {
|
|
26
|
+
private readonly events;
|
|
27
|
+
private readonly calls;
|
|
28
|
+
private readonly options;
|
|
29
|
+
private readonly incomingUnsubscribe;
|
|
30
|
+
private activeCallId;
|
|
31
|
+
private incomingSessionSnapshot?;
|
|
32
|
+
private readonly callSessions;
|
|
33
|
+
private readonly callOwners;
|
|
34
|
+
private readonly ownerLostCalls;
|
|
35
|
+
private pendingDialCount;
|
|
36
|
+
private readonly pendingDestinations;
|
|
37
|
+
private activeOperationPromise;
|
|
38
|
+
private operationGeneration;
|
|
39
|
+
private automaticActiveTransition?;
|
|
40
|
+
private disposed;
|
|
41
|
+
private readonly terminalNotified;
|
|
42
|
+
private readonly terminalOperations;
|
|
43
|
+
private disposeOperation?;
|
|
44
|
+
constructor(options: CallManagerOptions);
|
|
45
|
+
on<K extends keyof CallManagerEvents>(event: K, handler: (payload: CallManagerEvents[K]) => void): () => void;
|
|
46
|
+
dial(options: DialOptions, session: WebPhoneSession): Promise<CCBarCall>;
|
|
47
|
+
answer(callId: string, session: WebPhoneSession, mediaConstraints?: MediaConstraints, tabId?: string): Promise<void>;
|
|
48
|
+
reject(callId: string, options?: RejectOptions, tabId?: string): Promise<void>;
|
|
49
|
+
getCalls(): readonly CCBarCall[];
|
|
50
|
+
hasNonTerminalCalls(): boolean;
|
|
51
|
+
/** @internal Diagnostics exposes counts only; call transports remain private. */
|
|
52
|
+
getResourceCounts(): {
|
|
53
|
+
readonly timers: number;
|
|
54
|
+
readonly listeners: number;
|
|
55
|
+
};
|
|
56
|
+
getActiveCall(): CCBarCall | undefined;
|
|
57
|
+
setActiveCall(callId: string, tabId?: string): Promise<void>;
|
|
58
|
+
claimCall(callId: string, tabId: string): Promise<void>;
|
|
59
|
+
releaseCall(callId: string, tabId: string): Promise<void>;
|
|
60
|
+
getCallOwner(callId: string): string | undefined;
|
|
61
|
+
/** @internal Called when a SharedWorker MessagePort is detached. */
|
|
62
|
+
releaseOwnedCalls(tabId: string): void;
|
|
63
|
+
dispose(options?: {
|
|
64
|
+
readonly terminateCalls?: boolean;
|
|
65
|
+
}): Promise<void>;
|
|
66
|
+
updateSession(session: WebPhoneSession): void;
|
|
67
|
+
private switchActiveCall;
|
|
68
|
+
private handleStateChanged;
|
|
69
|
+
private switchAutomaticActiveCall;
|
|
70
|
+
private restoreAutomaticActiveCall;
|
|
71
|
+
private handleDisposed;
|
|
72
|
+
private commitActive;
|
|
73
|
+
private handleIncoming;
|
|
74
|
+
private terminateUnsupportedIncoming;
|
|
75
|
+
private holdActiveCallForNewCall;
|
|
76
|
+
private enqueueActiveOperation;
|
|
77
|
+
private isManagedCall;
|
|
78
|
+
private isCurrentGeneration;
|
|
79
|
+
private assertGeneration;
|
|
80
|
+
private effectiveCapabilities;
|
|
81
|
+
private requireCapability;
|
|
82
|
+
private requireCall;
|
|
83
|
+
private emitOwnershipChanged;
|
|
84
|
+
private notifyCallTerminal;
|
|
85
|
+
private assertNotDisposed;
|
|
86
|
+
private callOperationError;
|
|
87
|
+
private capabilityError;
|
|
88
|
+
private compensationError;
|
|
89
|
+
private callLimit;
|
|
90
|
+
private dialOptions;
|
|
91
|
+
private dialError;
|
|
92
|
+
}
|
|
93
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function createCallId(): string;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { CallState, MediaManager as PublicMediaManager } from '../types.js';
|
|
2
|
+
import { DiagnosticsResourceCounts } from '../diagnostics/Diagnostics.js';
|
|
3
|
+
export interface ClientMediaBridge {
|
|
4
|
+
readonly publicMedia: PublicMediaManager;
|
|
5
|
+
registerCall(callId: string, session: unknown): void;
|
|
6
|
+
setCallOwnership(callId: string, state: 'owned' | 'released' | 'owner-lost'): Promise<void>;
|
|
7
|
+
contextFor(callId: string, state: CallState, capabilities?: ReadonlySet<string>): unknown;
|
|
8
|
+
releaseCall(callId: string): Promise<void>;
|
|
9
|
+
releaseAll(): Promise<void>;
|
|
10
|
+
dispose(): Promise<void>;
|
|
11
|
+
getResourceCounts(): Pick<DiagnosticsResourceCounts, 'listeners' | 'tracks' | 'peerConnections' | 'audioElements'>;
|
|
12
|
+
}
|
|
13
|
+
export interface ClientMediaBridgeOptions {
|
|
14
|
+
/** @internal SharedWorker mode delays native media binding until this tab owns the call. */
|
|
15
|
+
readonly ownershipRequired?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare function createClientMediaBridge(getActiveContext: () => unknown, options?: ClientMediaBridgeOptions): ClientMediaBridge;
|