@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.
- package/dist/components/phone.d.ts.map +1 -1
- package/dist/context/PhoneContext.d.ts +2 -0
- package/dist/context/PhoneContext.d.ts.map +1 -1
- package/dist/core/index.cjs +1 -1
- package/dist/core/index.js +1 -1
- package/dist/{index-Br8w8pI3.cjs → index-BTMeEufy.cjs} +1 -1
- package/dist/{index-TymkBND5.js → index-D8BnjTav.js} +2 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +3 -3
- package/dist/react/Phone.d.ts.map +1 -1
- package/dist/react/PhoneContext.d.ts +2 -0
- package/dist/react/PhoneContext.d.ts.map +1 -1
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.js +2 -2
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/{usePhoneManager-OZM1GaNS.js → usePhoneManager-B0omS154.js} +240 -221
- package/dist/usePhoneManager-DYQFwNDy.cjs +1 -0
- package/dist/vue/index.cjs +1 -1
- package/dist/vue/index.js +1 -1
- package/package.json +1 -1
- package/dist/usePhoneManager-uj2opBKT.cjs +0 -1
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { jsx as t, jsxs as o, Fragment as
|
|
2
|
-
import { useState as p, useRef as
|
|
3
|
-
import { J
|
|
4
|
-
let
|
|
5
|
-
function
|
|
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
|
|
9
|
-
const
|
|
10
|
-
if (
|
|
11
|
-
return
|
|
12
|
-
if (
|
|
8
|
+
function ne(e) {
|
|
9
|
+
const f = te(e);
|
|
10
|
+
if (D && _ === f)
|
|
11
|
+
return D;
|
|
12
|
+
if (D && _ !== f) {
|
|
13
13
|
try {
|
|
14
|
-
|
|
14
|
+
D.ua.stop();
|
|
15
15
|
} catch {
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
D = null;
|
|
18
18
|
}
|
|
19
|
-
|
|
19
|
+
_ = f;
|
|
20
20
|
const i = {
|
|
21
|
-
sockets: [new
|
|
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
|
|
29
|
+
}, a = new J.UA(i), g = document.createElement("audio");
|
|
30
30
|
g.autoplay = !0;
|
|
31
|
-
const
|
|
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
|
-
|
|
38
|
+
m.listeners.forEach((n) => n.onConnecting?.());
|
|
39
39
|
}), a.on("connected", () => {
|
|
40
|
-
|
|
40
|
+
m.listeners.forEach((n) => n.onConnected?.());
|
|
41
41
|
}), a.on("disconnected", () => {
|
|
42
|
-
|
|
42
|
+
m.listeners.forEach((n) => n.onDisconnected?.());
|
|
43
43
|
}), a.on("registered", () => {
|
|
44
|
-
|
|
44
|
+
m.listeners.forEach((n) => n.onRegistered?.());
|
|
45
45
|
}), a.on("unregistered", () => {
|
|
46
|
-
|
|
47
|
-
}), a.on("registrationFailed", (
|
|
48
|
-
|
|
49
|
-
}), a.on("newRTCSession", (
|
|
50
|
-
const l =
|
|
51
|
-
l.direction === "outgoing" && (
|
|
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
|
-
}),
|
|
58
|
+
}), D = m, m;
|
|
59
59
|
}
|
|
60
|
-
function
|
|
60
|
+
function re(e) {
|
|
61
61
|
e.isStarted || (e.ua.start(), e.isStarted = !0);
|
|
62
62
|
}
|
|
63
|
-
function
|
|
64
|
-
e.listeners.add(
|
|
63
|
+
function se(e, f) {
|
|
64
|
+
e.listeners.add(f);
|
|
65
65
|
}
|
|
66
|
-
function
|
|
67
|
-
e.listeners.delete(
|
|
66
|
+
function oe(e, f) {
|
|
67
|
+
e.listeners.delete(f);
|
|
68
68
|
}
|
|
69
|
-
function
|
|
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
|
|
76
|
-
function
|
|
75
|
+
const W = X(null);
|
|
76
|
+
function le({
|
|
77
77
|
config: e,
|
|
78
|
-
children:
|
|
78
|
+
children: f,
|
|
79
79
|
onCallStart: u,
|
|
80
80
|
onCallEnd: i,
|
|
81
81
|
onStatusChange: a
|
|
82
82
|
}) {
|
|
83
|
-
const [g,
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}, [d])
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
|
-
|
|
100
|
+
h("disconnected"), R(!1);
|
|
96
101
|
},
|
|
97
102
|
onRegistered: () => {
|
|
98
|
-
|
|
103
|
+
R(!0), h("connected");
|
|
99
104
|
},
|
|
100
|
-
onUnregistered: () =>
|
|
101
|
-
onRegistrationFailed: (
|
|
102
|
-
console.error("Registration failed:",
|
|
105
|
+
onUnregistered: () => R(!1),
|
|
106
|
+
onRegistrationFailed: (U) => {
|
|
107
|
+
console.error("Registration failed:", U), R(!1), h("failed");
|
|
103
108
|
},
|
|
104
|
-
onNewSession: (
|
|
105
|
-
|
|
109
|
+
onNewSession: (U) => {
|
|
110
|
+
z.current = U;
|
|
106
111
|
}
|
|
107
112
|
};
|
|
108
|
-
return
|
|
109
|
-
|
|
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]),
|
|
112
|
-
a?.(
|
|
113
|
-
}, [
|
|
114
|
-
const
|
|
115
|
-
if (
|
|
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
|
-
|
|
118
|
-
} catch (
|
|
119
|
-
console.error("Error loading call history",
|
|
122
|
+
I(JSON.parse(s));
|
|
123
|
+
} catch (b) {
|
|
124
|
+
console.error("Error loading call history", b);
|
|
120
125
|
}
|
|
121
|
-
}, []),
|
|
122
|
-
|
|
123
|
-
}, [
|
|
124
|
-
if (
|
|
125
|
-
const
|
|
126
|
-
|
|
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(
|
|
133
|
+
return () => clearInterval(s);
|
|
129
134
|
} else
|
|
130
|
-
|
|
131
|
-
}, [
|
|
132
|
-
const
|
|
133
|
-
const
|
|
134
|
-
|
|
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",
|
|
137
|
-
window.removeEventListener("StartCallEvent",
|
|
141
|
+
return window.addEventListener("StartCallEvent", s), () => {
|
|
142
|
+
window.removeEventListener("StartCallEvent", s);
|
|
138
143
|
};
|
|
139
|
-
}, [
|
|
140
|
-
const
|
|
141
|
-
const
|
|
144
|
+
}, [n]);
|
|
145
|
+
const r = k((s, b, P) => {
|
|
146
|
+
const U = {
|
|
142
147
|
id: Date.now().toString(),
|
|
143
|
-
number:
|
|
148
|
+
number: s,
|
|
144
149
|
timestamp: Date.now(),
|
|
145
|
-
duration:
|
|
146
|
-
status:
|
|
150
|
+
duration: b,
|
|
151
|
+
status: P
|
|
147
152
|
};
|
|
148
|
-
|
|
149
|
-
}, []),
|
|
150
|
-
|
|
151
|
-
}, []),
|
|
152
|
-
const
|
|
153
|
-
if (!
|
|
154
|
-
if (!
|
|
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
|
-
|
|
159
|
-
const
|
|
163
|
+
m(s), u?.(s);
|
|
164
|
+
const U = {
|
|
160
165
|
eventHandlers: {
|
|
161
166
|
progress: () => {
|
|
162
167
|
l("progress");
|
|
163
168
|
},
|
|
164
|
-
failed: (
|
|
165
|
-
console.error("Call failed:",
|
|
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
|
|
170
|
-
|
|
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
|
|
183
|
-
|
|
184
|
-
} catch (
|
|
185
|
-
console.error("Failed to start call:",
|
|
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
|
-
}, [
|
|
188
|
-
status:
|
|
192
|
+
}, [r, u, i, c]), G = {
|
|
193
|
+
status: n,
|
|
189
194
|
callNumber: g,
|
|
190
|
-
setCallNumber:
|
|
191
|
-
callHistory:
|
|
192
|
-
currentCallDuration:
|
|
193
|
-
startCall:
|
|
194
|
-
endCall:
|
|
195
|
-
isReady:
|
|
196
|
-
connectionStatus:
|
|
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(
|
|
205
|
+
return /* @__PURE__ */ t(W.Provider, { value: G, children: f });
|
|
199
206
|
}
|
|
200
|
-
function
|
|
201
|
-
const e =
|
|
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
|
|
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
|
-
] }),
|
|
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
|
-
] }),
|
|
213
|
-
function
|
|
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:
|
|
220
|
-
startCall:
|
|
226
|
+
currentCallDuration: m,
|
|
227
|
+
startCall: n,
|
|
221
228
|
endCall: l,
|
|
222
229
|
isReady: d,
|
|
223
|
-
connectionStatus: x
|
|
224
|
-
|
|
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: `${
|
|
236
|
+
return { text: `${c.calling}...`, color: "text-yellow-500", Icon: ie };
|
|
228
237
|
case "confirmed":
|
|
229
|
-
return { text: `${
|
|
238
|
+
return { text: `${c.inCall} - ${O(m)}`, color: "text-green-500", Icon: de };
|
|
230
239
|
case "failed":
|
|
231
|
-
return { text:
|
|
240
|
+
return { text: c.callEnded, color: "text-red-500", Icon: q };
|
|
232
241
|
case "ended":
|
|
233
|
-
return { text:
|
|
242
|
+
return { text: c.callEnded, color: "text-gray-500", Icon: B };
|
|
234
243
|
default:
|
|
235
|
-
return { text:
|
|
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
|
-
|
|
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: () =>
|
|
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(
|
|
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: (
|
|
258
|
-
onKeyDown: (
|
|
259
|
-
|
|
276
|
+
onChange: (h) => a(h.target.value),
|
|
277
|
+
onKeyDown: (h) => {
|
|
278
|
+
h.key === "Enter" && n(i);
|
|
260
279
|
},
|
|
261
|
-
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: () =>
|
|
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(
|
|
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(
|
|
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
|
-
|
|
303
|
+
c.calling,
|
|
285
304
|
" ",
|
|
286
305
|
i
|
|
287
306
|
] }),
|
|
288
|
-
/* @__PURE__ */ t("p", { className: "text-sm text-gray-500", children:
|
|
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(
|
|
298
|
-
|
|
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(
|
|
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:
|
|
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(
|
|
320
|
-
|
|
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
|
-
|
|
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:
|
|
354
|
+
/* @__PURE__ */ t("div", { className: "text-center", children: /* @__PURE__ */ t("p", { className: "text-base font-semibold", children: v.text }) })
|
|
336
355
|
] }),
|
|
337
|
-
|
|
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: () =>
|
|
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:
|
|
349
|
-
/* @__PURE__ */ t("p", { className: "text-sm text-gray-500", children: g.length === 0 ?
|
|
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: () =>
|
|
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(
|
|
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(
|
|
363
|
-
/* @__PURE__ */ t("p", { children:
|
|
364
|
-
] }) : /* @__PURE__ */ t("div", { className: "space-y-2", children: g.map((
|
|
365
|
-
|
|
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:
|
|
368
|
-
index:
|
|
386
|
+
entry: h,
|
|
387
|
+
index: y,
|
|
369
388
|
onCall: () => {
|
|
370
|
-
a(
|
|
389
|
+
a(h.number), I(!1), n(h.number);
|
|
371
390
|
}
|
|
372
391
|
},
|
|
373
|
-
|
|
392
|
+
h.id
|
|
374
393
|
)) }) })
|
|
375
394
|
] }) })
|
|
376
395
|
] })
|
|
377
396
|
] });
|
|
378
397
|
}
|
|
379
|
-
function
|
|
398
|
+
function xe({
|
|
380
399
|
entry: e,
|
|
381
|
-
index:
|
|
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(
|
|
406
|
+
return /* @__PURE__ */ t(ue, { className: "w-4 h-4 text-green-600" });
|
|
388
407
|
case "failed":
|
|
389
|
-
return /* @__PURE__ */ t(
|
|
408
|
+
return /* @__PURE__ */ t(he, { className: "w-4 h-4 text-red-600" });
|
|
390
409
|
case "missed":
|
|
391
|
-
return /* @__PURE__ */ t(
|
|
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: `${
|
|
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(
|
|
441
|
+
e.duration > 0 && /* @__PURE__ */ o(Q, { children: [
|
|
423
442
|
/* @__PURE__ */ t("span", { children: "•" }),
|
|
424
|
-
/* @__PURE__ */ t("span", { className: "font-mono tabular-nums", children:
|
|
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(
|
|
453
|
+
children: /* @__PURE__ */ t(V, { className: "w-4 h-4" })
|
|
435
454
|
}
|
|
436
455
|
)
|
|
437
456
|
]
|
|
438
457
|
}
|
|
439
458
|
);
|
|
440
459
|
}
|
|
441
|
-
function
|
|
460
|
+
function be({ config: e, className: f, onCallStart: u, onCallEnd: i, onStatusChange: a, labels: g }) {
|
|
442
461
|
return /* @__PURE__ */ t(
|
|
443
|
-
|
|
462
|
+
le,
|
|
444
463
|
{
|
|
445
464
|
config: e,
|
|
446
465
|
onCallStart: u,
|
|
447
466
|
onCallEnd: i,
|
|
448
467
|
onStatusChange: a,
|
|
449
|
-
children: /* @__PURE__ */ t(
|
|
468
|
+
children: /* @__PURE__ */ t(pe, { className: f, labels: g })
|
|
450
469
|
}
|
|
451
470
|
);
|
|
452
471
|
}
|
|
453
|
-
function
|
|
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:
|
|
460
|
-
historyKey:
|
|
461
|
-
} =
|
|
462
|
-
|
|
463
|
-
const
|
|
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: (
|
|
467
|
-
d(
|
|
485
|
+
onStatusChange: (N) => {
|
|
486
|
+
d(N), a?.(N);
|
|
468
487
|
},
|
|
469
|
-
onConnectionChange: (
|
|
470
|
-
y(
|
|
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:
|
|
475
|
-
onHistoryUpdate:
|
|
476
|
-
onRegistered: () =>
|
|
477
|
-
onUnregistered: () =>
|
|
493
|
+
onDurationUpdate: c,
|
|
494
|
+
onHistoryUpdate: w,
|
|
495
|
+
onRegistered: () => v(!0),
|
|
496
|
+
onUnregistered: () => v(!1)
|
|
478
497
|
},
|
|
479
498
|
{
|
|
480
|
-
persistHistory:
|
|
481
|
-
historyKey:
|
|
499
|
+
persistHistory: m,
|
|
500
|
+
historyKey: n
|
|
482
501
|
}
|
|
483
502
|
);
|
|
484
|
-
return
|
|
485
|
-
|
|
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
|
-
|
|
495
|
-
|
|
496
|
-
]),
|
|
497
|
-
|
|
513
|
+
m,
|
|
514
|
+
n
|
|
515
|
+
]), H(() => {
|
|
516
|
+
C.current && C.current.setEvents({
|
|
498
517
|
onCallStart: u,
|
|
499
518
|
onCallEnd: i,
|
|
500
|
-
onStatusChange: (
|
|
501
|
-
d(
|
|
519
|
+
onStatusChange: (r) => {
|
|
520
|
+
d(r), a?.(r);
|
|
502
521
|
},
|
|
503
|
-
onConnectionChange: (
|
|
504
|
-
y(
|
|
522
|
+
onConnectionChange: (r) => {
|
|
523
|
+
y(r), g?.(r);
|
|
505
524
|
}
|
|
506
525
|
});
|
|
507
526
|
}, [u, i, a, g]);
|
|
508
|
-
const
|
|
509
|
-
|
|
510
|
-
}, []),
|
|
511
|
-
|
|
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
|
-
|
|
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:
|
|
521
|
-
callHistory:
|
|
522
|
-
clearCallHistory:
|
|
523
|
-
currentCallDuration:
|
|
524
|
-
startCall:
|
|
525
|
-
endCall:
|
|
526
|
-
isReady:
|
|
527
|
-
connectionStatus:
|
|
528
|
-
ua:
|
|
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
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
551
|
+
be as P,
|
|
552
|
+
le as a,
|
|
553
|
+
we as b,
|
|
554
|
+
ce as u
|
|
536
555
|
};
|