@tbisoftware/phone 2.0.8 → 2.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/vue/index.js CHANGED
@@ -1,47 +1,53 @@
1
- import { defineComponent as re, ref as p, computed as ee, onMounted as X, onUnmounted as Y, createElementBlock as m, openBlock as f, normalizeClass as K, unref as B, createCommentVNode as V, createBlock as ie, createElementVNode as e, withDirectives as ce, vModelText as de, toDisplayString as k, createTextVNode as te, Teleport as ue, Fragment as F, renderList as ve, normalizeStyle as fe, readonly as D, provide as ge, inject as he } from "vue";
2
- import { d as me, f as G, c as J, J as W, P as pe } from "../index-D8BnjTav.js";
3
- const ye = {
1
+ import { defineComponent as fe, ref as b, computed as ie, onMounted as ae, onUnmounted as re, createElementBlock as w, openBlock as y, normalizeClass as Z, unref as G, createCommentVNode as F, createBlock as ge, createElementVNode as e, withDirectives as me, vModelText as he, toDisplayString as I, createTextVNode as ee, Teleport as pe, Fragment as te, renderList as Ce, normalizeStyle as ye, readonly as j, provide as xe, inject as we } from "vue";
2
+ import { d as be, f as le, c as ne, J as oe, P as Se } from "../index-8z_LWKp3.js";
3
+ const Ee = {
4
4
  key: 0,
5
5
  class: "flex gap-2 items-center"
6
- }, Ce = ["placeholder"], xe = ["disabled", "title"], we = {
6
+ }, _e = ["placeholder"], ke = ["disabled", "title"], ze = {
7
7
  key: 0,
8
8
  class: "w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin"
9
- }, be = {
9
+ }, Ie = {
10
10
  key: 1,
11
11
  class: "w-4 h-4",
12
12
  viewBox: "0 0 24 24",
13
13
  fill: "currentColor"
14
- }, Se = {
14
+ }, Me = {
15
15
  key: 1,
16
16
  class: "flex flex-col items-center gap-3 py-6"
17
- }, Ee = { class: "text-center" }, _e = { class: "text-base font-semibold" }, ke = { class: "text-sm text-gray-500" }, ze = {
17
+ }, De = { class: "text-center" }, He = { class: "text-base font-semibold" }, Ue = { class: "text-sm text-gray-500" }, Re = {
18
18
  key: 2,
19
- class: "flex flex-col items-center gap-4 py-6"
20
- }, He = { class: "text-center space-y-1" }, Ue = { class: "text-xl font-bold" }, Me = { class: "text-2xl font-mono text-green-600 tabular-nums" }, De = {
19
+ class: "flex flex-col items-center gap-3 py-6"
20
+ }, Te = { class: "text-center" }, Le = { class: "text-sm text-gray-500" }, je = { class: "text-base font-semibold" }, Be = {
21
+ key: 0,
22
+ class: "text-sm text-gray-600"
23
+ }, Ne = { class: "flex gap-3" }, Pe = {
21
24
  key: 3,
25
+ class: "flex flex-col items-center gap-4 py-6"
26
+ }, Oe = { class: "text-center space-y-1" }, $e = { class: "text-xl font-bold" }, Ae = { class: "text-2xl font-mono text-green-600 tabular-nums" }, Ve = {
27
+ key: 4,
22
28
  class: "flex flex-col items-center gap-3 py-6"
23
- }, Re = {
29
+ }, Fe = {
24
30
  key: 0,
25
31
  d: "M6.5 5.5 12 11l7-7-1-1-6 6-4.5-4.5H11V3H5v6h1.5V5.5zm17.21 11.17C20.66 13.78 16.54 12 12 12 7.46 12 3.34 13.78.29 16.67c-.18.18-.29.43-.29.71s.11.53.29.71l2.48 2.48c.18.18.43.29.71.29.27 0 .52-.11.7-.28.79-.74 1.69-1.36 2.66-1.85.33-.16.56-.5.56-.9v-3.1c1.45-.48 3-.73 4.6-.73 1.6 0 3.15.25 4.6.72v3.1c0 .39.23.74.56.9.98.49 1.87 1.12 2.67 1.85.18.18.43.28.7.28.28 0 .53-.11.71-.29l2.48-2.48c.18-.18.29-.43.29-.71s-.12-.52-.3-.7z"
26
- }, Ne = {
32
+ }, Ke = {
27
33
  key: 1,
28
34
  d: "M12 9c-1.6 0-3.15.25-4.6.72v3.1c0 .39-.23.74-.56.9-.98.49-1.87 1.12-2.66 1.85-.18.18-.43.28-.7.28-.28 0-.53-.11-.71-.29L.29 13.08a.956.956 0 0 1-.29-.7c0-.28.11-.53.29-.71C3.34 8.78 7.46 7 12 7s8.66 1.78 11.71 4.67c.18.18.29.43.29.71 0 .28-.11.53-.29.71l-2.48 2.48c-.18.18-.43.29-.71.29-.27 0-.52-.11-.7-.28a11.27 11.27 0 0 0-2.67-1.85.996.996 0 0 1-.56-.9v-3.1C15.15 9.25 13.6 9 12 9z"
29
- }, Ie = { class: "text-center" }, Te = { class: "text-base font-semibold" }, Le = {
35
+ }, Je = { class: "text-center" }, We = { class: "text-base font-semibold" }, qe = {
30
36
  key: 0,
31
37
  class: "fixed inset-0 z-50 flex"
32
- }, Pe = {
38
+ }, Ge = {
33
39
  class: "fixed right-0 top-0 h-full w-full max-w-md bg-white shadow-xl",
34
40
  style: { "background-color": "white" }
35
- }, $e = { class: "flex flex-col h-full" }, Be = { class: "flex items-center justify-between p-4 border-b" }, Ve = { class: "text-lg font-semibold" }, je = { class: "text-sm text-gray-500" }, Ae = { class: "flex-1 overflow-y-auto p-4" }, Oe = {
41
+ }, Qe = { class: "flex flex-col h-full" }, Xe = { class: "flex items-center justify-between p-4 border-b" }, Ye = { class: "text-lg font-semibold" }, Ze = { class: "text-sm text-gray-500" }, et = { class: "flex-1 overflow-y-auto p-4" }, tt = {
36
42
  key: 0,
37
43
  class: "text-center py-12 text-gray-500"
38
- }, Ke = {
44
+ }, nt = {
39
45
  key: 1,
40
46
  class: "space-y-2"
41
- }, Fe = {
47
+ }, ot = {
42
48
  key: 2,
43
49
  d: "M6.5 5.5 12 11l7-7-1-1-6 6-4.5-4.5H11V3H5v6h1.5V5.5zm17.21 11.17C20.66 13.78 16.54 12 12 12 7.46 12 3.34 13.78.29 16.67c-.18.18-.29.43-.29.71s.11.53.29.71l2.48 2.48c.18.18.43.29.71.29.27 0 .52-.11.7-.28.79-.74 1.69-1.36 2.66-1.85.33-.16.56-.5.56-.9v-3.1c1.45-.48 3-.73 4.6-.73 1.6 0 3.15.25 4.6.72v3.1c0 .39.23.74.56.9.98.49 1.87 1.12 2.67 1.85.18.18.43.28.7.28.28 0 .53-.11.71-.29l2.48-2.48c.18-.18.29-.43.29-.71s-.12-.52-.3-.7z"
44
- }, Je = { class: "flex-1 min-w-0" }, We = { class: "font-medium text-sm truncate" }, qe = { class: "flex items-center gap-2 text-xs text-gray-500" }, Ge = { class: "font-mono tabular-nums" }, Qe = ["onClick"], tt = /* @__PURE__ */ re({
50
+ }, lt = { class: "flex-1 min-w-0" }, st = { class: "font-medium text-sm truncate" }, at = { class: "flex items-center gap-2 text-xs text-gray-500" }, rt = { class: "font-mono tabular-nums" }, it = ["onClick"], ft = /* @__PURE__ */ fe({
45
51
  __name: "Phone",
46
52
  props: {
47
53
  config: {},
@@ -49,146 +55,186 @@ const ye = {
49
55
  labels: { default: () => ({}) },
50
56
  onCallStart: {},
51
57
  onCallEnd: {},
52
- onStatusChange: {}
58
+ onStatusChange: {},
59
+ onIncomingCall: {}
53
60
  },
54
- emits: ["callStart", "callEnd", "statusChange"],
55
- setup(v, { emit: R }) {
56
- const y = v, C = R;
57
- let c = null, g = null;
58
- function w(s) {
59
- return `${s.websocketUrl}|${s.sipUri}|${s.authorizationUser}`;
61
+ emits: ["callStart", "callEnd", "statusChange", "incomingCall"],
62
+ setup(S, { emit: O }) {
63
+ const c = S, d = O;
64
+ let a = null, B = null;
65
+ function r(l) {
66
+ return `${l.websocketUrl}|${l.sipUri}|${l.authorizationUser}`;
60
67
  }
61
- function d(s) {
62
- const t = w(s);
63
- if (c && g === t)
64
- return c;
65
- if (c && g !== t) {
68
+ function p(l) {
69
+ const t = r(l);
70
+ if (a && B === t)
71
+ return a;
72
+ if (a && B !== t) {
66
73
  try {
67
- c.ua.stop();
74
+ a.ua.stop();
68
75
  } catch {
69
76
  }
70
- c = null;
77
+ a = null;
71
78
  }
72
- g = t;
73
- const E = {
74
- sockets: [new W.WebSocketInterface(s.websocketUrl)],
75
- uri: s.sipUri,
76
- password: s.password,
77
- registrar_server: s.registrarServer,
78
- display_name: s.displayName,
79
- authorization_user: s.authorizationUser,
79
+ B = t;
80
+ const m = {
81
+ sockets: [new oe.WebSocketInterface(l.websocketUrl)],
82
+ uri: l.sipUri,
83
+ password: l.password,
84
+ registrar_server: l.registrarServer,
85
+ display_name: l.displayName,
86
+ authorization_user: l.authorizationUser,
80
87
  connection_recovery_min_interval: 2,
81
88
  connection_recovery_max_interval: 30
82
- }, U = new W.UA(E), Z = document.createElement("audio");
83
- Z.autoplay = !0;
84
- const T = {
85
- ua: U,
86
- audio: Z,
89
+ }, D = new oe.UA(m), V = document.createElement("audio");
90
+ V.autoplay = !0;
91
+ const P = {
92
+ ua: D,
93
+ audio: V,
87
94
  isStarted: !1,
88
95
  listeners: /* @__PURE__ */ new Set()
89
96
  };
90
- return U.on("connecting", () => {
91
- T.listeners.forEach((_) => _.onConnecting?.());
92
- }), U.on("connected", () => {
93
- T.listeners.forEach((_) => _.onConnected?.());
94
- }), U.on("disconnected", () => {
95
- T.listeners.forEach((_) => _.onDisconnected?.());
96
- }), U.on("registered", () => {
97
- T.listeners.forEach((_) => _.onRegistered?.());
98
- }), U.on("unregistered", () => {
99
- T.listeners.forEach((_) => _.onUnregistered?.());
100
- }), U.on("registrationFailed", (_) => {
101
- T.listeners.forEach((P) => P.onRegistrationFailed?.(_?.cause));
102
- }), U.on("newRTCSession", (_) => {
103
- const P = _.session;
104
- P.direction === "outgoing" && (T.listeners.forEach(($) => $.onNewSession?.(P)), P.connection && (P.connection.addEventListener("addstream", ($) => {
105
- if (!$.streams?.length) return;
106
- const O = document.createElement("audio");
107
- O.srcObject = $.streams[0], O.play();
108
- }), P.connection.addEventListener("track", ($) => {
109
- const O = document.createElement("audio");
110
- O.srcObject = $.streams[0], O.play();
111
- })));
112
- }), c = T, T;
97
+ return D.on("connecting", () => {
98
+ P.listeners.forEach((U) => U.onConnecting?.());
99
+ }), D.on("connected", () => {
100
+ P.listeners.forEach((U) => U.onConnected?.());
101
+ }), D.on("disconnected", () => {
102
+ P.listeners.forEach((U) => U.onDisconnected?.());
103
+ }), D.on("registered", () => {
104
+ P.listeners.forEach((U) => U.onRegistered?.());
105
+ }), D.on("unregistered", () => {
106
+ P.listeners.forEach((U) => U.onUnregistered?.());
107
+ }), D.on("registrationFailed", (U) => {
108
+ P.listeners.forEach((T) => T.onRegistrationFailed?.(U?.cause));
109
+ }), D.on("newRTCSession", (U) => {
110
+ const T = U.session;
111
+ if (T.direction === "incoming") {
112
+ const A = T.remote_identity, K = A?.uri?.user || "Unknown", ve = A?.display_name || void 0;
113
+ P.listeners.forEach((q) => q.onIncomingSession?.(T, K, ve)), T.on("peerconnection", () => {
114
+ T.connection.addEventListener("addstream", (q) => {
115
+ if (!q.streams?.length) return;
116
+ const X = document.createElement("audio");
117
+ X.srcObject = q.streams[0], X.play();
118
+ }), T.connection.addEventListener("track", (q) => {
119
+ const X = document.createElement("audio");
120
+ X.srcObject = q.streams[0], X.play();
121
+ });
122
+ });
123
+ return;
124
+ }
125
+ P.listeners.forEach((A) => A.onNewSession?.(T)), T.connection && (T.connection.addEventListener("addstream", (A) => {
126
+ if (!A.streams?.length) return;
127
+ const K = document.createElement("audio");
128
+ K.srcObject = A.streams[0], K.play();
129
+ }), T.connection.addEventListener("track", (A) => {
130
+ const K = document.createElement("audio");
131
+ K.srcObject = A.streams[0], K.play();
132
+ }));
133
+ }), a = P, P;
113
134
  }
114
- const o = p("disconnected"), r = p(""), i = p([]), b = p(0), u = p(!1), x = p("connecting"), S = p(!1);
115
- let l = null, z = null, M = null, H = null, N = null;
116
- const n = ee(() => ({ ...me, ...y.labels })), L = ee(() => {
117
- switch (o.value) {
135
+ const n = b("disconnected"), u = b(""), f = b([]), _ = b(0), i = b(!1), g = b("connecting"), k = b(!1), o = b(null);
136
+ let h = null, M = null, x = null, H = null, E = null;
137
+ const z = ie(() => ({ ...be, ...c.labels })), Y = ie(() => {
138
+ switch (n.value) {
139
+ case "ringing":
140
+ return { text: z.value.incomingCall, color: "text-blue-500", icon: "ring" };
118
141
  case "progress":
119
- return { text: `${n.value.calling}...`, color: "text-yellow-500", icon: "ring" };
142
+ return { text: `${z.value.calling}...`, color: "text-yellow-500", icon: "ring" };
120
143
  case "confirmed":
121
- return { text: `${n.value.inCall} - ${G(b.value)}`, color: "text-green-500", icon: "inTalk" };
144
+ return { text: `${z.value.inCall} - ${le(_.value)}`, color: "text-green-500", icon: "inTalk" };
122
145
  case "failed":
123
- return { text: n.value.callEnded, color: "text-red-500", icon: "missed" };
146
+ return { text: z.value.callEnded, color: "text-red-500", icon: "missed" };
124
147
  case "ended":
125
- return { text: n.value.callEnded, color: "text-gray-500", icon: "hangup" };
148
+ return { text: z.value.callEnded, color: "text-gray-500", icon: "hangup" };
126
149
  default:
127
- return { text: n.value.inactive, color: "text-gray-300", icon: "phone" };
150
+ return { text: z.value.inactive, color: "text-gray-300", icon: "phone" };
128
151
  }
129
152
  });
130
- function I(s, t, a) {
131
- const E = {
153
+ function N(l, t, s) {
154
+ const m = {
132
155
  id: Date.now().toString(),
133
- number: s,
156
+ number: l,
134
157
  timestamp: Date.now(),
135
158
  duration: t,
136
- status: a
159
+ status: s
137
160
  };
138
- i.value = [E, ...i.value].slice(0, 50), localStorage.setItem("tbi-phone-call-history", JSON.stringify(i.value));
161
+ f.value = [m, ...f.value].slice(0, 50), localStorage.setItem("tbi-phone-call-history", JSON.stringify(f.value));
139
162
  }
140
- function h() {
141
- z && (z.terminate(), z = null);
163
+ function C() {
164
+ M && (M.terminate(), M = null), o.value = null;
142
165
  }
143
- function A(s) {
144
- if (!s.trim() || !l) return;
145
- if (!u.value) {
166
+ function R() {
167
+ if (!o.value) return;
168
+ const { session: l, callerNumber: t } = o.value, s = {
169
+ mediaConstraints: { audio: !0, video: !1 }
170
+ };
171
+ try {
172
+ l.answer(s), M = l, c.onCallStart?.(t), d("callStart", t);
173
+ } catch (m) {
174
+ console.error("Failed to answer call:", m), n.value = "failed", c.onStatusChange?.("failed"), d("statusChange", "failed"), N(t, 0, "missed"), o.value = null, setTimeout(() => {
175
+ n.value = "disconnected", c.onStatusChange?.("disconnected"), d("statusChange", "disconnected");
176
+ }, 3e3);
177
+ }
178
+ }
179
+ function L() {
180
+ if (!o.value) return;
181
+ const { session: l, callerNumber: t } = o.value;
182
+ try {
183
+ l.terminate({ status_code: 603, reason_phrase: "Decline" });
184
+ } catch (s) {
185
+ console.error("Failed to reject call:", s);
186
+ }
187
+ N(t, 0, "missed"), o.value = null, n.value = "disconnected", c.onStatusChange?.("disconnected"), d("statusChange", "disconnected");
188
+ }
189
+ function v(l) {
190
+ if (!l.trim() || !h) return;
191
+ if (!i.value) {
146
192
  console.warn("Phone is not ready yet. Please wait for registration.");
147
193
  return;
148
194
  }
149
- r.value = s, y.onCallStart?.(s), C("callStart", s);
150
- const a = {
195
+ u.value = l, c.onCallStart?.(l), d("callStart", l);
196
+ const s = {
151
197
  eventHandlers: {
152
198
  progress: () => {
153
- o.value = "progress", y.onStatusChange?.("progress"), C("statusChange", "progress");
199
+ n.value = "progress", c.onStatusChange?.("progress"), d("statusChange", "progress");
154
200
  },
155
- failed: (E) => {
156
- console.error("Call failed:", E?.cause), o.value = "failed", y.onStatusChange?.("failed"), C("statusChange", "failed"), I(s, 0, "failed"), y.onCallEnd?.(s, 0, "failed"), C("callEnd", s, 0, "failed"), z = null, setTimeout(() => {
157
- o.value = "disconnected", y.onStatusChange?.("disconnected"), C("statusChange", "disconnected");
201
+ failed: (m) => {
202
+ console.error("Call failed:", m?.cause), n.value = "failed", c.onStatusChange?.("failed"), d("statusChange", "failed"), N(l, 0, "failed"), c.onCallEnd?.(l, 0, "failed"), d("callEnd", l, 0, "failed"), M = null, setTimeout(() => {
203
+ n.value = "disconnected", c.onStatusChange?.("disconnected"), d("statusChange", "disconnected");
158
204
  }, 3e3);
159
205
  },
160
206
  ended: () => {
161
- o.value = "ended", y.onStatusChange?.("ended"), C("statusChange", "ended");
162
- const E = M ? Math.floor((Date.now() - M) / 1e3) : 0;
163
- I(s, E, "completed"), y.onCallEnd?.(s, E, "completed"), C("callEnd", s, E, "completed"), z = null, H && (clearInterval(H), H = null), setTimeout(() => {
164
- o.value = "disconnected", y.onStatusChange?.("disconnected"), C("statusChange", "disconnected"), M = null, b.value = 0;
207
+ n.value = "ended", c.onStatusChange?.("ended"), d("statusChange", "ended");
208
+ const m = x ? Math.floor((Date.now() - x) / 1e3) : 0;
209
+ N(l, m, "completed"), c.onCallEnd?.(l, m, "completed"), d("callEnd", l, m, "completed"), M = null, H && (clearInterval(H), H = null), setTimeout(() => {
210
+ n.value = "disconnected", c.onStatusChange?.("disconnected"), d("statusChange", "disconnected"), x = null, _.value = 0;
165
211
  }, 2e3);
166
212
  },
167
213
  confirmed: () => {
168
- o.value = "confirmed", y.onStatusChange?.("confirmed"), C("statusChange", "confirmed"), M = Date.now(), H = setInterval(() => {
169
- M && (b.value = Math.floor((Date.now() - M) / 1e3));
214
+ n.value = "confirmed", c.onStatusChange?.("confirmed"), d("statusChange", "confirmed"), x = Date.now(), H = setInterval(() => {
215
+ x && (_.value = Math.floor((Date.now() - x) / 1e3));
170
216
  }, 1e3);
171
217
  }
172
218
  },
173
219
  mediaConstraints: { audio: !0, video: !1 }
174
220
  };
175
- o.value = "progress", y.onStatusChange?.("progress"), C("statusChange", "progress");
221
+ n.value = "progress", c.onStatusChange?.("progress"), d("statusChange", "progress");
176
222
  try {
177
- z = l.ua.call(s, a);
178
- } catch (E) {
179
- console.error("Failed to start call:", E), o.value = "failed", y.onStatusChange?.("failed"), C("statusChange", "failed"), I(s, 0, "failed"), setTimeout(() => {
180
- o.value = "disconnected", y.onStatusChange?.("disconnected"), C("statusChange", "disconnected");
223
+ M = h.ua.call(l, s);
224
+ } catch (m) {
225
+ console.error("Failed to start call:", m), n.value = "failed", c.onStatusChange?.("failed"), d("statusChange", "failed"), N(l, 0, "failed"), setTimeout(() => {
226
+ n.value = "disconnected", c.onStatusChange?.("disconnected"), d("statusChange", "disconnected");
181
227
  }, 3e3);
182
228
  }
183
229
  }
184
- function q(s) {
185
- s.key === "Enter" && A(r.value);
230
+ function $(l) {
231
+ l.key === "Enter" && v(u.value);
186
232
  }
187
- function se(s) {
188
- r.value = s.number, S.value = !1, A(s.number);
233
+ function J(l) {
234
+ u.value = l.number, k.value = !1, v(l.number);
189
235
  }
190
- function oe(s) {
191
- switch (s) {
236
+ function W(l) {
237
+ switch (l) {
192
238
  case "completed":
193
239
  return "bg-green-100";
194
240
  case "failed":
@@ -197,8 +243,8 @@ const ye = {
197
243
  return "bg-yellow-100";
198
244
  }
199
245
  }
200
- function le(s) {
201
- switch (s) {
246
+ function de(l) {
247
+ switch (l) {
202
248
  case "completed":
203
249
  return "text-green-600";
204
250
  case "failed":
@@ -207,58 +253,79 @@ const ye = {
207
253
  return "text-yellow-600";
208
254
  }
209
255
  }
210
- function ae(s) {
211
- return new Date(s).toLocaleString("es-ES", {
256
+ function ue(l) {
257
+ return new Date(l).toLocaleString("es-ES", {
212
258
  day: "2-digit",
213
259
  month: "2-digit",
214
260
  hour: "2-digit",
215
261
  minute: "2-digit"
216
262
  });
217
263
  }
218
- return X(() => {
219
- l = d(y.config), l.ua.isRegistered() ? (u.value = !0, x.value = "connected") : l.ua.isConnected() && (x.value = "connected"), N = {
264
+ return ae(() => {
265
+ h = p(c.config), h.ua.isRegistered() ? (i.value = !0, g.value = "connected") : h.ua.isConnected() && (g.value = "connected"), E = {
220
266
  onConnecting: () => {
221
- x.value = "connecting";
267
+ g.value = "connecting";
222
268
  },
223
269
  onConnected: () => {
224
- x.value = "connected";
270
+ g.value = "connected";
225
271
  },
226
272
  onDisconnected: () => {
227
- x.value = "disconnected", u.value = !1;
273
+ g.value = "disconnected", i.value = !1;
228
274
  },
229
275
  onRegistered: () => {
230
- u.value = !0, x.value = "connected";
276
+ i.value = !0, g.value = "connected";
231
277
  },
232
278
  onUnregistered: () => {
233
- u.value = !1;
279
+ i.value = !1;
234
280
  },
235
- onRegistrationFailed: (a) => {
236
- console.error("Registration failed:", a), u.value = !1, x.value = "failed";
281
+ onRegistrationFailed: (s) => {
282
+ console.error("Registration failed:", s), i.value = !1, g.value = "failed";
237
283
  },
238
- onNewSession: (a) => {
239
- z = a;
284
+ onNewSession: (s) => {
285
+ M = s;
286
+ },
287
+ onIncomingSession: (s, m, D) => {
288
+ if (M) {
289
+ s.terminate({ status_code: 486, reason_phrase: "Busy Here" });
290
+ return;
291
+ }
292
+ o.value = { session: s, callerNumber: m, callerName: D }, u.value = m, n.value = "ringing", c.onStatusChange?.("ringing"), d("statusChange", "ringing"), c.onIncomingCall?.(m, D), d("incomingCall", m, D), s.on("failed", (V) => {
293
+ console.error("Incoming call failed:", V?.cause), n.value = "failed", c.onStatusChange?.("failed"), d("statusChange", "failed"), N(m, 0, "missed"), o.value = null, M = null, setTimeout(() => {
294
+ n.value = "disconnected", c.onStatusChange?.("disconnected"), d("statusChange", "disconnected");
295
+ }, 3e3);
296
+ }), s.on("ended", () => {
297
+ n.value = "ended", c.onStatusChange?.("ended"), d("statusChange", "ended");
298
+ const V = x ? Math.floor((Date.now() - x) / 1e3) : 0;
299
+ N(m, V, "completed"), c.onCallEnd?.(m, V, "completed"), d("callEnd", m, V, "completed"), o.value = null, M = null, H && (clearInterval(H), H = null), setTimeout(() => {
300
+ n.value = "disconnected", c.onStatusChange?.("disconnected"), d("statusChange", "disconnected"), x = null, _.value = 0;
301
+ }, 2e3);
302
+ }), s.on("confirmed", () => {
303
+ n.value = "confirmed", c.onStatusChange?.("confirmed"), d("statusChange", "confirmed"), x = Date.now(), o.value = null, H = setInterval(() => {
304
+ x && (_.value = Math.floor((Date.now() - x) / 1e3));
305
+ }, 1e3);
306
+ });
240
307
  }
241
- }, l.listeners.add(N), l.isStarted || (l.ua.start(), l.isStarted = !0);
242
- const s = localStorage.getItem("tbi-phone-call-history");
243
- if (s)
308
+ }, h.listeners.add(E), h.isStarted || (h.ua.start(), h.isStarted = !0);
309
+ const l = localStorage.getItem("tbi-phone-call-history");
310
+ if (l)
244
311
  try {
245
- i.value = JSON.parse(s);
246
- } catch (a) {
247
- console.error("Error loading call history", a);
312
+ f.value = JSON.parse(l);
313
+ } catch (s) {
314
+ console.error("Error loading call history", s);
248
315
  }
249
- const t = (a) => {
250
- const U = a.detail.number;
251
- o.value === "disconnected" && A(U);
316
+ const t = (s) => {
317
+ const D = s.detail.number;
318
+ n.value === "disconnected" && v(D);
252
319
  };
253
320
  window.addEventListener("StartCallEvent", t);
254
- }), Y(() => {
255
- H && clearInterval(H), l && N && l.listeners.delete(N);
256
- }), (s, t) => (f(), m("div", {
257
- class: K(B(J)("tbi-phone w-full max-w-md mx-auto bg-white rounded-2xl shadow-lg border border-gray-200 p-2", v.className))
321
+ }), re(() => {
322
+ H && clearInterval(H), h && E && h.listeners.delete(E);
323
+ }), (l, t) => (y(), w("div", {
324
+ class: Z(G(ne)("tbi-phone w-full max-w-md mx-auto bg-white rounded-2xl shadow-lg border border-gray-200 p-2", S.className))
258
325
  }, [
259
- o.value === "disconnected" ? (f(), m("div", ye, [
326
+ n.value === "disconnected" ? (y(), w("div", Ee, [
260
327
  e("button", {
261
- onClick: t[0] || (t[0] = (a) => S.value = !0),
328
+ onClick: t[0] || (t[0] = (s) => k.value = !0),
262
329
  class: "h-8 w-8 flex items-center justify-center rounded-xl border border-gray-200 hover:bg-gray-50 transition-colors",
263
330
  type: "button"
264
331
  }, [...t[5] || (t[5] = [
@@ -270,28 +337,28 @@ const ye = {
270
337
  e("path", { d: "M13 3a9 9 0 0 0-9 9H1l3.89 3.89.07.14L9 12H6c0-3.87 3.13-7 7-7s7 3.13 7 7-3.13 7-7 7c-1.93 0-3.68-.79-4.94-2.06l-1.42 1.42A8.954 8.954 0 0 0 13 21a9 9 0 0 0 0-18zm-1 5v5l4.28 2.54.72-1.21-3.5-2.08V8H12z" })
271
338
  ], -1)
272
339
  ])]),
273
- ce(e("input", {
340
+ me(e("input", {
274
341
  type: "text",
275
- "onUpdate:modelValue": t[1] || (t[1] = (a) => r.value = a),
276
- onKeydown: q,
277
- placeholder: n.value.placeholder,
342
+ "onUpdate:modelValue": t[1] || (t[1] = (s) => u.value = s),
343
+ onKeydown: $,
344
+ placeholder: z.value.placeholder,
278
345
  class: "flex-1 w-full h-8 px-3 rounded-xl border border-gray-200 text-sm focus:outline-none focus:ring-2 focus:ring-green-500 focus:border-transparent"
279
- }, null, 40, Ce), [
280
- [de, r.value]
346
+ }, null, 40, _e), [
347
+ [he, u.value]
281
348
  ]),
282
349
  e("button", {
283
- onClick: t[2] || (t[2] = (a) => A(r.value)),
284
- disabled: r.value.length < 9 || !u.value,
350
+ onClick: t[2] || (t[2] = (s) => v(u.value)),
351
+ disabled: u.value.length < 9 || !i.value,
285
352
  class: "h-8 w-8 flex items-center justify-center rounded-xl bg-green-500 hover:bg-green-600 disabled:bg-gray-300 disabled:cursor-not-allowed text-white transition-colors",
286
353
  type: "button",
287
- title: u.value ? "Call" : "Connecting..."
354
+ title: i.value ? "Call" : "Connecting..."
288
355
  }, [
289
- x.value === "connecting" ? (f(), m("div", we)) : (f(), m("svg", be, [...t[6] || (t[6] = [
356
+ g.value === "connecting" ? (y(), w("div", ze)) : (y(), w("svg", Ie, [...t[6] || (t[6] = [
290
357
  e("path", { d: "M6.62 10.79c1.44 2.83 3.76 5.14 6.59 6.59l2.2-2.2c.27-.27.67-.36 1.02-.24 1.12.37 2.33.57 3.57.57.55 0 1 .45 1 1V20c0 .55-.45 1-1 1-9.39 0-17-7.61-17-17 0-.55.45-1 1-1h3.5c.55 0 1 .45 1 1 0 1.25.2 2.45.57 3.57.11.35.03.74-.25 1.02l-2.2 2.2z" }, null, -1)
291
358
  ])]))
292
- ], 8, xe)
293
- ])) : V("", !0),
294
- o.value === "progress" ? (f(), m("div", Se, [
359
+ ], 8, ke)
360
+ ])) : F("", !0),
361
+ n.value === "progress" ? (y(), w("div", Me, [
295
362
  t[8] || (t[8] = e("div", { class: "relative" }, [
296
363
  e("svg", {
297
364
  class: "w-12 h-12 text-yellow-500 animate-pulse",
@@ -302,12 +369,12 @@ const ye = {
302
369
  ]),
303
370
  e("div", { class: "absolute inset-0 rounded-full border-4 border-yellow-500/30 animate-ping" })
304
371
  ], -1)),
305
- e("div", Ee, [
306
- e("p", _e, k(n.value.calling) + " " + k(r.value), 1),
307
- e("p", ke, k(n.value.waitingResponse), 1)
372
+ e("div", De, [
373
+ e("p", He, I(z.value.calling) + " " + I(u.value), 1),
374
+ e("p", Ue, I(z.value.waitingResponse), 1)
308
375
  ]),
309
376
  e("button", {
310
- onClick: h,
377
+ onClick: C,
311
378
  class: "flex items-center gap-2 px-6 py-2 rounded-full bg-red-500 hover:bg-red-600 text-white text-sm font-medium transition-colors",
312
379
  type: "button"
313
380
  }, [
@@ -318,11 +385,58 @@ const ye = {
318
385
  }, [
319
386
  e("path", { d: "M12 9c-1.6 0-3.15.25-4.6.72v3.1c0 .39-.23.74-.56.9-.98.49-1.87 1.12-2.66 1.85-.18.18-.43.28-.7.28-.28 0-.53-.11-.71-.29L.29 13.08a.956.956 0 0 1-.29-.7c0-.28.11-.53.29-.71C3.34 8.78 7.46 7 12 7s8.66 1.78 11.71 4.67c.18.18.29.43.29.71 0 .28-.11.53-.29.71l-2.48 2.48c-.18.18-.43.29-.71.29-.27 0-.52-.11-.7-.28a11.27 11.27 0 0 0-2.67-1.85.996.996 0 0 1-.56-.9v-3.1C15.15 9.25 13.6 9 12 9z" })
320
387
  ], -1)),
321
- te(" " + k(n.value.cancel), 1)
388
+ ee(" " + I(z.value.cancel), 1)
389
+ ])
390
+ ])) : F("", !0),
391
+ n.value === "ringing" && o.value ? (y(), w("div", Re, [
392
+ t[11] || (t[11] = e("div", { class: "relative" }, [
393
+ e("svg", {
394
+ class: "w-12 h-12 text-blue-500 animate-bounce",
395
+ viewBox: "0 0 24 24",
396
+ fill: "currentColor"
397
+ }, [
398
+ e("path", { d: "M15.05 5A7 7 0 0 1 19 8.95M15.05 1A11 11 0 0 1 23 8.94m-1 7.98v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z" })
399
+ ]),
400
+ e("div", { class: "absolute inset-0 rounded-full border-4 border-blue-500/30 animate-ping" })
401
+ ], -1)),
402
+ e("div", Te, [
403
+ e("p", Le, I(z.value.incomingCall), 1),
404
+ e("p", je, I(o.value.callerNumber), 1),
405
+ o.value.callerName ? (y(), w("p", Be, I(o.value.callerName), 1)) : F("", !0)
406
+ ]),
407
+ e("div", Ne, [
408
+ e("button", {
409
+ onClick: L,
410
+ class: "flex items-center gap-2 px-6 py-2 rounded-full bg-red-500 hover:bg-red-600 text-white text-sm font-medium transition-colors",
411
+ type: "button"
412
+ }, [
413
+ t[9] || (t[9] = e("svg", {
414
+ class: "w-4 h-4",
415
+ viewBox: "0 0 24 24",
416
+ fill: "currentColor"
417
+ }, [
418
+ e("path", { d: "M12 9c-1.6 0-3.15.25-4.6.72v3.1c0 .39-.23.74-.56.9-.98.49-1.87 1.12-2.66 1.85-.18.18-.43.28-.7.28-.28 0-.53-.11-.71-.29L.29 13.08a.956.956 0 0 1-.29-.7c0-.28.11-.53.29-.71C3.34 8.78 7.46 7 12 7s8.66 1.78 11.71 4.67c.18.18.29.43.29.71 0 .28-.11.53-.29.71l-2.48 2.48c-.18.18-.43.29-.71.29-.27 0-.52-.11-.7-.28a11.27 11.27 0 0 0-2.67-1.85.996.996 0 0 1-.56-.9v-3.1C15.15 9.25 13.6 9 12 9z" })
419
+ ], -1)),
420
+ ee(" " + I(z.value.reject), 1)
421
+ ]),
422
+ e("button", {
423
+ onClick: R,
424
+ class: "flex items-center gap-2 px-6 py-2 rounded-full bg-green-500 hover:bg-green-600 text-white text-sm font-medium transition-colors",
425
+ type: "button"
426
+ }, [
427
+ t[10] || (t[10] = e("svg", {
428
+ class: "w-4 h-4",
429
+ viewBox: "0 0 24 24",
430
+ fill: "currentColor"
431
+ }, [
432
+ e("path", { d: "M6.62 10.79c1.44 2.83 3.76 5.14 6.59 6.59l2.2-2.2c.27-.27.67-.36 1.02-.24 1.12.37 2.33.57 3.57.57.55 0 1 .45 1 1V20c0 .55-.45 1-1 1-9.39 0-17-7.61-17-17 0-.55.45-1 1-1h3.5c.55 0 1 .45 1 1 0 1.25.2 2.45.57 3.57.11.35.03.74-.25 1.02l-2.2 2.2z" })
433
+ ], -1)),
434
+ ee(" " + I(z.value.answer), 1)
435
+ ])
322
436
  ])
323
- ])) : V("", !0),
324
- o.value === "confirmed" ? (f(), m("div", ze, [
325
- t[10] || (t[10] = e("div", { class: "relative" }, [
437
+ ])) : F("", !0),
438
+ n.value === "confirmed" ? (y(), w("div", Pe, [
439
+ t[13] || (t[13] = e("div", { class: "relative" }, [
326
440
  e("svg", {
327
441
  class: "w-12 h-12 text-green-500",
328
442
  viewBox: "0 0 24 24",
@@ -332,55 +446,55 @@ const ye = {
332
446
  ]),
333
447
  e("div", { class: "absolute inset-0 rounded-full bg-green-500/20 animate-pulse" })
334
448
  ], -1)),
335
- e("div", He, [
336
- e("p", Ue, k(r.value), 1),
337
- e("p", Me, k(B(G)(b.value)), 1)
449
+ e("div", Oe, [
450
+ e("p", $e, I(u.value), 1),
451
+ e("p", Ae, I(G(le)(_.value)), 1)
338
452
  ]),
339
453
  e("button", {
340
- onClick: h,
454
+ onClick: C,
341
455
  class: "flex items-center gap-2 px-6 py-2 rounded-full bg-red-500 hover:bg-red-600 text-white text-sm font-medium transition-colors",
342
456
  type: "button"
343
457
  }, [
344
- t[9] || (t[9] = e("svg", {
458
+ t[12] || (t[12] = e("svg", {
345
459
  class: "w-4 h-4",
346
460
  viewBox: "0 0 24 24",
347
461
  fill: "currentColor"
348
462
  }, [
349
463
  e("path", { d: "M12 9c-1.6 0-3.15.25-4.6.72v3.1c0 .39-.23.74-.56.9-.98.49-1.87 1.12-2.66 1.85-.18.18-.43.28-.7.28-.28 0-.53-.11-.71-.29L.29 13.08a.956.956 0 0 1-.29-.7c0-.28.11-.53.29-.71C3.34 8.78 7.46 7 12 7s8.66 1.78 11.71 4.67c.18.18.29.43.29.71 0 .28-.11.53-.29.71l-2.48 2.48c-.18.18-.43.29-.71.29-.27 0-.52-.11-.7-.28a11.27 11.27 0 0 0-2.67-1.85.996.996 0 0 1-.56-.9v-3.1C15.15 9.25 13.6 9 12 9z" })
350
464
  ], -1)),
351
- te(" " + k(n.value.hangUp), 1)
465
+ ee(" " + I(z.value.hangUp), 1)
352
466
  ])
353
- ])) : V("", !0),
354
- o.value === "failed" || o.value === "ended" ? (f(), m("div", De, [
355
- (f(), m("svg", {
356
- class: K(B(J)("w-12 h-12", o.value === "failed" ? "text-red-500" : "text-gray-500")),
467
+ ])) : F("", !0),
468
+ n.value === "failed" || n.value === "ended" ? (y(), w("div", Ve, [
469
+ (y(), w("svg", {
470
+ class: Z(G(ne)("w-12 h-12", n.value === "failed" ? "text-red-500" : "text-gray-500")),
357
471
  viewBox: "0 0 24 24",
358
472
  fill: "currentColor"
359
473
  }, [
360
- o.value === "failed" ? (f(), m("path", Re)) : (f(), m("path", Ne))
474
+ n.value === "failed" ? (y(), w("path", Fe)) : (y(), w("path", Ke))
361
475
  ], 2)),
362
- e("div", Ie, [
363
- e("p", Te, k(L.value.text), 1)
476
+ e("div", Je, [
477
+ e("p", We, I(Y.value.text), 1)
364
478
  ])
365
- ])) : V("", !0),
366
- (f(), ie(ue, { to: "body" }, [
367
- S.value ? (f(), m("div", Le, [
479
+ ])) : F("", !0),
480
+ (y(), ge(pe, { to: "body" }, [
481
+ k.value ? (y(), w("div", qe, [
368
482
  e("div", {
369
483
  class: "fixed inset-0 bg-black/50",
370
- onClick: t[3] || (t[3] = (a) => S.value = !1)
484
+ onClick: t[3] || (t[3] = (s) => k.value = !1)
371
485
  }),
372
- e("div", Pe, [
373
- e("div", $e, [
374
- e("div", Be, [
486
+ e("div", Ge, [
487
+ e("div", Qe, [
488
+ e("div", Xe, [
375
489
  e("div", null, [
376
- e("h2", Ve, k(n.value.callHistory), 1),
377
- e("p", je, k(i.value.length === 0 ? n.value.noCallsRegistered : `${i.value.length} ${n.value.callsRegistered}`), 1)
490
+ e("h2", Ye, I(z.value.callHistory), 1),
491
+ e("p", Ze, I(f.value.length === 0 ? z.value.noCallsRegistered : `${f.value.length} ${z.value.callsRegistered}`), 1)
378
492
  ]),
379
493
  e("button", {
380
- onClick: t[4] || (t[4] = (a) => S.value = !1),
494
+ onClick: t[4] || (t[4] = (s) => k.value = !1),
381
495
  class: "h-8 w-8 flex items-center justify-center rounded-lg hover:bg-gray-100 transition-colors",
382
496
  type: "button"
383
- }, [...t[11] || (t[11] = [
497
+ }, [...t[14] || (t[14] = [
384
498
  e("svg", {
385
499
  class: "w-5 h-5",
386
500
  viewBox: "0 0 24 24",
@@ -390,54 +504,54 @@ const ye = {
390
504
  ], -1)
391
505
  ])])
392
506
  ]),
393
- e("div", Ae, [
394
- i.value.length === 0 ? (f(), m("div", Oe, [
395
- t[12] || (t[12] = e("svg", {
507
+ e("div", et, [
508
+ f.value.length === 0 ? (y(), w("div", tt, [
509
+ t[15] || (t[15] = e("svg", {
396
510
  class: "w-12 h-12 mx-auto mb-2 opacity-50",
397
511
  viewBox: "0 0 24 24",
398
512
  fill: "currentColor"
399
513
  }, [
400
514
  e("path", { d: "M12 9c-1.6 0-3.15.25-4.6.72v3.1c0 .39-.23.74-.56.9-.98.49-1.87 1.12-2.66 1.85-.18.18-.43.28-.7.28-.28 0-.53-.11-.71-.29L.29 13.08a.956.956 0 0 1-.29-.7c0-.28.11-.53.29-.71C3.34 8.78 7.46 7 12 7s8.66 1.78 11.71 4.67c.18.18.29.43.29.71 0 .28-.11.53-.29.71l-2.48 2.48c-.18.18-.43.29-.71.29-.27 0-.52-.11-.7-.28a11.27 11.27 0 0 0-2.67-1.85.996.996 0 0 1-.56-.9v-3.1C15.15 9.25 13.6 9 12 9z" })
401
515
  ], -1)),
402
- e("p", null, k(n.value.noCalls), 1)
403
- ])) : (f(), m("div", Ke, [
404
- (f(!0), m(F, null, ve(i.value, (a, E) => (f(), m("div", {
405
- key: a.id,
516
+ e("p", null, I(z.value.noCalls), 1)
517
+ ])) : (y(), w("div", nt, [
518
+ (y(!0), w(te, null, Ce(f.value, (s, m) => (y(), w("div", {
519
+ key: s.id,
406
520
  class: "flex items-center gap-3 p-3 rounded-lg hover:bg-gray-50 transition-colors duration-200",
407
- style: fe({ animationDelay: `${E * 30}ms` })
521
+ style: ye({ animationDelay: `${m * 30}ms` })
408
522
  }, [
409
523
  e("div", {
410
- class: K(B(J)("w-9 h-9 rounded-full flex items-center justify-center shrink-0", oe(a.status)))
524
+ class: Z(G(ne)("w-9 h-9 rounded-full flex items-center justify-center shrink-0", W(s.status)))
411
525
  }, [
412
- (f(), m("svg", {
413
- class: K(B(J)("w-4 h-4", le(a.status))),
526
+ (y(), w("svg", {
527
+ class: Z(G(ne)("w-4 h-4", de(s.status))),
414
528
  viewBox: "0 0 24 24",
415
529
  fill: "currentColor"
416
530
  }, [
417
- a.status === "completed" ? (f(), m(F, { key: 0 }, [
418
- t[13] || (t[13] = e("path", { d: "M6.62 10.79c1.44 2.83 3.76 5.14 6.59 6.59l2.2-2.2c.27-.27.67-.36 1.02-.24 1.12.37 2.33.57 3.57.57.55 0 1 .45 1 1V20c0 .55-.45 1-1 1-9.39 0-17-7.61-17-17 0-.55.45-1 1-1h3.5c.55 0 1 .45 1 1 0 1.25.2 2.45.57 3.57.11.35.03.74-.25 1.02l-2.2 2.2z" }, null, -1)),
419
- t[14] || (t[14] = e("path", { d: "M16 3l-5 5-2-2-1.5 1.5L11 11l6.5-6.5z" }, null, -1))
420
- ], 64)) : a.status === "failed" ? (f(), m(F, { key: 1 }, [
421
- t[15] || (t[15] = e("path", { d: "M6.62 10.79c1.44 2.83 3.76 5.14 6.59 6.59l2.2-2.2c.27-.27.67-.36 1.02-.24 1.12.37 2.33.57 3.57.57.55 0 1 .45 1 1V20c0 .55-.45 1-1 1-9.39 0-17-7.61-17-17 0-.55.45-1 1-1h3.5c.55 0 1 .45 1 1 0 1.25.2 2.45.57 3.57.11.35.03.74-.25 1.02l-2.2 2.2z" }, null, -1)),
422
- t[16] || (t[16] = e("path", { d: "M19 6.41L17.59 5 15 7.59 12.41 5 11 6.41 13.59 9 11 11.59 12.41 13 15 10.41 17.59 13 19 11.59 16.41 9z" }, null, -1))
423
- ], 64)) : (f(), m("path", Fe))
531
+ s.status === "completed" ? (y(), w(te, { key: 0 }, [
532
+ t[16] || (t[16] = e("path", { d: "M6.62 10.79c1.44 2.83 3.76 5.14 6.59 6.59l2.2-2.2c.27-.27.67-.36 1.02-.24 1.12.37 2.33.57 3.57.57.55 0 1 .45 1 1V20c0 .55-.45 1-1 1-9.39 0-17-7.61-17-17 0-.55.45-1 1-1h3.5c.55 0 1 .45 1 1 0 1.25.2 2.45.57 3.57.11.35.03.74-.25 1.02l-2.2 2.2z" }, null, -1)),
533
+ t[17] || (t[17] = e("path", { d: "M16 3l-5 5-2-2-1.5 1.5L11 11l6.5-6.5z" }, null, -1))
534
+ ], 64)) : s.status === "failed" ? (y(), w(te, { key: 1 }, [
535
+ t[18] || (t[18] = e("path", { d: "M6.62 10.79c1.44 2.83 3.76 5.14 6.59 6.59l2.2-2.2c.27-.27.67-.36 1.02-.24 1.12.37 2.33.57 3.57.57.55 0 1 .45 1 1V20c0 .55-.45 1-1 1-9.39 0-17-7.61-17-17 0-.55.45-1 1-1h3.5c.55 0 1 .45 1 1 0 1.25.2 2.45.57 3.57.11.35.03.74-.25 1.02l-2.2 2.2z" }, null, -1)),
536
+ t[19] || (t[19] = e("path", { d: "M19 6.41L17.59 5 15 7.59 12.41 5 11 6.41 13.59 9 11 11.59 12.41 13 15 10.41 17.59 13 19 11.59 16.41 9z" }, null, -1))
537
+ ], 64)) : (y(), w("path", ot))
424
538
  ], 2))
425
539
  ], 2),
426
- e("div", Je, [
427
- e("p", We, k(a.number), 1),
428
- e("div", qe, [
429
- e("span", null, k(ae(a.timestamp)), 1),
430
- a.duration > 0 ? (f(), m(F, { key: 0 }, [
431
- t[17] || (t[17] = e("span", null, "•", -1)),
432
- e("span", Ge, k(B(G)(a.duration)), 1)
433
- ], 64)) : V("", !0)
540
+ e("div", lt, [
541
+ e("p", st, I(s.number), 1),
542
+ e("div", at, [
543
+ e("span", null, I(ue(s.timestamp)), 1),
544
+ s.duration > 0 ? (y(), w(te, { key: 0 }, [
545
+ t[20] || (t[20] = e("span", null, "•", -1)),
546
+ e("span", rt, I(G(le)(s.duration)), 1)
547
+ ], 64)) : F("", !0)
434
548
  ])
435
549
  ]),
436
550
  e("button", {
437
- onClick: (U) => se(a),
551
+ onClick: (D) => J(s),
438
552
  class: "h-8 w-8 flex items-center justify-center shrink-0 rounded-lg hover:bg-gray-100 transition-colors",
439
553
  type: "button"
440
- }, [...t[18] || (t[18] = [
554
+ }, [...t[21] || (t[21] = [
441
555
  e("svg", {
442
556
  class: "w-4 h-4",
443
557
  viewBox: "0 0 24 24",
@@ -445,262 +559,321 @@ const ye = {
445
559
  }, [
446
560
  e("path", { d: "M6.62 10.79c1.44 2.83 3.76 5.14 6.59 6.59l2.2-2.2c.27-.27.67-.36 1.02-.24 1.12.37 2.33.57 3.57.57.55 0 1 .45 1 1V20c0 .55-.45 1-1 1-9.39 0-17-7.61-17-17 0-.55.45-1 1-1h3.5c.55 0 1 .45 1 1 0 1.25.2 2.45.57 3.57.11.35.03.74-.25 1.02l-2.2 2.2z" })
447
561
  ], -1)
448
- ])], 8, Qe)
562
+ ])], 8, it)
449
563
  ], 4))), 128))
450
564
  ]))
451
565
  ])
452
566
  ])
453
567
  ])
454
- ])) : V("", !0)
568
+ ])) : F("", !0)
455
569
  ]))
456
570
  ], 2));
457
571
  }
458
- }), ne = /* @__PURE__ */ Symbol("Phone");
459
- let j = null, Q = null;
460
- function Xe(v) {
461
- return `${v.websocketUrl}|${v.sipUri}|${v.authorizationUser}`;
572
+ }), ce = /* @__PURE__ */ Symbol("Phone");
573
+ let Q = null, se = null;
574
+ function ct(S) {
575
+ return `${S.websocketUrl}|${S.sipUri}|${S.authorizationUser}`;
462
576
  }
463
- function Ye(v) {
464
- const R = Xe(v);
465
- if (j && Q === R)
466
- return j;
467
- if (j && Q !== R) {
577
+ function dt(S) {
578
+ const O = ct(S);
579
+ if (Q && se === O)
580
+ return Q;
581
+ if (Q && se !== O) {
468
582
  try {
469
- j.ua.stop();
583
+ Q.ua.stop();
470
584
  } catch {
471
585
  }
472
- j = null;
586
+ Q = null;
473
587
  }
474
- Q = R;
475
- const C = {
476
- sockets: [new W.WebSocketInterface(v.websocketUrl)],
477
- uri: v.sipUri,
478
- password: v.password,
479
- registrar_server: v.registrarServer,
480
- display_name: v.displayName,
481
- authorization_user: v.authorizationUser,
588
+ se = O;
589
+ const d = {
590
+ sockets: [new oe.WebSocketInterface(S.websocketUrl)],
591
+ uri: S.sipUri,
592
+ password: S.password,
593
+ registrar_server: S.registrarServer,
594
+ display_name: S.displayName,
595
+ authorization_user: S.authorizationUser,
482
596
  connection_recovery_min_interval: 2,
483
597
  connection_recovery_max_interval: 30
484
- }, c = new W.UA(C), g = document.createElement("audio");
485
- g.autoplay = !0;
486
- const w = {
487
- ua: c,
488
- audio: g,
598
+ }, a = new oe.UA(d), B = document.createElement("audio");
599
+ B.autoplay = !0;
600
+ const r = {
601
+ ua: a,
602
+ audio: B,
489
603
  isStarted: !1,
490
604
  listeners: /* @__PURE__ */ new Set()
491
605
  };
492
- return c.on("connecting", () => {
493
- w.listeners.forEach((d) => d.onConnecting?.());
494
- }), c.on("connected", () => {
495
- w.listeners.forEach((d) => d.onConnected?.());
496
- }), c.on("disconnected", () => {
497
- w.listeners.forEach((d) => d.onDisconnected?.());
498
- }), c.on("registered", () => {
499
- w.listeners.forEach((d) => d.onRegistered?.());
500
- }), c.on("unregistered", () => {
501
- w.listeners.forEach((d) => d.onUnregistered?.());
502
- }), c.on("registrationFailed", (d) => {
503
- w.listeners.forEach((o) => o.onRegistrationFailed?.(d?.cause));
504
- }), c.on("newRTCSession", (d) => {
505
- const o = d.session;
506
- o.direction === "outgoing" && (w.listeners.forEach((r) => r.onNewSession?.(o)), o.connection && (o.connection.addEventListener("addstream", (r) => {
507
- if (!r.streams?.length) return;
508
- const i = document.createElement("audio");
509
- i.srcObject = r.streams[0], i.play();
510
- }), o.connection.addEventListener("track", (r) => {
511
- const i = document.createElement("audio");
512
- i.srcObject = r.streams[0], i.play();
513
- })));
514
- }), j = w, w;
606
+ return a.on("connecting", () => {
607
+ r.listeners.forEach((p) => p.onConnecting?.());
608
+ }), a.on("connected", () => {
609
+ r.listeners.forEach((p) => p.onConnected?.());
610
+ }), a.on("disconnected", () => {
611
+ r.listeners.forEach((p) => p.onDisconnected?.());
612
+ }), a.on("registered", () => {
613
+ r.listeners.forEach((p) => p.onRegistered?.());
614
+ }), a.on("unregistered", () => {
615
+ r.listeners.forEach((p) => p.onUnregistered?.());
616
+ }), a.on("registrationFailed", (p) => {
617
+ r.listeners.forEach((n) => n.onRegistrationFailed?.(p?.cause));
618
+ }), a.on("newRTCSession", (p) => {
619
+ const n = p.session;
620
+ if (n.direction === "incoming") {
621
+ const u = n.remote_identity, f = u?.uri?.user || "Unknown", _ = u?.display_name || void 0;
622
+ r.listeners.forEach((i) => i.onIncomingSession?.(n, f, _)), n.on("peerconnection", () => {
623
+ n.connection.addEventListener("addstream", (i) => {
624
+ if (!i.streams?.length) return;
625
+ const g = document.createElement("audio");
626
+ g.srcObject = i.streams[0], g.play();
627
+ }), n.connection.addEventListener("track", (i) => {
628
+ const g = document.createElement("audio");
629
+ g.srcObject = i.streams[0], g.play();
630
+ });
631
+ });
632
+ return;
633
+ }
634
+ r.listeners.forEach((u) => u.onNewSession?.(n)), n.connection && (n.connection.addEventListener("addstream", (u) => {
635
+ if (!u.streams?.length) return;
636
+ const f = document.createElement("audio");
637
+ f.srcObject = u.streams[0], f.play();
638
+ }), n.connection.addEventListener("track", (u) => {
639
+ const f = document.createElement("audio");
640
+ f.srcObject = u.streams[0], f.play();
641
+ }));
642
+ }), Q = r, r;
515
643
  }
516
- function nt(v) {
517
- const { config: R, onCallStart: y, onCallEnd: C, onStatusChange: c } = v, g = p("disconnected"), w = p(""), d = p([]), o = p(0), r = p(!1), i = p("connecting");
518
- let b = null, u = null, x = null, S = null;
519
- const l = (n) => {
520
- w.value = n;
521
- }, z = (n, L, I) => {
522
- const h = {
644
+ function gt(S) {
645
+ const { config: O, onCallStart: c, onCallEnd: d, onStatusChange: a, onIncomingCall: B } = S, r = b("disconnected"), p = b(""), n = b([]), u = b(0), f = b(!1), _ = b("connecting"), i = b(null);
646
+ let g = null, k = null, o = null, h = null;
647
+ const M = (C) => {
648
+ p.value = C;
649
+ }, x = (C, R, L) => {
650
+ const v = {
523
651
  id: Date.now().toString(),
524
- number: n,
652
+ number: C,
525
653
  timestamp: Date.now(),
526
- duration: L,
527
- status: I
654
+ duration: R,
655
+ status: L
528
656
  };
529
- d.value = [h, ...d.value].slice(0, 50), localStorage.setItem("tbi-phone-call-history", JSON.stringify(d.value));
530
- }, M = () => {
531
- u && (u.terminate(), u = null);
532
- }, H = (n) => {
533
- if (!n.trim() || !b) return;
534
- if (!r.value) {
657
+ n.value = [v, ...n.value].slice(0, 50), localStorage.setItem("tbi-phone-call-history", JSON.stringify(n.value));
658
+ }, H = () => {
659
+ k && (k.terminate(), k = null), i.value = null;
660
+ }, E = () => {
661
+ if (!i.value) return;
662
+ const { session: C, callerNumber: R } = i.value, L = {
663
+ mediaConstraints: { audio: !0, video: !1 }
664
+ };
665
+ try {
666
+ C.answer(L), k = C, c?.(R);
667
+ } catch (v) {
668
+ console.error("Failed to answer call:", v), r.value = "failed", a?.("failed"), x(R, 0, "missed"), i.value = null, setTimeout(() => {
669
+ r.value = "disconnected", a?.("disconnected");
670
+ }, 3e3);
671
+ }
672
+ }, z = () => {
673
+ if (!i.value) return;
674
+ const { session: C, callerNumber: R } = i.value;
675
+ try {
676
+ C.terminate({ status_code: 603, reason_phrase: "Decline" });
677
+ } catch (L) {
678
+ console.error("Failed to reject call:", L);
679
+ }
680
+ x(R, 0, "missed"), i.value = null, r.value = "disconnected", a?.("disconnected");
681
+ }, Y = (C) => {
682
+ if (!C.trim() || !g) return;
683
+ if (!f.value) {
535
684
  console.warn("Phone is not ready yet. Please wait for registration.");
536
685
  return;
537
686
  }
538
- w.value = n, y?.(n);
539
- const I = {
687
+ p.value = C, c?.(C);
688
+ const L = {
540
689
  eventHandlers: {
541
690
  progress: () => {
542
- g.value = "progress", c?.("progress");
691
+ r.value = "progress", a?.("progress");
543
692
  },
544
- failed: (h) => {
545
- console.error("Call failed:", h?.cause), g.value = "failed", c?.("failed"), z(n, 0, "failed"), C?.(n, 0, "failed"), u = null, setTimeout(() => {
546
- g.value = "disconnected", c?.("disconnected");
693
+ failed: (v) => {
694
+ console.error("Call failed:", v?.cause), r.value = "failed", a?.("failed"), x(C, 0, "failed"), d?.(C, 0, "failed"), k = null, setTimeout(() => {
695
+ r.value = "disconnected", a?.("disconnected");
547
696
  }, 3e3);
548
697
  },
549
698
  ended: () => {
550
- g.value = "ended", c?.("ended");
551
- const h = x ? Math.floor((Date.now() - x) / 1e3) : 0;
552
- z(n, h, "completed"), C?.(n, h, "completed"), u = null, S && (clearInterval(S), S = null), setTimeout(() => {
553
- g.value = "disconnected", c?.("disconnected"), x = null, o.value = 0;
699
+ r.value = "ended", a?.("ended");
700
+ const v = o ? Math.floor((Date.now() - o) / 1e3) : 0;
701
+ x(C, v, "completed"), d?.(C, v, "completed"), k = null, h && (clearInterval(h), h = null), setTimeout(() => {
702
+ r.value = "disconnected", a?.("disconnected"), o = null, u.value = 0;
554
703
  }, 2e3);
555
704
  },
556
705
  confirmed: () => {
557
- g.value = "confirmed", c?.("confirmed"), x = Date.now(), S = setInterval(() => {
558
- x && (o.value = Math.floor((Date.now() - x) / 1e3));
706
+ r.value = "confirmed", a?.("confirmed"), o = Date.now(), h = setInterval(() => {
707
+ o && (u.value = Math.floor((Date.now() - o) / 1e3));
559
708
  }, 1e3);
560
709
  }
561
710
  },
562
711
  mediaConstraints: { audio: !0, video: !1 }
563
712
  };
564
- g.value = "progress", c?.("progress");
713
+ r.value = "progress", a?.("progress");
565
714
  try {
566
- u = b.ua.call(n, I);
567
- } catch (h) {
568
- console.error("Failed to start call:", h), g.value = "failed", c?.("failed"), z(n, 0, "failed"), setTimeout(() => {
569
- g.value = "disconnected", c?.("disconnected");
715
+ k = g.ua.call(C, L);
716
+ } catch (v) {
717
+ console.error("Failed to start call:", v), r.value = "failed", a?.("failed"), x(C, 0, "failed"), setTimeout(() => {
718
+ r.value = "disconnected", a?.("disconnected");
570
719
  }, 3e3);
571
720
  }
572
721
  };
573
- X(() => {
574
- b = Ye(R), b.ua.isRegistered() ? (r.value = !0, i.value = "connected") : b.ua.isConnected() && (i.value = "connected");
575
- const n = {
722
+ ae(() => {
723
+ g = dt(O), g.ua.isRegistered() ? (f.value = !0, _.value = "connected") : g.ua.isConnected() && (_.value = "connected");
724
+ const C = {
576
725
  onConnecting: () => {
577
- i.value = "connecting";
726
+ _.value = "connecting";
578
727
  },
579
728
  onConnected: () => {
580
- i.value = "connected";
729
+ _.value = "connected";
581
730
  },
582
731
  onDisconnected: () => {
583
- i.value = "disconnected", r.value = !1;
732
+ _.value = "disconnected", f.value = !1;
584
733
  },
585
734
  onRegistered: () => {
586
- r.value = !0, i.value = "connected";
735
+ f.value = !0, _.value = "connected";
587
736
  },
588
737
  onUnregistered: () => {
589
- r.value = !1;
738
+ f.value = !1;
739
+ },
740
+ onRegistrationFailed: (v) => {
741
+ console.error("Registration failed:", v), f.value = !1, _.value = "failed";
590
742
  },
591
- onRegistrationFailed: (h) => {
592
- console.error("Registration failed:", h), r.value = !1, i.value = "failed";
743
+ onNewSession: (v) => {
744
+ k = v;
593
745
  },
594
- onNewSession: (h) => {
595
- u = h;
746
+ onIncomingSession: (v, $, J) => {
747
+ if (k) {
748
+ v.terminate({ status_code: 486, reason_phrase: "Busy Here" });
749
+ return;
750
+ }
751
+ i.value = { session: v, callerNumber: $, callerName: J }, p.value = $, r.value = "ringing", a?.("ringing"), B?.($, J), v.on("failed", (W) => {
752
+ console.error("Incoming call failed:", W?.cause), r.value = "failed", a?.("failed"), x($, 0, "missed"), i.value = null, k = null, setTimeout(() => {
753
+ r.value = "disconnected", a?.("disconnected");
754
+ }, 3e3);
755
+ }), v.on("ended", () => {
756
+ r.value = "ended", a?.("ended");
757
+ const W = o ? Math.floor((Date.now() - o) / 1e3) : 0;
758
+ x($, W, "completed"), d?.($, W, "completed"), i.value = null, k = null, h && (clearInterval(h), h = null), setTimeout(() => {
759
+ r.value = "disconnected", a?.("disconnected"), o = null, u.value = 0;
760
+ }, 2e3);
761
+ }), v.on("confirmed", () => {
762
+ r.value = "confirmed", a?.("confirmed"), o = Date.now(), i.value = null, h = setInterval(() => {
763
+ o && (u.value = Math.floor((Date.now() - o) / 1e3));
764
+ }, 1e3);
765
+ });
596
766
  }
597
767
  };
598
- b.listeners.add(n), b.isStarted || (b.ua.start(), b.isStarted = !0);
599
- const L = localStorage.getItem("tbi-phone-call-history");
600
- if (L)
768
+ g.listeners.add(C), g.isStarted || (g.ua.start(), g.isStarted = !0);
769
+ const R = localStorage.getItem("tbi-phone-call-history");
770
+ if (R)
601
771
  try {
602
- d.value = JSON.parse(L);
603
- } catch (h) {
604
- console.error("Error loading call history", h);
772
+ n.value = JSON.parse(R);
773
+ } catch (v) {
774
+ console.error("Error loading call history", v);
605
775
  }
606
- const I = (h) => {
607
- const q = h.detail.number;
608
- g.value === "disconnected" && H(q);
776
+ const L = (v) => {
777
+ const J = v.detail.number;
778
+ r.value === "disconnected" && Y(J);
609
779
  };
610
- window.addEventListener("StartCallEvent", I);
611
- }), Y(() => {
612
- S && clearInterval(S);
780
+ window.addEventListener("StartCallEvent", L);
781
+ }), re(() => {
782
+ h && clearInterval(h);
613
783
  });
614
784
  const N = {
615
- status: D(g),
616
- callNumber: w,
617
- setCallNumber: l,
618
- callHistory: D(d),
619
- currentCallDuration: D(o),
620
- startCall: H,
621
- endCall: M,
622
- isReady: D(r),
623
- connectionStatus: D(i)
785
+ status: j(r),
786
+ callNumber: p,
787
+ setCallNumber: M,
788
+ callHistory: j(n),
789
+ currentCallDuration: j(u),
790
+ startCall: Y,
791
+ endCall: H,
792
+ answerCall: E,
793
+ rejectCall: z,
794
+ isReady: j(f),
795
+ connectionStatus: j(_),
796
+ incomingCall: j(i)
624
797
  };
625
- return ge(ne, N), N;
798
+ return xe(ce, N), N;
626
799
  }
627
- function st() {
628
- const v = he(ne);
629
- if (!v)
800
+ function mt() {
801
+ const S = we(ce);
802
+ if (!S)
630
803
  throw new Error("usePhone must be used within a component that has called usePhoneProvider");
631
- return v;
804
+ return S;
632
805
  }
633
- function ot(v, R = {}) {
806
+ function ht(S, O = {}) {
634
807
  const {
635
- onCallStart: y,
636
- onCallEnd: C,
637
- onStatusChange: c,
638
- onConnectionChange: g,
639
- persistHistory: w = !0,
640
- historyKey: d = "tbi-phone-call-history"
641
- } = R, o = p("disconnected"), r = p(""), i = p([]), b = p(0), u = p(!1), x = p("connecting"), S = p(null);
642
- let l = null;
643
- X(() => {
644
- l = new pe(
645
- v,
808
+ onCallStart: c,
809
+ onCallEnd: d,
810
+ onStatusChange: a,
811
+ onConnectionChange: B,
812
+ persistHistory: r = !0,
813
+ historyKey: p = "tbi-phone-call-history"
814
+ } = O, n = b("disconnected"), u = b(""), f = b([]), _ = b(0), i = b(!1), g = b("connecting"), k = b(null);
815
+ let o = null;
816
+ ae(() => {
817
+ o = new Se(
818
+ S,
646
819
  {
647
- onStatusChange: (n) => {
648
- o.value = n, c?.(n);
820
+ onStatusChange: (E) => {
821
+ n.value = E, a?.(E);
649
822
  },
650
- onConnectionChange: (n) => {
651
- x.value = n, l && (u.value = l.state.isReady), g?.(n);
823
+ onConnectionChange: (E) => {
824
+ g.value = E, o && (i.value = o.state.isReady), B?.(E);
652
825
  },
653
- onCallStart: y,
654
- onCallEnd: C,
655
- onDurationUpdate: (n) => {
656
- b.value = n;
826
+ onCallStart: c,
827
+ onCallEnd: d,
828
+ onDurationUpdate: (E) => {
829
+ _.value = E;
657
830
  },
658
- onHistoryUpdate: (n) => {
659
- i.value = n;
831
+ onHistoryUpdate: (E) => {
832
+ f.value = E;
660
833
  },
661
834
  onRegistered: () => {
662
- u.value = !0;
835
+ i.value = !0;
663
836
  },
664
837
  onUnregistered: () => {
665
- u.value = !1;
838
+ i.value = !1;
666
839
  }
667
840
  },
668
841
  {
669
- persistHistory: w,
670
- historyKey: d
842
+ persistHistory: r,
843
+ historyKey: p
671
844
  }
672
- ), l.initialize(), o.value = l.state.status, r.value = l.state.callNumber, i.value = l.state.callHistory, u.value = l.state.isReady, x.value = l.state.connectionStatus, S.value = l.ua;
673
- }), Y(() => {
674
- l && (l.destroy(), l = null);
845
+ ), o.initialize(), n.value = o.state.status, u.value = o.state.callNumber, f.value = o.state.callHistory, i.value = o.state.isReady, g.value = o.state.connectionStatus, k.value = o.ua;
846
+ }), re(() => {
847
+ o && (o.destroy(), o = null);
675
848
  });
676
- const z = (n) => {
677
- r.value = n, l?.setCallNumber(n);
678
- }, M = (n) => {
679
- l?.startCall(n);
849
+ const h = (E) => {
850
+ u.value = E, o?.setCallNumber(E);
851
+ }, M = (E) => {
852
+ o?.startCall(E);
853
+ }, x = () => {
854
+ o?.endCall();
680
855
  }, H = () => {
681
- l?.endCall();
682
- }, N = () => {
683
- l?.clearHistory(), i.value = [];
856
+ o?.clearHistory(), f.value = [];
684
857
  };
685
858
  return {
686
- status: D(o),
687
- callNumber: r,
688
- setCallNumber: z,
689
- callHistory: D(i),
690
- clearCallHistory: N,
691
- currentCallDuration: D(b),
859
+ status: j(n),
860
+ callNumber: u,
861
+ setCallNumber: h,
862
+ callHistory: j(f),
863
+ clearCallHistory: H,
864
+ currentCallDuration: j(_),
692
865
  startCall: M,
693
- endCall: H,
694
- isReady: D(u),
695
- connectionStatus: D(x),
696
- ua: S
866
+ endCall: x,
867
+ isReady: j(i),
868
+ connectionStatus: j(g),
869
+ ua: k
697
870
  };
698
871
  }
699
872
  export {
700
- tt as Phone,
701
- ne as PhoneKey,
702
- tt as default,
703
- st as usePhone,
704
- ot as usePhoneManager,
705
- nt as usePhoneProvider
873
+ ft as Phone,
874
+ ce as PhoneKey,
875
+ ft as default,
876
+ mt as usePhone,
877
+ ht as usePhoneManager,
878
+ gt as usePhoneProvider
706
879
  };