@tbisoftware/phone 2.0.6 → 2.0.8

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.
@@ -1,24 +1,24 @@
1
- import { jsx as t, jsxs as o, Fragment as W } from "react/jsx-runtime";
2
- import { useState as p, useRef as j, useEffect as I, useCallback as k, createContext as q, useContext as G } from "react";
3
- import { J as F, d as Q, c as _, f as $, P as X } from "./index-TymkBND5.js";
4
- let z = null, B = null;
5
- function Y(e) {
1
+ import { jsx as t, jsxs as o, Fragment as Q } from "react/jsx-runtime";
2
+ import { useState as p, useRef as T, useEffect as H, useCallback as k, createContext as X, useContext as Y } from "react";
3
+ import { J, d as Z, c as $, f as O, P as ee } from "./index-D8BnjTav.js";
4
+ let D = null, _ = null;
5
+ function te(e) {
6
6
  return `${e.websocketUrl}|${e.sipUri}|${e.authorizationUser}`;
7
7
  }
8
- function Z(e) {
9
- const m = Y(e);
10
- if (z && B === m)
11
- return z;
12
- if (z && B !== m) {
8
+ function ne(e) {
9
+ const f = te(e);
10
+ if (D && _ === f)
11
+ return D;
12
+ if (D && _ !== f) {
13
13
  try {
14
- z.ua.stop();
14
+ D.ua.stop();
15
15
  } catch {
16
16
  }
17
- z = null;
17
+ D = null;
18
18
  }
19
- B = m;
19
+ _ = f;
20
20
  const i = {
21
- sockets: [new F.WebSocketInterface(e.websocketUrl)],
21
+ sockets: [new J.WebSocketInterface(e.websocketUrl)],
22
22
  uri: e.sipUri,
23
23
  password: e.password,
24
24
  registrar_server: e.registrarServer,
@@ -26,148 +26,153 @@ function Z(e) {
26
26
  authorization_user: e.authorizationUser,
27
27
  connection_recovery_min_interval: 2,
28
28
  connection_recovery_max_interval: 30
29
- }, a = new F.UA(i), g = document.createElement("audio");
29
+ }, a = new J.UA(i), g = document.createElement("audio");
30
30
  g.autoplay = !0;
31
- const h = {
31
+ const m = {
32
32
  ua: a,
33
33
  audio: g,
34
34
  isStarted: !1,
35
35
  listeners: /* @__PURE__ */ new Set()
36
36
  };
37
37
  return a.on("connecting", () => {
38
- h.listeners.forEach((r) => r.onConnecting?.());
38
+ m.listeners.forEach((n) => n.onConnecting?.());
39
39
  }), a.on("connected", () => {
40
- h.listeners.forEach((r) => r.onConnected?.());
40
+ m.listeners.forEach((n) => n.onConnected?.());
41
41
  }), a.on("disconnected", () => {
42
- h.listeners.forEach((r) => r.onDisconnected?.());
42
+ m.listeners.forEach((n) => n.onDisconnected?.());
43
43
  }), a.on("registered", () => {
44
- h.listeners.forEach((r) => r.onRegistered?.());
44
+ m.listeners.forEach((n) => n.onRegistered?.());
45
45
  }), a.on("unregistered", () => {
46
- h.listeners.forEach((r) => r.onUnregistered?.());
47
- }), a.on("registrationFailed", (r) => {
48
- h.listeners.forEach((l) => l.onRegistrationFailed?.(r?.cause));
49
- }), a.on("newRTCSession", (r) => {
50
- const l = r.session;
51
- l.direction === "outgoing" && (h.listeners.forEach((d) => d.onNewSession?.(l)), l.connection && (l.connection.addEventListener("addstream", (d) => {
46
+ m.listeners.forEach((n) => n.onUnregistered?.());
47
+ }), a.on("registrationFailed", (n) => {
48
+ m.listeners.forEach((l) => l.onRegistrationFailed?.(n?.cause));
49
+ }), a.on("newRTCSession", (n) => {
50
+ const l = n.session;
51
+ l.direction === "outgoing" && (m.listeners.forEach((d) => d.onNewSession?.(l)), l.connection && (l.connection.addEventListener("addstream", (d) => {
52
52
  var x = document.createElement("audio");
53
53
  d.streams !== void 0 && d.streams.length !== 0 && (x.srcObject = d.streams[0], x.play());
54
54
  }), l.connection.addEventListener("track", (d) => {
55
55
  var x = document.createElement("audio");
56
56
  x.srcObject = d.streams[0], x.play();
57
57
  })));
58
- }), z = h, h;
58
+ }), D = m, m;
59
59
  }
60
- function ee(e) {
60
+ function re(e) {
61
61
  e.isStarted || (e.ua.start(), e.isStarted = !0);
62
62
  }
63
- function te(e, m) {
64
- e.listeners.add(m);
63
+ function se(e, f) {
64
+ e.listeners.add(f);
65
65
  }
66
- function ne(e, m) {
67
- e.listeners.delete(m);
66
+ function oe(e, f) {
67
+ e.listeners.delete(f);
68
68
  }
69
- function re(e) {
69
+ function ae(e) {
70
70
  return {
71
71
  isReady: e.ua.isRegistered(),
72
72
  isConnected: e.ua.isConnected()
73
73
  };
74
74
  }
75
- const K = q(null);
76
- function se({
75
+ const W = X(null);
76
+ function le({
77
77
  config: e,
78
- children: m,
78
+ children: f,
79
79
  onCallStart: u,
80
80
  onCallEnd: i,
81
81
  onStatusChange: a
82
82
  }) {
83
- const [g, h] = p(""), [r, l] = p("disconnected"), [d, x] = p(null), [P, N] = p(0), [s, M] = p([]), [b, f] = p(!1), [H, S] = p("connecting"), y = j(null), v = j(null), D = j(null);
84
- I(() => {
85
- v.current = d;
86
- }, [d]), I(() => {
87
- const n = Z(e);
88
- D.current = n;
89
- const C = re(n);
90
- C.isReady ? (f(!0), S("connected")) : C.isConnected && S("connected");
91
- const R = {
92
- onConnecting: () => S("connecting"),
93
- onConnected: () => S("connected"),
83
+ const [g, m] = p(""), [n, l] = p("disconnected"), [d, x] = p(null), [E, M] = p(0), [w, I] = p([]), [c, R] = p(!1), [v, h] = p("disconnected"), [y, C] = p(!1), z = T(null), L = T(null), j = T(null);
84
+ H(() => {
85
+ L.current = d;
86
+ }, [d]);
87
+ const A = k(() => {
88
+ y || (C(!0), h("connecting"));
89
+ }, [y]);
90
+ H(() => {
91
+ if (!y) return;
92
+ const s = ne(e);
93
+ j.current = s;
94
+ const b = ae(s);
95
+ b.isReady ? (R(!0), h("connected")) : b.isConnected && h("connected");
96
+ const P = {
97
+ onConnecting: () => h("connecting"),
98
+ onConnected: () => h("connected"),
94
99
  onDisconnected: () => {
95
- S("disconnected"), f(!1);
100
+ h("disconnected"), R(!1);
96
101
  },
97
102
  onRegistered: () => {
98
- f(!0), S("connected");
103
+ R(!0), h("connected");
99
104
  },
100
- onUnregistered: () => f(!1),
101
- onRegistrationFailed: (E) => {
102
- console.error("Registration failed:", E), f(!1), S("failed");
105
+ onUnregistered: () => R(!1),
106
+ onRegistrationFailed: (U) => {
107
+ console.error("Registration failed:", U), R(!1), h("failed");
103
108
  },
104
- onNewSession: (E) => {
105
- y.current = E;
109
+ onNewSession: (U) => {
110
+ z.current = U;
106
111
  }
107
112
  };
108
- return te(n, R), ee(n), () => {
109
- ne(n, R);
113
+ return se(s, P), re(s), () => {
114
+ oe(s, P);
110
115
  };
111
- }, [e.websocketUrl, e.sipUri, e.password, e.registrarServer, e.displayName, e.authorizationUser]), I(() => {
112
- a?.(r);
113
- }, [r, a]), I(() => {
114
- const n = localStorage.getItem("tbi-phone-call-history");
115
- if (n)
116
+ }, [y, e.websocketUrl, e.sipUri, e.password, e.registrarServer, e.displayName, e.authorizationUser]), H(() => {
117
+ a?.(n);
118
+ }, [n, a]), H(() => {
119
+ const s = localStorage.getItem("tbi-phone-call-history");
120
+ if (s)
116
121
  try {
117
- M(JSON.parse(n));
118
- } catch (C) {
119
- console.error("Error loading call history", C);
122
+ I(JSON.parse(s));
123
+ } catch (b) {
124
+ console.error("Error loading call history", b);
120
125
  }
121
- }, []), I(() => {
122
- s.length > 0 && localStorage.setItem("tbi-phone-call-history", JSON.stringify(s));
123
- }, [s]), I(() => {
124
- if (r === "confirmed" && d) {
125
- const n = setInterval(() => {
126
- N(Math.floor((Date.now() - d) / 1e3));
126
+ }, []), H(() => {
127
+ w.length > 0 && localStorage.setItem("tbi-phone-call-history", JSON.stringify(w));
128
+ }, [w]), H(() => {
129
+ if (n === "confirmed" && d) {
130
+ const s = setInterval(() => {
131
+ M(Math.floor((Date.now() - d) / 1e3));
127
132
  }, 1e3);
128
- return () => clearInterval(n);
133
+ return () => clearInterval(s);
129
134
  } else
130
- N(0);
131
- }, [r, d]), I(() => {
132
- const n = (C) => {
133
- const R = C.detail.number;
134
- r === "disconnected" && L(R);
135
+ M(0);
136
+ }, [n, d]), H(() => {
137
+ const s = (b) => {
138
+ const P = b.detail.number;
139
+ n === "disconnected" && F(P);
135
140
  };
136
- return window.addEventListener("StartCallEvent", n), () => {
137
- window.removeEventListener("StartCallEvent", n);
141
+ return window.addEventListener("StartCallEvent", s), () => {
142
+ window.removeEventListener("StartCallEvent", s);
138
143
  };
139
- }, [r]);
140
- const U = k((n, C, R) => {
141
- const E = {
144
+ }, [n]);
145
+ const r = k((s, b, P) => {
146
+ const U = {
142
147
  id: Date.now().toString(),
143
- number: n,
148
+ number: s,
144
149
  timestamp: Date.now(),
145
- duration: C,
146
- status: R
150
+ duration: b,
151
+ status: P
147
152
  };
148
- M((w) => [E, ...w].slice(0, 50));
149
- }, []), A = k(() => {
150
- y.current && (y.current.terminate(), y.current = null);
151
- }, []), L = k((n) => {
152
- const C = D.current;
153
- if (!n.trim() || !C) return;
154
- if (!b) {
153
+ I((S) => [U, ...S].slice(0, 50));
154
+ }, []), N = k(() => {
155
+ z.current && (z.current.terminate(), z.current = null);
156
+ }, []), F = k((s) => {
157
+ const b = j.current;
158
+ if (!s.trim() || !b) return;
159
+ if (!c) {
155
160
  console.warn("Phone is not ready yet. Please wait for registration.");
156
161
  return;
157
162
  }
158
- h(n), u?.(n);
159
- const E = {
163
+ m(s), u?.(s);
164
+ const U = {
160
165
  eventHandlers: {
161
166
  progress: () => {
162
167
  l("progress");
163
168
  },
164
- failed: (w) => {
165
- console.error("Call failed:", w?.cause), l("failed"), U(n, 0, "failed"), i?.(n, 0, "failed"), y.current = null, setTimeout(() => l("disconnected"), 3e3);
169
+ failed: (S) => {
170
+ console.error("Call failed:", S?.cause), l("failed"), r(s, 0, "failed"), i?.(s, 0, "failed"), z.current = null, setTimeout(() => l("disconnected"), 3e3);
166
171
  },
167
172
  ended: () => {
168
173
  l("ended");
169
- const w = v.current, V = w ? Math.floor((Date.now() - w) / 1e3) : 0;
170
- U(n, V, "completed"), i?.(n, V, "completed"), y.current = null, setTimeout(() => {
174
+ const S = L.current, K = S ? Math.floor((Date.now() - S) / 1e3) : 0;
175
+ r(s, K, "completed"), i?.(s, K, "completed"), z.current = null, setTimeout(() => {
171
176
  l("disconnected"), x(null);
172
177
  }, 2e3);
173
178
  },
@@ -179,74 +184,88 @@ function se({
179
184
  };
180
185
  l("progress");
181
186
  try {
182
- const w = C.ua.call(n, E);
183
- y.current = w;
184
- } catch (w) {
185
- console.error("Failed to start call:", w), l("failed"), U(n, 0, "failed"), setTimeout(() => l("disconnected"), 3e3);
187
+ const S = b.ua.call(s, U);
188
+ z.current = S;
189
+ } catch (S) {
190
+ console.error("Failed to start call:", S), l("failed"), r(s, 0, "failed"), setTimeout(() => l("disconnected"), 3e3);
186
191
  }
187
- }, [U, u, i, b]), c = {
188
- status: r,
192
+ }, [r, u, i, c]), G = {
193
+ status: n,
189
194
  callNumber: g,
190
- setCallNumber: h,
191
- callHistory: s,
192
- currentCallDuration: P,
193
- startCall: L,
194
- endCall: A,
195
- isReady: b,
196
- connectionStatus: H
195
+ setCallNumber: m,
196
+ callHistory: w,
197
+ currentCallDuration: E,
198
+ startCall: F,
199
+ endCall: N,
200
+ isReady: c,
201
+ connectionStatus: v,
202
+ isInitialized: y,
203
+ initialize: A
197
204
  };
198
- return /* @__PURE__ */ t(K.Provider, { value: c, children: m });
205
+ return /* @__PURE__ */ t(W.Provider, { value: G, children: f });
199
206
  }
200
- function oe() {
201
- const e = G(K);
207
+ function ce() {
208
+ const e = Y(W);
202
209
  if (!e)
203
210
  throw new Error("usePhone must be used within a PhoneProvider");
204
211
  return e;
205
212
  }
206
- const O = ({ className: e }) => /* @__PURE__ */ t("svg", { className: e, viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ t("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" }) }), ae = ({ className: e }) => /* @__PURE__ */ t("svg", { className: e, viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ t("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" }) }), le = ({ className: e }) => /* @__PURE__ */ t("svg", { className: e, viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ t("path", { d: "M20 15.5c-1.25 0-2.45-.2-3.57-.57-.35-.12-.74-.03-1.02.24l-2.2 2.2c-2.83-1.45-5.15-3.76-6.59-6.59l2.2-2.21c.28-.26.36-.65.25-1C8.7 6.45 8.5 5.25 8.5 4c0-.55-.45-1-1-1H4c-.55 0-1 .45-1 1 0 9.39 7.61 17 17 17 .55 0 1-.45 1-1v-3.5c0-.55-.45-1-1-1zM19 12h2c0-4.97-4.03-9-9-9v2c3.87 0 7 3.13 7 7zm-4 0h2c0-2.76-2.24-5-5-5v2c1.66 0 3 1.34 3 3z" }) }), T = ({ className: e }) => /* @__PURE__ */ t("svg", { className: e, viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ t("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" }) }), J = ({ className: e }) => /* @__PURE__ */ t("svg", { className: e, viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ t("path", { 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" }) }), ce = ({ className: e }) => /* @__PURE__ */ o("svg", { className: e, viewBox: "0 0 24 24", fill: "currentColor", children: [
213
+ const V = ({ className: e }) => /* @__PURE__ */ t("svg", { className: e, viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ t("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" }) }), ie = ({ className: e }) => /* @__PURE__ */ t("svg", { className: e, viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ t("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" }) }), de = ({ className: e }) => /* @__PURE__ */ t("svg", { className: e, viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ t("path", { d: "M20 15.5c-1.25 0-2.45-.2-3.57-.57-.35-.12-.74-.03-1.02.24l-2.2 2.2c-2.83-1.45-5.15-3.76-6.59-6.59l2.2-2.21c.28-.26.36-.65.25-1C8.7 6.45 8.5 5.25 8.5 4c0-.55-.45-1-1-1H4c-.55 0-1 .45-1 1 0 9.39 7.61 17 17 17 .55 0 1-.45 1-1v-3.5c0-.55-.45-1-1-1zM19 12h2c0-4.97-4.03-9-9-9v2c3.87 0 7 3.13 7 7zm-4 0h2c0-2.76-2.24-5-5-5v2c1.66 0 3 1.34 3 3z" }) }), B = ({ className: e }) => /* @__PURE__ */ t("svg", { className: e, viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ t("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" }) }), q = ({ className: e }) => /* @__PURE__ */ t("svg", { className: e, viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ t("path", { 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" }) }), ue = ({ className: e }) => /* @__PURE__ */ o("svg", { className: e, viewBox: "0 0 24 24", fill: "currentColor", children: [
207
214
  /* @__PURE__ */ t("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" }),
208
215
  /* @__PURE__ */ t("path", { d: "M16 3l-5 5-2-2-1.5 1.5L11 11l6.5-6.5z" })
209
- ] }), ie = ({ className: e }) => /* @__PURE__ */ o("svg", { className: e, viewBox: "0 0 24 24", fill: "currentColor", children: [
216
+ ] }), he = ({ className: e }) => /* @__PURE__ */ o("svg", { className: e, viewBox: "0 0 24 24", fill: "currentColor", children: [
210
217
  /* @__PURE__ */ t("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" }),
211
218
  /* @__PURE__ */ t("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" })
212
- ] }), de = ({ className: e }) => /* @__PURE__ */ t("svg", { className: e, viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ t("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" }) }), ue = ({ className: e }) => /* @__PURE__ */ t("svg", { className: e, viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ t("path", { d: "M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z" }) });
213
- function he({ className: e, labels: m }) {
219
+ ] }), me = ({ className: e }) => /* @__PURE__ */ t("svg", { className: e, viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ t("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" }) }), fe = ({ className: e }) => /* @__PURE__ */ t("svg", { className: e, viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ t("path", { d: "M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z" }) }), ge = ({ className: e }) => /* @__PURE__ */ t("svg", { className: e, viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ t("path", { d: "M13 3h-2v10h2V3zm4.83 2.17l-1.42 1.42C17.99 7.86 19 9.81 19 12c0 3.87-3.13 7-7 7s-7-3.13-7-7c0-2.19 1.01-4.14 2.58-5.42L6.17 5.17C4.23 6.82 3 9.26 3 12c0 4.97 4.03 9 9 9s9-4.03 9-9c0-2.74-1.23-5.18-3.17-6.83z" }) });
220
+ function pe({ className: e, labels: f }) {
214
221
  const {
215
222
  status: u,
216
223
  callNumber: i,
217
224
  setCallNumber: a,
218
225
  callHistory: g,
219
- currentCallDuration: h,
220
- startCall: r,
226
+ currentCallDuration: m,
227
+ startCall: n,
221
228
  endCall: l,
222
229
  isReady: d,
223
- connectionStatus: x
224
- } = oe(), [P, N] = p(!1), s = { ...Q, ...m }, b = (() => {
230
+ connectionStatus: x,
231
+ isInitialized: E,
232
+ initialize: M
233
+ } = ce(), [w, I] = p(!1), c = { ...Z, ...f }, v = (() => {
225
234
  switch (u) {
226
235
  case "progress":
227
- return { text: `${s.calling}...`, color: "text-yellow-500", Icon: ae };
236
+ return { text: `${c.calling}...`, color: "text-yellow-500", Icon: ie };
228
237
  case "confirmed":
229
- return { text: `${s.inCall} - ${$(h)}`, color: "text-green-500", Icon: le };
238
+ return { text: `${c.inCall} - ${O(m)}`, color: "text-green-500", Icon: de };
230
239
  case "failed":
231
- return { text: s.callEnded, color: "text-red-500", Icon: J };
240
+ return { text: c.callEnded, color: "text-red-500", Icon: q };
232
241
  case "ended":
233
- return { text: s.callEnded, color: "text-gray-500", Icon: T };
242
+ return { text: c.callEnded, color: "text-gray-500", Icon: B };
234
243
  default:
235
- return { text: s.inactive, color: "text-gray-300", Icon: O };
244
+ return { text: c.inactive, color: "text-gray-300", Icon: V };
236
245
  }
237
246
  })();
238
- return /* @__PURE__ */ o("div", { className: _(
247
+ return /* @__PURE__ */ o("div", { className: $(
239
248
  "tbi-phone w-full max-w-md mx-auto bg-white rounded-2xl shadow-lg border border-gray-200 p-2",
240
249
  e
241
250
  ), children: [
242
- u === "disconnected" && /* @__PURE__ */ o("div", { className: "flex gap-2 items-center", children: [
251
+ !E && /* @__PURE__ */ t("div", { className: "flex items-center justify-center", children: /* @__PURE__ */ t(
252
+ "button",
253
+ {
254
+ onClick: M,
255
+ className: "h-8 w-8 flex items-center justify-center rounded-xl bg-gray-100 hover:bg-green-100 hover:text-green-600 text-gray-500 transition-colors",
256
+ type: "button",
257
+ title: c.turnOn,
258
+ children: /* @__PURE__ */ t(ge, { className: "w-5 h-5" })
259
+ }
260
+ ) }),
261
+ E && u === "disconnected" && /* @__PURE__ */ o("div", { className: "flex gap-2 items-center", children: [
243
262
  /* @__PURE__ */ t(
244
263
  "button",
245
264
  {
246
- onClick: () => N(!0),
265
+ onClick: () => I(!0),
247
266
  className: "h-8 w-8 flex items-center justify-center rounded-xl border border-gray-200 hover:bg-gray-50 transition-colors",
248
267
  type: "button",
249
- children: /* @__PURE__ */ t(de, { className: "w-4 h-4" })
268
+ children: /* @__PURE__ */ t(me, { className: "w-4 h-4" })
250
269
  }
251
270
  ),
252
271
  /* @__PURE__ */ t(
@@ -254,38 +273,38 @@ function he({ className: e, labels: m }) {
254
273
  {
255
274
  type: "text",
256
275
  value: i,
257
- onChange: (f) => a(f.target.value),
258
- onKeyDown: (f) => {
259
- f.key === "Enter" && r(i);
276
+ onChange: (h) => a(h.target.value),
277
+ onKeyDown: (h) => {
278
+ h.key === "Enter" && n(i);
260
279
  },
261
- placeholder: s.placeholder,
280
+ placeholder: c.placeholder,
262
281
  className: "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"
263
282
  }
264
283
  ),
265
284
  /* @__PURE__ */ t(
266
285
  "button",
267
286
  {
268
- onClick: () => r(i),
287
+ onClick: () => n(i),
269
288
  disabled: i.length < 9 || !d,
270
289
  className: "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",
271
290
  type: "button",
272
291
  title: d ? "Call" : "Connecting...",
273
- children: x === "connecting" ? /* @__PURE__ */ t("div", { className: "w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin" }) : /* @__PURE__ */ t(O, { className: "w-4 h-4" })
292
+ children: x === "connecting" ? /* @__PURE__ */ t("div", { className: "w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin" }) : /* @__PURE__ */ t(V, { className: "w-4 h-4" })
274
293
  }
275
294
  )
276
295
  ] }),
277
296
  u === "progress" && /* @__PURE__ */ o("div", { className: "flex flex-col items-center gap-3 py-6", children: [
278
297
  /* @__PURE__ */ o("div", { className: "relative", children: [
279
- /* @__PURE__ */ t(b.Icon, { className: "w-12 h-12 text-yellow-500 animate-pulse" }),
298
+ /* @__PURE__ */ t(v.Icon, { className: "w-12 h-12 text-yellow-500 animate-pulse" }),
280
299
  /* @__PURE__ */ t("div", { className: "absolute inset-0 rounded-full border-4 border-yellow-500/30 animate-ping" })
281
300
  ] }),
282
301
  /* @__PURE__ */ o("div", { className: "text-center", children: [
283
302
  /* @__PURE__ */ o("p", { className: "text-base font-semibold", children: [
284
- s.calling,
303
+ c.calling,
285
304
  " ",
286
305
  i
287
306
  ] }),
288
- /* @__PURE__ */ t("p", { className: "text-sm text-gray-500", children: s.waitingResponse })
307
+ /* @__PURE__ */ t("p", { className: "text-sm text-gray-500", children: c.waitingResponse })
289
308
  ] }),
290
309
  /* @__PURE__ */ o(
291
310
  "button",
@@ -294,20 +313,20 @@ function he({ className: e, labels: m }) {
294
313
  className: "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",
295
314
  type: "button",
296
315
  children: [
297
- /* @__PURE__ */ t(T, { className: "w-4 h-4" }),
298
- s.cancel
316
+ /* @__PURE__ */ t(B, { className: "w-4 h-4" }),
317
+ c.cancel
299
318
  ]
300
319
  }
301
320
  )
302
321
  ] }),
303
322
  u === "confirmed" && /* @__PURE__ */ o("div", { className: "flex flex-col items-center gap-4 py-6", children: [
304
323
  /* @__PURE__ */ o("div", { className: "relative", children: [
305
- /* @__PURE__ */ t(b.Icon, { className: "w-12 h-12 text-green-500" }),
324
+ /* @__PURE__ */ t(v.Icon, { className: "w-12 h-12 text-green-500" }),
306
325
  /* @__PURE__ */ t("div", { className: "absolute inset-0 rounded-full bg-green-500/20 animate-pulse" })
307
326
  ] }),
308
327
  /* @__PURE__ */ o("div", { className: "text-center space-y-1", children: [
309
328
  /* @__PURE__ */ t("p", { className: "text-xl font-bold", children: i }),
310
- /* @__PURE__ */ t("p", { className: "text-2xl font-mono text-green-600 tabular-nums", children: $(h) })
329
+ /* @__PURE__ */ t("p", { className: "text-2xl font-mono text-green-600 tabular-nums", children: O(m) })
311
330
  ] }),
312
331
  /* @__PURE__ */ o(
313
332
  "button",
@@ -316,79 +335,79 @@ function he({ className: e, labels: m }) {
316
335
  className: "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",
317
336
  type: "button",
318
337
  children: [
319
- /* @__PURE__ */ t(T, { className: "w-4 h-4" }),
320
- s.hangUp
338
+ /* @__PURE__ */ t(B, { className: "w-4 h-4" }),
339
+ c.hangUp
321
340
  ]
322
341
  }
323
342
  )
324
343
  ] }),
325
344
  (u === "failed" || u === "ended") && /* @__PURE__ */ o("div", { className: "flex flex-col items-center gap-3 py-6", children: [
326
345
  /* @__PURE__ */ t(
327
- b.Icon,
346
+ v.Icon,
328
347
  {
329
- className: _(
348
+ className: $(
330
349
  "w-12 h-12",
331
350
  u === "failed" ? "text-red-500" : "text-gray-500"
332
351
  )
333
352
  }
334
353
  ),
335
- /* @__PURE__ */ t("div", { className: "text-center", children: /* @__PURE__ */ t("p", { className: "text-base font-semibold", children: b.text }) })
354
+ /* @__PURE__ */ t("div", { className: "text-center", children: /* @__PURE__ */ t("p", { className: "text-base font-semibold", children: v.text }) })
336
355
  ] }),
337
- P && /* @__PURE__ */ o("div", { className: "fixed inset-0 z-50 flex", children: [
356
+ w && /* @__PURE__ */ o("div", { className: "fixed inset-0 z-50 flex", children: [
338
357
  /* @__PURE__ */ t(
339
358
  "div",
340
359
  {
341
360
  className: "fixed inset-0 bg-black/50",
342
- onClick: () => N(!1)
361
+ onClick: () => I(!1)
343
362
  }
344
363
  ),
345
364
  /* @__PURE__ */ t("div", { className: "fixed right-0 top-0 h-full w-full max-w-md bg-white shadow-xl", style: { backgroundColor: "white" }, children: /* @__PURE__ */ o("div", { className: "flex flex-col h-full", children: [
346
365
  /* @__PURE__ */ o("div", { className: "flex items-center justify-between p-4 border-b", children: [
347
366
  /* @__PURE__ */ o("div", { children: [
348
- /* @__PURE__ */ t("h2", { className: "text-lg font-semibold", children: s.callHistory }),
349
- /* @__PURE__ */ t("p", { className: "text-sm text-gray-500", children: g.length === 0 ? s.noCallsRegistered : `${g.length} ${s.callsRegistered}` })
367
+ /* @__PURE__ */ t("h2", { className: "text-lg font-semibold", children: c.callHistory }),
368
+ /* @__PURE__ */ t("p", { className: "text-sm text-gray-500", children: g.length === 0 ? c.noCallsRegistered : `${g.length} ${c.callsRegistered}` })
350
369
  ] }),
351
370
  /* @__PURE__ */ t(
352
371
  "button",
353
372
  {
354
- onClick: () => N(!1),
373
+ onClick: () => I(!1),
355
374
  className: "h-8 w-8 flex items-center justify-center rounded-lg hover:bg-gray-100 transition-colors",
356
375
  type: "button",
357
- children: /* @__PURE__ */ t(ue, { className: "w-5 h-5" })
376
+ children: /* @__PURE__ */ t(fe, { className: "w-5 h-5" })
358
377
  }
359
378
  )
360
379
  ] }),
361
380
  /* @__PURE__ */ t("div", { className: "flex-1 overflow-y-auto p-4", children: g.length === 0 ? /* @__PURE__ */ o("div", { className: "text-center py-12 text-gray-500", children: [
362
- /* @__PURE__ */ t(T, { className: "w-12 h-12 mx-auto mb-2 opacity-50" }),
363
- /* @__PURE__ */ t("p", { children: s.noCalls })
364
- ] }) : /* @__PURE__ */ t("div", { className: "space-y-2", children: g.map((f, H) => /* @__PURE__ */ t(
365
- me,
381
+ /* @__PURE__ */ t(B, { className: "w-12 h-12 mx-auto mb-2 opacity-50" }),
382
+ /* @__PURE__ */ t("p", { children: c.noCalls })
383
+ ] }) : /* @__PURE__ */ t("div", { className: "space-y-2", children: g.map((h, y) => /* @__PURE__ */ t(
384
+ xe,
366
385
  {
367
- entry: f,
368
- index: H,
386
+ entry: h,
387
+ index: y,
369
388
  onCall: () => {
370
- a(f.number), N(!1), r(f.number);
389
+ a(h.number), I(!1), n(h.number);
371
390
  }
372
391
  },
373
- f.id
392
+ h.id
374
393
  )) }) })
375
394
  ] }) })
376
395
  ] })
377
396
  ] });
378
397
  }
379
- function me({
398
+ function xe({
380
399
  entry: e,
381
- index: m,
400
+ index: f,
382
401
  onCall: u
383
402
  }) {
384
403
  const i = () => {
385
404
  switch (e.status) {
386
405
  case "completed":
387
- return /* @__PURE__ */ t(ce, { className: "w-4 h-4 text-green-600" });
406
+ return /* @__PURE__ */ t(ue, { className: "w-4 h-4 text-green-600" });
388
407
  case "failed":
389
- return /* @__PURE__ */ t(ie, { className: "w-4 h-4 text-red-600" });
408
+ return /* @__PURE__ */ t(he, { className: "w-4 h-4 text-red-600" });
390
409
  case "missed":
391
- return /* @__PURE__ */ t(J, { className: "w-4 h-4 text-yellow-600" });
410
+ return /* @__PURE__ */ t(q, { className: "w-4 h-4 text-yellow-600" });
392
411
  }
393
412
  }, a = () => {
394
413
  switch (e.status) {
@@ -404,9 +423,9 @@ function me({
404
423
  "div",
405
424
  {
406
425
  className: "flex items-center gap-3 p-3 rounded-lg hover:bg-gray-50 transition-colors duration-200",
407
- style: { animationDelay: `${m * 30}ms` },
426
+ style: { animationDelay: `${f * 30}ms` },
408
427
  children: [
409
- /* @__PURE__ */ t("div", { className: _(
428
+ /* @__PURE__ */ t("div", { className: $(
410
429
  "w-9 h-9 rounded-full flex items-center justify-center shrink-0",
411
430
  a()
412
431
  ), children: i() }),
@@ -419,9 +438,9 @@ function me({
419
438
  hour: "2-digit",
420
439
  minute: "2-digit"
421
440
  }) }),
422
- e.duration > 0 && /* @__PURE__ */ o(W, { children: [
441
+ e.duration > 0 && /* @__PURE__ */ o(Q, { children: [
423
442
  /* @__PURE__ */ t("span", { children: "•" }),
424
- /* @__PURE__ */ t("span", { className: "font-mono tabular-nums", children: $(e.duration) })
443
+ /* @__PURE__ */ t("span", { className: "font-mono tabular-nums", children: O(e.duration) })
425
444
  ] })
426
445
  ] })
427
446
  ] }),
@@ -431,58 +450,58 @@ function me({
431
450
  onClick: u,
432
451
  className: "h-8 w-8 flex items-center justify-center shrink-0 rounded-lg hover:bg-gray-100 transition-colors",
433
452
  type: "button",
434
- children: /* @__PURE__ */ t(O, { className: "w-4 h-4" })
453
+ children: /* @__PURE__ */ t(V, { className: "w-4 h-4" })
435
454
  }
436
455
  )
437
456
  ]
438
457
  }
439
458
  );
440
459
  }
441
- function xe({ config: e, className: m, onCallStart: u, onCallEnd: i, onStatusChange: a, labels: g }) {
460
+ function be({ config: e, className: f, onCallStart: u, onCallEnd: i, onStatusChange: a, labels: g }) {
442
461
  return /* @__PURE__ */ t(
443
- se,
462
+ le,
444
463
  {
445
464
  config: e,
446
465
  onCallStart: u,
447
466
  onCallEnd: i,
448
467
  onStatusChange: a,
449
- children: /* @__PURE__ */ t(he, { className: m, labels: g })
468
+ children: /* @__PURE__ */ t(pe, { className: f, labels: g })
450
469
  }
451
470
  );
452
471
  }
453
- function ve(e, m = {}) {
472
+ function we(e, f = {}) {
454
473
  const {
455
474
  onCallStart: u,
456
475
  onCallEnd: i,
457
476
  onStatusChange: a,
458
477
  onConnectionChange: g,
459
- persistHistory: h = !0,
460
- historyKey: r = "tbi-phone-call-history"
461
- } = m, [l, d] = p("disconnected"), [x, P] = p(""), [N, s] = p([]), [M, b] = p(0), [f, H] = p(!1), [S, y] = p("connecting"), v = j(null);
462
- I(() => {
463
- const c = new X(
478
+ persistHistory: m = !0,
479
+ historyKey: n = "tbi-phone-call-history"
480
+ } = f, [l, d] = p("disconnected"), [x, E] = p(""), [M, w] = p([]), [I, c] = p(0), [R, v] = p(!1), [h, y] = p("connecting"), C = T(null);
481
+ H(() => {
482
+ const r = new ee(
464
483
  e,
465
484
  {
466
- onStatusChange: (n) => {
467
- d(n), a?.(n);
485
+ onStatusChange: (N) => {
486
+ d(N), a?.(N);
468
487
  },
469
- onConnectionChange: (n) => {
470
- y(n), (n === "connected" || n === "disconnected" || n === "failed") && H(c.state.isReady), g?.(n);
488
+ onConnectionChange: (N) => {
489
+ y(N), (N === "connected" || N === "disconnected" || N === "failed") && v(r.state.isReady), g?.(N);
471
490
  },
472
491
  onCallStart: u,
473
492
  onCallEnd: i,
474
- onDurationUpdate: b,
475
- onHistoryUpdate: s,
476
- onRegistered: () => H(!0),
477
- onUnregistered: () => H(!1)
493
+ onDurationUpdate: c,
494
+ onHistoryUpdate: w,
495
+ onRegistered: () => v(!0),
496
+ onUnregistered: () => v(!1)
478
497
  },
479
498
  {
480
- persistHistory: h,
481
- historyKey: r
499
+ persistHistory: m,
500
+ historyKey: n
482
501
  }
483
502
  );
484
- return c.initialize(), v.current = c, d(c.state.status), P(c.state.callNumber), s(c.state.callHistory), H(c.state.isReady), y(c.state.connectionStatus), () => {
485
- c.destroy(), v.current = null;
503
+ return r.initialize(), C.current = r, d(r.state.status), E(r.state.callNumber), w(r.state.callHistory), v(r.state.isReady), y(r.state.connectionStatus), () => {
504
+ r.destroy(), C.current = null;
486
505
  };
487
506
  }, [
488
507
  e.websocketUrl,
@@ -491,46 +510,46 @@ function ve(e, m = {}) {
491
510
  e.registrarServer,
492
511
  e.displayName,
493
512
  e.authorizationUser,
494
- h,
495
- r
496
- ]), I(() => {
497
- v.current && v.current.setEvents({
513
+ m,
514
+ n
515
+ ]), H(() => {
516
+ C.current && C.current.setEvents({
498
517
  onCallStart: u,
499
518
  onCallEnd: i,
500
- onStatusChange: (c) => {
501
- d(c), a?.(c);
519
+ onStatusChange: (r) => {
520
+ d(r), a?.(r);
502
521
  },
503
- onConnectionChange: (c) => {
504
- y(c), g?.(c);
522
+ onConnectionChange: (r) => {
523
+ y(r), g?.(r);
505
524
  }
506
525
  });
507
526
  }, [u, i, a, g]);
508
- const D = k((c) => {
509
- P(c), v.current?.setCallNumber(c);
510
- }, []), U = k((c) => {
511
- v.current?.startCall(c);
527
+ const z = k((r) => {
528
+ E(r), C.current?.setCallNumber(r);
529
+ }, []), L = k((r) => {
530
+ C.current?.startCall(r);
531
+ }, []), j = k(() => {
532
+ C.current?.endCall();
512
533
  }, []), A = k(() => {
513
- v.current?.endCall();
514
- }, []), L = k(() => {
515
- v.current?.clearHistory(), s([]);
534
+ C.current?.clearHistory(), w([]);
516
535
  }, []);
517
536
  return {
518
537
  status: l,
519
538
  callNumber: x,
520
- setCallNumber: D,
521
- callHistory: N,
522
- clearCallHistory: L,
523
- currentCallDuration: M,
524
- startCall: U,
525
- endCall: A,
526
- isReady: f,
527
- connectionStatus: S,
528
- ua: v.current?.ua ?? null
539
+ setCallNumber: z,
540
+ callHistory: M,
541
+ clearCallHistory: A,
542
+ currentCallDuration: I,
543
+ startCall: L,
544
+ endCall: j,
545
+ isReady: R,
546
+ connectionStatus: h,
547
+ ua: C.current?.ua ?? null
529
548
  };
530
549
  }
531
550
  export {
532
- xe as P,
533
- se as a,
534
- ve as b,
535
- oe as u
551
+ be as P,
552
+ le as a,
553
+ we as b,
554
+ ce as u
536
555
  };