@16x/webphone-sdk 3.1.18 → 3.1.19
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 +267 -40
- package/LICENSE +1 -1
- package/README.md +214 -161
- package/dist/{Diagnostics-DhX9Uc67.cjs → Diagnostics-CgDSPlQx.cjs} +1 -1
- package/dist/{Diagnostics-qnipur6s.js → Diagnostics-DJdBDGad.js} +1 -1
- package/dist/{JsSipAdapter-l97xq1ao.cjs → JsSipAdapter-CgBtmR16.cjs} +1 -1
- package/dist/{JsSipAdapter-B8ueIoBA.js → JsSipAdapter-CiqM4KOq.js} +1 -1
- package/dist/SharedWorkerProtocol-4VARy5ma.cjs +1 -0
- package/dist/SharedWorkerProtocol-DvLUl0JZ.js +93 -0
- package/dist/core/CCBarCall.d.ts +1 -1
- package/dist/createJsSipFactory-9CPsweDR.js +9665 -0
- package/dist/createJsSipFactory-Dr8HbLl-.cjs +75 -0
- package/dist/crypto/legacySipTicket.d.ts +40 -0
- package/dist/diagnostics/index.cjs +1 -1
- package/dist/diagnostics/index.js +1 -1
- package/dist/errors/CCBarError.d.ts +2 -0
- package/dist/i18n/index.d.ts +22 -0
- package/dist/i18n/messages/en-US.d.ts +2 -0
- package/dist/i18n/messages/es-ES.d.ts +2 -0
- package/dist/i18n/messages/id-ID.d.ts +2 -0
- package/dist/i18n/messages/index.d.ts +7 -0
- package/dist/i18n/messages/zh-CN.d.ts +2 -0
- package/dist/i18n/types.d.ts +5 -0
- package/dist/i18n-BbEy6K9z.cjs +1 -0
- package/dist/i18n-D-DdHtGz.js +150 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +9 -8
- package/dist/index.umd.js +69 -16
- package/dist/legacy/index.cjs +1 -1
- package/dist/legacy/index.js +10 -276
- package/dist/legacy/legacySessionProvider.d.ts +20 -9
- package/dist/legacySessionProvider-CKJyrade.cjs +1 -0
- package/dist/{CCBarClient-5z2ZCceq.js → legacySessionProvider-DBrRBB3S.js} +778 -501
- package/dist/shared/SharedWorkerFactory.d.ts +2 -0
- package/dist/shared/SharedWorkerProtocol.d.ts +2 -0
- package/dist/shared-worker.cjs +1 -1
- package/dist/shared-worker.js +65 -64
- package/dist/styles.css +7 -7
- package/dist/ui/i18n/es-ES.d.ts +2 -0
- package/dist/ui/i18n/id-ID.d.ts +2 -0
- package/dist/ui/i18n/index.d.ts +2 -0
- package/dist/ui/index.cjs +1 -1
- package/dist/ui/index.js +278 -170
- package/dist/version.d.ts +1 -1
- package/package.json +114 -109
- package/dist/CCBarClient-UAJK9WcJ.cjs +0 -1
- package/dist/SharedWorkerProtocol-C-4KpECM.cjs +0 -1
- package/dist/SharedWorkerProtocol-CffZrUXg.js +0 -119
- package/dist/createJsSipFactory-B1ORbJiP.cjs +0 -22
- package/dist/createJsSipFactory-CoWZN-BC.js +0 -7410
package/README.md
CHANGED
|
@@ -1,161 +1,214 @@
|
|
|
1
|
-
# CCBar WebPhone SDK
|
|
2
|
-
|
|
3
|
-
`@16x/webphone-sdk`
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
```
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
1.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
await
|
|
59
|
-
await
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
client.on(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
console.
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
client.on('
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
1
|
+
# CCBar WebPhone SDK
|
|
2
|
+
|
|
3
|
+
`@16x/webphone-sdk` 是浏览器端 WebPhone SDK。客户只需提供服务端取票接口,并在前端配置 `createTokenSessionProvider`。SDK 会在内部获取坐席账号、创建会话、登录 SIP、刷新凭证并请求坐席状态。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @16x/webphone-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
公开包地址:[npmjs](https://www.npmjs.com/package/@16x/webphone-sdk)。
|
|
12
|
+
|
|
13
|
+
## 最简接入
|
|
14
|
+
|
|
15
|
+
### 1. 服务端实现取票接口
|
|
16
|
+
|
|
17
|
+
浏览器通过客户自己的 `POST /get-token` 接口取短期 fs token。服务端从已登录用户的会话中取得分机号,使用服务端环境变量中的 APP Key 和 security(APP Secret)签名调用 `POST /openapi/v1/token/fs`,然后返回上游的 token 和 expires。不要接受浏览器提交的 APP Key、security 或任意分机号。
|
|
18
|
+
|
|
19
|
+
取票请求与签名示例见[会话服务指南](docs/guides/session-service.md)。
|
|
20
|
+
|
|
21
|
+
### 2. 创建客户端并连接
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { CCBarClient, createTokenSessionProvider } from '@16x/webphone-sdk';
|
|
25
|
+
|
|
26
|
+
const client = new CCBarClient({
|
|
27
|
+
platform: 'web',
|
|
28
|
+
sessionProvider: createTokenSessionProvider({
|
|
29
|
+
// 请向商务经理或对接人获取 HTTP API 网关地址
|
|
30
|
+
host: 'https://api.example.com',
|
|
31
|
+
// 请向商务经理或对接人获取完整的 SIP WebSocket 地址
|
|
32
|
+
sipWsUrl: 'wss://sip.example.com/api/fs/sip-ws',
|
|
33
|
+
// 这是客户需要实现的唯一服务端方法
|
|
34
|
+
getToken: async () => {
|
|
35
|
+
const response = await fetch('/get-token', {
|
|
36
|
+
method: 'POST',
|
|
37
|
+
credentials: 'include',
|
|
38
|
+
});
|
|
39
|
+
if (!response.ok) throw new Error('获取 token 失败');
|
|
40
|
+
return response.json();
|
|
41
|
+
},
|
|
42
|
+
}),
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
await client.initialize();
|
|
46
|
+
await client.connect();
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
`host` 用于 SDK 内部请求坐席账号和状态接口;`sipWsUrl` 是完整的 SIP WebSocket 地址。get-token 应返回 `{ token, expires }`(或上游 token 响应)。
|
|
50
|
+
|
|
51
|
+
请向商务经理或对接人获取 HTTP API 网关地址 `host` 和完整的 SIP WebSocket 地址 `sipWsUrl`。`host` 用于坐席账号/状态接口;`sipWsUrl` 应包含 `wss://` 协议和服务端提供的路径。另请获取 APP Key、security(仅供客户服务端实现 `getToken`,不要放进浏览器代码)以及话单查询/推送接口资料;话单由客户业务系统另行集成,SDK 不提供查询或推送能力。
|
|
52
|
+
|
|
53
|
+
### 3. 拨打、控制和挂断
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
const call = await client.dial({ destination: '9196' });
|
|
57
|
+
await call.mute();
|
|
58
|
+
await call.unmute();
|
|
59
|
+
await call.hold();
|
|
60
|
+
await call.resume();
|
|
61
|
+
await call.hangup();
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### 4. 传递 userData 并关联话单
|
|
65
|
+
|
|
66
|
+
拨打时可以通过 `userdata` 传递业务关联信息。SDK 会把它放进 SIP `INVITE` 请求的 `X-User-Data` header,供平台侧读取:
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
const userdata = encodeURIComponent(JSON.stringify({
|
|
70
|
+
orderId: 'ORDER-20261003-001',
|
|
71
|
+
source: 'crm',
|
|
72
|
+
}));
|
|
73
|
+
|
|
74
|
+
const call = await client.dial({
|
|
75
|
+
destination: '9196',
|
|
76
|
+
userdata,
|
|
77
|
+
});
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
`userdata` 必须是字符串;未传、空字符串或纯空白不会发送该 header。值只支持可见 ASCII,不能包含换行、制表符或未编码的中文;传入不合规内容会以 `CALL_INVALID_USERDATA` 拒绝拨打。像上例一样先对 JSON 做 `encodeURIComponent()`,平台侧收到 `X-User-Data` 后再 `decodeURIComponent()` 和解析即可。不要放入密码、token 等敏感信息,因为 SIP header 可能经过或记录在平台网络设备中。
|
|
81
|
+
|
|
82
|
+
SDK 负责把 `userdata` 透传到 SIP 请求。若要让它出现在话单推送或话单查询结果中,平台服务端还需要读取 `X-User-Data`,将其解析并保存到话单字段;请与平台侧确认字段映射和推送、查询接口是否都返回该字段。SDK 不会直接写入或查询话单。
|
|
83
|
+
|
|
84
|
+
### 5. 查看连接状态、坐席状态和拨打结果
|
|
85
|
+
|
|
86
|
+
通过 `client.on()` 监听连接状态。连接注册成功和连接状态是不同事件:
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
const offConnection = client.on('connection.stateChanged', ({ state }) => {
|
|
90
|
+
// offline | connecting | connected | reconnecting | failed
|
|
91
|
+
console.log('SIP connection:', state);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
const offRegistered = client.on('connection.registered', () => {
|
|
95
|
+
console.log('SIP registered');
|
|
96
|
+
});
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
调用 `setAgentStatus()` 修改坐席状态;`agent.statusChanged` 在状态接口成功后发出:
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
const offAgentStatus = client.on('agent.statusChanged', ({ status }) => {
|
|
103
|
+
console.log('Agent status:', status); // available | break | offline
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
await client.setAgentStatus('available');
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
坐席状态表示坐席在业务平台上的工作状态,不表示 SIP WebSocket 是否已连接,也不表示当前通话状态:
|
|
110
|
+
|
|
111
|
+
| 坐席状态 | 含义 |
|
|
112
|
+
|---|---|
|
|
113
|
+
| `available` | 坐席空闲/就绪;是否能接听新呼叫仍由平台的队列和路由策略决定。 |
|
|
114
|
+
| `break` | 坐席暂时休息或暂停接听,平台侧对应 `On Break`。 |
|
|
115
|
+
| `offline` | 坐席在业务平台登出,平台侧对应 `Logged Out`。它本身不关闭 SIP 连接;如需断开连接,还要调用 `client.disconnect()`。 |
|
|
116
|
+
|
|
117
|
+
因此,`client.setAgentStatus('offline')` 和 `client.disconnect()` 是两个独立操作:前者更新平台坐席状态,后者断开 SDK 的 SIP 连接。反过来,连接掉线也不一定会自动把坐席状态改为 `offline`。
|
|
118
|
+
|
|
119
|
+
`client.dial()` 成功返回 Call 对象不代表通话已接通。监听 `call.stateChanged` 并检查 `to` 是否为 `active`;结束或失败分别通过 `call.ended`、`call.failed` 通知:
|
|
120
|
+
|
|
121
|
+
```ts
|
|
122
|
+
const offCallState = client.on('call.stateChanged', ({ callId, from, to }) => {
|
|
123
|
+
console.log(`Call ${callId}: ${from} -> ${to}`);
|
|
124
|
+
// new | dialing | ringing | connecting | active | held | ended | failed
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
const offCallEnded = client.on('call.ended', ({ callId, reason }) => {
|
|
128
|
+
console.log('Call ended:', callId, reason);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
const offCallFailed = client.on('call.failed', ({ callId, error }) => {
|
|
132
|
+
showCallError(error.code);
|
|
133
|
+
});
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
拨号发起阶段的错误会让 `dial()` 拒绝;接通后的通话错误通过 `call.failed` 事件报告。npm SDK 与 CCBar Script 使用相同的字符串 `code` 和可读 `message`。若后端返回数字错误码,SDK 将其保留在可选的 `platformCode` 中:
|
|
137
|
+
|
|
138
|
+
```ts
|
|
139
|
+
import { CCBarError } from '@16x/webphone-sdk';
|
|
140
|
+
|
|
141
|
+
try {
|
|
142
|
+
await client.dial({ destination: '9196' });
|
|
143
|
+
} catch (error) {
|
|
144
|
+
if (error instanceof CCBarError) {
|
|
145
|
+
showCallError(error.message);
|
|
146
|
+
reportSafeError({ code: error.code, platformCode: error.platformCode });
|
|
147
|
+
} else {
|
|
148
|
+
showCallError('拨号失败,请稍后重试。');
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
客户代码应使用 `error.code` 做程序判断、将 `error.message` 显示给用户;`platformCode` 仅用于排查后端响应,不应作为 SDK 业务分支的依据。错误码清单和处理建议见 [错误码说明](./docs/customer/webphone/05-error-codes.md)。
|
|
154
|
+
|
|
155
|
+
通话状态含义如下。`ended` 和 `failed` 都是终态;一个 Call 到达终态后不会再恢复到其他状态。
|
|
156
|
+
|
|
157
|
+
| 状态 | 含义 |
|
|
158
|
+
|---|---|
|
|
159
|
+
| `new` | SDK 已创建 Call 对象,呼叫尚未开始处理;通常是很短暂的初始状态。 |
|
|
160
|
+
| `dialing` | SDK 已发起呼叫,正在等待对端响应。 |
|
|
161
|
+
| `ringing` | 对端正在振铃,或呼叫流程已进入振铃/早期进展阶段。 |
|
|
162
|
+
| `connecting` | 呼叫已应答,正在完成媒体协商或建立音频连接;此时还不能当作通话已接通。 |
|
|
163
|
+
| `active` | 通话已接通,可以进行通话控制。 |
|
|
164
|
+
| `held` | 通话已保持;调用 `call.resume()` 可恢复到 `active`。 |
|
|
165
|
+
| `ended` | 通话已正常结束、被挂断或被拒接。 |
|
|
166
|
+
| `failed` | 呼叫建立或通话过程中发生失败;查看 `call.failed` 事件中的错误码。 |
|
|
167
|
+
|
|
168
|
+
`client.on()` 返回取消监听函数。页面或组件卸载时调用对应的 `off...()`,或在客户端销毁时统一清理监听器。
|
|
169
|
+
|
|
170
|
+
## 网络和安全要求
|
|
171
|
+
|
|
172
|
+
- 页面须运行在 HTTPS 或 localhost,并取得浏览器麦克风权限。
|
|
173
|
+
- 网关须允许页面的 Origin 和客户出口 IP 调用坐席账号与状态接口;这两项与客户自己的 get-token 接口是分开的,请在上线前确认 CORS 和 IP 白名单。
|
|
174
|
+
- APP Key 和 security 只保存在服务端。浏览器运行时会持有短期 fs token 和 SIP 凭证;不要记录含 token 的 WSS URL、Authorization 请求头或 SIP 密码。
|
|
175
|
+
- 按客户系统的登录态调用 get-token,避免浏览器自行指定分机号。
|
|
176
|
+
|
|
177
|
+
## 连接生命周期
|
|
178
|
+
|
|
179
|
+
建议在系统账号登录成功或进入拨打列表页时调用 `client.connect()`。退出账号或离开拨打列表页时,按需先调用 `client.setAgentStatus('offline')`,再调用 `client.disconnect()`。客户端实例不再使用时调用 `client.dispose()` 释放监听器、定时器、连接和媒体资源。重复调用正在连接或已连接的 `connect()` 会复用当前连接。
|
|
180
|
+
|
|
181
|
+
## 常用 API
|
|
182
|
+
|
|
183
|
+
- `client.initialize()`、`client.connect()`、`client.disconnect()`、`client.dispose()`
|
|
184
|
+
- `client.dial({ destination, userdata? })`
|
|
185
|
+
- `client.setAgentStatus('available' | 'break' | 'offline')`
|
|
186
|
+
- `call.mute()`、`call.unmute()`、`call.hold()`、`call.resume()`、`call.hangup()`
|
|
187
|
+
- `client.on(event, handler)`、`client.getDiagnostics()`
|
|
188
|
+
|
|
189
|
+
详细 API 和完整事件说明见[客户端 API 文档](docs/api/client.md);服务端取票签名示例见[会话服务指南](docs/guides/session-service.md)。
|
|
190
|
+
|
|
191
|
+
## 开发与验证
|
|
192
|
+
|
|
193
|
+
```bash
|
|
194
|
+
npm run lint
|
|
195
|
+
npm run typecheck
|
|
196
|
+
npm test
|
|
197
|
+
npm run pack:check
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## License
|
|
201
|
+
|
|
202
|
+
Copyright 16X. All rights reserved.
|
|
203
|
+
|
|
204
|
+
Private customer distribution only. No redistribution or sublicensing without written permission.
|
|
205
|
+
|
|
206
|
+
## Live acceptance (maintainers)
|
|
207
|
+
|
|
208
|
+
Real-call acceptance is opt-in and runs outside `npm test`. Copy `scripts/live-call-acceptance.env.example` to a local `.env` file, fill it with a dedicated test account, and start a Chromium-based browser with remote debugging enabled at `CCBAR_LIVE_CDP_URL`. The runner requests microphone permission through CDP and uses only routes 9196 and 9199.
|
|
209
|
+
|
|
210
|
+
```sh
|
|
211
|
+
npm run test:live
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
The runner verifies token signing, account lookup, SIP registration, seat status, repeated `connect()`, disconnect/reconnect, call controls, credential failures, delayed/lost HTTP requests, browser network loss, and malformed/unreachable STUN behavior. Repeated-connect assertions compare SDK token, account, session, connect, and registration-event counts; they do not claim server-side REGISTER packet counts. It measures dial-to-active time against `CC_DIAL_ACTIVE_SLO_MS`; each sample must meet the threshold. JSON output contains scenario, stage, status codes, elapsed times, and SDK resource counts; it omits credentials, tokens, raw errors, and WebSocket URLs. Live tests require the gateway Origin/IP allowlists, browser microphone permission, reachable WSS, and both test routes.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require("./redact-Bq26pObO.cjs");var t=`3.1.
|
|
1
|
+
const e=require("./redact-Bq26pObO.cjs");var t=`3.1.19`,n=class{capacity;entries=[];constructor(e){if(this.capacity=e,!Number.isInteger(e)||e<=0)throw RangeError(`RingBuffer capacity must be a positive integer`)}push(e){this.entries.length===this.capacity&&this.entries.shift(),this.entries.push(e)}toArray(){return[...this.entries]}},r=`@16x/webphone-sdk`,i=200,a=class{dependencies;logs=new n(i);now;constructor(e){this.dependencies=e,this.now=e.now??(()=>new Date)}log(t,n,r){this.logs.push({timestamp:this.now().toISOString(),level:t,message:e.t(n),...r===void 0?{}:{context:e.n(r)}})}async getReport(n={}){let i=n.includeRecentLogs!==!1,a=n.includeDeviceNames===!0,u=n.maskPhoneNumbers!==!1,d=this.dependencies.getSnapshot(),f=this.dependencies.getPermission===void 0?d.permission:await o(this.dependencies.getPermission,d.permission),p=a?await s(this.dependencies.getDeviceNames):void 0,m=l(c(this.dependencies.getUserAgent)),h={generatedAt:this.now().toISOString(),sdk:{name:r,version:t},browser:m.browser,os:m.os,...d,permission:f,recentLogs:i?this.logs.toArray():[],...p===void 0?{}:{deviceNames:p}};return e.n(h,{maskPhoneNumbers:u})}};async function o(e,t){try{return await e()}catch{return t}}async function s(e){if(e===void 0)return[];try{return[...await e()]}catch{return[]}}function c(e){if(e!==void 0)try{return e()}catch{return``}return typeof navigator>`u`?``:navigator.userAgent}function l(e){return{browser:u(e),os:d(e)}}function u(e){for(let[t,n]of[[`Edge`,/Edg\/([\d.]+)/],[`Chrome`,/(?:Chrome|CriOS)\/([\d.]+)/],[`Firefox`,/(?:Firefox|FxiOS)\/([\d.]+)/],[`Safari`,/Version\/([\d.]+).*Safari/]]){let r=e.match(n);if(r?.[1]!==void 0)return{name:t,version:r[1]}}return{name:`unknown`,version:``}}function d(e){let t=e.match(/(?:iPhone|iPad).*OS ([\d_]+)/);if(t?.[1]!==void 0)return{name:`iOS`,version:t[1].replaceAll(`_`,`.`)};let n=e.match(/Android ([\d.]+)/);if(n?.[1]!==void 0)return{name:`Android`,version:n[1]};let r=e.match(/Windows NT ([\d.]+)/);if(r?.[1]!==void 0)return{name:`Windows`,version:r[1]};let i=e.match(/Mac OS X ([\d_]+)/);return i?.[1]===void 0?/Linux/.test(e)?{name:`Linux`,version:``}:{name:`unknown`,version:``}:{name:`macOS`,version:i[1].replaceAll(`_`,`.`)}}Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return a}});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require("./SharedWorkerProtocol-C-4KpECM.cjs");require("./createJsSipFactory-B1ORbJiP.cjs");function t(e){let t=new Map;return{peerConnection:{getSenders:()=>e.getSenders().map(n=>{let r=t.get(n);if(r!==void 0)return r;let i={get track(){return n.track},get senderKind(){let t=n.track;if(t!==null)return t.kind===`audio`||t.kind===`video`?t.kind:void 0;let r=e.getTransceivers().find(e=>e.sender===n)?.receiver.track;if(r?.kind===`audio`||r?.kind===`video`)return r.kind;let i=n.getParameters().codecs?.find(e=>typeof e.mimeType==`string`);if(i?.mimeType?.toLowerCase().startsWith(`video/`))return`video`;if(i?.mimeType?.toLowerCase().startsWith(`audio/`))return`audio`},replaceTrack:e=>n.replaceTrack(e)};return t.set(n,i),i}),close:()=>{e.connectionState!==`closed`&&e.close()}},trackSource:{onTrack(t){let n=e=>{let n=e.track;t({streams:[...e.streams],track:n})};return e.addEventListener(`track`,n),()=>e.removeEventListener(`track`,n)}}}}var n=2e3,r=[5e3,15e3,6e4];function i(){return{runs:0,lastMs:null,udpOk:!1,tcpRelayOk:!1,convergedServers:null,unchanged:null,status:`idle`,lastProbeAt:null,cacheAgeMs:null,unknownCount:0,unavailableCount:0,dialMode:`original`}}function a(e){if(!e)return``;let t=String(e.type??``);return t===``?/ typ (\w+)/.exec(String(e.candidate??``))?.[1]??``:t}function o(e){return/^turns:/i.test(e)?`tls`:/transport=tcp/i.test(e)?`tcp`:`udp`}function s(e,t){let n=t.flatMap(e=>(Array.isArray(e.urls)?e.urls:[e.urls]).map(t=>[String(t),e])),r=new Map(n),i=[];for(let t of e){let e=Array.isArray(t.urls)?t.urls:[t.urls];for(let t of e){let e=r.get(String(t));e&&i.push({...e,urls:[t]})}}return i}function c(e,t={}){let r=Number.isFinite(t.timeoutMs)&&t.timeoutMs>0?t.timeoutMs:n;if(!Array.isArray(e))return Promise.resolve([]);let i=[];for(let t of e){if(!t)continue;let e=Array.isArray(t.urls)?t.urls:[t.urls];for(let n of e){let e=String(n??``).trim();/^(stun|turn|turns):/i.test(e)&&i.push({url:e,entry:t})}}return Promise.all(i.map(e=>new Promise(t=>{let n=!1,i=!1,s,c=o(e.url),l=(r,i)=>{if(!n){n=!0,clearTimeout(u);try{s?.close()}catch{}t({url:e.url,status:r,transport:c,reason:i})}},u=setTimeout(()=>l(i?`unavailable`:`unknown`,i?`server-error`:`timeout`),r);try{if(typeof RTCPeerConnection>`u`){l(`unknown`,`local-error`);return}let t={urls:[e.url]};e.entry.username&&(t.username=e.entry.username),e.entry.credential&&(t.credential=e.entry.credential),s=new RTCPeerConnection({iceServers:[t]}),s.createDataChannel(`webphone-ice-probe`),s.onicecandidate=e=>{if(!e||!e.candidate)return;let t=a(e.candidate);(t===`srflx`||t===`relay`)&&l(`available`,`candidate`)},s.onicecandidateerror=t=>{t?.url&&t.url===e.url&&(i=!0)},s.createOffer().then(e=>s?.setLocalDescription(e)).catch(()=>l(`unknown`,`local-error`))}catch{l(`unknown`,`local-error`)}})))}function l(e,t){let n=new Map;for(let e of t)e&&e.url&&n.set(String(e.url),e.status===`available`);let r=[];for(let t of e??[]){if(!t)continue;let e=(Array.isArray(t.urls)?t.urls:[t.urls]).filter(Boolean).filter(e=>n.get(String(e))===!0);if(e.length===0)continue;let i={...t,urls:e};r.push(i)}return r}var u=class{availableList;lastGoodList;lastGoodAt;lastResults=[];snapshotState=i();running=!1;seq=0;consecutiveFailures=0;lastAttemptAt;retryTimer;pendingRequest;serversForDial(e,t=Date.now()){if(!e)return;if(!this.lastResults.length)return this.setDialMode(`original`),e;let n=this.lastGoodAt===void 0?null:Math.max(0,t-this.lastGoodAt);this.snapshotState={...this.snapshotState,cacheAgeMs:n};let r=n!==null&&n>3e5,i=this.snapshotState.lastProbeAt===null?null:Math.max(0,t-this.snapshotState.lastProbeAt);if(r||i!==null&&i>3e5)return this.snapshotState={...this.snapshotState,status:`stale`,cacheAgeMs:n??i},this.assess(e,`ttl-expired`),this.availableList&&this.availableList.length>0?(this.setDialMode(`original`),e):(this.setDialMode(`host-only`),[]);if(!r&&this.availableList&&this.availableList.length>0)return this.setDialMode(`known-available`),this.availableList.map(e=>({...e,urls:Array.isArray(e.urls)?[...e.urls]:e.urls}));if(this.lastGoodList&&n!==null&&n<=3e5){let t=s(this.lastGoodList,e);if(t.length>0)return this.setDialMode(`last-known-good`),t}return this.setDialMode(`host-only`),[]}snapshot(){return this.snapshotState}reset(){this.retryTimer!==void 0&&clearTimeout(this.retryTimer),this.retryTimer=void 0,this.pendingRequest=void 0,this.seq++,this.running=!1,this.availableList=void 0,this.lastGoodList=void 0,this.lastGoodAt=void 0,this.lastResults=[],this.consecutiveFailures=0,this.lastAttemptAt=void 0,this.snapshotState=i()}cancelInFlight(){this.seq++,this.running=!1,this.retryTimer!==void 0&&clearTimeout(this.retryTimer),this.retryTimer=void 0,this.pendingRequest=void 0}assess(e,t=`initial-registration`){if(e===void 0)return;if(e.length===0){this.reset();return}if(this.running){t!==`initial-registration`&&(this.pendingRequest={servers:e,trigger:t});return}let n=Date.now();if(t!==`initial-registration`&&this.consecutiveFailures>0&&this.lastAttemptAt!==void 0){let i=r[Math.min(this.consecutiveFailures-1,r.length-1)]-(n-this.lastAttemptAt);if(i>0){this.pendingRequest={servers:e,trigger:t},this.retryTimer===void 0&&(this.retryTimer=setTimeout(()=>{this.retryTimer=void 0;let e=this.pendingRequest;this.pendingRequest=void 0,e&&this.assess(e.servers,e.trigger)},i));return}}let i=e.map(e=>({...e,urls:Array.isArray(e.urls)?[...e.urls]:[e.urls]}));if(!i.some(e=>(Array.isArray(e.urls)?e.urls:[e.urls]).some(e=>/^(stun|turn|turns):/i.test(String(e??``)))))return;let a=++this.seq;this.running=!0,this.lastAttemptAt=n,this.availableList=void 0,this.snapshotState={...this.snapshotState,status:t===`ttl-expired`?`stale`:`probing`};let o=Date.now();c(i).then(e=>{if(a!==this.seq)return;this.lastResults=e;let t=i,n=l(t,e);this.availableList=n.length>0?n:void 0,this.availableList&&(this.lastGoodList=n.map(e=>({...e,urls:Array.isArray(e.urls)?[...e.urls]:e.urls})),this.lastGoodAt=Date.now());let s=e.filter(e=>e.status===`unknown`).length,c=e.filter(e=>e.status===`unavailable`).length;this.consecutiveFailures=n.length===0?this.consecutiveFailures+1:0,n.length===0&&this.consecutiveFailures<=r.length&&this.pendingRequest===void 0&&(this.pendingRequest={servers:i,trigger:`retry-backoff`}),this.snapshotState={runs:this.snapshotState.runs+1,lastMs:Date.now()-o,udpOk:e.some(e=>e.status===`available`&&e.transport===`udp`),tcpRelayOk:e.some(e=>e.status===`available`&&(e.transport===`tcp`||e.transport===`tls`)),convergedServers:n.length,unchanged:JSON.stringify(n)===JSON.stringify(t),status:s+c>0?`degraded`:`healthy`,lastProbeAt:Date.now(),cacheAgeMs:0,unknownCount:s,unavailableCount:c,dialMode:n.length>0?`known-available`:`host-only`}}).catch(()=>{this.seq}).finally(()=>{if(a!==this.seq)return;this.running=!1;let e=this.pendingRequest;this.pendingRequest=void 0,e&&this.assess(e.servers,e.trigger)})}isRunning(){return this.running}setDialMode(e){let t=this.snapshotState.status;this.snapshotState={...this.snapshotState,dialMode:e,status:t===`healthy`&&e===`host-only`?`stale`:t}}},d=3e3;function f(e){if(!e)return``;let t=String(e.type??``);return t===``?/ typ (\w+)/.exec(String(e.candidate??``))?.[1]??``:t}function p(e,t={}){if(typeof e.on!=`function`)return()=>void 0;let n=Number.isFinite(t.timeoutMs)&&t.timeoutMs>0?t.timeoutMs:d,r=!1,i,a=()=>{if(!r){r=!0,clearTimeout(s);try{i?.()}catch{}}},o=e=>{let t=e;if(!t||typeof t.ready!=`function`)return;i=t.ready;let n=f(t.candidate);(n===`srflx`||n===`relay`)&&a()};e.on(`icecandidate`,o);let s=setTimeout(a,n);return()=>{clearTimeout(s);try{e.off?.(`icecandidate`,o)}catch{}}}var m=300,h=25,g=2,_=``,v=120;function y(e){let t=Math.floor(Number(e.sip.registerExpires));return Number.isFinite(t)&&t>0?t:m}var b=class{factory;transportBaseUrl;keepaliveSeconds;agentTerminal;sessionTimers;ua;uaListeners;incomingHandlers;iceServers;pendingConnection;disposed=!1;warmPc;keepaliveTimer;keepaliveBusy=!1;registerExpiresSeconds=0;connectionHandlers=new Set;iceQuality=new u;constructor(e,t,n=h,r=_,i=!1){this.factory=e,this.transportBaseUrl=t,this.keepaliveSeconds=n,this.agentTerminal=r,this.sessionTimers=i}terminalHeaders(){return this.agentTerminal===``?[]:[`X-Agent-Terminal: ${this.agentTerminal}`]}warmIceCandidatePool(){if(this.closeWarmPc(),typeof RTCPeerConnection<`u`&&this.iceServers!==void 0)try{this.warmPc=new RTCPeerConnection({iceServers:[...this.iceServers],iceCandidatePoolSize:g})}catch{this.warmPc=void 0}}closeWarmPc(){try{this.warmPc?.close()}catch{}this.warmPc=void 0}keepaliveTick(e){if(this.isCurrentUa(e)&&!this.keepaliveBusy)try{if(typeof e.isConnected==`function`&&e.isConnected()===!1||typeof e.register!=`function`)return;this.keepaliveBusy=!0,e.register({extraHeaders:this.terminalHeaders()})}catch{}finally{this.keepaliveBusy=!1}}startKeepalive(e,t){if(this.stopKeepalive(),!Number.isFinite(this.keepaliveSeconds)||this.keepaliveSeconds<=0||t>0&&t<=this.keepaliveSeconds)return;let n=Math.max(10,Math.floor(this.keepaliveSeconds))*1e3;this.keepaliveTimer=setInterval(()=>this.keepaliveTick(e),n)}stopKeepalive(){this.keepaliveTimer!==void 0&&clearInterval(this.keepaliveTimer),this.keepaliveTimer=void 0}connect(t){this.assertNotDisposed();let n=this.iceQuality.snapshot().runs>0;this.disconnect(this.registrationError(`SIP connection replaced`),!n);try{let e=this.factory.createUa({sockets:w(this.factory.createSocket(this.withoutTicket(this.resolveWssUrl(t.transport.wssUrl)),t.transport.ticket)),uri:t.sip.uri,password:t.sip.registerTicket,registrar_server:t.sip.registrar,register:!0,register_expires:y(t),session_timers:this.sessionTimers,...this.agentTerminal===``?{}:{user_agent:this.agentTerminal}});return this.ua=e,this.registerExpiresSeconds=y(t),this.iceServers=t.iceServers,this.uaListeners=[],this.startRegistration(e)}catch(t){let n=t instanceof e.i&&t.code===`CONFIG_INVALID`?t:this.transportError(t);return this.disconnect(n),Promise.reject(n)}}disconnect(e=this.registrationError(`SIP connection disconnected`),t=!0){this.stopKeepalive(),this.closeWarmPc(),t?this.iceQuality.reset():this.iceQuality.cancelInFlight();let n=this.pendingConnection;this.pendingConnection=void 0,this.ua!==void 0&&(this.removeUaListeners(this.ua),this.ua.stop()),this.ua=void 0,this.uaListeners=void 0,this.iceServers=void 0,n?.reject(e)}dial(t,n){let r=this.requireUa();if(t.trim()===``)throw new e.i(`CALL_INVALID_DESTINATION`,`call`,!1);try{let e=n===void 0?{mediaConstraints:{audio:!0,video:!1},sessionTimersExpires:v,pcConfig:{iceServers:this.dialIceServers(),iceCandidatePoolSize:g}}:{mediaConstraints:{audio:!0,video:!1},sessionTimersExpires:v,pcConfig:{iceServers:[...n.iceServers],iceCandidatePoolSize:g},extraHeaders:[...this.terminalHeaders(),...n.extraHeaders,...n.type===`extension`?[`X-XCall-Destination-Type: extension`]:[]]};return this.createSessionHandle(r.call(t,e))}catch(t){throw new e.i(`CALL_OPERATION_NOT_ALLOWED`,`call`,!1,{cause:t})}}onIncoming(e){this.assertNotDisposed();let t=this.incomingHandlers??new Set;return this.incomingHandlers=t,t.add(e),()=>t.delete(e)}onConnectionStateChanged(e){return this.disposed?()=>void 0:(this.connectionHandlers.add(e),()=>this.connectionHandlers.delete(e))}dispose(){this.disposed||(this.disposed=!0,this.disconnect(),this.incomingHandlers=void 0,this.connectionHandlers.clear())}dialIceServers(){return this.iceQuality.serversForDial(this.iceServers)}iceQualitySnapshot(){return this.iceQuality.snapshot()}reassessIceServers(e=`network-online`){this.iceQuality.assess(this.iceServers,e)}getResourceCounts(){return{listeners:(this.uaListeners?.length??0)+(this.incomingHandlers?.size??0)+this.connectionHandlers.size,webSockets:this.ua===void 0?0:1}}handleIncoming(e){if(!S(e))return;let t=e.session;if(t===void 0)return;let n=this.createSessionHandle(t);this.incomingHandlers?.forEach(e=>e(n))}createSessionHandle(e){return new x(e,()=>this.reassessIceServers(`ice-failed`))}startRegistration(e){let t=!0,n=!1,r=new Promise((t,n)=>{this.pendingConnection={ua:e,resolve:t,reject:n}});this.listen(e,`registered`,()=>{if(this.isCurrentUa(e)){if(t){n=!0;return}this.resolveConnection(e)}}),this.listen(e,`registrationFailed`,t=>{if(!this.isCurrentUa(e))return;let n=this.registrationError(this.registrationFailureCause(t));this.connectionHandlers.forEach(e=>e(`failed`,n)),this.disconnect(n)}),this.listen(e,`disconnected`,t=>{if(!this.isCurrentUa(e))return;let n=this.transportError(t);this.connectionHandlers.forEach(e=>e(`disconnected`,n)),this.disconnect(n,!1)}),this.listen(e,`newRTCSession`,t=>{this.isCurrentUa(e)&&this.handleIncoming(t)});try{e.start()}catch(e){let t=this.transportError(e);this.connectionHandlers.forEach(e=>e(`failed`,t)),this.disconnect(t)}finally{t=!1}return n&&this.resolveConnection(e),r}listen(e,t,n){e.on(t,n),this.uaListeners?.push({event:t,handler:n})}removeUaListeners(e){this.uaListeners?.forEach(({event:t,handler:n})=>e.off(t,n))}isCurrentUa(e){return this.ua===e}resolveConnection(e){let t=this.pendingConnection;if(t?.ua!==e)return;this.pendingConnection=void 0,t.resolve(),this.warmIceCandidatePool();let n=this.iceQuality.snapshot().runs>0?`sip-reconnected`:`initial-registration`;this.iceQuality.assess(this.iceServers,n),this.startKeepalive(e,this.registerExpiresSeconds),this.connectionHandlers.forEach(e=>e(`registered`))}resolveWssUrl(e){let t=this.transportBaseUrl?.trim()===``||this.transportBaseUrl===void 0?typeof location>`u`?`http://localhost`:location.origin:this.transportBaseUrl,n=e.startsWith(`/`)?new URL(e,t):new URL(e);return n.protocol===`http:`&&(n.protocol=`ws:`),n.protocol===`https:`&&(n.protocol=`wss:`),this.assertAllowedWssUrl(n),n.toString()}assertAllowedWssUrl(t){if(t.protocol!==`wss:`&&!(t.protocol===`ws:`&&T(t.hostname)))throw new e.i(`CONFIG_INVALID`,`configuration`,!1,{cause:t.origin})}withoutTicket(e){let t=new URL(e);return t.searchParams.delete(`ticket`),t.toString()}requireUa(){if(this.assertNotDisposed(),this.ua===void 0)throw new e.i(`CALL_NOT_CONNECTED`,`call`,!1);return this.ua}assertNotDisposed(){if(this.disposed)throw new e.i(`SDK_ALREADY_DISPOSED`,`internal`,!1)}registrationError(t){return new e.i(`REGISTRATION_FAILED`,`registration`,!0,{cause:t})}transportError(t){return new e.i(`SIP_WS_UNAVAILABLE`,`registration`,!0,{cause:t})}registrationFailureCause(e){return typeof e==`object`&&e&&`cause`in e?e.cause:e}},x=class{session;pendingHoldReject;mediaRegistration;mediaConnection;mediaHandlers=new Set;mediaWatchStarted=!1;sessionUnsubscribeFromPeerConnection;detachIceGatheringTimeout;detachIceFailureWatch;constructor(e,t){this.session=e,this.detachIceGatheringTimeout=p(e),t!==void 0&&this.watchIceFailure(t)}get id(){return this.session.id}get from(){return this.session.from??E(this.session.remote_identity)}getMediaRegistration(){let e=this.session.connection;if(e!=null)return this.mediaRegistration!==void 0&&this.mediaConnection===e?this.mediaRegistration:(this.mediaConnection=e,this.mediaRegistration=t(e),this.mediaRegistration)}answer(e){this.session.answer({mediaConstraints:e.mediaConstraints,pcConfig:{iceServers:[...e.pcConfig.iceServers],iceCandidatePoolSize:g}})}terminate(){this.detachIceGatheringTimeout?.(),this.detachIceGatheringTimeout=void 0,this.detachIceFailureWatch?.(),this.detachIceFailureWatch=void 0,this.pendingHoldReject?.(Error(`SIP session terminated`)),this.session.terminate()}watchIceFailure(e){let t,n=()=>{t?.iceConnectionState===`failed`&&e()},r=e=>{e&&e!==t&&(t?.removeEventListener(`iceconnectionstatechange`,n),t=e,t.addEventListener(`iceconnectionstatechange`,n),n())},i=e=>{r(e?.peerconnection)},a=()=>{this.session.off(`peerconnection`,i),this.session.off(`ended`,a),this.session.off(`failed`,a),t?.removeEventListener(`iceconnectionstatechange`,n),t=void 0},o=this.session.connection;o!=null&&r(o),this.session.on(`peerconnection`,i),this.session.on(`ended`,a),this.session.on(`failed`,a),this.detachIceFailureWatch=a}hold(){return this.changeHoldState(`hold`)}unhold(){return this.changeHoldState(`unhold`)}mute(){this.session.mute()}unmute(){this.session.unmute()}sendDtmf(e){this.session.sendDTMF(e)}refer(e){this.session.refer(e)}on(e,t){return e===`mediaConnected`?(this.mediaHandlers.add(t),this.watchMediaConnection(),()=>{this.mediaHandlers.delete(t),this.mediaHandlers.size===0&&(this.sessionUnsubscribeFromPeerConnection?.(),this.sessionUnsubscribeFromPeerConnection=void 0)}):(this.session.on(e,t),()=>this.session.off(e,t))}watchMediaConnection(){if(this.mediaWatchStarted)return;this.mediaWatchStarted=!0;let e=!1,t=t=>{if(t==null)return;let n=()=>{if(e)return;let n=t.connectionState||t.iceConnectionState;if(n===`connected`){e=!0;for(let e of this.mediaHandlers)try{e({state:n})}catch{}}};t.addEventListener(`connectionstatechange`,n),n()},n=this.session.connection;if(n!=null){t(n);return}let r=e=>{t(e?.peerconnection??void 0)};this.session.on(`peerconnection`,r),this.sessionUnsubscribeFromPeerConnection=()=>this.session.off(`peerconnection`,r)}changeHoldState(t){return new Promise((n,r)=>{let i=!1,a=e=>{c(e)},o=()=>{try{this.session.off(`ended`,a)}catch{}try{this.session.off(`failed`,a)}catch{}this.pendingHoldReject===c&&(this.pendingHoldReject=void 0)},s=()=>{i||(i=!0,o(),n())},c=t=>{i||(i=!0,o(),r(new e.i(`CALL_OPERATION_NOT_ALLOWED`,`call`,!1,{cause:t})))};try{this.session.on(`ended`,a),this.session.on(`failed`,a)}catch(e){c(e);return}this.pendingHoldReject=c;try{this.session[t](void 0,s)||c({reason:`jssip_operation_rejected`,operation:t})}catch(e){c(e)}})}};function S(e){if(typeof e!=`object`||!e)return!1;let t=e;return t.originator===`remote`&&C(t.session)}function C(e){return typeof e==`object`&&!!e&&`id`in e}function w(e){return typeof e==`object`&&e&&(e.via_transport=`WSS`),e}function T(e){let t=e.replace(/^\[|\]$/g,``).toLowerCase();return t===`localhost`||t===`127.0.0.1`||t===`::1`||t===`0:0:0:0:0:0:0:1`}function E(e){let t=e?.uri;if(t==null)return;if(typeof t.user==`string`&&t.user!==``)return t.user;let n=t.toString();return n.match(/^sips?:([^@;>]+)/i)?.[1]??(n===``?void 0:n)}exports.JsSipAdapter=b;
|
|
1
|
+
const e=require("./SharedWorkerProtocol-4VARy5ma.cjs");require("./createJsSipFactory-Dr8HbLl-.cjs");function t(e){let t=new Map;return{peerConnection:{getSenders:()=>e.getSenders().map(n=>{let r=t.get(n);if(r!==void 0)return r;let i={get track(){return n.track},get senderKind(){let t=n.track;if(t!==null)return t.kind===`audio`||t.kind===`video`?t.kind:void 0;let r=e.getTransceivers().find(e=>e.sender===n)?.receiver.track;if(r?.kind===`audio`||r?.kind===`video`)return r.kind;let i=n.getParameters().codecs?.find(e=>typeof e.mimeType==`string`);if(i?.mimeType?.toLowerCase().startsWith(`video/`))return`video`;if(i?.mimeType?.toLowerCase().startsWith(`audio/`))return`audio`},replaceTrack:e=>n.replaceTrack(e)};return t.set(n,i),i}),close:()=>{e.connectionState!==`closed`&&e.close()}},trackSource:{onTrack(t){let n=e=>{let n=e.track;t({streams:[...e.streams],track:n})};return e.addEventListener(`track`,n),()=>e.removeEventListener(`track`,n)}}}}var n=2e3,r=[5e3,15e3,6e4];function i(){return{runs:0,lastMs:null,udpOk:!1,tcpRelayOk:!1,convergedServers:null,unchanged:null,status:`idle`,lastProbeAt:null,cacheAgeMs:null,unknownCount:0,unavailableCount:0,dialMode:`original`}}function a(e){if(!e)return``;let t=String(e.type??``);return t===``?/ typ (\w+)/.exec(String(e.candidate??``))?.[1]??``:t}function o(e){return/^turns:/i.test(e)?`tls`:/transport=tcp/i.test(e)?`tcp`:`udp`}function s(e,t){let n=t.flatMap(e=>(Array.isArray(e.urls)?e.urls:[e.urls]).map(t=>[String(t),e])),r=new Map(n),i=[];for(let t of e){let e=Array.isArray(t.urls)?t.urls:[t.urls];for(let t of e){let e=r.get(String(t));e&&i.push({...e,urls:[t]})}}return i}function c(e,t={}){let r=Number.isFinite(t.timeoutMs)&&t.timeoutMs>0?t.timeoutMs:n;if(!Array.isArray(e))return Promise.resolve([]);let i=[];for(let t of e){if(!t)continue;let e=Array.isArray(t.urls)?t.urls:[t.urls];for(let n of e){let e=String(n??``).trim();/^(stun|turn|turns):/i.test(e)&&i.push({url:e,entry:t})}}return Promise.all(i.map(e=>new Promise(t=>{let n=!1,i=!1,s,c=o(e.url),l=(r,i)=>{if(!n){n=!0,clearTimeout(u);try{s?.close()}catch{}t({url:e.url,status:r,transport:c,reason:i})}},u=setTimeout(()=>l(i?`unavailable`:`unknown`,i?`server-error`:`timeout`),r);try{if(typeof RTCPeerConnection>`u`){l(`unknown`,`local-error`);return}let t={urls:[e.url]};e.entry.username&&(t.username=e.entry.username),e.entry.credential&&(t.credential=e.entry.credential),s=new RTCPeerConnection({iceServers:[t]}),s.createDataChannel(`webphone-ice-probe`),s.onicecandidate=e=>{if(!e||!e.candidate)return;let t=a(e.candidate);(t===`srflx`||t===`relay`)&&l(`available`,`candidate`)},s.onicecandidateerror=t=>{t?.url&&t.url===e.url&&(i=!0)},s.createOffer().then(e=>s?.setLocalDescription(e)).catch(()=>l(`unknown`,`local-error`))}catch{l(`unknown`,`local-error`)}})))}function l(e,t){let n=new Map;for(let e of t)e&&e.url&&n.set(String(e.url),e.status===`available`);let r=[];for(let t of e??[]){if(!t)continue;let e=(Array.isArray(t.urls)?t.urls:[t.urls]).filter(Boolean).filter(e=>n.get(String(e))===!0);if(e.length===0)continue;let i={...t,urls:e};r.push(i)}return r}var u=class{availableList;lastGoodList;lastGoodAt;lastResults=[];snapshotState=i();running=!1;seq=0;consecutiveFailures=0;lastAttemptAt;retryTimer;pendingRequest;serversForDial(e,t=Date.now()){if(!e)return;if(!this.lastResults.length)return this.setDialMode(`original`),e;let n=this.lastGoodAt===void 0?null:Math.max(0,t-this.lastGoodAt);this.snapshotState={...this.snapshotState,cacheAgeMs:n};let r=n!==null&&n>3e5,i=this.snapshotState.lastProbeAt===null?null:Math.max(0,t-this.snapshotState.lastProbeAt);if(r||i!==null&&i>3e5)return this.snapshotState={...this.snapshotState,status:`stale`,cacheAgeMs:n??i},this.assess(e,`ttl-expired`),this.availableList&&this.availableList.length>0?(this.setDialMode(`original`),e):(this.setDialMode(`host-only`),[]);if(!r&&this.availableList&&this.availableList.length>0)return this.setDialMode(`known-available`),this.availableList.map(e=>({...e,urls:Array.isArray(e.urls)?[...e.urls]:e.urls}));if(this.lastGoodList&&n!==null&&n<=3e5){let t=s(this.lastGoodList,e);if(t.length>0)return this.setDialMode(`last-known-good`),t}return this.setDialMode(`host-only`),[]}snapshot(){return this.snapshotState}reset(){this.retryTimer!==void 0&&clearTimeout(this.retryTimer),this.retryTimer=void 0,this.pendingRequest=void 0,this.seq++,this.running=!1,this.availableList=void 0,this.lastGoodList=void 0,this.lastGoodAt=void 0,this.lastResults=[],this.consecutiveFailures=0,this.lastAttemptAt=void 0,this.snapshotState=i()}cancelInFlight(){this.seq++,this.running=!1,this.retryTimer!==void 0&&clearTimeout(this.retryTimer),this.retryTimer=void 0,this.pendingRequest=void 0}assess(e,t=`initial-registration`){if(e===void 0)return;if(e.length===0){this.reset();return}if(this.running){t!==`initial-registration`&&(this.pendingRequest={servers:e,trigger:t});return}let n=Date.now();if(t!==`initial-registration`&&this.consecutiveFailures>0&&this.lastAttemptAt!==void 0){let i=r[Math.min(this.consecutiveFailures-1,r.length-1)]-(n-this.lastAttemptAt);if(i>0){this.pendingRequest={servers:e,trigger:t},this.retryTimer===void 0&&(this.retryTimer=setTimeout(()=>{this.retryTimer=void 0;let e=this.pendingRequest;this.pendingRequest=void 0,e&&this.assess(e.servers,e.trigger)},i));return}}let i=e.map(e=>({...e,urls:Array.isArray(e.urls)?[...e.urls]:[e.urls]}));if(!i.some(e=>(Array.isArray(e.urls)?e.urls:[e.urls]).some(e=>/^(stun|turn|turns):/i.test(String(e??``)))))return;let a=++this.seq;this.running=!0,this.lastAttemptAt=n,this.availableList=void 0,this.snapshotState={...this.snapshotState,status:t===`ttl-expired`?`stale`:`probing`};let o=Date.now();c(i).then(e=>{if(a!==this.seq)return;this.lastResults=e;let t=i,n=l(t,e);this.availableList=n.length>0?n:void 0,this.availableList&&(this.lastGoodList=n.map(e=>({...e,urls:Array.isArray(e.urls)?[...e.urls]:e.urls})),this.lastGoodAt=Date.now());let s=e.filter(e=>e.status===`unknown`).length,c=e.filter(e=>e.status===`unavailable`).length;this.consecutiveFailures=n.length===0?this.consecutiveFailures+1:0,n.length===0&&this.consecutiveFailures<=r.length&&this.pendingRequest===void 0&&(this.pendingRequest={servers:i,trigger:`retry-backoff`}),this.snapshotState={runs:this.snapshotState.runs+1,lastMs:Date.now()-o,udpOk:e.some(e=>e.status===`available`&&e.transport===`udp`),tcpRelayOk:e.some(e=>e.status===`available`&&(e.transport===`tcp`||e.transport===`tls`)),convergedServers:n.length,unchanged:JSON.stringify(n)===JSON.stringify(t),status:s+c>0?`degraded`:`healthy`,lastProbeAt:Date.now(),cacheAgeMs:0,unknownCount:s,unavailableCount:c,dialMode:n.length>0?`known-available`:`host-only`}}).catch(()=>{this.seq}).finally(()=>{if(a!==this.seq)return;this.running=!1;let e=this.pendingRequest;this.pendingRequest=void 0,e&&this.assess(e.servers,e.trigger)})}isRunning(){return this.running}setDialMode(e){let t=this.snapshotState.status;this.snapshotState={...this.snapshotState,dialMode:e,status:t===`healthy`&&e===`host-only`?`stale`:t}}},d=3e3;function f(e){if(!e)return``;let t=String(e.type??``);return t===``?/ typ (\w+)/.exec(String(e.candidate??``))?.[1]??``:t}function p(e,t={}){if(typeof e.on!=`function`)return()=>void 0;let n=Number.isFinite(t.timeoutMs)&&t.timeoutMs>0?t.timeoutMs:d,r=!1,i,a=()=>{if(!r){r=!0,clearTimeout(s);try{i?.()}catch{}}},o=e=>{let t=e;if(!t||typeof t.ready!=`function`)return;i=t.ready;let n=f(t.candidate);(n===`srflx`||n===`relay`)&&a()};e.on(`icecandidate`,o);let s=setTimeout(a,n);return()=>{clearTimeout(s);try{e.off?.(`icecandidate`,o)}catch{}}}var m=300,h=25,g=2,_=``,v=120;function y(e){let t=Math.floor(Number(e.sip.registerExpires));return Number.isFinite(t)&&t>0?t:m}var b=class{factory;transportBaseUrl;keepaliveSeconds;agentTerminal;sessionTimers;ua;uaListeners;incomingHandlers;iceServers;pendingConnection;disposed=!1;warmPc;keepaliveTimer;keepaliveBusy=!1;registerExpiresSeconds=0;connectionHandlers=new Set;iceQuality=new u;constructor(e,t,n=h,r=_,i=!1){this.factory=e,this.transportBaseUrl=t,this.keepaliveSeconds=n,this.agentTerminal=r,this.sessionTimers=i}terminalHeaders(){return this.agentTerminal===``?[]:[`X-Agent-Terminal: ${this.agentTerminal}`]}warmIceCandidatePool(){if(this.closeWarmPc(),typeof RTCPeerConnection<`u`&&this.iceServers!==void 0)try{this.warmPc=new RTCPeerConnection({iceServers:[...this.iceServers],iceCandidatePoolSize:g})}catch{this.warmPc=void 0}}closeWarmPc(){try{this.warmPc?.close()}catch{}this.warmPc=void 0}keepaliveTick(e){if(this.isCurrentUa(e)&&!this.keepaliveBusy)try{if(typeof e.isConnected==`function`&&e.isConnected()===!1||typeof e.register!=`function`)return;this.keepaliveBusy=!0,e.register({extraHeaders:this.terminalHeaders()})}catch{}finally{this.keepaliveBusy=!1}}startKeepalive(e,t){if(this.stopKeepalive(),!Number.isFinite(this.keepaliveSeconds)||this.keepaliveSeconds<=0||t>0&&t<=this.keepaliveSeconds)return;let n=Math.max(10,Math.floor(this.keepaliveSeconds))*1e3;this.keepaliveTimer=setInterval(()=>this.keepaliveTick(e),n)}stopKeepalive(){this.keepaliveTimer!==void 0&&clearInterval(this.keepaliveTimer),this.keepaliveTimer=void 0}connect(t){this.assertNotDisposed();let n=this.iceQuality.snapshot().runs>0;this.disconnect(this.registrationError(`SIP connection replaced`),!n);try{let e=this.factory.createUa({sockets:w(this.factory.createSocket(this.withoutTicket(this.resolveWssUrl(t.transport.wssUrl)),t.transport.ticket)),uri:t.sip.uri,password:t.sip.registerTicket,registrar_server:t.sip.registrar,register:!0,register_expires:y(t),session_timers:this.sessionTimers,...this.agentTerminal===``?{}:{user_agent:this.agentTerminal}});return this.ua=e,this.registerExpiresSeconds=y(t),this.iceServers=t.iceServers,this.uaListeners=[],this.startRegistration(e)}catch(t){let n=t instanceof e.i&&t.code===`CONFIG_INVALID`?t:this.transportError(t);return this.disconnect(n),Promise.reject(n)}}disconnect(e=this.registrationError(`SIP connection disconnected`),t=!0){this.stopKeepalive(),this.closeWarmPc(),t?this.iceQuality.reset():this.iceQuality.cancelInFlight();let n=this.pendingConnection;this.pendingConnection=void 0,this.ua!==void 0&&(this.removeUaListeners(this.ua),this.ua.stop()),this.ua=void 0,this.uaListeners=void 0,this.iceServers=void 0,n?.reject(e)}dial(t,n){let r=this.requireUa();if(t.trim()===``)throw new e.i(`CALL_INVALID_DESTINATION`,`call`,!1);try{let e=n===void 0?{mediaConstraints:{audio:!0,video:!1},sessionTimersExpires:v,pcConfig:{iceServers:this.dialIceServers(),iceCandidatePoolSize:g}}:{mediaConstraints:{audio:!0,video:!1},sessionTimersExpires:v,pcConfig:{iceServers:[...n.iceServers],iceCandidatePoolSize:g},extraHeaders:[...this.terminalHeaders(),...n.extraHeaders,...n.type===`extension`?[`X-XCall-Destination-Type: extension`]:[]]};return this.createSessionHandle(r.call(t,e))}catch(t){throw new e.i(`CALL_OPERATION_NOT_ALLOWED`,`call`,!1,{cause:t})}}onIncoming(e){this.assertNotDisposed();let t=this.incomingHandlers??new Set;return this.incomingHandlers=t,t.add(e),()=>t.delete(e)}onConnectionStateChanged(e){return this.disposed?()=>void 0:(this.connectionHandlers.add(e),()=>this.connectionHandlers.delete(e))}dispose(){this.disposed||(this.disposed=!0,this.disconnect(),this.incomingHandlers=void 0,this.connectionHandlers.clear())}dialIceServers(){return this.iceQuality.serversForDial(this.iceServers)}iceQualitySnapshot(){return this.iceQuality.snapshot()}reassessIceServers(e=`network-online`){this.iceQuality.assess(this.iceServers,e)}getResourceCounts(){return{listeners:(this.uaListeners?.length??0)+(this.incomingHandlers?.size??0)+this.connectionHandlers.size,webSockets:this.ua===void 0?0:1}}handleIncoming(e){if(!S(e))return;let t=e.session;if(t===void 0)return;let n=this.createSessionHandle(t);this.incomingHandlers?.forEach(e=>e(n))}createSessionHandle(e){return new x(e,()=>this.reassessIceServers(`ice-failed`))}startRegistration(e){let t=!0,n=!1,r=new Promise((t,n)=>{this.pendingConnection={ua:e,resolve:t,reject:n}});this.listen(e,`registered`,()=>{if(this.isCurrentUa(e)){if(t){n=!0;return}this.resolveConnection(e)}}),this.listen(e,`registrationFailed`,t=>{if(!this.isCurrentUa(e))return;let n=this.registrationError(this.registrationFailureCause(t));this.connectionHandlers.forEach(e=>e(`failed`,n)),this.disconnect(n)}),this.listen(e,`disconnected`,t=>{if(!this.isCurrentUa(e))return;let n=this.transportError(t);this.connectionHandlers.forEach(e=>e(`disconnected`,n)),this.disconnect(n,!1)}),this.listen(e,`newRTCSession`,t=>{this.isCurrentUa(e)&&this.handleIncoming(t)});try{e.start()}catch(e){let t=this.transportError(e);this.connectionHandlers.forEach(e=>e(`failed`,t)),this.disconnect(t)}finally{t=!1}return n&&this.resolveConnection(e),r}listen(e,t,n){e.on(t,n),this.uaListeners?.push({event:t,handler:n})}removeUaListeners(e){this.uaListeners?.forEach(({event:t,handler:n})=>e.off(t,n))}isCurrentUa(e){return this.ua===e}resolveConnection(e){let t=this.pendingConnection;if(t?.ua!==e)return;this.pendingConnection=void 0,t.resolve(),this.warmIceCandidatePool();let n=this.iceQuality.snapshot().runs>0?`sip-reconnected`:`initial-registration`;this.iceQuality.assess(this.iceServers,n),this.startKeepalive(e,this.registerExpiresSeconds),this.connectionHandlers.forEach(e=>e(`registered`))}resolveWssUrl(e){let t=this.transportBaseUrl?.trim()===``||this.transportBaseUrl===void 0?typeof location>`u`?`http://localhost`:location.origin:this.transportBaseUrl,n=e.startsWith(`/`)?new URL(e,t):new URL(e);return n.protocol===`http:`&&(n.protocol=`ws:`),n.protocol===`https:`&&(n.protocol=`wss:`),this.assertAllowedWssUrl(n),n.toString()}assertAllowedWssUrl(t){if(t.protocol!==`wss:`&&!(t.protocol===`ws:`&&T(t.hostname)))throw new e.i(`CONFIG_INVALID`,`configuration`,!1,{cause:t.origin})}withoutTicket(e){let t=new URL(e);return t.searchParams.delete(`ticket`),t.toString()}requireUa(){if(this.assertNotDisposed(),this.ua===void 0)throw new e.i(`CALL_NOT_CONNECTED`,`call`,!1);return this.ua}assertNotDisposed(){if(this.disposed)throw new e.i(`SDK_ALREADY_DISPOSED`,`internal`,!1)}registrationError(t){return new e.i(`REGISTRATION_FAILED`,`registration`,!0,{cause:t})}transportError(t){return new e.i(`SIP_WS_UNAVAILABLE`,`registration`,!0,{cause:t})}registrationFailureCause(e){return typeof e==`object`&&e&&`cause`in e?e.cause:e}},x=class{session;pendingHoldReject;mediaRegistration;mediaConnection;mediaHandlers=new Set;mediaWatchStarted=!1;sessionUnsubscribeFromPeerConnection;detachIceGatheringTimeout;detachIceFailureWatch;constructor(e,t){this.session=e,this.detachIceGatheringTimeout=p(e),t!==void 0&&this.watchIceFailure(t)}get id(){return this.session.id}get from(){return this.session.from??E(this.session.remote_identity)}getMediaRegistration(){let e=this.session.connection;if(e!=null)return this.mediaRegistration!==void 0&&this.mediaConnection===e?this.mediaRegistration:(this.mediaConnection=e,this.mediaRegistration=t(e),this.mediaRegistration)}answer(e){this.session.answer({mediaConstraints:e.mediaConstraints,pcConfig:{iceServers:[...e.pcConfig.iceServers],iceCandidatePoolSize:g}})}terminate(){this.detachIceGatheringTimeout?.(),this.detachIceGatheringTimeout=void 0,this.detachIceFailureWatch?.(),this.detachIceFailureWatch=void 0,this.pendingHoldReject?.(Error(`SIP session terminated`)),this.session.terminate()}watchIceFailure(e){let t,n=()=>{t?.iceConnectionState===`failed`&&e()},r=e=>{e&&e!==t&&(t?.removeEventListener(`iceconnectionstatechange`,n),t=e,t.addEventListener(`iceconnectionstatechange`,n),n())},i=e=>{r(e?.peerconnection)},a=()=>{this.session.off(`peerconnection`,i),this.session.off(`ended`,a),this.session.off(`failed`,a),t?.removeEventListener(`iceconnectionstatechange`,n),t=void 0},o=this.session.connection;o!=null&&r(o),this.session.on(`peerconnection`,i),this.session.on(`ended`,a),this.session.on(`failed`,a),this.detachIceFailureWatch=a}hold(){return this.changeHoldState(`hold`)}unhold(){return this.changeHoldState(`unhold`)}mute(){this.session.mute()}unmute(){this.session.unmute()}sendDtmf(e){this.session.sendDTMF(e)}refer(e){this.session.refer(e)}on(e,t){return e===`mediaConnected`?(this.mediaHandlers.add(t),this.watchMediaConnection(),()=>{this.mediaHandlers.delete(t),this.mediaHandlers.size===0&&(this.sessionUnsubscribeFromPeerConnection?.(),this.sessionUnsubscribeFromPeerConnection=void 0)}):(this.session.on(e,t),()=>this.session.off(e,t))}watchMediaConnection(){if(this.mediaWatchStarted)return;this.mediaWatchStarted=!0;let e=!1,t=t=>{if(t==null)return;let n=()=>{if(e)return;let n=t.connectionState||t.iceConnectionState;if(n===`connected`){e=!0;for(let e of this.mediaHandlers)try{e({state:n})}catch{}}};t.addEventListener(`connectionstatechange`,n),n()},n=this.session.connection;if(n!=null){t(n);return}let r=e=>{t(e?.peerconnection??void 0)};this.session.on(`peerconnection`,r),this.sessionUnsubscribeFromPeerConnection=()=>this.session.off(`peerconnection`,r)}changeHoldState(t){return new Promise((n,r)=>{let i=!1,a=e=>{c(e)},o=()=>{try{this.session.off(`ended`,a)}catch{}try{this.session.off(`failed`,a)}catch{}this.pendingHoldReject===c&&(this.pendingHoldReject=void 0)},s=()=>{i||(i=!0,o(),n())},c=t=>{i||(i=!0,o(),r(new e.i(`CALL_OPERATION_NOT_ALLOWED`,`call`,!1,{cause:t})))};try{this.session.on(`ended`,a),this.session.on(`failed`,a)}catch(e){c(e);return}this.pendingHoldReject=c;try{this.session[t](void 0,s)||c({reason:`jssip_operation_rejected`,operation:t})}catch(e){c(e)}})}};function S(e){if(typeof e!=`object`||!e)return!1;let t=e;return t.originator===`remote`&&C(t.session)}function C(e){return typeof e==`object`&&!!e&&`id`in e}function w(e){return typeof e==`object`&&e&&(e.via_transport=`WSS`),e}function T(e){let t=e.replace(/^\[|\]$/g,``).toLowerCase();return t===`localhost`||t===`127.0.0.1`||t===`::1`||t===`0:0:0:0:0:0:0:1`}function E(e){let t=e?.uri;if(t==null)return;if(typeof t.user==`string`&&t.user!==``)return t.user;let n=t.toString();return n.match(/^sips?:([^@;>]+)/i)?.[1]??(n===``?void 0:n)}exports.JsSipAdapter=b;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require("./i18n-BbEy6K9z.cjs"),t=require("./redact-Bq26pObO.cjs");var n=class extends Error{code;category;retryable;requestId;callId;cause;serverCode;platformCode;status;constructor(t,n,r,i={}){super(e.r(t)),this.name=`CCBarError`,this.code=t,this.category=n,this.retryable=r,this.requestId=i.requestId,this.callId=i.callId,this.cause=i.cause,this.serverCode=i.serverCode,this.platformCode=i.platformCode,this.status=i.status}localizedMessage(t){return e.r(this.code,t)}},r=[`new`,`dialing`,`ringing`,`connecting`,`active`,`held`,`ended`,`failed`];function i(e){if(!l(e)||typeof e.id!=`string`||typeof e.destination!=`string`||typeof e.incoming!=`boolean`||!c(e.state))throw d(`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 a(e){return e instanceof n?{code:e.code,category:e.category,retryable:e.retryable,...e.requestId===void 0?{}:{requestId:e.requestId},...e.callId===void 0?{}:{callId:e.callId},...e.serverCode===void 0?{}:{serverCode:e.serverCode},...e.platformCode===void 0?{}:{platformCode:e.platformCode},...e.status===void 0?{}:{status:e.status},message:u(e.message)}:{code:`SDK_INTERNAL_ERROR`,category:`internal`,retryable:!1,message:u(e instanceof Error?e.message:String(e))}}function o(e){if(!l(e))throw d(`Invalid worker message`);if(e.version!==1)throw d(`Unsupported worker protocol version`);if(e.type===`attach`||e.type===`detach`)return s(e),e;if(e.type===`command`){if(s(e),typeof e.command!=`string`||e.payload!==void 0&&!l(e.payload))throw d(`Invalid worker command`);return e}if(e.type===`response`){if(typeof e.requestId!=`string`||typeof e.ok!=`boolean`)throw d(`Invalid worker response`);return e}if(e.type===`event`){if(typeof e.event!=`string`||!(`payload`in e))throw d(`Invalid worker event`);return e}throw d(`Unknown worker message type`)}function s(e){if(typeof e.requestId!=`string`||typeof e.tabId!=`string`)throw d(`Worker request requires requestId and tabId`)}function c(e){return typeof e==`string`&&r.includes(e)}function l(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function u(e){return t.t(e).replace(/(?:authorization|token|ticket|credential|password|secret)/gi,`[REDACTED]`)}function d(e){return new n(`SDK_INTERNAL_ERROR`,`internal`,!1,{cause:e})}Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return o}});
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { r as e } from "./i18n-D-DdHtGz.js";
|
|
2
|
+
import { t } from "./redact-DB3CMbsK.js";
|
|
3
|
+
//#region src/errors/CCBarError.ts
|
|
4
|
+
var n = class extends Error {
|
|
5
|
+
code;
|
|
6
|
+
category;
|
|
7
|
+
retryable;
|
|
8
|
+
requestId;
|
|
9
|
+
callId;
|
|
10
|
+
cause;
|
|
11
|
+
serverCode;
|
|
12
|
+
platformCode;
|
|
13
|
+
status;
|
|
14
|
+
constructor(t, n, r, i = {}) {
|
|
15
|
+
super(e(t)), this.name = "CCBarError", this.code = t, this.category = n, this.retryable = r, this.requestId = i.requestId, this.callId = i.callId, this.cause = i.cause, this.serverCode = i.serverCode, this.platformCode = i.platformCode, this.status = i.status;
|
|
16
|
+
}
|
|
17
|
+
localizedMessage(t) {
|
|
18
|
+
return e(this.code, t);
|
|
19
|
+
}
|
|
20
|
+
}, r = [
|
|
21
|
+
"new",
|
|
22
|
+
"dialing",
|
|
23
|
+
"ringing",
|
|
24
|
+
"connecting",
|
|
25
|
+
"active",
|
|
26
|
+
"held",
|
|
27
|
+
"ended",
|
|
28
|
+
"failed"
|
|
29
|
+
];
|
|
30
|
+
function i(e) {
|
|
31
|
+
if (!l(e) || typeof e.id != "string" || typeof e.destination != "string" || typeof e.incoming != "boolean" || !c(e.state)) throw d("Invalid call snapshot");
|
|
32
|
+
return {
|
|
33
|
+
id: e.id,
|
|
34
|
+
...typeof e.from == "string" ? { from: e.from } : {},
|
|
35
|
+
destination: e.destination,
|
|
36
|
+
state: e.state,
|
|
37
|
+
incoming: e.incoming,
|
|
38
|
+
...typeof e.ownerTabId == "string" ? { ownerTabId: e.ownerTabId } : {}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function a(e) {
|
|
42
|
+
return e instanceof n ? {
|
|
43
|
+
code: e.code,
|
|
44
|
+
category: e.category,
|
|
45
|
+
retryable: e.retryable,
|
|
46
|
+
...e.requestId === void 0 ? {} : { requestId: e.requestId },
|
|
47
|
+
...e.callId === void 0 ? {} : { callId: e.callId },
|
|
48
|
+
...e.serverCode === void 0 ? {} : { serverCode: e.serverCode },
|
|
49
|
+
...e.platformCode === void 0 ? {} : { platformCode: e.platformCode },
|
|
50
|
+
...e.status === void 0 ? {} : { status: e.status },
|
|
51
|
+
message: u(e.message)
|
|
52
|
+
} : {
|
|
53
|
+
code: "SDK_INTERNAL_ERROR",
|
|
54
|
+
category: "internal",
|
|
55
|
+
retryable: !1,
|
|
56
|
+
message: u(e instanceof Error ? e.message : String(e))
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function o(e) {
|
|
60
|
+
if (!l(e)) throw d("Invalid worker message");
|
|
61
|
+
if (e.version !== 1) throw d("Unsupported worker protocol version");
|
|
62
|
+
if (e.type === "attach" || e.type === "detach") return s(e), e;
|
|
63
|
+
if (e.type === "command") {
|
|
64
|
+
if (s(e), typeof e.command != "string" || e.payload !== void 0 && !l(e.payload)) throw d("Invalid worker command");
|
|
65
|
+
return e;
|
|
66
|
+
}
|
|
67
|
+
if (e.type === "response") {
|
|
68
|
+
if (typeof e.requestId != "string" || typeof e.ok != "boolean") throw d("Invalid worker response");
|
|
69
|
+
return e;
|
|
70
|
+
}
|
|
71
|
+
if (e.type === "event") {
|
|
72
|
+
if (typeof e.event != "string" || !("payload" in e)) throw d("Invalid worker event");
|
|
73
|
+
return e;
|
|
74
|
+
}
|
|
75
|
+
throw d("Unknown worker message type");
|
|
76
|
+
}
|
|
77
|
+
function s(e) {
|
|
78
|
+
if (typeof e.requestId != "string" || typeof e.tabId != "string") throw d("Worker request requires requestId and tabId");
|
|
79
|
+
}
|
|
80
|
+
function c(e) {
|
|
81
|
+
return typeof e == "string" && r.includes(e);
|
|
82
|
+
}
|
|
83
|
+
function l(e) {
|
|
84
|
+
return typeof e == "object" && !!e && !Array.isArray(e);
|
|
85
|
+
}
|
|
86
|
+
function u(e) {
|
|
87
|
+
return t(e).replace(/(?:authorization|token|ticket|credential|password|secret)/gi, "[REDACTED]");
|
|
88
|
+
}
|
|
89
|
+
function d(e) {
|
|
90
|
+
return new n("SDK_INTERNAL_ERROR", "internal", !1, { cause: e });
|
|
91
|
+
}
|
|
92
|
+
//#endregion
|
|
93
|
+
export { n as i, i as n, a as r, o as t };
|
package/dist/core/CCBarCall.d.ts
CHANGED
|
@@ -69,8 +69,8 @@ export declare class CCBarCall {
|
|
|
69
69
|
dispose(): void;
|
|
70
70
|
private handleSessionEvent;
|
|
71
71
|
private transitionToActive;
|
|
72
|
-
private transitionIfAllowed;
|
|
73
72
|
private updateHoldState;
|
|
73
|
+
private transitionIfAllowed;
|
|
74
74
|
private transitionIfStillRinging;
|
|
75
75
|
private transitionTo;
|
|
76
76
|
private startPendingOperation;
|