@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.
@@ -1,5 +1,10 @@
1
1
  import type { InjectionKey, Ref } from 'vue';
2
2
  import type { PhoneConfig, PhoneStatus, CallHistoryEntry, ConnectionStatus } from '../types';
3
+ export interface IncomingCallInfo {
4
+ session: any;
5
+ callerNumber: string;
6
+ callerName?: string;
7
+ }
3
8
  export interface PhoneContextValue {
4
9
  status: Ref<PhoneStatus>;
5
10
  callNumber: Ref<string>;
@@ -8,8 +13,11 @@ export interface PhoneContextValue {
8
13
  currentCallDuration: Ref<number>;
9
14
  startCall: (number: string) => void;
10
15
  endCall: () => void;
16
+ answerCall: () => void;
17
+ rejectCall: () => void;
11
18
  isReady: Ref<boolean>;
12
19
  connectionStatus: Ref<ConnectionStatus>;
20
+ incomingCall: Ref<IncomingCallInfo | null>;
13
21
  }
14
22
  export declare const PhoneKey: InjectionKey<PhoneContextValue>;
15
23
  export interface UsePhoneProviderOptions {
@@ -17,6 +25,7 @@ export interface UsePhoneProviderOptions {
17
25
  onCallStart?: (number: string) => void;
18
26
  onCallEnd?: (number: string, duration: number, status: 'completed' | 'failed') => void;
19
27
  onStatusChange?: (status: PhoneStatus) => void;
28
+ onIncomingCall?: (callerNumber: string, callerName?: string) => void;
20
29
  }
21
30
  /**
22
31
  * Composable that provides phone functionality to child components.
@@ -1 +1 @@
1
- {"version":3,"file":"usePhone.d.ts","sourceRoot":"","sources":["../../src/vue/usePhone.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE7C,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAM7F,MAAM,WAAW,iBAAiB;IAC9B,MAAM,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC;IACzB,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACxB,aAAa,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,WAAW,EAAE,GAAG,CAAC,gBAAgB,EAAE,CAAC,CAAC;IACrC,mBAAmB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACjC,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACpC,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IACtB,gBAAgB,EAAE,GAAG,CAAC,gBAAgB,CAAC,CAAC;CAC3C;AAGD,eAAO,MAAM,QAAQ,EAAE,YAAY,CAAC,iBAAiB,CAAmB,CAAC;AA8HzE,MAAM,WAAW,uBAAuB;IACpC,MAAM,EAAE,WAAW,CAAC;IACpB,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,QAAQ,KAAK,IAAI,CAAC;IACvF,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,IAAI,CAAC;CAClD;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,iBAAiB,CAoNpF;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,QAAQ,IAAI,iBAAiB,CAM5C"}
1
+ {"version":3,"file":"usePhone.d.ts","sourceRoot":"","sources":["../../src/vue/usePhone.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE7C,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAM7F,MAAM,WAAW,gBAAgB;IAC7B,OAAO,EAAE,GAAG,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,iBAAiB;IAC9B,MAAM,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC;IACzB,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACxB,aAAa,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,WAAW,EAAE,GAAG,CAAC,gBAAgB,EAAE,CAAC,CAAC;IACrC,mBAAmB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACjC,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACpC,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IACtB,gBAAgB,EAAE,GAAG,CAAC,gBAAgB,CAAC,CAAC;IACxC,YAAY,EAAE,GAAG,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAAC;CAC9C;AAGD,eAAO,MAAM,QAAQ,EAAE,YAAY,CAAC,iBAAiB,CAAmB,CAAC;AAuJzE,MAAM,WAAW,uBAAuB;IACpC,MAAM,EAAE,WAAW,CAAC;IACpB,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,QAAQ,KAAK,IAAI,CAAC;IACvF,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,IAAI,CAAC;IAC/C,cAAc,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;CACxE;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,iBAAiB,CA+TpF;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,QAAQ,IAAI,iBAAiB,CAM5C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tbisoftware/phone",
3
- "version": "2.0.8",
3
+ "version": "2.0.9",
4
4
  "type": "module",
5
5
  "description": "A reusable SIP phone component for React and Vue applications",
6
6
  "author": "TBI",
@@ -1,555 +0,0 @@
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
- return `${e.websocketUrl}|${e.sipUri}|${e.authorizationUser}`;
7
- }
8
- function ne(e) {
9
- const f = te(e);
10
- if (D && _ === f)
11
- return D;
12
- if (D && _ !== f) {
13
- try {
14
- D.ua.stop();
15
- } catch {
16
- }
17
- D = null;
18
- }
19
- _ = f;
20
- const i = {
21
- sockets: [new J.WebSocketInterface(e.websocketUrl)],
22
- uri: e.sipUri,
23
- password: e.password,
24
- registrar_server: e.registrarServer,
25
- display_name: e.displayName,
26
- authorization_user: e.authorizationUser,
27
- connection_recovery_min_interval: 2,
28
- connection_recovery_max_interval: 30
29
- }, a = new J.UA(i), g = document.createElement("audio");
30
- g.autoplay = !0;
31
- const m = {
32
- ua: a,
33
- audio: g,
34
- isStarted: !1,
35
- listeners: /* @__PURE__ */ new Set()
36
- };
37
- return a.on("connecting", () => {
38
- m.listeners.forEach((n) => n.onConnecting?.());
39
- }), a.on("connected", () => {
40
- m.listeners.forEach((n) => n.onConnected?.());
41
- }), a.on("disconnected", () => {
42
- m.listeners.forEach((n) => n.onDisconnected?.());
43
- }), a.on("registered", () => {
44
- m.listeners.forEach((n) => n.onRegistered?.());
45
- }), a.on("unregistered", () => {
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
- var x = document.createElement("audio");
53
- d.streams !== void 0 && d.streams.length !== 0 && (x.srcObject = d.streams[0], x.play());
54
- }), l.connection.addEventListener("track", (d) => {
55
- var x = document.createElement("audio");
56
- x.srcObject = d.streams[0], x.play();
57
- })));
58
- }), D = m, m;
59
- }
60
- function re(e) {
61
- e.isStarted || (e.ua.start(), e.isStarted = !0);
62
- }
63
- function se(e, f) {
64
- e.listeners.add(f);
65
- }
66
- function oe(e, f) {
67
- e.listeners.delete(f);
68
- }
69
- function ae(e) {
70
- return {
71
- isReady: e.ua.isRegistered(),
72
- isConnected: e.ua.isConnected()
73
- };
74
- }
75
- const W = X(null);
76
- function le({
77
- config: e,
78
- children: f,
79
- onCallStart: u,
80
- onCallEnd: i,
81
- onStatusChange: a
82
- }) {
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"),
99
- onDisconnected: () => {
100
- h("disconnected"), R(!1);
101
- },
102
- onRegistered: () => {
103
- R(!0), h("connected");
104
- },
105
- onUnregistered: () => R(!1),
106
- onRegistrationFailed: (U) => {
107
- console.error("Registration failed:", U), R(!1), h("failed");
108
- },
109
- onNewSession: (U) => {
110
- z.current = U;
111
- }
112
- };
113
- return se(s, P), re(s), () => {
114
- oe(s, P);
115
- };
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)
121
- try {
122
- I(JSON.parse(s));
123
- } catch (b) {
124
- console.error("Error loading call history", b);
125
- }
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));
132
- }, 1e3);
133
- return () => clearInterval(s);
134
- } else
135
- M(0);
136
- }, [n, d]), H(() => {
137
- const s = (b) => {
138
- const P = b.detail.number;
139
- n === "disconnected" && F(P);
140
- };
141
- return window.addEventListener("StartCallEvent", s), () => {
142
- window.removeEventListener("StartCallEvent", s);
143
- };
144
- }, [n]);
145
- const r = k((s, b, P) => {
146
- const U = {
147
- id: Date.now().toString(),
148
- number: s,
149
- timestamp: Date.now(),
150
- duration: b,
151
- status: P
152
- };
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) {
160
- console.warn("Phone is not ready yet. Please wait for registration.");
161
- return;
162
- }
163
- m(s), u?.(s);
164
- const U = {
165
- eventHandlers: {
166
- progress: () => {
167
- l("progress");
168
- },
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);
171
- },
172
- ended: () => {
173
- l("ended");
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(() => {
176
- l("disconnected"), x(null);
177
- }, 2e3);
178
- },
179
- confirmed: () => {
180
- l("confirmed"), x(Date.now());
181
- }
182
- },
183
- mediaConstraints: { audio: !0, video: !1 }
184
- };
185
- l("progress");
186
- try {
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);
191
- }
192
- }, [r, u, i, c]), G = {
193
- status: n,
194
- callNumber: g,
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
204
- };
205
- return /* @__PURE__ */ t(W.Provider, { value: G, children: f });
206
- }
207
- function ce() {
208
- const e = Y(W);
209
- if (!e)
210
- throw new Error("usePhone must be used within a PhoneProvider");
211
- return e;
212
- }
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: [
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" }),
215
- /* @__PURE__ */ t("path", { d: "M16 3l-5 5-2-2-1.5 1.5L11 11l6.5-6.5z" })
216
- ] }), he = ({ className: e }) => /* @__PURE__ */ o("svg", { className: e, viewBox: "0 0 24 24", fill: "currentColor", children: [
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" }),
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" })
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 }) {
221
- const {
222
- status: u,
223
- callNumber: i,
224
- setCallNumber: a,
225
- callHistory: g,
226
- currentCallDuration: m,
227
- startCall: n,
228
- endCall: l,
229
- isReady: d,
230
- connectionStatus: x,
231
- isInitialized: E,
232
- initialize: M
233
- } = ce(), [w, I] = p(!1), c = { ...Z, ...f }, v = (() => {
234
- switch (u) {
235
- case "progress":
236
- return { text: `${c.calling}...`, color: "text-yellow-500", Icon: ie };
237
- case "confirmed":
238
- return { text: `${c.inCall} - ${O(m)}`, color: "text-green-500", Icon: de };
239
- case "failed":
240
- return { text: c.callEnded, color: "text-red-500", Icon: q };
241
- case "ended":
242
- return { text: c.callEnded, color: "text-gray-500", Icon: B };
243
- default:
244
- return { text: c.inactive, color: "text-gray-300", Icon: V };
245
- }
246
- })();
247
- return /* @__PURE__ */ o("div", { className: $(
248
- "tbi-phone w-full max-w-md mx-auto bg-white rounded-2xl shadow-lg border border-gray-200 p-2",
249
- e
250
- ), 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: [
262
- /* @__PURE__ */ t(
263
- "button",
264
- {
265
- onClick: () => I(!0),
266
- className: "h-8 w-8 flex items-center justify-center rounded-xl border border-gray-200 hover:bg-gray-50 transition-colors",
267
- type: "button",
268
- children: /* @__PURE__ */ t(me, { className: "w-4 h-4" })
269
- }
270
- ),
271
- /* @__PURE__ */ t(
272
- "input",
273
- {
274
- type: "text",
275
- value: i,
276
- onChange: (h) => a(h.target.value),
277
- onKeyDown: (h) => {
278
- h.key === "Enter" && n(i);
279
- },
280
- placeholder: c.placeholder,
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"
282
- }
283
- ),
284
- /* @__PURE__ */ t(
285
- "button",
286
- {
287
- onClick: () => n(i),
288
- disabled: i.length < 9 || !d,
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",
290
- type: "button",
291
- title: d ? "Call" : "Connecting...",
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" })
293
- }
294
- )
295
- ] }),
296
- u === "progress" && /* @__PURE__ */ o("div", { className: "flex flex-col items-center gap-3 py-6", children: [
297
- /* @__PURE__ */ o("div", { className: "relative", children: [
298
- /* @__PURE__ */ t(v.Icon, { className: "w-12 h-12 text-yellow-500 animate-pulse" }),
299
- /* @__PURE__ */ t("div", { className: "absolute inset-0 rounded-full border-4 border-yellow-500/30 animate-ping" })
300
- ] }),
301
- /* @__PURE__ */ o("div", { className: "text-center", children: [
302
- /* @__PURE__ */ o("p", { className: "text-base font-semibold", children: [
303
- c.calling,
304
- " ",
305
- i
306
- ] }),
307
- /* @__PURE__ */ t("p", { className: "text-sm text-gray-500", children: c.waitingResponse })
308
- ] }),
309
- /* @__PURE__ */ o(
310
- "button",
311
- {
312
- onClick: l,
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",
314
- type: "button",
315
- children: [
316
- /* @__PURE__ */ t(B, { className: "w-4 h-4" }),
317
- c.cancel
318
- ]
319
- }
320
- )
321
- ] }),
322
- u === "confirmed" && /* @__PURE__ */ o("div", { className: "flex flex-col items-center gap-4 py-6", children: [
323
- /* @__PURE__ */ o("div", { className: "relative", children: [
324
- /* @__PURE__ */ t(v.Icon, { className: "w-12 h-12 text-green-500" }),
325
- /* @__PURE__ */ t("div", { className: "absolute inset-0 rounded-full bg-green-500/20 animate-pulse" })
326
- ] }),
327
- /* @__PURE__ */ o("div", { className: "text-center space-y-1", children: [
328
- /* @__PURE__ */ t("p", { className: "text-xl font-bold", children: i }),
329
- /* @__PURE__ */ t("p", { className: "text-2xl font-mono text-green-600 tabular-nums", children: O(m) })
330
- ] }),
331
- /* @__PURE__ */ o(
332
- "button",
333
- {
334
- onClick: l,
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",
336
- type: "button",
337
- children: [
338
- /* @__PURE__ */ t(B, { className: "w-4 h-4" }),
339
- c.hangUp
340
- ]
341
- }
342
- )
343
- ] }),
344
- (u === "failed" || u === "ended") && /* @__PURE__ */ o("div", { className: "flex flex-col items-center gap-3 py-6", children: [
345
- /* @__PURE__ */ t(
346
- v.Icon,
347
- {
348
- className: $(
349
- "w-12 h-12",
350
- u === "failed" ? "text-red-500" : "text-gray-500"
351
- )
352
- }
353
- ),
354
- /* @__PURE__ */ t("div", { className: "text-center", children: /* @__PURE__ */ t("p", { className: "text-base font-semibold", children: v.text }) })
355
- ] }),
356
- w && /* @__PURE__ */ o("div", { className: "fixed inset-0 z-50 flex", children: [
357
- /* @__PURE__ */ t(
358
- "div",
359
- {
360
- className: "fixed inset-0 bg-black/50",
361
- onClick: () => I(!1)
362
- }
363
- ),
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: [
365
- /* @__PURE__ */ o("div", { className: "flex items-center justify-between p-4 border-b", children: [
366
- /* @__PURE__ */ o("div", { children: [
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}` })
369
- ] }),
370
- /* @__PURE__ */ t(
371
- "button",
372
- {
373
- onClick: () => I(!1),
374
- className: "h-8 w-8 flex items-center justify-center rounded-lg hover:bg-gray-100 transition-colors",
375
- type: "button",
376
- children: /* @__PURE__ */ t(fe, { className: "w-5 h-5" })
377
- }
378
- )
379
- ] }),
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: [
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,
385
- {
386
- entry: h,
387
- index: y,
388
- onCall: () => {
389
- a(h.number), I(!1), n(h.number);
390
- }
391
- },
392
- h.id
393
- )) }) })
394
- ] }) })
395
- ] })
396
- ] });
397
- }
398
- function xe({
399
- entry: e,
400
- index: f,
401
- onCall: u
402
- }) {
403
- const i = () => {
404
- switch (e.status) {
405
- case "completed":
406
- return /* @__PURE__ */ t(ue, { className: "w-4 h-4 text-green-600" });
407
- case "failed":
408
- return /* @__PURE__ */ t(he, { className: "w-4 h-4 text-red-600" });
409
- case "missed":
410
- return /* @__PURE__ */ t(q, { className: "w-4 h-4 text-yellow-600" });
411
- }
412
- }, a = () => {
413
- switch (e.status) {
414
- case "completed":
415
- return "bg-green-100";
416
- case "failed":
417
- return "bg-red-100";
418
- case "missed":
419
- return "bg-yellow-100";
420
- }
421
- };
422
- return /* @__PURE__ */ o(
423
- "div",
424
- {
425
- className: "flex items-center gap-3 p-3 rounded-lg hover:bg-gray-50 transition-colors duration-200",
426
- style: { animationDelay: `${f * 30}ms` },
427
- children: [
428
- /* @__PURE__ */ t("div", { className: $(
429
- "w-9 h-9 rounded-full flex items-center justify-center shrink-0",
430
- a()
431
- ), children: i() }),
432
- /* @__PURE__ */ o("div", { className: "flex-1 min-w-0", children: [
433
- /* @__PURE__ */ t("p", { className: "font-medium text-sm truncate", children: e.number }),
434
- /* @__PURE__ */ o("div", { className: "flex items-center gap-2 text-xs text-gray-500", children: [
435
- /* @__PURE__ */ t("span", { children: new Date(e.timestamp).toLocaleString("es-ES", {
436
- day: "2-digit",
437
- month: "2-digit",
438
- hour: "2-digit",
439
- minute: "2-digit"
440
- }) }),
441
- e.duration > 0 && /* @__PURE__ */ o(Q, { children: [
442
- /* @__PURE__ */ t("span", { children: "•" }),
443
- /* @__PURE__ */ t("span", { className: "font-mono tabular-nums", children: O(e.duration) })
444
- ] })
445
- ] })
446
- ] }),
447
- /* @__PURE__ */ t(
448
- "button",
449
- {
450
- onClick: u,
451
- className: "h-8 w-8 flex items-center justify-center shrink-0 rounded-lg hover:bg-gray-100 transition-colors",
452
- type: "button",
453
- children: /* @__PURE__ */ t(V, { className: "w-4 h-4" })
454
- }
455
- )
456
- ]
457
- }
458
- );
459
- }
460
- function be({ config: e, className: f, onCallStart: u, onCallEnd: i, onStatusChange: a, labels: g }) {
461
- return /* @__PURE__ */ t(
462
- le,
463
- {
464
- config: e,
465
- onCallStart: u,
466
- onCallEnd: i,
467
- onStatusChange: a,
468
- children: /* @__PURE__ */ t(pe, { className: f, labels: g })
469
- }
470
- );
471
- }
472
- function we(e, f = {}) {
473
- const {
474
- onCallStart: u,
475
- onCallEnd: i,
476
- onStatusChange: a,
477
- onConnectionChange: g,
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(
483
- e,
484
- {
485
- onStatusChange: (N) => {
486
- d(N), a?.(N);
487
- },
488
- onConnectionChange: (N) => {
489
- y(N), (N === "connected" || N === "disconnected" || N === "failed") && v(r.state.isReady), g?.(N);
490
- },
491
- onCallStart: u,
492
- onCallEnd: i,
493
- onDurationUpdate: c,
494
- onHistoryUpdate: w,
495
- onRegistered: () => v(!0),
496
- onUnregistered: () => v(!1)
497
- },
498
- {
499
- persistHistory: m,
500
- historyKey: n
501
- }
502
- );
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;
505
- };
506
- }, [
507
- e.websocketUrl,
508
- e.sipUri,
509
- e.password,
510
- e.registrarServer,
511
- e.displayName,
512
- e.authorizationUser,
513
- m,
514
- n
515
- ]), H(() => {
516
- C.current && C.current.setEvents({
517
- onCallStart: u,
518
- onCallEnd: i,
519
- onStatusChange: (r) => {
520
- d(r), a?.(r);
521
- },
522
- onConnectionChange: (r) => {
523
- y(r), g?.(r);
524
- }
525
- });
526
- }, [u, i, a, g]);
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();
533
- }, []), A = k(() => {
534
- C.current?.clearHistory(), w([]);
535
- }, []);
536
- return {
537
- status: l,
538
- callNumber: x,
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
548
- };
549
- }
550
- export {
551
- be as P,
552
- le as a,
553
- we as b,
554
- ce as u
555
- };
@@ -1 +0,0 @@
1
- "use strict";const e=require("react/jsx-runtime"),s=require("react"),N=require("./index-BTMeEufy.cjs");let H=null,B=null;function J(t){return`${t.websocketUrl}|${t.sipUri}|${t.authorizationUser}`}function q(t){const m=J(t);if(H&&B===m)return H;if(H&&B!==m){try{H.ua.stop()}catch{}H=null}B=m;const i={sockets:[new N.JsSIP.WebSocketInterface(t.websocketUrl)],uri:t.sipUri,password:t.password,registrar_server:t.registrarServer,display_name:t.displayName,authorization_user:t.authorizationUser,connection_recovery_min_interval:2,connection_recovery_max_interval:30},l=new N.JsSIP.UA(i),f=document.createElement("audio");f.autoplay=!0;const h={ua:l,audio:f,isStarted:!1,listeners:new Set};return l.on("connecting",()=>{h.listeners.forEach(n=>n.onConnecting?.())}),l.on("connected",()=>{h.listeners.forEach(n=>n.onConnected?.())}),l.on("disconnected",()=>{h.listeners.forEach(n=>n.onDisconnected?.())}),l.on("registered",()=>{h.listeners.forEach(n=>n.onRegistered?.())}),l.on("unregistered",()=>{h.listeners.forEach(n=>n.onUnregistered?.())}),l.on("registrationFailed",n=>{h.listeners.forEach(o=>o.onRegistrationFailed?.(n?.cause))}),l.on("newRTCSession",n=>{const o=n.session;o.direction==="outgoing"&&(h.listeners.forEach(d=>d.onNewSession?.(o)),o.connection&&(o.connection.addEventListener("addstream",d=>{var g=document.createElement("audio");d.streams!==void 0&&d.streams.length!==0&&(g.srcObject=d.streams[0],g.play())}),o.connection.addEventListener("track",d=>{var g=document.createElement("audio");g.srcObject=d.streams[0],g.play()})))}),H=h,h}function W(t){t.isStarted||(t.ua.start(),t.isStarted=!0)}function G(t,m){t.listeners.add(m)}function Q(t,m){t.listeners.delete(m)}function X(t){return{isReady:t.ua.isRegistered(),isConnected:t.ua.isConnected()}}const $=s.createContext(null);function O({config:t,children:m,onCallStart:u,onCallEnd:i,onStatusChange:l}){const[f,h]=s.useState(""),[n,o]=s.useState("disconnected"),[d,g]=s.useState(null),[k,P]=s.useState(0),[C,S]=s.useState([]),[c,E]=s.useState(!1),[p,x]=s.useState("disconnected"),[v,j]=s.useState(!1),I=s.useRef(null),U=s.useRef(null),M=s.useRef(null);s.useEffect(()=>{U.current=d},[d]);const L=s.useCallback(()=>{v||(j(!0),x("connecting"))},[v]);s.useEffect(()=>{if(!v)return;const a=q(t);M.current=a;const y=X(a);y.isReady?(E(!0),x("connected")):y.isConnected&&x("connected");const z={onConnecting:()=>x("connecting"),onConnected:()=>x("connected"),onDisconnected:()=>{x("disconnected"),E(!1)},onRegistered:()=>{E(!0),x("connected")},onUnregistered:()=>E(!1),onRegistrationFailed:R=>{console.error("Registration failed:",R),E(!1),x("failed")},onNewSession:R=>{I.current=R}};return G(a,z),W(a),()=>{Q(a,z)}},[v,t.websocketUrl,t.sipUri,t.password,t.registrarServer,t.displayName,t.authorizationUser]),s.useEffect(()=>{l?.(n)},[n,l]),s.useEffect(()=>{const a=localStorage.getItem("tbi-phone-call-history");if(a)try{S(JSON.parse(a))}catch(y){console.error("Error loading call history",y)}},[]),s.useEffect(()=>{C.length>0&&localStorage.setItem("tbi-phone-call-history",JSON.stringify(C))},[C]),s.useEffect(()=>{if(n==="confirmed"&&d){const a=setInterval(()=>{P(Math.floor((Date.now()-d)/1e3))},1e3);return()=>clearInterval(a)}else P(0)},[n,d]),s.useEffect(()=>{const a=y=>{const z=y.detail.number;n==="disconnected"&&A(z)};return window.addEventListener("StartCallEvent",a),()=>{window.removeEventListener("StartCallEvent",a)}},[n]);const r=s.useCallback((a,y,z)=>{const R={id:Date.now().toString(),number:a,timestamp:Date.now(),duration:y,status:z};S(w=>[R,...w].slice(0,50))},[]),b=s.useCallback(()=>{I.current&&(I.current.terminate(),I.current=null)},[]),A=s.useCallback(a=>{const y=M.current;if(!a.trim()||!y)return;if(!c){console.warn("Phone is not ready yet. Please wait for registration.");return}h(a),u?.(a);const R={eventHandlers:{progress:()=>{o("progress")},failed:w=>{console.error("Call failed:",w?.cause),o("failed"),r(a,0,"failed"),i?.(a,0,"failed"),I.current=null,setTimeout(()=>o("disconnected"),3e3)},ended:()=>{o("ended");const w=U.current,_=w?Math.floor((Date.now()-w)/1e3):0;r(a,_,"completed"),i?.(a,_,"completed"),I.current=null,setTimeout(()=>{o("disconnected"),g(null)},2e3)},confirmed:()=>{o("confirmed"),g(Date.now())}},mediaConstraints:{audio:!0,video:!1}};o("progress");try{const w=y.ua.call(a,R);I.current=w}catch(w){console.error("Failed to start call:",w),o("failed"),r(a,0,"failed"),setTimeout(()=>o("disconnected"),3e3)}},[r,u,i,c]),K={status:n,callNumber:f,setCallNumber:h,callHistory:C,currentCallDuration:k,startCall:A,endCall:b,isReady:c,connectionStatus:p,isInitialized:v,initialize:L};return e.jsx($.Provider,{value:K,children:m})}function V(){const t=s.useContext($);if(!t)throw new Error("usePhone must be used within a PhoneProvider");return t}const T=({className:t})=>e.jsx("svg",{className:t,viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("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"})}),Y=({className:t})=>e.jsx("svg",{className:t,viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("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"})}),Z=({className:t})=>e.jsx("svg",{className:t,viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("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"})}),D=({className:t})=>e.jsx("svg",{className:t,viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("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"})}),F=({className:t})=>e.jsx("svg",{className:t,viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("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"})}),ee=({className:t})=>e.jsxs("svg",{className:t,viewBox:"0 0 24 24",fill:"currentColor",children:[e.jsx("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"}),e.jsx("path",{d:"M16 3l-5 5-2-2-1.5 1.5L11 11l6.5-6.5z"})]}),te=({className:t})=>e.jsxs("svg",{className:t,viewBox:"0 0 24 24",fill:"currentColor",children:[e.jsx("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"}),e.jsx("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"})]}),se=({className:t})=>e.jsx("svg",{className:t,viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("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"})}),ne=({className:t})=>e.jsx("svg",{className:t,viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("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"})}),re=({className:t})=>e.jsx("svg",{className:t,viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("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"})});function ae({className:t,labels:m}){const{status:u,callNumber:i,setCallNumber:l,callHistory:f,currentCallDuration:h,startCall:n,endCall:o,isReady:d,connectionStatus:g,isInitialized:k,initialize:P}=V(),[C,S]=s.useState(!1),c={...N.defaultLabels,...m},p=(()=>{switch(u){case"progress":return{text:`${c.calling}...`,color:"text-yellow-500",Icon:Y};case"confirmed":return{text:`${c.inCall} - ${N.formatDuration(h)}`,color:"text-green-500",Icon:Z};case"failed":return{text:c.callEnded,color:"text-red-500",Icon:F};case"ended":return{text:c.callEnded,color:"text-gray-500",Icon:D};default:return{text:c.inactive,color:"text-gray-300",Icon:T}}})();return e.jsxs("div",{className:N.cn("tbi-phone w-full max-w-md mx-auto bg-white rounded-2xl shadow-lg border border-gray-200 p-2",t),children:[!k&&e.jsx("div",{className:"flex items-center justify-center",children:e.jsx("button",{onClick:P,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",type:"button",title:c.turnOn,children:e.jsx(re,{className:"w-5 h-5"})})}),k&&u==="disconnected"&&e.jsxs("div",{className:"flex gap-2 items-center",children:[e.jsx("button",{onClick:()=>S(!0),className:"h-8 w-8 flex items-center justify-center rounded-xl border border-gray-200 hover:bg-gray-50 transition-colors",type:"button",children:e.jsx(se,{className:"w-4 h-4"})}),e.jsx("input",{type:"text",value:i,onChange:x=>l(x.target.value),onKeyDown:x=>{x.key==="Enter"&&n(i)},placeholder:c.placeholder,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"}),e.jsx("button",{onClick:()=>n(i),disabled:i.length<9||!d,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",type:"button",title:d?"Call":"Connecting...",children:g==="connecting"?e.jsx("div",{className:"w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin"}):e.jsx(T,{className:"w-4 h-4"})})]}),u==="progress"&&e.jsxs("div",{className:"flex flex-col items-center gap-3 py-6",children:[e.jsxs("div",{className:"relative",children:[e.jsx(p.Icon,{className:"w-12 h-12 text-yellow-500 animate-pulse"}),e.jsx("div",{className:"absolute inset-0 rounded-full border-4 border-yellow-500/30 animate-ping"})]}),e.jsxs("div",{className:"text-center",children:[e.jsxs("p",{className:"text-base font-semibold",children:[c.calling," ",i]}),e.jsx("p",{className:"text-sm text-gray-500",children:c.waitingResponse})]}),e.jsxs("button",{onClick:o,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",type:"button",children:[e.jsx(D,{className:"w-4 h-4"}),c.cancel]})]}),u==="confirmed"&&e.jsxs("div",{className:"flex flex-col items-center gap-4 py-6",children:[e.jsxs("div",{className:"relative",children:[e.jsx(p.Icon,{className:"w-12 h-12 text-green-500"}),e.jsx("div",{className:"absolute inset-0 rounded-full bg-green-500/20 animate-pulse"})]}),e.jsxs("div",{className:"text-center space-y-1",children:[e.jsx("p",{className:"text-xl font-bold",children:i}),e.jsx("p",{className:"text-2xl font-mono text-green-600 tabular-nums",children:N.formatDuration(h)})]}),e.jsxs("button",{onClick:o,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",type:"button",children:[e.jsx(D,{className:"w-4 h-4"}),c.hangUp]})]}),(u==="failed"||u==="ended")&&e.jsxs("div",{className:"flex flex-col items-center gap-3 py-6",children:[e.jsx(p.Icon,{className:N.cn("w-12 h-12",u==="failed"?"text-red-500":"text-gray-500")}),e.jsx("div",{className:"text-center",children:e.jsx("p",{className:"text-base font-semibold",children:p.text})})]}),C&&e.jsxs("div",{className:"fixed inset-0 z-50 flex",children:[e.jsx("div",{className:"fixed inset-0 bg-black/50",onClick:()=>S(!1)}),e.jsx("div",{className:"fixed right-0 top-0 h-full w-full max-w-md bg-white shadow-xl",style:{backgroundColor:"white"},children:e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 border-b",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold",children:c.callHistory}),e.jsx("p",{className:"text-sm text-gray-500",children:f.length===0?c.noCallsRegistered:`${f.length} ${c.callsRegistered}`})]}),e.jsx("button",{onClick:()=>S(!1),className:"h-8 w-8 flex items-center justify-center rounded-lg hover:bg-gray-100 transition-colors",type:"button",children:e.jsx(ne,{className:"w-5 h-5"})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:f.length===0?e.jsxs("div",{className:"text-center py-12 text-gray-500",children:[e.jsx(D,{className:"w-12 h-12 mx-auto mb-2 opacity-50"}),e.jsx("p",{children:c.noCalls})]}):e.jsx("div",{className:"space-y-2",children:f.map((x,v)=>e.jsx(le,{entry:x,index:v,onCall:()=>{l(x.number),S(!1),n(x.number)}},x.id))})})]})})]})]})}function le({entry:t,index:m,onCall:u}){const i=()=>{switch(t.status){case"completed":return e.jsx(ee,{className:"w-4 h-4 text-green-600"});case"failed":return e.jsx(te,{className:"w-4 h-4 text-red-600"});case"missed":return e.jsx(F,{className:"w-4 h-4 text-yellow-600"})}},l=()=>{switch(t.status){case"completed":return"bg-green-100";case"failed":return"bg-red-100";case"missed":return"bg-yellow-100"}};return e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-lg hover:bg-gray-50 transition-colors duration-200",style:{animationDelay:`${m*30}ms`},children:[e.jsx("div",{className:N.cn("w-9 h-9 rounded-full flex items-center justify-center shrink-0",l()),children:i()}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-sm truncate",children:t.number}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500",children:[e.jsx("span",{children:new Date(t.timestamp).toLocaleString("es-ES",{day:"2-digit",month:"2-digit",hour:"2-digit",minute:"2-digit"})}),t.duration>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"•"}),e.jsx("span",{className:"font-mono tabular-nums",children:N.formatDuration(t.duration)})]})]})]}),e.jsx("button",{onClick:u,className:"h-8 w-8 flex items-center justify-center shrink-0 rounded-lg hover:bg-gray-100 transition-colors",type:"button",children:e.jsx(T,{className:"w-4 h-4"})})]})}function oe({config:t,className:m,onCallStart:u,onCallEnd:i,onStatusChange:l,labels:f}){return e.jsx(O,{config:t,onCallStart:u,onCallEnd:i,onStatusChange:l,children:e.jsx(ae,{className:m,labels:f})})}function ce(t,m={}){const{onCallStart:u,onCallEnd:i,onStatusChange:l,onConnectionChange:f,persistHistory:h=!0,historyKey:n="tbi-phone-call-history"}=m,[o,d]=s.useState("disconnected"),[g,k]=s.useState(""),[P,C]=s.useState([]),[S,c]=s.useState(0),[E,p]=s.useState(!1),[x,v]=s.useState("connecting"),j=s.useRef(null);s.useEffect(()=>{const r=new N.PhoneManager(t,{onStatusChange:b=>{d(b),l?.(b)},onConnectionChange:b=>{v(b),(b==="connected"||b==="disconnected"||b==="failed")&&p(r.state.isReady),f?.(b)},onCallStart:u,onCallEnd:i,onDurationUpdate:c,onHistoryUpdate:C,onRegistered:()=>p(!0),onUnregistered:()=>p(!1)},{persistHistory:h,historyKey:n});return r.initialize(),j.current=r,d(r.state.status),k(r.state.callNumber),C(r.state.callHistory),p(r.state.isReady),v(r.state.connectionStatus),()=>{r.destroy(),j.current=null}},[t.websocketUrl,t.sipUri,t.password,t.registrarServer,t.displayName,t.authorizationUser,h,n]),s.useEffect(()=>{j.current&&j.current.setEvents({onCallStart:u,onCallEnd:i,onStatusChange:r=>{d(r),l?.(r)},onConnectionChange:r=>{v(r),f?.(r)}})},[u,i,l,f]);const I=s.useCallback(r=>{k(r),j.current?.setCallNumber(r)},[]),U=s.useCallback(r=>{j.current?.startCall(r)},[]),M=s.useCallback(()=>{j.current?.endCall()},[]),L=s.useCallback(()=>{j.current?.clearHistory(),C([])},[]);return{status:o,callNumber:g,setCallNumber:I,callHistory:P,clearCallHistory:L,currentCallDuration:S,startCall:U,endCall:M,isReady:E,connectionStatus:x,ua:j.current?.ua??null}}exports.Phone=oe;exports.PhoneProvider=O;exports.usePhone=V;exports.usePhoneManager=ce;