@16x/webphone-sdk 3.1.0 → 3.1.2

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.
@@ -42,42 +42,63 @@ function t(e) {
42
42
  }
43
43
  //#endregion
44
44
  //#region src/sip/JsSipAdapter.ts
45
- var n = 300;
46
- function r(e) {
45
+ var n = 300, r = 25, i = 2;
46
+ function a(e) {
47
47
  let t = Math.floor(Number(e.sip.registerExpires));
48
48
  return Number.isFinite(t) && t > 0 ? t : n;
49
49
  }
50
- var i = class {
50
+ var o = class {
51
51
  factory;
52
52
  transportBaseUrl;
53
+ keepaliveSeconds;
53
54
  ua;
54
55
  uaListeners;
55
56
  incomingHandlers;
56
57
  iceServers;
57
58
  pendingConnection;
58
59
  disposed = !1;
60
+ keepaliveTimer;
61
+ keepaliveBusy = !1;
62
+ registerExpiresSeconds = 0;
59
63
  connectionHandlers = /* @__PURE__ */ new Set();
60
- constructor(e, t) {
61
- this.factory = e, this.transportBaseUrl = t;
64
+ constructor(e, t, n = r) {
65
+ this.factory = e, this.transportBaseUrl = t, this.keepaliveSeconds = n;
66
+ }
67
+ keepaliveTick(e) {
68
+ if (this.isCurrentUa(e) && !this.keepaliveBusy) try {
69
+ if (typeof e.isConnected == "function" && e.isConnected() === !1 || typeof e.register != "function") return;
70
+ this.keepaliveBusy = !0, e.register();
71
+ } catch {} finally {
72
+ this.keepaliveBusy = !1;
73
+ }
74
+ }
75
+ startKeepalive(e, t) {
76
+ if (this.stopKeepalive(), !Number.isFinite(this.keepaliveSeconds) || this.keepaliveSeconds <= 0 || t > 0 && t <= this.keepaliveSeconds) return;
77
+ let n = Math.max(10, Math.floor(this.keepaliveSeconds)) * 1e3;
78
+ this.keepaliveTimer = setInterval(() => this.keepaliveTick(e), n);
79
+ }
80
+ stopKeepalive() {
81
+ this.keepaliveTimer !== void 0 && clearInterval(this.keepaliveTimer), this.keepaliveTimer = void 0;
62
82
  }
63
83
  connect(t) {
64
84
  this.assertNotDisposed(), this.disconnect(this.registrationError("SIP connection replaced"));
65
85
  try {
66
86
  let e = this.factory.createUa({
67
- sockets: c(this.factory.createSocket(this.withoutTicket(this.resolveWssUrl(t.transport.wssUrl)), t.transport.ticket)),
87
+ sockets: u(this.factory.createSocket(this.withoutTicket(this.resolveWssUrl(t.transport.wssUrl)), t.transport.ticket)),
68
88
  uri: t.sip.uri,
69
89
  password: t.sip.registerTicket,
70
90
  registrar_server: t.sip.registrar,
71
91
  register: !0,
72
- register_expires: r(t)
92
+ register_expires: a(t)
73
93
  });
74
- return this.ua = e, this.iceServers = t.iceServers, this.uaListeners = [], this.startRegistration(e);
94
+ return this.ua = e, this.registerExpiresSeconds = a(t), this.iceServers = t.iceServers, this.uaListeners = [], this.startRegistration(e);
75
95
  } catch (t) {
76
96
  let n = t instanceof e && t.code === "CONFIG_INVALID" ? t : this.transportError(t);
77
97
  return this.disconnect(n), Promise.reject(n);
78
98
  }
79
99
  }
80
100
  disconnect(e = this.registrationError("SIP connection disconnected")) {
101
+ this.stopKeepalive();
81
102
  let t = this.pendingConnection;
82
103
  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, t?.reject(e);
83
104
  }
@@ -91,17 +112,23 @@ var i = class {
91
112
  video: !1
92
113
  },
93
114
  sessionTimersExpires: 1800,
94
- pcConfig: { iceServers: this.iceServers }
115
+ pcConfig: {
116
+ iceServers: this.iceServers,
117
+ iceCandidatePoolSize: i
118
+ }
95
119
  } : {
96
120
  mediaConstraints: {
97
121
  audio: !0,
98
122
  video: !1
99
123
  },
100
124
  sessionTimersExpires: 1800,
101
- pcConfig: { iceServers: [...n.iceServers] },
125
+ pcConfig: {
126
+ iceServers: [...n.iceServers],
127
+ iceCandidatePoolSize: i
128
+ },
102
129
  extraHeaders: [...n.extraHeaders, ...n.type === "extension" ? ["X-XCall-Destination-Type: extension"] : []]
103
130
  };
104
- return new a(r.call(t, e));
131
+ return new s(r.call(t, e));
105
132
  } catch (t) {
106
133
  throw new e("CALL_OPERATION_NOT_ALLOWED", "call", !1, { cause: t });
107
134
  }
@@ -124,10 +151,10 @@ var i = class {
124
151
  };
125
152
  }
126
153
  handleIncoming(e) {
127
- if (!o(e)) return;
154
+ if (!c(e)) return;
128
155
  let t = e.session;
129
156
  if (t === void 0) return;
130
- let n = new a(t);
157
+ let n = new s(t);
131
158
  this.incomingHandlers?.forEach((e) => e(n));
132
159
  }
133
160
  startRegistration(e) {
@@ -181,14 +208,14 @@ var i = class {
181
208
  }
182
209
  resolveConnection(e) {
183
210
  let t = this.pendingConnection;
184
- t?.ua === e && (this.pendingConnection = void 0, t.resolve(), this.connectionHandlers.forEach((e) => e("registered")));
211
+ t?.ua === e && (this.pendingConnection = void 0, t.resolve(), this.startKeepalive(e, this.registerExpiresSeconds), this.connectionHandlers.forEach((e) => e("registered")));
185
212
  }
186
213
  resolveWssUrl(e) {
187
214
  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);
188
215
  return n.protocol === "http:" && (n.protocol = "ws:"), n.protocol === "https:" && (n.protocol = "wss:"), this.assertAllowedWssUrl(n), n.toString();
189
216
  }
190
217
  assertAllowedWssUrl(t) {
191
- if (t.protocol !== "wss:" && !(t.protocol === "ws:" && l(t.hostname))) throw new e("CONFIG_INVALID", "configuration", !1, { cause: t.origin });
218
+ if (t.protocol !== "wss:" && !(t.protocol === "ws:" && d(t.hostname))) throw new e("CONFIG_INVALID", "configuration", !1, { cause: t.origin });
192
219
  }
193
220
  withoutTicket(e) {
194
221
  let t = new URL(e);
@@ -210,7 +237,7 @@ var i = class {
210
237
  registrationFailureCause(e) {
211
238
  return typeof e == "object" && e && "cause" in e ? e.cause : e;
212
239
  }
213
- }, a = class {
240
+ }, s = class {
214
241
  session;
215
242
  pendingHoldReject;
216
243
  mediaRegistration;
@@ -222,7 +249,7 @@ var i = class {
222
249
  return this.session.id;
223
250
  }
224
251
  get from() {
225
- return this.session.from ?? u(this.session.remote_identity);
252
+ return this.session.from ?? f(this.session.remote_identity);
226
253
  }
227
254
  getMediaRegistration() {
228
255
  let e = this.session.connection;
@@ -290,22 +317,22 @@ var i = class {
290
317
  });
291
318
  }
292
319
  };
293
- function o(e) {
320
+ function c(e) {
294
321
  if (typeof e != "object" || !e) return !1;
295
322
  let t = e;
296
- return t.originator === "remote" && s(t.session);
323
+ return t.originator === "remote" && l(t.session);
297
324
  }
298
- function s(e) {
325
+ function l(e) {
299
326
  return typeof e == "object" && !!e && "id" in e;
300
327
  }
301
- function c(e) {
328
+ function u(e) {
302
329
  return typeof e == "object" && e && (e.via_transport = "WSS"), e;
303
330
  }
304
- function l(e) {
331
+ function d(e) {
305
332
  let t = e.replace(/^\[|\]$/g, "").toLowerCase();
306
333
  return t === "localhost" || t === "127.0.0.1" || t === "::1" || t === "0:0:0:0:0:0:0:1";
307
334
  }
308
- function u(e) {
335
+ function f(e) {
309
336
  let t = e?.uri;
310
337
  if (t == null) return;
311
338
  if (typeof t.user == "string" && t.user !== "") return t.user;
@@ -313,4 +340,4 @@ function u(e) {
313
340
  return n.match(/^sips?:([^@;>]+)/i)?.[1] ?? (n === "" ? void 0 : n);
314
341
  }
315
342
  //#endregion
316
- export { i as JsSipAdapter };
343
+ export { o as JsSipAdapter };
@@ -31,6 +31,12 @@ export interface CCBarClientOptions {
31
31
  readonly requestedCapabilities?: readonly string[];
32
32
  readonly maxConcurrentCalls?: number;
33
33
  readonly autoHoldPreviousCall?: boolean;
34
+ /**
35
+ * 已注册时主动重发 REGISTER 的间隔(秒),用来撑住 NAT/代理上的长连接,默认 25;0 = 关闭。
36
+ * 浏览器发不了 WebSocket ping,中间设备(nginx/NAT)会静默掐掉空闲的 WSS:
37
+ * 页面还显示已注册,下一次 INVITE 却直接失败。
38
+ */
39
+ readonly sipKeepaliveSeconds?: number;
34
40
  /** SharedWorker attach/close is attempted when this option is provided. SIP remains tab-local until the next-minor adapter. */
35
41
  readonly sharedWorker?: SharedWorkerOptions;
36
42
  /** @internal Test/integration dependency injection; not required by consumers. */
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../Diagnostics-D38Hm3NT.cjs"),t=require("../redact-Bq26pObO.cjs");require("../createJsSipFactory-Dr8HbLl-.cjs"),exports.Diagnostics=e.t,exports.RingBuffer=e.n,exports.diagnosticsVersion=e.r,exports.redactText=t.t,exports.redactValue=t.n;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../Diagnostics-BIK-fe3F.cjs"),t=require("../redact-Bq26pObO.cjs");require("../createJsSipFactory-Dr8HbLl-.cjs"),exports.Diagnostics=e.t,exports.RingBuffer=e.n,exports.diagnosticsVersion=e.r,exports.redactText=t.t,exports.redactValue=t.n;
@@ -1,3 +1,3 @@
1
- import { n as e, r as t, t as n } from "../Diagnostics-Di049OpT.js";
1
+ import { n as e, r as t, t as n } from "../Diagnostics-B0AJ4g-B.js";
2
2
  import { n as r, t as i } from "../redact-DB3CMbsK.js";
3
3
  export { n as Diagnostics, e as RingBuffer, t as diagnosticsVersion, i as redactText, r as redactValue };
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./SharedWorkerProtocol-39dch6xL.cjs"),t=require("./CCBarClient-DCQ8XjcL.cjs"),n=require("./Diagnostics-D38Hm3NT.cjs"),r=require("./redact-Bq26pObO.cjs");require("./diagnostics/index.cjs"),require("./createJsSipFactory-Dr8HbLl-.cjs");function i(e){if(e.code!==`OK`)throw TypeError(`Unexpected session response code: ${e.code}`);if(e.data===void 0||e.data===null)throw TypeError(`Unexpected session response: missing data`);return e.data}function a(e={}){return{version:`0.1.0`,options:e}}var o=`0.1.0`;exports.CCBarCall=t.a,exports.CCBarClient=t.t,exports.CCBarError=e.i,exports.CallManager=t.i,exports.CallStateError=t.c,exports.Diagnostics=n.t,exports.RingBuffer=n.n,exports.TokenManager=t.s,exports.TypedEventBus=t.p,exports.WebPhoneApi=t.o,exports.assertCallTransition=t.l,exports.canTransition=t.u,exports.createSdk=a,exports.createSharedWorkerSelection=t.n,exports.diagnosticsVersion=n.r,exports.parseSessionResponse=i,exports.redactText=r.t,exports.redactValue=r.n,exports.resolveWorkerUrl=t.r,exports.transition=t.d,exports.transitions=t.f,exports.version=o;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./SharedWorkerProtocol-39dch6xL.cjs"),t=require("./CCBarClient-CEybNVKb.cjs"),n=require("./Diagnostics-BIK-fe3F.cjs"),r=require("./redact-Bq26pObO.cjs");require("./diagnostics/index.cjs"),require("./createJsSipFactory-Dr8HbLl-.cjs");function i(e){if(e.code!==`OK`)throw TypeError(`Unexpected session response code: ${e.code}`);if(e.data===void 0||e.data===null)throw TypeError(`Unexpected session response: missing data`);return e.data}function a(e={}){return{version:`0.1.0`,options:e}}var o=`0.1.0`;exports.CCBarCall=t.a,exports.CCBarClient=t.t,exports.CCBarError=e.i,exports.CallManager=t.i,exports.CallStateError=t.c,exports.Diagnostics=n.t,exports.RingBuffer=n.n,exports.TokenManager=t.s,exports.TypedEventBus=t.p,exports.WebPhoneApi=t.o,exports.assertCallTransition=t.l,exports.canTransition=t.u,exports.createSdk=a,exports.createSharedWorkerSelection=t.n,exports.diagnosticsVersion=n.r,exports.parseSessionResponse=i,exports.redactText=r.t,exports.redactValue=r.n,exports.resolveWorkerUrl=t.r,exports.transition=t.d,exports.transitions=t.f,exports.version=o;
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { i as e } from "./SharedWorkerProtocol-DKVQ5-po.js";
2
- import { a as t, c as n, d as r, f as i, i as a, l as o, n as s, o as c, p as l, r as u, s as d, t as f, u as p } from "./CCBarClient-CcPfEToZ.js";
3
- import { n as m, r as h, t as g } from "./Diagnostics-Di049OpT.js";
2
+ import { a as t, c as n, d as r, f as i, i as a, l as o, n as s, o as c, p as l, r as u, s as d, t as f, u as p } from "./CCBarClient-BsVx2U72.js";
3
+ import { n as m, r as h, t as g } from "./Diagnostics-B0AJ4g-B.js";
4
4
  import { n as _, t as v } from "./redact-DB3CMbsK.js";
5
5
  import "./diagnostics/index.js";
6
6
  //#region src/api/contracts.ts