@z-api/call 1.0.0-staging.0
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/README.md +590 -0
- package/dist/core/AudioEngine.d.ts +25 -0
- package/dist/core/AudioEngine.d.ts.map +1 -0
- package/dist/core/CallState.d.ts +15 -0
- package/dist/core/CallState.d.ts.map +1 -0
- package/dist/core/CallWebSocket.d.ts +29 -0
- package/dist/core/CallWebSocket.d.ts.map +1 -0
- package/dist/core/EventEmitter.d.ts +12 -0
- package/dist/core/EventEmitter.d.ts.map +1 -0
- package/dist/core/VideoEngine.d.ts +37 -0
- package/dist/core/VideoEngine.d.ts.map +1 -0
- package/dist/core/ZAPICallClient.d.ts +39 -0
- package/dist/core/ZAPICallClient.d.ts.map +1 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/types.d.ts +155 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/format.d.ts +5 -0
- package/dist/utils/format.d.ts.map +1 -0
- package/dist/utils/pcm.d.ts +7 -0
- package/dist/utils/pcm.d.ts.map +1 -0
- package/dist/widget/CallWidget.css.d.ts +3 -0
- package/dist/widget/CallWidget.css.d.ts.map +1 -0
- package/dist/widget/CallWidget.d.ts +86 -0
- package/dist/widget/CallWidget.d.ts.map +1 -0
- package/dist/widget/icons.d.ts +16 -0
- package/dist/widget/icons.d.ts.map +1 -0
- package/dist/z-api-call.global.js +915 -0
- package/dist/z-api-call.global.js.map +1 -0
- package/dist/z-api-call.mjs +1830 -0
- package/dist/z-api-call.mjs.map +1 -0
- package/dist/z-api-call.umd.js +915 -0
- package/dist/z-api-call.umd.js.map +1 -0
- package/package.json +42 -0
|
@@ -0,0 +1,1830 @@
|
|
|
1
|
+
class B {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.listeners = /* @__PURE__ */ new Map();
|
|
4
|
+
}
|
|
5
|
+
on(t, e) {
|
|
6
|
+
return this.listeners.has(t) || this.listeners.set(t, /* @__PURE__ */ new Set()), this.listeners.get(t).add(e), this;
|
|
7
|
+
}
|
|
8
|
+
off(t, e) {
|
|
9
|
+
var a;
|
|
10
|
+
return (a = this.listeners.get(t)) == null || a.delete(e), this;
|
|
11
|
+
}
|
|
12
|
+
emit(t, ...e) {
|
|
13
|
+
const a = this.listeners.get(t);
|
|
14
|
+
if (a)
|
|
15
|
+
for (const i of a)
|
|
16
|
+
try {
|
|
17
|
+
i(...e);
|
|
18
|
+
} catch (s) {
|
|
19
|
+
console.error(`[ZAPICall] Event listener error (${String(t)}):`, s);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
removeAllListeners() {
|
|
23
|
+
this.listeners.clear();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const V = 1e3, H = 3e4, O = 25e3;
|
|
27
|
+
class F {
|
|
28
|
+
constructor(t, e, a) {
|
|
29
|
+
this.ws = null, this.reconnectMs = V, this.reconnectTimer = null, this.pingTimer = null, this.destroyed = !1, this.onJson = () => {
|
|
30
|
+
}, this.onBinary = () => {
|
|
31
|
+
}, this.onConnectionChange = () => {
|
|
32
|
+
}, this.baseUrl = t, this.instanceId = e, this.getToken = a;
|
|
33
|
+
}
|
|
34
|
+
buildUrl(t) {
|
|
35
|
+
const e = new URL(this.baseUrl);
|
|
36
|
+
return e.protocol = e.protocol === "https:" ? "wss:" : "ws:", e.pathname = "/ws/call", e.searchParams.set("instance", this.instanceId), e.searchParams.set("token", t), e.toString();
|
|
37
|
+
}
|
|
38
|
+
async connect() {
|
|
39
|
+
if (this.destroyed) return;
|
|
40
|
+
this.cleanup();
|
|
41
|
+
let t;
|
|
42
|
+
try {
|
|
43
|
+
t = await this.getToken();
|
|
44
|
+
} catch (i) {
|
|
45
|
+
console.warn("[ZAPICall] Failed to get token:", i), this.scheduleReconnect();
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (this.destroyed) return;
|
|
49
|
+
const e = this.buildUrl(t);
|
|
50
|
+
console.log("[ZAPICall] Connecting to", e);
|
|
51
|
+
const a = new WebSocket(e);
|
|
52
|
+
a.binaryType = "arraybuffer", this.ws = a, a.onopen = () => {
|
|
53
|
+
console.log("[ZAPICall] WebSocket connected"), this.reconnectMs = V, this.onConnectionChange(!0), this.startPing();
|
|
54
|
+
}, a.onmessage = (i) => {
|
|
55
|
+
if (typeof i.data == "string")
|
|
56
|
+
try {
|
|
57
|
+
const s = JSON.parse(i.data);
|
|
58
|
+
console.log("[ZAPICall] <<", s.type, s), this.onJson(s);
|
|
59
|
+
} catch {
|
|
60
|
+
}
|
|
61
|
+
else i.data instanceof ArrayBuffer && this.onBinary(i.data);
|
|
62
|
+
}, a.onclose = (i) => {
|
|
63
|
+
if (console.log("[ZAPICall] WebSocket closed:", i.code, i.reason), this.stopPing(), this.onConnectionChange(!1), i.code === 4001) {
|
|
64
|
+
console.warn("[ZAPICall] Invalid credentials (4001), not reconnecting");
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
this.scheduleReconnect();
|
|
68
|
+
}, a.onerror = (i) => {
|
|
69
|
+
console.warn("[ZAPICall] WebSocket error:", i);
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
send(t) {
|
|
73
|
+
var e;
|
|
74
|
+
((e = this.ws) == null ? void 0 : e.readyState) === WebSocket.OPEN && this.ws.send(t);
|
|
75
|
+
}
|
|
76
|
+
sendJson(t) {
|
|
77
|
+
this.send(JSON.stringify(t));
|
|
78
|
+
}
|
|
79
|
+
isConnected() {
|
|
80
|
+
var t;
|
|
81
|
+
return ((t = this.ws) == null ? void 0 : t.readyState) === WebSocket.OPEN;
|
|
82
|
+
}
|
|
83
|
+
destroy() {
|
|
84
|
+
this.destroyed = !0, this.cleanup(), this.reconnectTimer && (clearTimeout(this.reconnectTimer), this.reconnectTimer = null);
|
|
85
|
+
}
|
|
86
|
+
cleanup() {
|
|
87
|
+
this.stopPing(), this.ws && (this.ws.onopen = null, this.ws.onmessage = null, this.ws.onclose = null, this.ws.onerror = null, (this.ws.readyState === WebSocket.OPEN || this.ws.readyState === WebSocket.CONNECTING) && this.ws.close(), this.ws = null);
|
|
88
|
+
}
|
|
89
|
+
scheduleReconnect() {
|
|
90
|
+
this.destroyed || (this.reconnectTimer = setTimeout(() => {
|
|
91
|
+
this.connect();
|
|
92
|
+
}, this.reconnectMs), this.reconnectMs = Math.min(this.reconnectMs * 2, H));
|
|
93
|
+
}
|
|
94
|
+
startPing() {
|
|
95
|
+
this.pingTimer = setInterval(() => {
|
|
96
|
+
this.sendJson({ type: "ping" });
|
|
97
|
+
}, O);
|
|
98
|
+
}
|
|
99
|
+
stopPing() {
|
|
100
|
+
this.pingTimer && (clearInterval(this.pingTimer), this.pingTimer = null);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function U(c) {
|
|
104
|
+
const t = new Float32Array(c.length);
|
|
105
|
+
for (let e = 0; e < c.length; e++)
|
|
106
|
+
t[e] = c[e] / 32768;
|
|
107
|
+
return t;
|
|
108
|
+
}
|
|
109
|
+
function q(c) {
|
|
110
|
+
const t = new Int16Array(c.length);
|
|
111
|
+
for (let e = 0; e < c.length; e++) {
|
|
112
|
+
let a = c[e];
|
|
113
|
+
a > 1 ? a = 1 : a < -1 && (a = -1), t[e] = Math.round(a * 32767);
|
|
114
|
+
}
|
|
115
|
+
return t;
|
|
116
|
+
}
|
|
117
|
+
function j(c) {
|
|
118
|
+
if (c.length === 0) return 0;
|
|
119
|
+
let t = 0;
|
|
120
|
+
for (let e = 0; e < c.length; e++)
|
|
121
|
+
t += c[e] * c[e];
|
|
122
|
+
return Math.sqrt(t / c.length);
|
|
123
|
+
}
|
|
124
|
+
const P = 0.02, _ = 0.15;
|
|
125
|
+
class $ {
|
|
126
|
+
constructor(t = 48e3) {
|
|
127
|
+
this.playbackCtx = null, this.micCtx = null, this.micStream = null, this.micProcessor = null, this.micSource = null, this.nextPlayTime = 0, this.destroyed = !1, this.onMicData = () => {
|
|
128
|
+
}, this.onAudioLevel = () => {
|
|
129
|
+
}, this.playLogCount = 0, this.sampleRate = t;
|
|
130
|
+
}
|
|
131
|
+
playPcm(t) {
|
|
132
|
+
if (this.destroyed || t.byteLength === 0) return;
|
|
133
|
+
if (this.playbackCtx || (this.playbackCtx = new AudioContext({ sampleRate: this.sampleRate }), this.nextPlayTime = this.playbackCtx.currentTime), this.playbackCtx.state === "suspended" && this.playbackCtx.resume(), this.playLogCount++, this.playLogCount <= 5 || this.playLogCount % 250 === 0) {
|
|
134
|
+
const o = new Int16Array(t);
|
|
135
|
+
let l = 0;
|
|
136
|
+
for (let p = 0; p < Math.min(o.length, 100); p++) {
|
|
137
|
+
const u = Math.abs(o[p]);
|
|
138
|
+
u > l && (l = u);
|
|
139
|
+
}
|
|
140
|
+
console.log(`[AudioEngine] playPcm #${this.playLogCount} bytes=${t.byteLength} ctxState=${this.playbackCtx.state} sampleRate=${this.sampleRate} maxSample=${l} nextPlayT=${this.nextPlayTime.toFixed(3)} ctxTime=${this.playbackCtx.currentTime.toFixed(3)}`);
|
|
141
|
+
}
|
|
142
|
+
const e = new Int16Array(t), a = U(e), i = j(a);
|
|
143
|
+
this.onAudioLevel(i);
|
|
144
|
+
const s = this.playbackCtx.createBuffer(1, a.length, this.sampleRate);
|
|
145
|
+
s.getChannelData(0).set(a);
|
|
146
|
+
const n = this.playbackCtx.createBufferSource();
|
|
147
|
+
n.buffer = s, n.connect(this.playbackCtx.destination);
|
|
148
|
+
const r = this.playbackCtx.currentTime;
|
|
149
|
+
this.nextPlayTime < r ? this.nextPlayTime = r + P : this.nextPlayTime - r > _ && (this.nextPlayTime = r + P), n.start(this.nextPlayTime), this.nextPlayTime += s.duration;
|
|
150
|
+
}
|
|
151
|
+
/** Start capturing microphone audio and sending as PCM Int16LE */
|
|
152
|
+
async startMic() {
|
|
153
|
+
this.destroyed || this.micStream || (this.micStream = await navigator.mediaDevices.getUserMedia({
|
|
154
|
+
audio: {
|
|
155
|
+
sampleRate: this.sampleRate,
|
|
156
|
+
channelCount: 1,
|
|
157
|
+
echoCancellation: !0,
|
|
158
|
+
noiseSuppression: !0,
|
|
159
|
+
autoGainControl: !0
|
|
160
|
+
}
|
|
161
|
+
}), this.micCtx = new AudioContext({ sampleRate: this.sampleRate }), this.micSource = this.micCtx.createMediaStreamSource(this.micStream), this.micProcessor = this.micCtx.createScriptProcessor(4096, 1, 1), this.micProcessor.onaudioprocess = (t) => {
|
|
162
|
+
if (this.destroyed) return;
|
|
163
|
+
const e = t.inputBuffer.getChannelData(0), a = q(e);
|
|
164
|
+
this.onMicData(a.buffer);
|
|
165
|
+
}, this.micSource.connect(this.micProcessor), this.micProcessor.connect(this.micCtx.destination));
|
|
166
|
+
}
|
|
167
|
+
stopMic() {
|
|
168
|
+
if (this.micProcessor && (this.micProcessor.disconnect(), this.micProcessor = null), this.micSource && (this.micSource.disconnect(), this.micSource = null), this.micStream) {
|
|
169
|
+
for (const t of this.micStream.getTracks())
|
|
170
|
+
t.stop();
|
|
171
|
+
this.micStream = null;
|
|
172
|
+
}
|
|
173
|
+
this.micCtx && (this.micCtx.close().catch(() => {
|
|
174
|
+
}), this.micCtx = null);
|
|
175
|
+
}
|
|
176
|
+
/** Resume AudioContext (must be called from user gesture for autoplay policy) */
|
|
177
|
+
resume() {
|
|
178
|
+
this.playbackCtx || (this.playbackCtx = new AudioContext({ sampleRate: this.sampleRate }), this.nextPlayTime = this.playbackCtx.currentTime), this.playbackCtx.state === "suspended" && this.playbackCtx.resume();
|
|
179
|
+
}
|
|
180
|
+
destroy() {
|
|
181
|
+
this.destroyed = !0, this.stopMic(), this.playbackCtx && (this.playbackCtx.close().catch(() => {
|
|
182
|
+
}), this.playbackCtx = null);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
const W = 100, K = "avc1.42001E", G = 5;
|
|
186
|
+
class J {
|
|
187
|
+
constructor() {
|
|
188
|
+
this.canvas = null, this.ctx = null, this.localVideo = null, this.localStream = null, this.captureCanvas = null, this.captureCtx = null, this.tempCanvas = null, this.tempCtx = null, this.captureInterval = null, this.h264Decoder = null, this.h264ErrorCount = 0, this.orientationMap = /* @__PURE__ */ new Map(), this.onCameraFrame = null, this.onEncodedCameraFrame = null, this.h264Encoder = null, this.encoderKeyFrameInterval = 3e3, this.lastKeyFrameTs = 0, this.h264NeedKeyFrame = !1, this.h264GotKeyFrame = !1, this.h264FrameIndex = 0;
|
|
189
|
+
}
|
|
190
|
+
setRemoteCanvas(t) {
|
|
191
|
+
this.canvas = t, this.ctx = t.getContext("2d");
|
|
192
|
+
}
|
|
193
|
+
renderFrame(t) {
|
|
194
|
+
if (!this.canvas || !this.ctx) return;
|
|
195
|
+
const { width: e, height: a, data: i, orientation: s, format: n, isKeyFrame: r, timestamp: o } = t;
|
|
196
|
+
if (!(e <= 0 || a <= 0)) {
|
|
197
|
+
if (n === W) {
|
|
198
|
+
this.decodeH264Frame(i, e, a, s, r, o);
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
this.renderNV12Frame(i, e, a, s);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
decodeH264Frame(t, e, a, i, s, n) {
|
|
205
|
+
if (t.byteLength === 0) return;
|
|
206
|
+
if (!this.h264GotKeyFrame) {
|
|
207
|
+
if (!s) return;
|
|
208
|
+
this.h264GotKeyFrame = !0;
|
|
209
|
+
}
|
|
210
|
+
if (!this.h264Decoder || this.h264Decoder.state === "closed") {
|
|
211
|
+
if (this.h264ErrorCount >= G || (this.h264Decoder = this.createH264Decoder(), !this.h264Decoder) || (this.h264GotKeyFrame = !1, !s)) return;
|
|
212
|
+
this.h264GotKeyFrame = !0;
|
|
213
|
+
}
|
|
214
|
+
this.h264FrameIndex++;
|
|
215
|
+
const r = this.h264FrameIndex * 66666;
|
|
216
|
+
this.orientationMap.set(r, i);
|
|
217
|
+
try {
|
|
218
|
+
this.h264Decoder.decode(new EncodedVideoChunk({
|
|
219
|
+
type: s ? "key" : "delta",
|
|
220
|
+
timestamp: r,
|
|
221
|
+
data: t
|
|
222
|
+
}));
|
|
223
|
+
} catch {
|
|
224
|
+
this.h264ErrorCount++, this.h264GotKeyFrame = !1;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
createH264Decoder() {
|
|
228
|
+
if (typeof globalThis.VideoDecoder != "function") return null;
|
|
229
|
+
try {
|
|
230
|
+
const t = new VideoDecoder({
|
|
231
|
+
output: (e) => {
|
|
232
|
+
try {
|
|
233
|
+
if (!this.canvas || !this.ctx) {
|
|
234
|
+
e.close();
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
const a = this.orientationMap.get(e.timestamp) ?? 1;
|
|
238
|
+
this.orientationMap.delete(e.timestamp);
|
|
239
|
+
const i = e.codedWidth, s = e.codedHeight, n = a === 2 || a === 4, r = n ? s : i, o = n ? i : s;
|
|
240
|
+
(this.canvas.width !== r || this.canvas.height !== o) && (this.canvas.width = r, this.canvas.height = o), this.ctx.save(), a === 2 ? (this.ctx.translate(r, 0), this.ctx.rotate(Math.PI / 2)) : a === 3 ? (this.ctx.translate(r, o), this.ctx.rotate(Math.PI)) : a === 4 && (this.ctx.translate(0, o), this.ctx.rotate(-Math.PI / 2)), this.ctx.drawImage(e, 0, 0), this.ctx.restore();
|
|
241
|
+
} finally {
|
|
242
|
+
e.close();
|
|
243
|
+
}
|
|
244
|
+
},
|
|
245
|
+
error: () => {
|
|
246
|
+
this.h264ErrorCount++, this.orientationMap.clear();
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
return t.configure({ codec: K, optimizeForLatency: !0 }), this.h264ErrorCount = 0, t;
|
|
250
|
+
} catch {
|
|
251
|
+
return null;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
renderNV12Frame(t, e, a, i) {
|
|
255
|
+
if (!this.canvas || !this.ctx) return;
|
|
256
|
+
const s = i === 2 || i === 4, n = s ? a : e, r = s ? e : a;
|
|
257
|
+
if ((this.canvas.width !== n || this.canvas.height !== r) && (this.canvas.width = n, this.canvas.height = r), typeof globalThis.VideoFrame == "function")
|
|
258
|
+
try {
|
|
259
|
+
const u = new globalThis.VideoFrame(new Uint8Array(t), {
|
|
260
|
+
format: "NV12",
|
|
261
|
+
codedWidth: e,
|
|
262
|
+
codedHeight: a,
|
|
263
|
+
timestamp: 0
|
|
264
|
+
});
|
|
265
|
+
this.ctx.save(), i === 2 ? (this.ctx.translate(n, 0), this.ctx.rotate(Math.PI / 2)) : i === 3 ? (this.ctx.translate(n, r), this.ctx.rotate(Math.PI)) : i === 4 && (this.ctx.translate(0, r), this.ctx.rotate(-Math.PI / 2)), this.ctx.drawImage(u, 0, 0), this.ctx.restore(), u.close();
|
|
266
|
+
return;
|
|
267
|
+
} catch {
|
|
268
|
+
}
|
|
269
|
+
const o = new Uint8Array(t), l = this.nv12ToRgba(o, e, a), p = new ImageData(new Uint8ClampedArray(l.buffer), e, a);
|
|
270
|
+
i >= 2 && i <= 4 ? (this.tempCanvas || (this.tempCanvas = document.createElement("canvas"), this.tempCtx = this.tempCanvas.getContext("2d")), this.tempCanvas.width = e, this.tempCanvas.height = a, this.tempCtx.putImageData(p, 0, 0), this.ctx.save(), i === 2 ? (this.ctx.translate(n, 0), this.ctx.rotate(Math.PI / 2)) : i === 3 ? (this.ctx.translate(n, r), this.ctx.rotate(Math.PI)) : i === 4 && (this.ctx.translate(0, r), this.ctx.rotate(-Math.PI / 2)), this.ctx.drawImage(this.tempCanvas, 0, 0), this.ctx.restore()) : this.ctx.putImageData(p, 0, 0);
|
|
271
|
+
}
|
|
272
|
+
async startCamera(t, e = 640, a = 480, i = 15) {
|
|
273
|
+
this.localVideo = t;
|
|
274
|
+
const s = await navigator.mediaDevices.getUserMedia({
|
|
275
|
+
video: { width: { ideal: e }, height: { ideal: a }, frameRate: { ideal: i } },
|
|
276
|
+
audio: !1
|
|
277
|
+
});
|
|
278
|
+
this.localStream = s, t.srcObject = s, t.muted = !0, await t.play(), this.canUseH264Encoder() ? this.startH264Capture(s, e, a, i) : (this.captureCanvas = document.createElement("canvas"), this.captureCanvas.width = e, this.captureCanvas.height = a, this.captureCtx = this.captureCanvas.getContext("2d", { willReadFrequently: !0 }), this.captureInterval = setInterval(() => this.captureFrameRaw(), Math.floor(1e3 / i)));
|
|
279
|
+
}
|
|
280
|
+
stopCamera() {
|
|
281
|
+
if (this.captureInterval && (clearInterval(this.captureInterval), this.captureInterval = null), this.h264Encoder && this.h264Encoder.state !== "closed")
|
|
282
|
+
try {
|
|
283
|
+
this.h264Encoder.close();
|
|
284
|
+
} catch {
|
|
285
|
+
}
|
|
286
|
+
this.h264Encoder = null, this.localStream && (this.localStream.getTracks().forEach((t) => t.stop()), this.localStream = null), this.localVideo && (this.localVideo.srcObject = null, this.localVideo = null), this.captureCanvas = null, this.captureCtx = null;
|
|
287
|
+
}
|
|
288
|
+
canUseH264Encoder() {
|
|
289
|
+
return typeof globalThis.VideoEncoder == "function" && typeof globalThis.MediaStreamTrackProcessor == "function";
|
|
290
|
+
}
|
|
291
|
+
startH264Capture(t, e, a, i) {
|
|
292
|
+
const s = t.getVideoTracks()[0];
|
|
293
|
+
if (!s) return;
|
|
294
|
+
let n = e, r = a, o = 0;
|
|
295
|
+
const l = /* @__PURE__ */ new Map();
|
|
296
|
+
this.h264Encoder = new VideoEncoder({
|
|
297
|
+
output: (d, m) => {
|
|
298
|
+
var h, v;
|
|
299
|
+
if (!this.onEncodedCameraFrame) return;
|
|
300
|
+
const f = new ArrayBuffer(d.byteLength);
|
|
301
|
+
d.copyTo(f);
|
|
302
|
+
const g = d.type === "key", x = ((h = m == null ? void 0 : m.decoderConfig) == null ? void 0 : h.codedWidth) ?? n, w = ((v = m == null ? void 0 : m.decoderConfig) == null ? void 0 : v.codedHeight) ?? r;
|
|
303
|
+
let C = 0;
|
|
304
|
+
const y = l.get(d.timestamp);
|
|
305
|
+
y != null && (l.delete(d.timestamp), C = Date.now() - y);
|
|
306
|
+
const k = d.timestamp / 1e3;
|
|
307
|
+
this.onEncodedCameraFrame(f, x, w, k, g, C);
|
|
308
|
+
},
|
|
309
|
+
error: (d) => {
|
|
310
|
+
console.error("[VideoEngine] encoder error:", d);
|
|
311
|
+
}
|
|
312
|
+
}), this.h264Encoder.configure({
|
|
313
|
+
codec: "avc1.42001f",
|
|
314
|
+
width: n,
|
|
315
|
+
height: r,
|
|
316
|
+
bitrate: 5e5,
|
|
317
|
+
framerate: i,
|
|
318
|
+
latencyMode: "realtime",
|
|
319
|
+
bitrateMode: "constant",
|
|
320
|
+
avc: { format: "annexb" }
|
|
321
|
+
});
|
|
322
|
+
const u = new globalThis.MediaStreamTrackProcessor({ track: s }).readable.getReader();
|
|
323
|
+
(async () => {
|
|
324
|
+
for (; this.h264Encoder && this.h264Encoder.state !== "closed"; )
|
|
325
|
+
try {
|
|
326
|
+
const { value: d, done: m } = await u.read();
|
|
327
|
+
if (m || !d) break;
|
|
328
|
+
if (this.h264Encoder.state !== "configured") {
|
|
329
|
+
d.close();
|
|
330
|
+
continue;
|
|
331
|
+
}
|
|
332
|
+
const f = Date.now(), g = f - this.lastKeyFrameTs, x = this.h264NeedKeyFrame || g >= this.encoderKeyFrameInterval || o === 0;
|
|
333
|
+
l.set(d.timestamp, f), this.h264Encoder.encode(d, { keyFrame: x }), d.close(), o++, x && (this.lastKeyFrameTs = f, this.h264NeedKeyFrame = !1);
|
|
334
|
+
} catch {
|
|
335
|
+
break;
|
|
336
|
+
}
|
|
337
|
+
})();
|
|
338
|
+
}
|
|
339
|
+
captureFrameRaw() {
|
|
340
|
+
if (!this.captureCtx || !this.captureCanvas || !this.localVideo || !this.onCameraFrame || this.localVideo.readyState < 2) return;
|
|
341
|
+
const t = this.captureCanvas.width, e = this.captureCanvas.height;
|
|
342
|
+
this.captureCtx.drawImage(this.localVideo, 0, 0, t, e);
|
|
343
|
+
const a = this.captureCtx.getImageData(0, 0, t, e);
|
|
344
|
+
this.onCameraFrame(a.data.buffer, t, e);
|
|
345
|
+
}
|
|
346
|
+
nv12ToRgba(t, e, a) {
|
|
347
|
+
const i = new Uint8ClampedArray(e * a * 4), s = e * a;
|
|
348
|
+
for (let n = 0; n < a; n++)
|
|
349
|
+
for (let r = 0; r < e; r++) {
|
|
350
|
+
const o = n * e + r, l = s + (n >> 1) * e + (r & -2), p = t[o], u = t[l] - 128, b = t[l + 1] - 128, d = o * 4;
|
|
351
|
+
i[d] = M(p + 1.402 * b), i[d + 1] = M(p - 0.344 * u - 0.714 * b), i[d + 2] = M(p + 1.772 * u), i[d + 3] = 255;
|
|
352
|
+
}
|
|
353
|
+
return i;
|
|
354
|
+
}
|
|
355
|
+
clearCanvas() {
|
|
356
|
+
this.canvas && this.ctx && this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
|
357
|
+
}
|
|
358
|
+
destroy() {
|
|
359
|
+
if (this.stopCamera(), this.h264Decoder && this.h264Decoder.state !== "closed")
|
|
360
|
+
try {
|
|
361
|
+
this.h264Decoder.close();
|
|
362
|
+
} catch {
|
|
363
|
+
}
|
|
364
|
+
this.h264Decoder = null, this.orientationMap.clear(), this.canvas = null, this.ctx = null;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
function M(c) {
|
|
368
|
+
return c < 0 ? 0 : c > 255 ? 255 : c | 0;
|
|
369
|
+
}
|
|
370
|
+
class Z {
|
|
371
|
+
constructor() {
|
|
372
|
+
this.calls = /* @__PURE__ */ new Map();
|
|
373
|
+
}
|
|
374
|
+
addCall(t) {
|
|
375
|
+
this.calls.set(t.callId, { ...t });
|
|
376
|
+
}
|
|
377
|
+
updateState(t, e) {
|
|
378
|
+
const a = this.calls.get(t);
|
|
379
|
+
a && (a.state = e, e === "ended" && this.calls.delete(t));
|
|
380
|
+
}
|
|
381
|
+
updateIsVideo(t, e) {
|
|
382
|
+
const a = this.calls.get(t);
|
|
383
|
+
a && (a.isVideo = e);
|
|
384
|
+
}
|
|
385
|
+
removeCall(t) {
|
|
386
|
+
this.calls.delete(t);
|
|
387
|
+
}
|
|
388
|
+
getCall(t) {
|
|
389
|
+
return this.calls.get(t);
|
|
390
|
+
}
|
|
391
|
+
getActiveCall() {
|
|
392
|
+
for (const t of this.calls.values())
|
|
393
|
+
if (t.state === "accepted" || t.state === "active")
|
|
394
|
+
return t;
|
|
395
|
+
}
|
|
396
|
+
getRingingCalls() {
|
|
397
|
+
const t = [];
|
|
398
|
+
for (const e of this.calls.values())
|
|
399
|
+
(e.state === "ringing" || e.state === "preaccepted") && t.push(e);
|
|
400
|
+
return t;
|
|
401
|
+
}
|
|
402
|
+
getAllCalls() {
|
|
403
|
+
return Array.from(this.calls.values());
|
|
404
|
+
}
|
|
405
|
+
hasActiveCalls() {
|
|
406
|
+
for (const t of this.calls.values())
|
|
407
|
+
if (t.state !== "ended") return !0;
|
|
408
|
+
return !1;
|
|
409
|
+
}
|
|
410
|
+
clear() {
|
|
411
|
+
this.calls.clear();
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
function Y(c) {
|
|
415
|
+
const t = c.mode === "light", e = c.primaryColor || "#00a884", a = c.dangerColor || "#f44336", i = c.backgroundColor || (t ? "#f0f2f5" : "#202c33"), s = c.surfaceColor || (t ? "#ffffff" : "#111b21"), n = c.textColor || (t ? "#111b21" : "#e9edef"), r = c.textSecondaryColor || (t ? "#667781" : "#8696a0"), o = c.borderRadius || "16px", l = c.fontFamily || "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif", p = t ? "rgba(0,0,0,0.06)" : "rgba(255,255,255,0.08)", u = t ? "rgba(0,0,0,0.1)" : "rgba(255,255,255,0.1)", b = t ? "rgba(0,0,0,0.14)" : "rgba(255,255,255,0.15)", d = t ? "rgba(0,0,0,0.12)" : "rgba(0,0,0,0.3)", m = t ? "rgba(0,0,0,0.16)" : "rgba(0,0,0,0.4)", f = t ? "rgba(0,0,0,0.08)" : "rgba(255,255,255,0.06)", g = t ? "rgba(0,0,0,0.12)" : "rgba(255,255,255,0.1)";
|
|
416
|
+
return `
|
|
417
|
+
:host {
|
|
418
|
+
all: initial;
|
|
419
|
+
font-family: ${l};
|
|
420
|
+
color: ${n};
|
|
421
|
+
--primary: ${e};
|
|
422
|
+
--danger: ${a};
|
|
423
|
+
--bg: ${i};
|
|
424
|
+
--surface: ${s};
|
|
425
|
+
--text: ${n};
|
|
426
|
+
--text-sec: ${r};
|
|
427
|
+
--radius: ${o};
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
431
|
+
|
|
432
|
+
.zapi-call-root {
|
|
433
|
+
position: fixed;
|
|
434
|
+
z-index: 2147483647;
|
|
435
|
+
font-family: ${l};
|
|
436
|
+
}
|
|
437
|
+
.zapi-call-root.bottom-right { bottom: 20px; right: 20px; }
|
|
438
|
+
.zapi-call-root.bottom-left { bottom: 20px; left: 20px; }
|
|
439
|
+
.zapi-call-root.top-right { top: 20px; right: 20px; }
|
|
440
|
+
.zapi-call-root.top-left { top: 20px; left: 20px; }
|
|
441
|
+
|
|
442
|
+
/* Bubble */
|
|
443
|
+
.bubble {
|
|
444
|
+
width: 56px;
|
|
445
|
+
height: 56px;
|
|
446
|
+
border-radius: 50%;
|
|
447
|
+
background: var(--primary);
|
|
448
|
+
display: flex;
|
|
449
|
+
align-items: center;
|
|
450
|
+
justify-content: center;
|
|
451
|
+
cursor: pointer;
|
|
452
|
+
box-shadow: 0 4px 12px ${d};
|
|
453
|
+
transition: transform 0.2s, box-shadow 0.2s;
|
|
454
|
+
position: relative;
|
|
455
|
+
user-select: none;
|
|
456
|
+
}
|
|
457
|
+
.bubble:hover { transform: scale(1.08); box-shadow: 0 6px 20px ${m}; }
|
|
458
|
+
.bubble:active { transform: scale(0.95); }
|
|
459
|
+
.bubble svg { width: 26px; height: 26px; color: #fff; }
|
|
460
|
+
|
|
461
|
+
.bubble .badge {
|
|
462
|
+
position: absolute;
|
|
463
|
+
top: -2px;
|
|
464
|
+
right: -2px;
|
|
465
|
+
width: 18px;
|
|
466
|
+
height: 18px;
|
|
467
|
+
border-radius: 50%;
|
|
468
|
+
background: var(--danger);
|
|
469
|
+
color: #fff;
|
|
470
|
+
font-size: 11px;
|
|
471
|
+
font-weight: 700;
|
|
472
|
+
display: flex;
|
|
473
|
+
align-items: center;
|
|
474
|
+
justify-content: center;
|
|
475
|
+
display: none;
|
|
476
|
+
}
|
|
477
|
+
.bubble .badge.visible { display: flex; }
|
|
478
|
+
|
|
479
|
+
.bubble .conn-dot {
|
|
480
|
+
position: absolute;
|
|
481
|
+
bottom: 2px;
|
|
482
|
+
right: 2px;
|
|
483
|
+
width: 10px;
|
|
484
|
+
height: 10px;
|
|
485
|
+
border-radius: 50%;
|
|
486
|
+
background: #f44336;
|
|
487
|
+
border: 2px solid var(--primary);
|
|
488
|
+
}
|
|
489
|
+
.bubble .conn-dot.connected { background: #4caf50; }
|
|
490
|
+
|
|
491
|
+
.bubble.ringing {
|
|
492
|
+
animation: bubble-pulse 1.5s ease-in-out infinite;
|
|
493
|
+
}
|
|
494
|
+
@keyframes bubble-pulse {
|
|
495
|
+
0%, 100% { box-shadow: 0 4px 12px ${d}; }
|
|
496
|
+
50% { box-shadow: 0 4px 12px ${d}, 0 0 0 12px rgba(0,168,132,0.2); }
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/* Panel */
|
|
500
|
+
.panel {
|
|
501
|
+
position: absolute;
|
|
502
|
+
bottom: 66px;
|
|
503
|
+
right: 0;
|
|
504
|
+
width: 360px;
|
|
505
|
+
max-height: 560px;
|
|
506
|
+
background: var(--surface);
|
|
507
|
+
border-radius: var(--radius);
|
|
508
|
+
box-shadow: 0 8px 32px ${m};
|
|
509
|
+
overflow: hidden;
|
|
510
|
+
transform: translateY(10px);
|
|
511
|
+
opacity: 0;
|
|
512
|
+
pointer-events: none;
|
|
513
|
+
transition: transform 0.25s ease, opacity 0.25s ease;
|
|
514
|
+
display: flex;
|
|
515
|
+
flex-direction: column;
|
|
516
|
+
}
|
|
517
|
+
.panel.open {
|
|
518
|
+
transform: translateY(0);
|
|
519
|
+
opacity: 1;
|
|
520
|
+
pointer-events: auto;
|
|
521
|
+
}
|
|
522
|
+
.zapi-call-root.bottom-left .panel { right: auto; left: 0; }
|
|
523
|
+
.zapi-call-root.top-right .panel { bottom: auto; top: 66px; }
|
|
524
|
+
.zapi-call-root.top-left .panel { bottom: auto; top: 66px; right: auto; left: 0; }
|
|
525
|
+
|
|
526
|
+
/* Panel header with tabs */
|
|
527
|
+
.panel-header {
|
|
528
|
+
background: var(--bg);
|
|
529
|
+
border-bottom: 1px solid ${f};
|
|
530
|
+
flex-shrink: 0;
|
|
531
|
+
}
|
|
532
|
+
.panel-header-top {
|
|
533
|
+
padding: 10px 16px;
|
|
534
|
+
display: flex;
|
|
535
|
+
align-items: center;
|
|
536
|
+
justify-content: space-between;
|
|
537
|
+
}
|
|
538
|
+
.panel-header-top h3 {
|
|
539
|
+
font-size: 15px;
|
|
540
|
+
font-weight: 600;
|
|
541
|
+
color: var(--text);
|
|
542
|
+
}
|
|
543
|
+
.panel-header .close-btn {
|
|
544
|
+
width: 28px;
|
|
545
|
+
height: 28px;
|
|
546
|
+
border: none;
|
|
547
|
+
background: transparent;
|
|
548
|
+
color: var(--text-sec);
|
|
549
|
+
cursor: pointer;
|
|
550
|
+
border-radius: 50%;
|
|
551
|
+
display: flex;
|
|
552
|
+
align-items: center;
|
|
553
|
+
justify-content: center;
|
|
554
|
+
transition: background 0.2s;
|
|
555
|
+
}
|
|
556
|
+
.panel-header .close-btn:hover { background: ${p}; }
|
|
557
|
+
.panel-header .close-btn svg { width: 18px; height: 18px; }
|
|
558
|
+
|
|
559
|
+
/* Tabs */
|
|
560
|
+
.tabs {
|
|
561
|
+
display: flex;
|
|
562
|
+
padding: 0 8px;
|
|
563
|
+
}
|
|
564
|
+
.tab {
|
|
565
|
+
flex: 1;
|
|
566
|
+
padding: 10px 8px;
|
|
567
|
+
border: none;
|
|
568
|
+
background: transparent;
|
|
569
|
+
color: var(--text-sec);
|
|
570
|
+
font-size: 13px;
|
|
571
|
+
font-weight: 600;
|
|
572
|
+
cursor: pointer;
|
|
573
|
+
position: relative;
|
|
574
|
+
display: flex;
|
|
575
|
+
align-items: center;
|
|
576
|
+
justify-content: center;
|
|
577
|
+
gap: 6px;
|
|
578
|
+
transition: color 0.2s;
|
|
579
|
+
font-family: inherit;
|
|
580
|
+
}
|
|
581
|
+
.tab svg { width: 16px; height: 16px; }
|
|
582
|
+
.tab:hover { color: var(--text); }
|
|
583
|
+
.tab.active { color: var(--primary); }
|
|
584
|
+
.tab.active::after {
|
|
585
|
+
content: '';
|
|
586
|
+
position: absolute;
|
|
587
|
+
bottom: 0;
|
|
588
|
+
left: 16px;
|
|
589
|
+
right: 16px;
|
|
590
|
+
height: 2px;
|
|
591
|
+
background: var(--primary);
|
|
592
|
+
border-radius: 2px 2px 0 0;
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
/* Panel body / views */
|
|
596
|
+
.panel-body {
|
|
597
|
+
flex: 1;
|
|
598
|
+
overflow-y: auto;
|
|
599
|
+
overflow-x: hidden;
|
|
600
|
+
min-height: 0;
|
|
601
|
+
}
|
|
602
|
+
.view {
|
|
603
|
+
display: none;
|
|
604
|
+
animation: view-in 0.2s ease;
|
|
605
|
+
}
|
|
606
|
+
.view.active { display: block; }
|
|
607
|
+
@keyframes view-in {
|
|
608
|
+
from { opacity: 0; transform: translateY(6px); }
|
|
609
|
+
to { opacity: 1; transform: translateY(0); }
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
/* ── Dialer view ── */
|
|
613
|
+
.dialer {
|
|
614
|
+
padding: 8px 16px 14px;
|
|
615
|
+
display: flex;
|
|
616
|
+
flex-direction: column;
|
|
617
|
+
align-items: center;
|
|
618
|
+
}
|
|
619
|
+
.dialer-display {
|
|
620
|
+
width: 100%;
|
|
621
|
+
height: 56px;
|
|
622
|
+
display: flex;
|
|
623
|
+
align-items: center;
|
|
624
|
+
justify-content: center;
|
|
625
|
+
position: relative;
|
|
626
|
+
margin-bottom: 8px;
|
|
627
|
+
}
|
|
628
|
+
.dialer-input {
|
|
629
|
+
width: 100%;
|
|
630
|
+
background: transparent;
|
|
631
|
+
border: none;
|
|
632
|
+
padding: 0 40px;
|
|
633
|
+
color: var(--text);
|
|
634
|
+
font-size: 28px;
|
|
635
|
+
font-weight: 300;
|
|
636
|
+
font-family: inherit;
|
|
637
|
+
text-align: center;
|
|
638
|
+
letter-spacing: 1.5px;
|
|
639
|
+
outline: none;
|
|
640
|
+
font-variant-numeric: tabular-nums;
|
|
641
|
+
caret-color: var(--primary);
|
|
642
|
+
}
|
|
643
|
+
.dialer-input::placeholder { color: var(--text-sec); font-size: 16px; font-weight: 400; letter-spacing: 0; }
|
|
644
|
+
.dialer-input.error::placeholder { color: #e74c3c; }
|
|
645
|
+
.backspace-btn {
|
|
646
|
+
position: absolute;
|
|
647
|
+
right: 0;
|
|
648
|
+
width: 36px;
|
|
649
|
+
height: 36px;
|
|
650
|
+
border: none;
|
|
651
|
+
background: transparent;
|
|
652
|
+
color: var(--text-sec);
|
|
653
|
+
cursor: pointer;
|
|
654
|
+
border-radius: 50%;
|
|
655
|
+
display: flex;
|
|
656
|
+
align-items: center;
|
|
657
|
+
justify-content: center;
|
|
658
|
+
transition: background 0.2s, color 0.2s;
|
|
659
|
+
}
|
|
660
|
+
.backspace-btn:hover { background: ${p}; color: var(--text); }
|
|
661
|
+
.backspace-btn svg { width: 20px; height: 20px; }
|
|
662
|
+
|
|
663
|
+
/* Numpad */
|
|
664
|
+
.numpad {
|
|
665
|
+
display: grid;
|
|
666
|
+
grid-template-columns: repeat(3, 1fr);
|
|
667
|
+
gap: 6px;
|
|
668
|
+
width: 100%;
|
|
669
|
+
max-width: 240px;
|
|
670
|
+
margin-bottom: 12px;
|
|
671
|
+
}
|
|
672
|
+
.numpad-key {
|
|
673
|
+
width: 60px;
|
|
674
|
+
height: 60px;
|
|
675
|
+
border-radius: 50%;
|
|
676
|
+
border: none;
|
|
677
|
+
background: var(--bg);
|
|
678
|
+
color: var(--text);
|
|
679
|
+
font-size: 22px;
|
|
680
|
+
font-weight: 400;
|
|
681
|
+
cursor: pointer;
|
|
682
|
+
display: flex;
|
|
683
|
+
flex-direction: column;
|
|
684
|
+
align-items: center;
|
|
685
|
+
justify-content: center;
|
|
686
|
+
transition: background 0.15s, transform 0.1s;
|
|
687
|
+
user-select: none;
|
|
688
|
+
font-family: inherit;
|
|
689
|
+
justify-self: center;
|
|
690
|
+
line-height: 1;
|
|
691
|
+
}
|
|
692
|
+
.numpad-key:hover { background: ${u}; }
|
|
693
|
+
.numpad-key:active { transform: scale(0.92); background: ${b}; }
|
|
694
|
+
.numpad-key .sub {
|
|
695
|
+
font-size: 8px;
|
|
696
|
+
color: var(--text-sec);
|
|
697
|
+
letter-spacing: 1.5px;
|
|
698
|
+
margin-top: 1px;
|
|
699
|
+
font-weight: 600;
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
/* Call buttons */
|
|
703
|
+
.call-btns {
|
|
704
|
+
display: flex;
|
|
705
|
+
align-items: center;
|
|
706
|
+
gap: 16px;
|
|
707
|
+
}
|
|
708
|
+
.call-btn {
|
|
709
|
+
width: 56px;
|
|
710
|
+
height: 56px;
|
|
711
|
+
border-radius: 50%;
|
|
712
|
+
border: none;
|
|
713
|
+
background: var(--primary);
|
|
714
|
+
color: #fff;
|
|
715
|
+
cursor: pointer;
|
|
716
|
+
display: flex;
|
|
717
|
+
align-items: center;
|
|
718
|
+
justify-content: center;
|
|
719
|
+
box-shadow: 0 4px 16px rgba(0,168,132,0.3);
|
|
720
|
+
transition: transform 0.15s, box-shadow 0.15s;
|
|
721
|
+
}
|
|
722
|
+
.call-btn:hover { transform: scale(1.08); box-shadow: 0 6px 24px rgba(0,168,132,0.4); }
|
|
723
|
+
.call-btn:active { transform: scale(0.95); }
|
|
724
|
+
.call-btn svg { width: 26px; height: 26px; }
|
|
725
|
+
.call-btn:disabled {
|
|
726
|
+
opacity: 0.5;
|
|
727
|
+
cursor: not-allowed;
|
|
728
|
+
transform: none;
|
|
729
|
+
box-shadow: 0 4px 16px rgba(0,168,132,0.15);
|
|
730
|
+
}
|
|
731
|
+
.video-call-btn {
|
|
732
|
+
background: #2196f3;
|
|
733
|
+
box-shadow: 0 4px 16px rgba(33,150,243,0.3);
|
|
734
|
+
}
|
|
735
|
+
.video-call-btn:hover { box-shadow: 0 6px 24px rgba(33,150,243,0.4); }
|
|
736
|
+
|
|
737
|
+
/* ── Calls view ── */
|
|
738
|
+
.calls-view {
|
|
739
|
+
padding: 8px;
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
.empty-state {
|
|
743
|
+
padding: 40px 16px;
|
|
744
|
+
text-align: center;
|
|
745
|
+
color: var(--text-sec);
|
|
746
|
+
font-size: 13px;
|
|
747
|
+
}
|
|
748
|
+
.empty-state .icon {
|
|
749
|
+
font-size: 36px;
|
|
750
|
+
margin-bottom: 8px;
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
/* Call Card */
|
|
754
|
+
.call-card {
|
|
755
|
+
background: var(--bg);
|
|
756
|
+
border-radius: 12px;
|
|
757
|
+
padding: 14px;
|
|
758
|
+
margin-bottom: 8px;
|
|
759
|
+
animation: card-in 0.3s ease;
|
|
760
|
+
}
|
|
761
|
+
.call-card.ended {
|
|
762
|
+
opacity: 0.5;
|
|
763
|
+
animation: card-out 0.5s ease forwards;
|
|
764
|
+
}
|
|
765
|
+
@keyframes card-in {
|
|
766
|
+
from { transform: translateY(-8px); opacity: 0; }
|
|
767
|
+
to { transform: translateY(0); opacity: 1; }
|
|
768
|
+
}
|
|
769
|
+
@keyframes card-out {
|
|
770
|
+
to { transform: translateY(8px); opacity: 0; }
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
.call-card-top {
|
|
774
|
+
display: flex;
|
|
775
|
+
align-items: center;
|
|
776
|
+
gap: 10px;
|
|
777
|
+
margin-bottom: 10px;
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
.avatar {
|
|
781
|
+
width: 40px;
|
|
782
|
+
height: 40px;
|
|
783
|
+
border-radius: 50%;
|
|
784
|
+
background: var(--surface);
|
|
785
|
+
display: flex;
|
|
786
|
+
align-items: center;
|
|
787
|
+
justify-content: center;
|
|
788
|
+
flex-shrink: 0;
|
|
789
|
+
}
|
|
790
|
+
.avatar svg { width: 22px; height: 22px; color: var(--text-sec); }
|
|
791
|
+
.avatar .avatar-img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
|
|
792
|
+
|
|
793
|
+
.call-info { flex: 1; min-width: 0; }
|
|
794
|
+
.call-phone {
|
|
795
|
+
font-size: 15px;
|
|
796
|
+
font-weight: 600;
|
|
797
|
+
color: var(--text);
|
|
798
|
+
white-space: nowrap;
|
|
799
|
+
overflow: hidden;
|
|
800
|
+
text-overflow: ellipsis;
|
|
801
|
+
}
|
|
802
|
+
.call-meta {
|
|
803
|
+
font-size: 12px;
|
|
804
|
+
color: var(--text-sec);
|
|
805
|
+
display: flex;
|
|
806
|
+
align-items: center;
|
|
807
|
+
gap: 6px;
|
|
808
|
+
margin-top: 2px;
|
|
809
|
+
}
|
|
810
|
+
.call-meta svg { width: 13px; height: 13px; }
|
|
811
|
+
|
|
812
|
+
.state-badge {
|
|
813
|
+
padding: 3px 8px;
|
|
814
|
+
border-radius: 6px;
|
|
815
|
+
font-size: 11px;
|
|
816
|
+
font-weight: 700;
|
|
817
|
+
text-transform: uppercase;
|
|
818
|
+
letter-spacing: 0.5px;
|
|
819
|
+
flex-shrink: 0;
|
|
820
|
+
}
|
|
821
|
+
.state-badge.ringing {
|
|
822
|
+
background: #f9a825;
|
|
823
|
+
color: #000;
|
|
824
|
+
animation: badge-pulse 1.5s ease-in-out infinite;
|
|
825
|
+
}
|
|
826
|
+
.state-badge.preaccepted { background: #ff9800; color: #000; }
|
|
827
|
+
.state-badge.accepted { background: #2196f3; color: #fff; }
|
|
828
|
+
.state-badge.active { background: var(--primary); color: #fff; }
|
|
829
|
+
.state-badge.ended { background: var(--danger); color: #fff; }
|
|
830
|
+
@keyframes badge-pulse {
|
|
831
|
+
0%, 100% { opacity: 1; }
|
|
832
|
+
50% { opacity: 0.5; }
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
.timer {
|
|
836
|
+
font-size: 22px;
|
|
837
|
+
font-weight: 300;
|
|
838
|
+
text-align: center;
|
|
839
|
+
margin: 8px 0;
|
|
840
|
+
font-variant-numeric: tabular-nums;
|
|
841
|
+
color: var(--text);
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
.call-actions {
|
|
845
|
+
display: flex;
|
|
846
|
+
gap: 8px;
|
|
847
|
+
margin-top: 8px;
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
.btn {
|
|
851
|
+
flex: 1;
|
|
852
|
+
padding: 10px 16px;
|
|
853
|
+
border: none;
|
|
854
|
+
border-radius: 24px;
|
|
855
|
+
font-size: 14px;
|
|
856
|
+
font-weight: 600;
|
|
857
|
+
cursor: pointer;
|
|
858
|
+
transition: transform 0.15s, opacity 0.15s;
|
|
859
|
+
display: flex;
|
|
860
|
+
align-items: center;
|
|
861
|
+
justify-content: center;
|
|
862
|
+
gap: 6px;
|
|
863
|
+
font-family: inherit;
|
|
864
|
+
}
|
|
865
|
+
.btn:hover { transform: scale(1.03); }
|
|
866
|
+
.btn:active { transform: scale(0.97); }
|
|
867
|
+
.btn svg { width: 18px; height: 18px; }
|
|
868
|
+
.btn-accept { background: var(--primary); color: #fff; }
|
|
869
|
+
.btn-reject { background: var(--danger); color: #fff; }
|
|
870
|
+
.btn-mute {
|
|
871
|
+
width: 44px;
|
|
872
|
+
height: 44px;
|
|
873
|
+
flex: none;
|
|
874
|
+
border-radius: 50%;
|
|
875
|
+
background: var(--bg);
|
|
876
|
+
border: 1px solid ${g};
|
|
877
|
+
color: var(--text);
|
|
878
|
+
padding: 0;
|
|
879
|
+
display: flex;
|
|
880
|
+
align-items: center;
|
|
881
|
+
justify-content: center;
|
|
882
|
+
cursor: pointer;
|
|
883
|
+
transition: background 0.2s;
|
|
884
|
+
}
|
|
885
|
+
.btn-mute:hover { background: ${p}; }
|
|
886
|
+
.btn-mute.muted { background: var(--danger); color: #fff; border-color: transparent; }
|
|
887
|
+
.btn-mute svg { width: 20px; height: 20px; }
|
|
888
|
+
|
|
889
|
+
/* ── In-Call view ── */
|
|
890
|
+
.incall-view {
|
|
891
|
+
display: flex;
|
|
892
|
+
flex-direction: column;
|
|
893
|
+
align-items: center;
|
|
894
|
+
text-align: center;
|
|
895
|
+
}
|
|
896
|
+
.incall-view .audio-call-ui {
|
|
897
|
+
padding: 24px 16px;
|
|
898
|
+
}
|
|
899
|
+
.incall-avatar {
|
|
900
|
+
width: 80px;
|
|
901
|
+
height: 80px;
|
|
902
|
+
border-radius: 50%;
|
|
903
|
+
background: var(--bg);
|
|
904
|
+
display: flex;
|
|
905
|
+
align-items: center;
|
|
906
|
+
justify-content: center;
|
|
907
|
+
margin-bottom: 16px;
|
|
908
|
+
}
|
|
909
|
+
.incall-avatar svg { width: 40px; height: 40px; color: var(--text-sec); }
|
|
910
|
+
.incall-avatar .avatar-img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
|
|
911
|
+
.incall-phone {
|
|
912
|
+
font-size: 20px;
|
|
913
|
+
font-weight: 600;
|
|
914
|
+
color: var(--text);
|
|
915
|
+
margin-bottom: 4px;
|
|
916
|
+
}
|
|
917
|
+
.incall-state {
|
|
918
|
+
font-size: 14px;
|
|
919
|
+
color: var(--text-sec);
|
|
920
|
+
margin-bottom: 4px;
|
|
921
|
+
}
|
|
922
|
+
.incall-timer {
|
|
923
|
+
font-size: 28px;
|
|
924
|
+
font-weight: 300;
|
|
925
|
+
color: var(--text);
|
|
926
|
+
font-variant-numeric: tabular-nums;
|
|
927
|
+
margin-bottom: 20px;
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
/* Audio level bar */
|
|
931
|
+
.audio-level-wrap {
|
|
932
|
+
width: 100%;
|
|
933
|
+
max-width: 200px;
|
|
934
|
+
height: 6px;
|
|
935
|
+
background: var(--bg);
|
|
936
|
+
border-radius: 3px;
|
|
937
|
+
overflow: hidden;
|
|
938
|
+
margin-bottom: 28px;
|
|
939
|
+
}
|
|
940
|
+
.audio-level-bar {
|
|
941
|
+
height: 100%;
|
|
942
|
+
width: 0%;
|
|
943
|
+
background: var(--primary);
|
|
944
|
+
border-radius: 3px;
|
|
945
|
+
transition: width 0.1s ease;
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
/* In-call controls */
|
|
949
|
+
.incall-controls {
|
|
950
|
+
display: flex;
|
|
951
|
+
align-items: center;
|
|
952
|
+
gap: 32px;
|
|
953
|
+
}
|
|
954
|
+
.incall-btn {
|
|
955
|
+
width: 56px;
|
|
956
|
+
height: 56px;
|
|
957
|
+
border-radius: 50%;
|
|
958
|
+
border: none;
|
|
959
|
+
display: flex;
|
|
960
|
+
align-items: center;
|
|
961
|
+
justify-content: center;
|
|
962
|
+
cursor: pointer;
|
|
963
|
+
transition: transform 0.15s;
|
|
964
|
+
}
|
|
965
|
+
.incall-btn:hover { transform: scale(1.08); }
|
|
966
|
+
.incall-btn:active { transform: scale(0.95); }
|
|
967
|
+
.incall-btn svg { width: 24px; height: 24px; }
|
|
968
|
+
.incall-btn-mute {
|
|
969
|
+
background: var(--bg);
|
|
970
|
+
color: var(--text);
|
|
971
|
+
border: 1px solid ${g};
|
|
972
|
+
}
|
|
973
|
+
.incall-btn-mute.muted {
|
|
974
|
+
background: var(--danger);
|
|
975
|
+
color: #fff;
|
|
976
|
+
border-color: transparent;
|
|
977
|
+
}
|
|
978
|
+
.incall-btn-camera {
|
|
979
|
+
background: var(--bg);
|
|
980
|
+
color: var(--text);
|
|
981
|
+
border: 1px solid ${g};
|
|
982
|
+
}
|
|
983
|
+
.incall-btn-camera:hover { background: ${p}; }
|
|
984
|
+
.incall-btn-camera.muted {
|
|
985
|
+
color: var(--text-sec);
|
|
986
|
+
}
|
|
987
|
+
.incall-btn-end {
|
|
988
|
+
background: var(--danger);
|
|
989
|
+
color: #fff;
|
|
990
|
+
width: 64px;
|
|
991
|
+
height: 64px;
|
|
992
|
+
}
|
|
993
|
+
.incall-btn-end svg { width: 28px; height: 28px; }
|
|
994
|
+
|
|
995
|
+
/* ── Video Call ── */
|
|
996
|
+
.audio-call-ui {
|
|
997
|
+
display: flex;
|
|
998
|
+
flex-direction: column;
|
|
999
|
+
align-items: center;
|
|
1000
|
+
}
|
|
1001
|
+
.video-container {
|
|
1002
|
+
position: relative;
|
|
1003
|
+
width: 100%;
|
|
1004
|
+
height: 420px;
|
|
1005
|
+
overflow: hidden;
|
|
1006
|
+
background: #000;
|
|
1007
|
+
display: flex;
|
|
1008
|
+
align-items: center;
|
|
1009
|
+
justify-content: center;
|
|
1010
|
+
border-radius: 0 0 12px 12px;
|
|
1011
|
+
}
|
|
1012
|
+
.remote-video {
|
|
1013
|
+
max-width: 100%;
|
|
1014
|
+
max-height: 100%;
|
|
1015
|
+
display: block;
|
|
1016
|
+
object-fit: contain;
|
|
1017
|
+
}
|
|
1018
|
+
.video-overlay-top {
|
|
1019
|
+
position: absolute;
|
|
1020
|
+
top: 0; left: 0; right: 0;
|
|
1021
|
+
padding: 16px;
|
|
1022
|
+
background: linear-gradient(to bottom, rgba(0,0,0,0.6), transparent);
|
|
1023
|
+
z-index: 2;
|
|
1024
|
+
}
|
|
1025
|
+
.video-caller-info {
|
|
1026
|
+
display: flex;
|
|
1027
|
+
align-items: center;
|
|
1028
|
+
justify-content: space-between;
|
|
1029
|
+
}
|
|
1030
|
+
.video-phone {
|
|
1031
|
+
font-size: 15px;
|
|
1032
|
+
font-weight: 600;
|
|
1033
|
+
color: #fff;
|
|
1034
|
+
text-shadow: 0 1px 3px rgba(0,0,0,0.5);
|
|
1035
|
+
}
|
|
1036
|
+
.video-timer {
|
|
1037
|
+
font-size: 14px;
|
|
1038
|
+
font-weight: 500;
|
|
1039
|
+
color: rgba(255,255,255,0.85);
|
|
1040
|
+
font-variant-numeric: tabular-nums;
|
|
1041
|
+
text-shadow: 0 1px 3px rgba(0,0,0,0.5);
|
|
1042
|
+
}
|
|
1043
|
+
.video-overlay-bottom {
|
|
1044
|
+
position: absolute;
|
|
1045
|
+
bottom: 0; left: 0; right: 0;
|
|
1046
|
+
padding: 20px;
|
|
1047
|
+
background: linear-gradient(to top, rgba(0,0,0,0.6), transparent);
|
|
1048
|
+
display: flex;
|
|
1049
|
+
align-items: center;
|
|
1050
|
+
justify-content: center;
|
|
1051
|
+
gap: 32px;
|
|
1052
|
+
z-index: 2;
|
|
1053
|
+
}
|
|
1054
|
+
.video-overlay-bottom .incall-btn {
|
|
1055
|
+
backdrop-filter: blur(8px);
|
|
1056
|
+
}
|
|
1057
|
+
.video-btn-mute {
|
|
1058
|
+
background: rgba(255,255,255,0.2) !important;
|
|
1059
|
+
color: #fff !important;
|
|
1060
|
+
border: none !important;
|
|
1061
|
+
}
|
|
1062
|
+
.video-btn-mute.muted {
|
|
1063
|
+
background: var(--danger) !important;
|
|
1064
|
+
}
|
|
1065
|
+
.video-btn-camera {
|
|
1066
|
+
background: rgba(255,255,255,0.2) !important;
|
|
1067
|
+
color: #fff !important;
|
|
1068
|
+
border: none !important;
|
|
1069
|
+
}
|
|
1070
|
+
.video-btn-camera.muted {
|
|
1071
|
+
background: rgba(255,255,255,0.1) !important;
|
|
1072
|
+
color: rgba(255,255,255,0.5) !important;
|
|
1073
|
+
}
|
|
1074
|
+
.video-btn-end {
|
|
1075
|
+
background: var(--danger) !important;
|
|
1076
|
+
color: #fff !important;
|
|
1077
|
+
}
|
|
1078
|
+
.video-btn-end svg { width: 28px; height: 28px; }
|
|
1079
|
+
|
|
1080
|
+
/* ── Contacts view ── */
|
|
1081
|
+
.contacts-wrapper {
|
|
1082
|
+
display: flex;
|
|
1083
|
+
flex-direction: column;
|
|
1084
|
+
height: 400px;
|
|
1085
|
+
}
|
|
1086
|
+
.contacts-search-row {
|
|
1087
|
+
display: flex;
|
|
1088
|
+
align-items: center;
|
|
1089
|
+
gap: 8px;
|
|
1090
|
+
padding: 10px 12px;
|
|
1091
|
+
border-bottom: 1px solid ${f};
|
|
1092
|
+
flex-shrink: 0;
|
|
1093
|
+
}
|
|
1094
|
+
.contacts-search-input-wrap {
|
|
1095
|
+
flex: 1;
|
|
1096
|
+
display: flex;
|
|
1097
|
+
align-items: center;
|
|
1098
|
+
gap: 8px;
|
|
1099
|
+
background: var(--bg);
|
|
1100
|
+
border-radius: 20px;
|
|
1101
|
+
padding: 0 12px;
|
|
1102
|
+
height: 36px;
|
|
1103
|
+
}
|
|
1104
|
+
.contacts-search-input-wrap svg {
|
|
1105
|
+
width: 16px;
|
|
1106
|
+
height: 16px;
|
|
1107
|
+
color: var(--text-sec);
|
|
1108
|
+
flex-shrink: 0;
|
|
1109
|
+
}
|
|
1110
|
+
.contacts-search-input {
|
|
1111
|
+
flex: 1;
|
|
1112
|
+
border: none;
|
|
1113
|
+
background: transparent;
|
|
1114
|
+
color: var(--text);
|
|
1115
|
+
font-size: 13px;
|
|
1116
|
+
font-family: inherit;
|
|
1117
|
+
outline: none;
|
|
1118
|
+
}
|
|
1119
|
+
.contacts-search-input::placeholder { color: var(--text-sec); }
|
|
1120
|
+
.contacts-refresh-btn {
|
|
1121
|
+
width: 32px;
|
|
1122
|
+
height: 32px;
|
|
1123
|
+
border: none;
|
|
1124
|
+
background: transparent;
|
|
1125
|
+
color: var(--text-sec);
|
|
1126
|
+
cursor: pointer;
|
|
1127
|
+
border-radius: 50%;
|
|
1128
|
+
display: flex;
|
|
1129
|
+
align-items: center;
|
|
1130
|
+
justify-content: center;
|
|
1131
|
+
transition: background 0.2s, color 0.2s;
|
|
1132
|
+
flex-shrink: 0;
|
|
1133
|
+
}
|
|
1134
|
+
.contacts-refresh-btn:hover { background: ${p}; color: var(--text); }
|
|
1135
|
+
.contacts-refresh-btn svg { width: 18px; height: 18px; }
|
|
1136
|
+
|
|
1137
|
+
.contacts-list {
|
|
1138
|
+
flex: 1;
|
|
1139
|
+
overflow-y: auto;
|
|
1140
|
+
padding: 4px 8px;
|
|
1141
|
+
}
|
|
1142
|
+
.contacts-loading {
|
|
1143
|
+
display: flex;
|
|
1144
|
+
flex-direction: column;
|
|
1145
|
+
align-items: center;
|
|
1146
|
+
justify-content: center;
|
|
1147
|
+
padding: 40px 16px;
|
|
1148
|
+
color: var(--text-sec);
|
|
1149
|
+
font-size: 13px;
|
|
1150
|
+
gap: 12px;
|
|
1151
|
+
}
|
|
1152
|
+
.spinner {
|
|
1153
|
+
width: 24px;
|
|
1154
|
+
height: 24px;
|
|
1155
|
+
border: 3px solid ${p};
|
|
1156
|
+
border-top-color: var(--primary);
|
|
1157
|
+
border-radius: 50%;
|
|
1158
|
+
animation: spin 0.8s linear infinite;
|
|
1159
|
+
}
|
|
1160
|
+
@keyframes spin { to { transform: rotate(360deg); } }
|
|
1161
|
+
|
|
1162
|
+
.contact-item {
|
|
1163
|
+
display: flex;
|
|
1164
|
+
align-items: center;
|
|
1165
|
+
gap: 10px;
|
|
1166
|
+
padding: 8px 8px;
|
|
1167
|
+
border-radius: 10px;
|
|
1168
|
+
cursor: default;
|
|
1169
|
+
transition: background 0.15s;
|
|
1170
|
+
}
|
|
1171
|
+
.contact-item:hover { background: ${p}; }
|
|
1172
|
+
.contact-avatar {
|
|
1173
|
+
width: 36px;
|
|
1174
|
+
height: 36px;
|
|
1175
|
+
border-radius: 50%;
|
|
1176
|
+
background: var(--bg);
|
|
1177
|
+
display: flex;
|
|
1178
|
+
align-items: center;
|
|
1179
|
+
justify-content: center;
|
|
1180
|
+
flex-shrink: 0;
|
|
1181
|
+
overflow: hidden;
|
|
1182
|
+
font-size: 14px;
|
|
1183
|
+
font-weight: 600;
|
|
1184
|
+
color: var(--text-sec);
|
|
1185
|
+
}
|
|
1186
|
+
.contact-avatar img {
|
|
1187
|
+
width: 100%;
|
|
1188
|
+
height: 100%;
|
|
1189
|
+
object-fit: cover;
|
|
1190
|
+
}
|
|
1191
|
+
.contact-info {
|
|
1192
|
+
flex: 1;
|
|
1193
|
+
min-width: 0;
|
|
1194
|
+
}
|
|
1195
|
+
.contact-name {
|
|
1196
|
+
font-size: 14px;
|
|
1197
|
+
font-weight: 500;
|
|
1198
|
+
color: var(--text);
|
|
1199
|
+
white-space: nowrap;
|
|
1200
|
+
overflow: hidden;
|
|
1201
|
+
text-overflow: ellipsis;
|
|
1202
|
+
}
|
|
1203
|
+
.contact-phone {
|
|
1204
|
+
font-size: 12px;
|
|
1205
|
+
color: var(--text-sec);
|
|
1206
|
+
white-space: nowrap;
|
|
1207
|
+
overflow: hidden;
|
|
1208
|
+
text-overflow: ellipsis;
|
|
1209
|
+
}
|
|
1210
|
+
.contact-call-btn {
|
|
1211
|
+
width: 32px;
|
|
1212
|
+
height: 32px;
|
|
1213
|
+
border: none;
|
|
1214
|
+
background: var(--primary);
|
|
1215
|
+
color: #fff;
|
|
1216
|
+
border-radius: 50%;
|
|
1217
|
+
display: flex;
|
|
1218
|
+
align-items: center;
|
|
1219
|
+
justify-content: center;
|
|
1220
|
+
cursor: pointer;
|
|
1221
|
+
flex-shrink: 0;
|
|
1222
|
+
transition: transform 0.15s;
|
|
1223
|
+
}
|
|
1224
|
+
.contact-call-btn:hover { transform: scale(1.1); }
|
|
1225
|
+
.contact-call-btn:active { transform: scale(0.95); }
|
|
1226
|
+
.contact-call-btn svg { width: 16px; height: 16px; }
|
|
1227
|
+
|
|
1228
|
+
/* Hide header tabs during video call */
|
|
1229
|
+
.incall-view .video-container[style*="flex"] ~ .panel-header { display: none; }
|
|
1230
|
+
`;
|
|
1231
|
+
}
|
|
1232
|
+
const I = '<svg viewBox="0 0 24 24" fill="currentColor"><path d="M6.62 10.79a15.05 15.05 0 006.59 6.59l2.2-2.2a1 1 0 011.01-.24c1.12.37 2.33.57 3.57.57a1 1 0 011 1V20a1 1 0 01-1 1A17 17 0 013 4a1 1 0 011-1h3.5a1 1 0 011 1c0 1.25.2 2.45.57 3.57a1 1 0 01-.25 1.02l-2.2 2.2z"/></svg>', E = '<svg viewBox="0 0 24 24" fill="currentColor"><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 010-1.36C3.34 8.75 7.46 7 12 7s8.66 1.75 11.71 4.72c.18.18.29.44.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 00-2.67-1.85.99.99 0 01-.56-.9v-3.1C15.15 9.25 13.6 9 12 9z"/></svg>', X = '<svg viewBox="0 0 24 24" fill="currentColor"><path d="M20.01 15.38c-1.23 0-2.42-.2-3.53-.56a.977.977 0 00-1.01.24l-1.57 1.97c-2.83-1.35-5.48-3.9-6.89-6.83l1.95-1.66c.27-.28.35-.67.24-1.02-.37-1.11-.56-2.3-.56-3.53 0-.54-.45-.99-.99-.99H4.19C3.65 3 3 3.24 3 3.99 3 13.28 10.73 21 20.01 21c.71 0 .99-.63.99-1.18v-3.45c0-.54-.45-.99-.99-.99z"/></svg>', S = '<svg viewBox="0 0 24 24" fill="currentColor"><path d="M12 14c1.66 0 3-1.34 3-3V5c0-1.66-1.34-3-3-3S9 3.34 9 5v6c0 1.66 1.34 3 3 3zm-1-9c0-.55.45-1 1-1s1 .45 1 1v6c0 .55-.45 1-1 1s-1-.45-1-1V5z"/><path d="M17 11c0 2.76-2.24 5-5 5s-5-2.24-5-5H5c0 3.53 2.61 6.43 6 6.92V21h2v-3.08c3.39-.49 6-3.39 6-6.92h-2z"/></svg>', N = '<svg viewBox="0 0 24 24" fill="currentColor"><path d="M19 11h-1.7c0 .74-.16 1.43-.43 2.05l1.23 1.23c.56-.98.9-2.09.9-3.28zm-4.02.17c0-.06.02-.11.02-.17V5c0-1.66-1.34-3-3-3S9 3.34 9 5v.18l5.98 5.99zM4.27 3L3 4.27l6.01 6.01V11c0 1.66 1.33 3 2.99 3 .22 0 .44-.03.65-.08l1.66 1.66c-.71.33-1.5.52-2.31.52-2.76 0-5.3-2.1-5.3-5.1H5c0 3.41 2.72 6.23 6 6.72V21h2v-3.28c.91-.13 1.77-.45 2.54-.9L19.73 21 21 19.73 4.27 3z"/></svg>', z = '<svg viewBox="0 0 24 24" fill="currentColor"><path d="M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z"/></svg>', L = '<svg viewBox="0 0 24 24" fill="currentColor"><path d="M17 10.5V7c0-.55-.45-1-1-1H4c-.55 0-1 .45-1 1v10c0 .55.45 1 1 1h12c.55 0 1-.45 1-1v-3.5l4 4v-11l-4 4z"/></svg>', T = '<svg viewBox="0 0 24 24" fill="currentColor"><path d="M21 6.5l-4 4V7c0-.55-.45-1-1-1H9.82L21 17.18V6.5zM3.27 2L2 3.27 4.73 6H4c-.55 0-1 .45-1 1v10c0 .55.45 1 1 1h12c.21 0 .39-.08.54-.18L19.73 21 21 19.73 3.27 2z"/></svg>', Q = '<svg viewBox="0 0 24 24" fill="currentColor"><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 12 19 6.41z"/></svg>', tt = '<svg viewBox="0 0 24 24" fill="currentColor"><path d="M22 3H7c-.69 0-1.23.35-1.59.88L0 12l5.41 8.11c.36.53.9.89 1.59.89h15c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-3 12.59L17.59 17 14 13.41 10.41 17 9 15.59 12.59 12 9 8.41 10.41 7 14 10.59 17.59 7 19 8.41 15.41 12 19 15.59z"/></svg>', et = '<svg viewBox="0 0 24 24" fill="currentColor"><path d="M12 19c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zM6 1c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm12-8c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm-6 8c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm6 0c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0-6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm-6 0c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0-6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z"/></svg>', at = '<svg viewBox="0 0 24 24" fill="currentColor"><path d="M20 15.5c-1.25 0-2.45-.2-3.57-.57a1.02 1.02 0 00-1.02.24l-2.2 2.2a15.045 15.045 0 01-6.59-6.59l2.2-2.21a.96.96 0 00.25-1A11.36 11.36 0 018.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"/></svg>', it = '<svg viewBox="0 0 24 24" fill="currentColor"><path d="M16 11c1.66 0 2.99-1.34 2.99-3S17.66 5 16 5s-3 1.34-3 3 1.34 3 3 3zm-8 0c1.66 0 2.99-1.34 2.99-3S9.66 5 8 5 5 6.34 5 8s1.34 3 3 3zm0 2c-2.33 0-7 1.17-7 3.5V19h14v-2.5c0-2.33-4.67-3.5-7-3.5zm8 0c-.29 0-.62.02-.97.05 1.16.84 1.97 1.97 1.97 3.45V19h6v-2.5c0-2.33-4.67-3.5-7-3.5z"/></svg>', st = '<svg viewBox="0 0 24 24" fill="currentColor"><path d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"/></svg>', nt = '<svg viewBox="0 0 24 24" fill="currentColor"><path d="M17.65 6.35A7.958 7.958 0 0012 4c-4.42 0-7.99 3.58-7.99 8s3.57 8 7.99 8c3.73 0 6.84-2.55 7.73-6h-2.08A5.99 5.99 0 0112 18c-3.31 0-6-2.69-6-6s2.69-6 6-6c1.66 0 3.14.69 4.22 1.78L13 11h7V4l-2.35 2.35z"/></svg>';
|
|
1233
|
+
function R(c) {
|
|
1234
|
+
const t = Math.floor(c / 1e3), e = Math.floor(t / 60), a = t % 60;
|
|
1235
|
+
return `${String(e).padStart(2, "0")}:${String(a).padStart(2, "0")}`;
|
|
1236
|
+
}
|
|
1237
|
+
function A(c) {
|
|
1238
|
+
if (!c || c === "unknown") return c;
|
|
1239
|
+
const t = c.replace(/\D/g, "");
|
|
1240
|
+
return t.length <= 4 ? c : t.length === 13 && t.startsWith("55") ? `+${t.slice(0, 2)} (${t.slice(2, 4)}) ${t.slice(4, 9)}-${t.slice(9)}` : t.length === 12 && t.startsWith("55") ? `+${t.slice(0, 2)} (${t.slice(2, 4)}) ${t.slice(4, 8)}-${t.slice(8)}` : `+${t}`;
|
|
1241
|
+
}
|
|
1242
|
+
const rt = [
|
|
1243
|
+
{ digit: "1", sub: "" },
|
|
1244
|
+
{ digit: "2", sub: "ABC" },
|
|
1245
|
+
{ digit: "3", sub: "DEF" },
|
|
1246
|
+
{ digit: "4", sub: "GHI" },
|
|
1247
|
+
{ digit: "5", sub: "JKL" },
|
|
1248
|
+
{ digit: "6", sub: "MNO" },
|
|
1249
|
+
{ digit: "7", sub: "PQRS" },
|
|
1250
|
+
{ digit: "8", sub: "TUV" },
|
|
1251
|
+
{ digit: "9", sub: "WXYZ" },
|
|
1252
|
+
{ digit: "*", sub: "" },
|
|
1253
|
+
{ digit: "0", sub: "+" },
|
|
1254
|
+
{ digit: "#", sub: "" }
|
|
1255
|
+
];
|
|
1256
|
+
class ot {
|
|
1257
|
+
constructor(t) {
|
|
1258
|
+
this.open = !1, this.muted = !1, this.timers = /* @__PURE__ */ new Map(), this.timerStarts = /* @__PURE__ */ new Map(), this.currentView = "dialer", this.contactsLoaded = !1, this.contactsCache = [], this.pictureCache = /* @__PURE__ */ new Map(), this.pictureRequested = /* @__PURE__ */ new Set(), this.activeCallId = null, this.cameraOn = !1, this.incallTimer = null, this.config = t, this.host = document.createElement("div"), this.host.id = "zapi-call-widget", this.shadow = this.host.attachShadow({ mode: "closed" });
|
|
1259
|
+
const e = document.createElement("style");
|
|
1260
|
+
e.textContent = Y(t.theme), this.shadow.appendChild(e), this.buildDOM(), document.body.appendChild(this.host);
|
|
1261
|
+
}
|
|
1262
|
+
buildDOM() {
|
|
1263
|
+
this.root = document.createElement("div"), this.root.className = `zapi-call-root ${this.config.position}`, this.panel = document.createElement("div"), this.panel.className = "panel";
|
|
1264
|
+
const t = document.createElement("div");
|
|
1265
|
+
t.className = "panel-header", t.innerHTML = `
|
|
1266
|
+
<div class="panel-header-top">
|
|
1267
|
+
<h3>Telefone</h3>
|
|
1268
|
+
<button class="close-btn">${Q}</button>
|
|
1269
|
+
</div>
|
|
1270
|
+
<div class="tabs">
|
|
1271
|
+
<button class="tab active" data-tab="dialer">${et} Discador</button>
|
|
1272
|
+
<button class="tab" data-tab="calls">${at} Chamadas</button>
|
|
1273
|
+
<button class="tab" data-tab="contacts">${it} Contatos</button>
|
|
1274
|
+
</div>
|
|
1275
|
+
`, t.querySelector(".close-btn").addEventListener("click", () => this.togglePanel(!1)), this.tabDialer = t.querySelector('[data-tab="dialer"]'), this.tabCalls = t.querySelector('[data-tab="calls"]'), this.tabContacts = t.querySelector('[data-tab="contacts"]'), this.tabDialer.addEventListener("click", () => this.switchView("dialer")), this.tabCalls.addEventListener("click", () => this.switchView("calls")), this.tabContacts.addEventListener("click", () => this.switchView("contacts")), this.panel.appendChild(t);
|
|
1276
|
+
const e = document.createElement("div");
|
|
1277
|
+
e.className = "panel-body", this.dialerView = document.createElement("div"), this.dialerView.className = "view active", this.buildDialerView(), e.appendChild(this.dialerView), this.callsView = document.createElement("div"), this.callsView.className = "view", this.callsView.innerHTML = `
|
|
1278
|
+
<div class="calls-view">
|
|
1279
|
+
<div class="empty-state">
|
|
1280
|
+
<div class="icon">📞</div>
|
|
1281
|
+
<p>Nenhuma chamada ativa</p>
|
|
1282
|
+
</div>
|
|
1283
|
+
</div>
|
|
1284
|
+
`, e.appendChild(this.callsView), this.contactsView = document.createElement("div"), this.contactsView.className = "view", this.buildContactsView(), e.appendChild(this.contactsView), this.incallView = document.createElement("div"), this.incallView.className = "view", this.buildInCallView(), e.appendChild(this.incallView), this.panel.appendChild(e), this.root.appendChild(this.panel), this.bubble = document.createElement("div"), this.bubble.className = "bubble", this.bubble.innerHTML = `
|
|
1285
|
+
${I}
|
|
1286
|
+
<span class="badge">0</span>
|
|
1287
|
+
<span class="conn-dot"></span>
|
|
1288
|
+
`, this.badge = this.bubble.querySelector(".badge"), this.connDot = this.bubble.querySelector(".conn-dot"), this.bubble.addEventListener("click", () => {
|
|
1289
|
+
this.togglePanel(), this.config.onResume();
|
|
1290
|
+
}), this.root.appendChild(this.bubble), this.shadow.appendChild(this.root);
|
|
1291
|
+
}
|
|
1292
|
+
buildDialerView() {
|
|
1293
|
+
const t = document.createElement("div");
|
|
1294
|
+
t.className = "dialer";
|
|
1295
|
+
const e = document.createElement("div");
|
|
1296
|
+
e.className = "dialer-display", this.dialerInput = document.createElement("input"), this.dialerInput.className = "dialer-input", this.dialerInput.type = "tel", this.dialerInput.placeholder = "Digite o numero", this.dialerInput.addEventListener("keydown", (r) => {
|
|
1297
|
+
r.key === "Enter" && this.handleMakeCall();
|
|
1298
|
+
});
|
|
1299
|
+
const a = document.createElement("button");
|
|
1300
|
+
a.className = "backspace-btn", a.innerHTML = tt, a.addEventListener("click", () => {
|
|
1301
|
+
this.dialerInput.value = this.dialerInput.value.slice(0, -1), this.dialerInput.focus();
|
|
1302
|
+
}), e.appendChild(this.dialerInput), e.appendChild(a), t.appendChild(e);
|
|
1303
|
+
const i = document.createElement("div");
|
|
1304
|
+
i.className = "numpad";
|
|
1305
|
+
for (const r of rt) {
|
|
1306
|
+
const o = document.createElement("button");
|
|
1307
|
+
o.className = "numpad-key", o.innerHTML = `<span>${r.digit}</span>${r.sub ? `<span class="sub">${r.sub}</span>` : ""}`, o.addEventListener("click", () => {
|
|
1308
|
+
this.dialerInput.value += r.digit, this.dialerInput.focus();
|
|
1309
|
+
}), i.appendChild(o);
|
|
1310
|
+
}
|
|
1311
|
+
t.appendChild(i);
|
|
1312
|
+
const s = document.createElement("div");
|
|
1313
|
+
s.className = "call-btns";
|
|
1314
|
+
const n = document.createElement("button");
|
|
1315
|
+
if (n.className = "call-btn", n.innerHTML = I, n.addEventListener("click", () => this.handleMakeCall(!1)), s.appendChild(n), this.config.showVideoDialButton) {
|
|
1316
|
+
const r = document.createElement("button");
|
|
1317
|
+
r.className = "call-btn video-call-btn", r.innerHTML = L, r.addEventListener("click", () => this.handleMakeCall(!0)), s.appendChild(r);
|
|
1318
|
+
}
|
|
1319
|
+
t.appendChild(s), this.dialerView.appendChild(t);
|
|
1320
|
+
}
|
|
1321
|
+
buildContactsView() {
|
|
1322
|
+
const t = document.createElement("div");
|
|
1323
|
+
t.className = "contacts-wrapper";
|
|
1324
|
+
const e = document.createElement("div");
|
|
1325
|
+
e.className = "contacts-search-row", e.innerHTML = `
|
|
1326
|
+
<div class="contacts-search-input-wrap">
|
|
1327
|
+
${st}
|
|
1328
|
+
<input class="contacts-search-input" type="text" placeholder="Buscar contato..." />
|
|
1329
|
+
</div>
|
|
1330
|
+
<button class="contacts-refresh-btn">${nt}</button>
|
|
1331
|
+
`;
|
|
1332
|
+
const a = e.querySelector(".contacts-search-input");
|
|
1333
|
+
a.addEventListener("input", () => this.filterContacts(a.value)), e.querySelector(".contacts-refresh-btn").addEventListener("click", () => {
|
|
1334
|
+
this.contactsLoaded = !1, this.loadContacts();
|
|
1335
|
+
}), t.appendChild(e);
|
|
1336
|
+
const s = document.createElement("div");
|
|
1337
|
+
s.className = "contacts-list", s.innerHTML = '<div class="empty-state"><p>Clique na aba para carregar</p></div>', t.appendChild(s), this.contactsView.appendChild(t);
|
|
1338
|
+
}
|
|
1339
|
+
loadContacts() {
|
|
1340
|
+
const t = this.contactsView.querySelector(".contacts-list");
|
|
1341
|
+
t.innerHTML = '<div class="contacts-loading"><div class="spinner"></div><p>Carregando contatos...</p></div>', this.config.onRequestContacts();
|
|
1342
|
+
}
|
|
1343
|
+
filterContacts(t) {
|
|
1344
|
+
const e = t.toLowerCase().trim(), a = this.contactsView.querySelector(".contacts-list"), i = e ? this.contactsCache.filter(
|
|
1345
|
+
(s) => s.name.toLowerCase().includes(e) || s.phone.includes(e)
|
|
1346
|
+
) : this.contactsCache;
|
|
1347
|
+
this.renderContactsList(a, i);
|
|
1348
|
+
}
|
|
1349
|
+
renderContactsList(t, e) {
|
|
1350
|
+
if (e.length === 0) {
|
|
1351
|
+
t.innerHTML = '<div class="empty-state"><p>Nenhum contato encontrado</p></div>';
|
|
1352
|
+
return;
|
|
1353
|
+
}
|
|
1354
|
+
t.innerHTML = "";
|
|
1355
|
+
for (const a of e) {
|
|
1356
|
+
const i = document.createElement("div");
|
|
1357
|
+
i.className = "contact-item";
|
|
1358
|
+
const s = (a.short || a.name || "?").charAt(0).toUpperCase();
|
|
1359
|
+
i.innerHTML = `
|
|
1360
|
+
<div class="contact-avatar">${a.imgUrl ? `<img src="${a.imgUrl}" />` : `<span>${s}</span>`}</div>
|
|
1361
|
+
<div class="contact-info">
|
|
1362
|
+
<div class="contact-name">${a.name || a.phone}</div>
|
|
1363
|
+
<div class="contact-phone">${a.phone}</div>
|
|
1364
|
+
</div>
|
|
1365
|
+
<button class="contact-call-btn">${I}</button>
|
|
1366
|
+
`, i.querySelector(".contact-call-btn").addEventListener("click", () => {
|
|
1367
|
+
const n = a.phone.replace(/[^0-9+]/g, "");
|
|
1368
|
+
this.config.onMakeCall(n, !1);
|
|
1369
|
+
}), t.appendChild(i);
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
updateContacts(t) {
|
|
1373
|
+
this.contactsCache = t, this.contactsLoaded = !0;
|
|
1374
|
+
const e = this.contactsView.querySelector(".contacts-list");
|
|
1375
|
+
e && this.renderContactsList(e, t);
|
|
1376
|
+
}
|
|
1377
|
+
buildInCallView() {
|
|
1378
|
+
const t = document.createElement("div");
|
|
1379
|
+
t.className = "incall-view", t.innerHTML = `
|
|
1380
|
+
<div class="video-container" style="display:none;">
|
|
1381
|
+
<canvas class="remote-video"></canvas>
|
|
1382
|
+
<div class="video-overlay-top">
|
|
1383
|
+
<div class="video-caller-info">
|
|
1384
|
+
<div class="video-phone"></div>
|
|
1385
|
+
<div class="video-timer">00:00</div>
|
|
1386
|
+
</div>
|
|
1387
|
+
</div>
|
|
1388
|
+
<div class="video-overlay-bottom">
|
|
1389
|
+
<button class="incall-btn video-btn-mute">${S}</button>
|
|
1390
|
+
<button class="incall-btn video-btn-camera">${T}</button>
|
|
1391
|
+
<button class="incall-btn video-btn-end">${E}</button>
|
|
1392
|
+
</div>
|
|
1393
|
+
</div>
|
|
1394
|
+
<div class="audio-call-ui">
|
|
1395
|
+
<div class="incall-avatar">${z}</div>
|
|
1396
|
+
<div class="incall-phone"></div>
|
|
1397
|
+
<div class="incall-state"></div>
|
|
1398
|
+
<div class="incall-timer">00:00</div>
|
|
1399
|
+
<div class="audio-level-wrap">
|
|
1400
|
+
<div class="audio-level-bar"></div>
|
|
1401
|
+
</div>
|
|
1402
|
+
<div class="incall-controls">
|
|
1403
|
+
<button class="incall-btn incall-btn-mute">${S}</button>
|
|
1404
|
+
<button class="incall-btn incall-btn-camera">${T}</button>
|
|
1405
|
+
<button class="incall-btn incall-btn-end">${E}</button>
|
|
1406
|
+
</div>
|
|
1407
|
+
</div>
|
|
1408
|
+
`, this.videoContainer = t.querySelector(".video-container"), this.remoteVideoCanvas = t.querySelector(".remote-video"), this.incallPhoneEl = t.querySelector(".incall-phone"), this.incallStateEl = t.querySelector(".incall-state"), this.incallTimerEl = t.querySelector(".incall-timer"), this.audioLevelBar = t.querySelector(".audio-level-bar"), this.videoPhoneEl = t.querySelector(".video-phone"), this.videoTimerEl = t.querySelector(".video-timer"), this.incallMuteBtn = t.querySelector(".incall-btn-mute"), this.incallMuteBtn.addEventListener("click", () => {
|
|
1409
|
+
this.muted = !this.muted, this.config.onMute(this.muted), this.updateMuteButtons();
|
|
1410
|
+
}), t.querySelector(".video-btn-mute").addEventListener("click", () => {
|
|
1411
|
+
this.muted = !this.muted, this.config.onMute(this.muted), this.updateMuteButtons();
|
|
1412
|
+
}), t.querySelectorAll(".video-btn-camera, .incall-btn-camera").forEach((n) => {
|
|
1413
|
+
n.addEventListener("click", () => {
|
|
1414
|
+
this.cameraOn = !this.cameraOn, this.config.onCamera(this.cameraOn), this.updateCameraButton();
|
|
1415
|
+
});
|
|
1416
|
+
}), t.querySelector(".incall-btn-end").addEventListener("click", () => {
|
|
1417
|
+
this.activeCallId && this.config.onReject(this.activeCallId);
|
|
1418
|
+
}), t.querySelector(".video-btn-end").addEventListener("click", () => {
|
|
1419
|
+
this.activeCallId && this.config.onReject(this.activeCallId);
|
|
1420
|
+
}), this.incallView.appendChild(t);
|
|
1421
|
+
}
|
|
1422
|
+
handleMakeCall(t = !1) {
|
|
1423
|
+
const e = this.dialerInput.value.replace(/\s/g, "");
|
|
1424
|
+
e && (this.config.onMakeCall(e, t), console.log("[ZAPICall] makeCall from widget:", e, t ? "(video)" : "(audio)"));
|
|
1425
|
+
}
|
|
1426
|
+
switchView(t) {
|
|
1427
|
+
this.currentView = t, this.dialerView.classList.toggle("active", t === "dialer"), this.callsView.classList.toggle("active", t === "calls"), this.contactsView.classList.toggle("active", t === "contacts"), this.incallView.classList.toggle("active", t === "incall"), this.tabDialer.classList.toggle("active", t === "dialer"), this.tabCalls.classList.toggle("active", t === "calls"), this.tabContacts.classList.toggle("active", t === "contacts"), t === "contacts" && !this.contactsLoaded && this.loadContacts();
|
|
1428
|
+
}
|
|
1429
|
+
togglePanel(t) {
|
|
1430
|
+
this.open = t !== void 0 ? t : !this.open, this.panel.classList.toggle("open", this.open);
|
|
1431
|
+
}
|
|
1432
|
+
updateCalls(t, e) {
|
|
1433
|
+
this.connDot.classList.toggle("connected", e);
|
|
1434
|
+
const a = t.filter((n) => n.state !== "ended"), i = t.filter((n) => n.state === "ringing" || n.state === "preaccepted" || n.state === "calling"), s = t.find((n) => n.state === "active") || t.find((n) => n.state === "accepted") || t.find((n) => n.state === "calling");
|
|
1435
|
+
if (a.length > 0 ? (this.badge.textContent = String(a.length), this.badge.classList.add("visible")) : this.badge.classList.remove("visible"), this.bubble.classList.toggle("ringing", i.length > 0), i.length > 0 && !this.open && this.togglePanel(!0), s) {
|
|
1436
|
+
this.activeCallId = s.callId, this.incallPhoneEl.textContent = s.notify || A(s.from), this.incallStateEl.textContent = this.stateLabel(s.state), this.videoPhoneEl && (this.videoPhoneEl.textContent = s.notify || A(s.from));
|
|
1437
|
+
const n = this.incallView.querySelector(".incall-avatar");
|
|
1438
|
+
n && n.dataset.avatarPhone !== s.from && (n.dataset.avatarPhone = s.from, n.innerHTML = this.renderAvatar(s.from)), s.state === "accepted" || s.state === "active" ? (this.timerStarts.has(s.callId) || this.timerStarts.set(s.callId, Date.now()), this.startInCallTimer(s.callId)) : this.stopInCallTimer(), this.currentView !== "incall" && this.switchView("incall");
|
|
1439
|
+
} else this.currentView === "incall" && (this.activeCallId = null, this.stopInCallTimer(), i.length > 0 ? this.switchView("calls") : this.switchView("dialer"));
|
|
1440
|
+
i.length > 0 && !s && this.currentView === "dialer" && this.switchView("calls"), this.renderCallsList(t);
|
|
1441
|
+
}
|
|
1442
|
+
renderCallsList(t) {
|
|
1443
|
+
const e = this.callsView.querySelector(".calls-view");
|
|
1444
|
+
if (t.length === 0) {
|
|
1445
|
+
e.innerHTML = `
|
|
1446
|
+
<div class="empty-state">
|
|
1447
|
+
<div class="icon">📞</div>
|
|
1448
|
+
<p>Nenhuma chamada ativa</p>
|
|
1449
|
+
</div>
|
|
1450
|
+
`, this.clearAllTimers();
|
|
1451
|
+
return;
|
|
1452
|
+
}
|
|
1453
|
+
e.innerHTML = "";
|
|
1454
|
+
for (const a of t)
|
|
1455
|
+
e.appendChild(this.buildCallCard(a));
|
|
1456
|
+
}
|
|
1457
|
+
buildCallCard(t) {
|
|
1458
|
+
const e = document.createElement("div");
|
|
1459
|
+
e.className = `call-card${t.state === "ended" ? " ended" : ""}`, e.dataset.callId = t.callId;
|
|
1460
|
+
const a = t.state === "ringing" || t.state === "preaccepted", i = t.state === "calling", s = t.state === "accepted" || t.state === "active";
|
|
1461
|
+
e.innerHTML = `
|
|
1462
|
+
<div class="call-card-top">
|
|
1463
|
+
<div class="avatar" data-avatar-phone="${t.from}">${this.renderAvatar(t.from)}</div>
|
|
1464
|
+
<div class="call-info">
|
|
1465
|
+
${t.notify ? `<div class="call-name">${t.notify}</div>` : ""}
|
|
1466
|
+
<div class="call-phone">${A(t.from)}</div>
|
|
1467
|
+
<div class="call-meta">
|
|
1468
|
+
${t.isVideo ? L : I}
|
|
1469
|
+
<span>${t.isVideo ? "Video" : "Audio"}${t.isGroup ? " (Grupo)" : ""}</span>
|
|
1470
|
+
</div>
|
|
1471
|
+
</div>
|
|
1472
|
+
<span class="state-badge ${t.state}">${this.stateLabel(t.state)}</span>
|
|
1473
|
+
</div>
|
|
1474
|
+
${s ? `<div class="timer" data-timer="${t.callId}">00:00</div>` : ""}
|
|
1475
|
+
${a ? `
|
|
1476
|
+
<div class="call-actions">
|
|
1477
|
+
<button class="btn btn-accept" data-accept="${t.callId}">
|
|
1478
|
+
${X} Aceitar
|
|
1479
|
+
</button>
|
|
1480
|
+
<button class="btn btn-reject" data-reject="${t.callId}">
|
|
1481
|
+
${E} Rejeitar
|
|
1482
|
+
</button>
|
|
1483
|
+
</div>
|
|
1484
|
+
` : ""}
|
|
1485
|
+
${i || s ? `
|
|
1486
|
+
<div class="call-actions">
|
|
1487
|
+
<button class="btn btn-reject" data-reject="${t.callId}" style="flex:1">
|
|
1488
|
+
${E} Encerrar
|
|
1489
|
+
</button>
|
|
1490
|
+
</div>
|
|
1491
|
+
` : ""}
|
|
1492
|
+
`;
|
|
1493
|
+
const n = e.querySelector(`[data-accept="${t.callId}"]`);
|
|
1494
|
+
return n == null || n.addEventListener("click", () => {
|
|
1495
|
+
this.config.onAccept(t.callId), this.config.onResume();
|
|
1496
|
+
}), e.querySelectorAll(`[data-reject="${t.callId}"]`).forEach((o) => o.addEventListener("click", () => this.config.onReject(t.callId))), s && (this.timerStarts.has(t.callId) || this.timerStarts.set(t.callId, Date.now()), this.startTimer(t.callId, e)), t.state === "ended" && this.stopTimer(t.callId), e;
|
|
1497
|
+
}
|
|
1498
|
+
stateLabel(t) {
|
|
1499
|
+
switch (t) {
|
|
1500
|
+
case "ringing":
|
|
1501
|
+
return "Chamando";
|
|
1502
|
+
case "calling":
|
|
1503
|
+
return "Ligando...";
|
|
1504
|
+
case "preaccepted":
|
|
1505
|
+
return "Conectando";
|
|
1506
|
+
case "accepted":
|
|
1507
|
+
return "Aceita";
|
|
1508
|
+
case "active":
|
|
1509
|
+
return "Ativa";
|
|
1510
|
+
case "ended":
|
|
1511
|
+
return "Encerrada";
|
|
1512
|
+
default:
|
|
1513
|
+
return t;
|
|
1514
|
+
}
|
|
1515
|
+
}
|
|
1516
|
+
// Timers for call cards in list view
|
|
1517
|
+
startTimer(t, e) {
|
|
1518
|
+
this.stopTimer(t);
|
|
1519
|
+
const a = this.timerStarts.get(t) || Date.now(), i = e.querySelector(`[data-timer="${t}"]`);
|
|
1520
|
+
if (!i) return;
|
|
1521
|
+
const s = () => {
|
|
1522
|
+
i.textContent = R(Date.now() - a);
|
|
1523
|
+
};
|
|
1524
|
+
s(), this.timers.set(t, setInterval(s, 1e3));
|
|
1525
|
+
}
|
|
1526
|
+
stopTimer(t) {
|
|
1527
|
+
const e = this.timers.get(t);
|
|
1528
|
+
e && (clearInterval(e), this.timers.delete(t));
|
|
1529
|
+
}
|
|
1530
|
+
startInCallTimer(t) {
|
|
1531
|
+
this.stopInCallTimer();
|
|
1532
|
+
const e = this.timerStarts.get(t) || Date.now(), a = () => {
|
|
1533
|
+
const i = R(Date.now() - e);
|
|
1534
|
+
this.incallTimerEl.textContent = i, this.videoTimerEl && (this.videoTimerEl.textContent = i);
|
|
1535
|
+
};
|
|
1536
|
+
a(), this.incallTimer = setInterval(a, 1e3);
|
|
1537
|
+
}
|
|
1538
|
+
stopInCallTimer() {
|
|
1539
|
+
this.incallTimer && (clearInterval(this.incallTimer), this.incallTimer = null), this.incallTimerEl.textContent = "00:00";
|
|
1540
|
+
}
|
|
1541
|
+
/** Show video container for video calls */
|
|
1542
|
+
showVideo(t) {
|
|
1543
|
+
if (!this.videoContainer) return;
|
|
1544
|
+
this.videoContainer.style.display = t ? "flex" : "none";
|
|
1545
|
+
const e = this.incallView.querySelector(".audio-call-ui");
|
|
1546
|
+
e && (e.style.display = t ? "none" : ""), t && (this.videoPhoneEl.textContent = this.incallPhoneEl.textContent, this.videoTimerEl.textContent = this.incallTimerEl.textContent);
|
|
1547
|
+
}
|
|
1548
|
+
getRemoteCanvas() {
|
|
1549
|
+
return this.remoteVideoCanvas;
|
|
1550
|
+
}
|
|
1551
|
+
resetCamera() {
|
|
1552
|
+
this.cameraOn = !1, this.updateCameraButton();
|
|
1553
|
+
}
|
|
1554
|
+
updateMuteButtons() {
|
|
1555
|
+
this.incallMuteBtn.classList.toggle("muted", this.muted), this.incallMuteBtn.innerHTML = this.muted ? N : S;
|
|
1556
|
+
const t = this.incallView.querySelector(".video-btn-mute");
|
|
1557
|
+
t && (t.classList.toggle("muted", this.muted), t.innerHTML = this.muted ? N : S);
|
|
1558
|
+
}
|
|
1559
|
+
updateCameraButton() {
|
|
1560
|
+
this.incallView.querySelectorAll(".video-btn-camera, .incall-btn-camera").forEach((e) => {
|
|
1561
|
+
e.classList.toggle("muted", !this.cameraOn), e.innerHTML = this.cameraOn ? L : T;
|
|
1562
|
+
});
|
|
1563
|
+
}
|
|
1564
|
+
showMakeCallError(t) {
|
|
1565
|
+
const e = t.includes("PHONE_NOT_ON_WHATSAPP") ? "Número não encontrado" : "Erro ao realizar chamada", a = this.dialerInput.placeholder;
|
|
1566
|
+
this.dialerInput.value = "", this.dialerInput.placeholder = e, this.dialerInput.classList.add("error"), setTimeout(() => {
|
|
1567
|
+
this.dialerInput.placeholder = a, this.dialerInput.classList.remove("error");
|
|
1568
|
+
}, 3e3);
|
|
1569
|
+
}
|
|
1570
|
+
updateAudioLevel(t) {
|
|
1571
|
+
const e = Math.min(100, Math.max(0, t * 100));
|
|
1572
|
+
this.audioLevelBar.style.width = `${e}%`;
|
|
1573
|
+
}
|
|
1574
|
+
renderAvatar(t) {
|
|
1575
|
+
const e = this.pictureCache.get(t);
|
|
1576
|
+
return e ? `<img src="${e}" class="avatar-img" />` : (!this.pictureRequested.has(t) && t && (this.pictureRequested.add(t), this.config.onRequestProfilePicture(t)), z);
|
|
1577
|
+
}
|
|
1578
|
+
updateProfilePicture(t, e) {
|
|
1579
|
+
if (this.pictureCache.set(t, e), !e) return;
|
|
1580
|
+
const a = `<img src="${e}" class="avatar-img" />`;
|
|
1581
|
+
this.shadow.querySelectorAll(`[data-avatar-phone="${t}"]`).forEach((i) => {
|
|
1582
|
+
i.innerHTML = a;
|
|
1583
|
+
});
|
|
1584
|
+
}
|
|
1585
|
+
clearAllTimers() {
|
|
1586
|
+
for (const t of this.timers.values())
|
|
1587
|
+
clearInterval(t);
|
|
1588
|
+
this.timers.clear(), this.timerStarts.clear(), this.stopInCallTimer();
|
|
1589
|
+
}
|
|
1590
|
+
destroy() {
|
|
1591
|
+
this.clearAllTimers(), this.host.remove();
|
|
1592
|
+
}
|
|
1593
|
+
}
|
|
1594
|
+
class D extends B {
|
|
1595
|
+
constructor(t) {
|
|
1596
|
+
super(), this.widget = null, this.audioConfig = { sampleRate: 16e3, channels: 1 }, this.connected = !1, this.micStarted = !1, this.cameraStarted = !1, this.destroyed = !1, this.sdkId = "", this.contacts = [], this.opts = t, this.state = new Z(), this.audio = new $(this.audioConfig.sampleRate), this.video = new J(), this.ws = new F("https://staging-call.z-api.io", t.instanceId, t.getToken), this.ws.onJson = (e) => this.handleJsonMessage(e), this.ws.onBinary = (e) => this.handleBinaryMessage(e), this.ws.onConnectionChange = (e) => this.handleConnectionChange(e), this.audio.onMicData = (e) => {
|
|
1597
|
+
const a = new ArrayBuffer(1 + e.byteLength);
|
|
1598
|
+
new Uint8Array(a)[0] = 1, new Uint8Array(a, 1).set(new Uint8Array(e)), this.ws.send(a);
|
|
1599
|
+
}, this.audio.onAudioLevel = (e) => {
|
|
1600
|
+
var a;
|
|
1601
|
+
this.emit("audio:level", e), (a = this.widget) == null || a.updateAudioLevel(e);
|
|
1602
|
+
}, this.on("video:frame", (e) => this.video.renderFrame(e)), this.video.onEncodedCameraFrame = (e, a, i, s, n, r) => {
|
|
1603
|
+
const o = new ArrayBuffer(22 + e.byteLength), l = new DataView(o);
|
|
1604
|
+
l.setUint8(0, 3), l.setUint16(1, a, !0), l.setUint16(3, i, !0), l.setFloat64(5, s), l.setUint8(13, n ? 1 : 0), l.setFloat64(14, r), new Uint8Array(o, 22).set(new Uint8Array(e)), this.ws.send(o);
|
|
1605
|
+
}, this.video.onCameraFrame = (e, a, i) => {
|
|
1606
|
+
const s = this.rgbaToNv12(new Uint8Array(e), a, i), n = new ArrayBuffer(5 + s.byteLength), r = new DataView(n);
|
|
1607
|
+
r.setUint8(0, 2), r.setUint16(1, a, !0), r.setUint16(3, i, !0), new Uint8Array(n, 5).set(s), this.ws.send(n);
|
|
1608
|
+
}, t.autoWidget !== !1 && (this.widget = new ot({
|
|
1609
|
+
position: t.position || "bottom-right",
|
|
1610
|
+
theme: t.theme || {},
|
|
1611
|
+
showVideoDialButton: t.showVideoDialButton === !0,
|
|
1612
|
+
onAccept: (e) => this.accept(e),
|
|
1613
|
+
onReject: (e) => this.reject(e),
|
|
1614
|
+
onMute: (e) => this.mute(e),
|
|
1615
|
+
onCamera: (e) => this.setCamera(e),
|
|
1616
|
+
onResume: () => this.audio.resume(),
|
|
1617
|
+
onMakeCall: (e, a) => this.makeCall(e, a),
|
|
1618
|
+
onRequestContacts: () => this.requestContacts(),
|
|
1619
|
+
onRequestProfilePicture: (e) => this.requestProfilePicture(e)
|
|
1620
|
+
}), this.video.setRemoteCanvas(this.widget.getRemoteCanvas())), this.ws.connect();
|
|
1621
|
+
}
|
|
1622
|
+
// -- Public API --
|
|
1623
|
+
accept(t) {
|
|
1624
|
+
console.log("[ZAPICall] >> call:accept", t), this.ws.sendJson({ type: "call:accept", callId: t }), this.startMicIfNeeded();
|
|
1625
|
+
}
|
|
1626
|
+
reject(t) {
|
|
1627
|
+
console.log("[ZAPICall] >> call:reject", t), this.ws.sendJson({ type: "call:reject", callId: t });
|
|
1628
|
+
}
|
|
1629
|
+
mute(t) {
|
|
1630
|
+
this.ws.sendJson({ type: "call:mute", muted: t });
|
|
1631
|
+
}
|
|
1632
|
+
async setCamera(t) {
|
|
1633
|
+
var e;
|
|
1634
|
+
this.ws.sendJson({ type: "call:camera", enabled: t }), t ? (await this.startCameraIfNeeded(), (e = this.widget) == null || e.showVideo(!0)) : (this.video.stopCamera(), this.cameraStarted = !1);
|
|
1635
|
+
}
|
|
1636
|
+
isCameraActive() {
|
|
1637
|
+
return this.cameraStarted;
|
|
1638
|
+
}
|
|
1639
|
+
makeCall(t, e = !1) {
|
|
1640
|
+
var a, i;
|
|
1641
|
+
console.log("[ZAPICall] >> call:make", t, e ? "(video)" : "(audio)"), this.audio.resume(), this.ws.sendJson({ type: "call:make", number: t, isVideo: e }), this.emit("call:make", t), (i = (a = this.opts).onMakeCall) == null || i.call(a, t);
|
|
1642
|
+
}
|
|
1643
|
+
getCalls() {
|
|
1644
|
+
return this.state.getAllCalls();
|
|
1645
|
+
}
|
|
1646
|
+
getActiveCall() {
|
|
1647
|
+
return this.state.getActiveCall();
|
|
1648
|
+
}
|
|
1649
|
+
isConnected() {
|
|
1650
|
+
return this.connected;
|
|
1651
|
+
}
|
|
1652
|
+
getSdkId() {
|
|
1653
|
+
return this.sdkId;
|
|
1654
|
+
}
|
|
1655
|
+
requestContacts() {
|
|
1656
|
+
this.ws.sendJson({ type: "contacts:list" });
|
|
1657
|
+
}
|
|
1658
|
+
requestProfilePicture(t) {
|
|
1659
|
+
this.ws.sendJson({ type: "profile:picture", phone: t });
|
|
1660
|
+
}
|
|
1661
|
+
getContacts() {
|
|
1662
|
+
return this.contacts;
|
|
1663
|
+
}
|
|
1664
|
+
destroy() {
|
|
1665
|
+
var t;
|
|
1666
|
+
this.destroyed || (this.destroyed = !0, this.ws.destroy(), this.audio.destroy(), this.video.destroy(), (t = this.widget) == null || t.destroy(), this.state.clear(), this.removeAllListeners());
|
|
1667
|
+
}
|
|
1668
|
+
// -- Internal --
|
|
1669
|
+
handleJsonMessage(t) {
|
|
1670
|
+
var e, a, i, s, n, r, o, l, p, u, b, d, m, f, g, x, w, C, y, k;
|
|
1671
|
+
switch (t.type) {
|
|
1672
|
+
case "connected":
|
|
1673
|
+
this.sdkId = t.sdkId || "", t.audioConfig && (t.audioConfig.sampleRate !== this.audioConfig.sampleRate && (this.audio.destroy(), this.audio = new $(t.audioConfig.sampleRate), this.audio.onMicData = (h) => {
|
|
1674
|
+
const v = new ArrayBuffer(1 + h.byteLength);
|
|
1675
|
+
new Uint8Array(v)[0] = 1, new Uint8Array(v, 1).set(new Uint8Array(h)), this.ws.send(v);
|
|
1676
|
+
}, this.audio.onAudioLevel = (h) => {
|
|
1677
|
+
var v;
|
|
1678
|
+
this.emit("audio:level", h), (v = this.widget) == null || v.updateAudioLevel(h);
|
|
1679
|
+
}), this.audioConfig = t.audioConfig);
|
|
1680
|
+
break;
|
|
1681
|
+
case "call:incoming": {
|
|
1682
|
+
const h = {
|
|
1683
|
+
callId: t.callId,
|
|
1684
|
+
from: t.from,
|
|
1685
|
+
notify: t.notify,
|
|
1686
|
+
isVideo: t.isVideo,
|
|
1687
|
+
isGroup: t.isGroup,
|
|
1688
|
+
state: t.state || "ringing",
|
|
1689
|
+
timestamp: t.timestamp
|
|
1690
|
+
};
|
|
1691
|
+
this.state.addCall(h), this.emit("call:incoming", h), (a = (e = this.opts).onIncomingCall) == null || a.call(e, h), (i = this.widget) == null || i.updateCalls(this.state.getAllCalls(), this.connected);
|
|
1692
|
+
break;
|
|
1693
|
+
}
|
|
1694
|
+
case "call:outgoing": {
|
|
1695
|
+
const h = {
|
|
1696
|
+
callId: t.callId,
|
|
1697
|
+
from: t.to,
|
|
1698
|
+
isVideo: t.isVideo,
|
|
1699
|
+
isGroup: !1,
|
|
1700
|
+
state: "calling",
|
|
1701
|
+
timestamp: Date.now()
|
|
1702
|
+
};
|
|
1703
|
+
this.state.addCall(h), this.emit("call:outgoing", h), (s = this.widget) == null || s.updateCalls(this.state.getAllCalls(), this.connected), this.startMicIfNeeded();
|
|
1704
|
+
break;
|
|
1705
|
+
}
|
|
1706
|
+
case "call:state": {
|
|
1707
|
+
if (!this.state.getCall(t.callId)) break;
|
|
1708
|
+
if (this.state.updateState(t.callId, t.state), this.emit("call:state", t.callId, t.state), t.state === "accepted" || t.state === "active") {
|
|
1709
|
+
this.startMicIfNeeded();
|
|
1710
|
+
const h = this.state.getCall(t.callId);
|
|
1711
|
+
h != null && h.isVideo ? ((n = this.widget) == null || n.showVideo(!0), this.startCameraIfNeeded()) : (this.video.stopCamera(), this.cameraStarted = !1, (r = this.widget) == null || r.showVideo(!1));
|
|
1712
|
+
}
|
|
1713
|
+
(o = this.widget) == null || o.updateCalls(this.state.getAllCalls(), this.connected);
|
|
1714
|
+
break;
|
|
1715
|
+
}
|
|
1716
|
+
case "call:terminated": {
|
|
1717
|
+
this.state.updateState(t.callId, "ended"), this.emit("call:terminated", t.callId, t.reason), (p = (l = this.opts).onCallTerminated) == null || p.call(l, t.callId), this.video.stopCamera(), this.video.clearCanvas(), this.cameraStarted = !1, (u = this.widget) == null || u.showVideo(!1), (b = this.widget) == null || b.resetCamera(), setTimeout(() => {
|
|
1718
|
+
var h;
|
|
1719
|
+
this.state.removeCall(t.callId), (h = this.widget) == null || h.updateCalls(this.state.getAllCalls(), this.connected), this.state.hasActiveCalls() || (this.audio.stopMic(), this.micStarted = !1);
|
|
1720
|
+
}, 3e3), (d = this.widget) == null || d.updateCalls(this.state.getAllCalls(), this.connected);
|
|
1721
|
+
break;
|
|
1722
|
+
}
|
|
1723
|
+
case "call:video-state": {
|
|
1724
|
+
this.state.updateIsVideo(t.callId, t.isVideo), this.emit("call:video-state", t.callId, t.isVideo);
|
|
1725
|
+
const h = this.state.getCall(t.callId);
|
|
1726
|
+
h && (h.state === "accepted" || h.state === "active") && (t.isVideo ? (m = this.widget) == null || m.showVideo(!0) : (this.video.stopCamera(), this.cameraStarted = !1, (f = this.widget) == null || f.showVideo(!1))), (g = this.widget) == null || g.updateCalls(this.state.getAllCalls(), this.connected);
|
|
1727
|
+
break;
|
|
1728
|
+
}
|
|
1729
|
+
case "call:claimed": {
|
|
1730
|
+
this.state.removeCall(t.callId), this.emit("call:claimed", t.callId), (x = this.widget) == null || x.updateCalls(this.state.getAllCalls(), this.connected);
|
|
1731
|
+
break;
|
|
1732
|
+
}
|
|
1733
|
+
case "call:dismissed": {
|
|
1734
|
+
this.state.removeCall(t.callId), this.emit("call:dismissed", t.callId), (w = this.widget) == null || w.updateCalls(this.state.getAllCalls(), this.connected);
|
|
1735
|
+
break;
|
|
1736
|
+
}
|
|
1737
|
+
case "contacts:list": {
|
|
1738
|
+
this.contacts = t.contacts || [], this.emit("contacts:list", this.contacts), (C = this.widget) == null || C.updateContacts(this.contacts);
|
|
1739
|
+
break;
|
|
1740
|
+
}
|
|
1741
|
+
case "profile:picture": {
|
|
1742
|
+
this.emit("profile:picture", t.phone, t.url), (y = this.widget) == null || y.updateProfilePicture(t.phone, t.url);
|
|
1743
|
+
break;
|
|
1744
|
+
}
|
|
1745
|
+
case "pong":
|
|
1746
|
+
break;
|
|
1747
|
+
case "error":
|
|
1748
|
+
t.command === "call:make" && (this.emit("call:make:error", "", t.message || "UNKNOWN_ERROR"), (k = this.widget) == null || k.showMakeCallError(t.message || "UNKNOWN_ERROR")), this.emit("error", new Error(`${t.command}: ${t.message}`));
|
|
1749
|
+
break;
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
handleBinaryMessage(t) {
|
|
1753
|
+
if (t.byteLength < 2) return;
|
|
1754
|
+
const e = new DataView(t), a = e.getUint8(0);
|
|
1755
|
+
if (a === 1 && t.byteLength >= 16) {
|
|
1756
|
+
const i = e.getUint16(1, !0), s = e.getUint16(3, !0), n = e.getUint8(5), r = e.getUint8(6), o = e.getUint8(7) !== 0, l = e.getFloat64(8, !1), p = t.slice(16), u = {
|
|
1757
|
+
width: i,
|
|
1758
|
+
height: s,
|
|
1759
|
+
format: n,
|
|
1760
|
+
orientation: r,
|
|
1761
|
+
isKeyFrame: o,
|
|
1762
|
+
timestamp: l,
|
|
1763
|
+
data: p
|
|
1764
|
+
};
|
|
1765
|
+
this.emit("video:frame", u);
|
|
1766
|
+
return;
|
|
1767
|
+
}
|
|
1768
|
+
if (a === 0 && t.byteLength % 2 === 1) {
|
|
1769
|
+
this.audio.playPcm(t.slice(1));
|
|
1770
|
+
return;
|
|
1771
|
+
}
|
|
1772
|
+
this.audio.playPcm(t);
|
|
1773
|
+
}
|
|
1774
|
+
handleConnectionChange(t) {
|
|
1775
|
+
var e, a, i;
|
|
1776
|
+
this.connected = t, t ? this.emit("connected") : this.emit("disconnected"), (a = (e = this.opts).onConnectionChange) == null || a.call(e, t), (i = this.widget) == null || i.updateCalls(this.state.getAllCalls(), t);
|
|
1777
|
+
}
|
|
1778
|
+
async startCameraIfNeeded() {
|
|
1779
|
+
if (!(this.cameraStarted || this.destroyed)) {
|
|
1780
|
+
this.cameraStarted = !0;
|
|
1781
|
+
try {
|
|
1782
|
+
const t = document.createElement("video");
|
|
1783
|
+
t.style.display = "none", document.body.appendChild(t), await this.video.startCamera(t, 320, 240, 30);
|
|
1784
|
+
} catch (t) {
|
|
1785
|
+
console.warn("[ZAPICall] Camera start failed:", t), this.cameraStarted = !1;
|
|
1786
|
+
}
|
|
1787
|
+
}
|
|
1788
|
+
}
|
|
1789
|
+
rgbaToNv12(t, e, a) {
|
|
1790
|
+
const i = e * a, s = new Uint8Array(i + (i >> 1));
|
|
1791
|
+
for (let r = 0; r < a; r++)
|
|
1792
|
+
for (let o = 0; o < e; o++) {
|
|
1793
|
+
const l = (r * e + o) * 4;
|
|
1794
|
+
s[r * e + o] = (66 * t[l] + 129 * t[l + 1] + 25 * t[l + 2] + 128 >> 8) + 16;
|
|
1795
|
+
}
|
|
1796
|
+
let n = i;
|
|
1797
|
+
for (let r = 0; r < a; r += 2)
|
|
1798
|
+
for (let o = 0; o < e; o += 2) {
|
|
1799
|
+
const l = (r * e + o) * 4;
|
|
1800
|
+
s[n++] = (-38 * t[l] - 74 * t[l + 1] + 112 * t[l + 2] + 128 >> 8) + 128, s[n++] = (112 * t[l] - 94 * t[l + 1] - 18 * t[l + 2] + 128 >> 8) + 128;
|
|
1801
|
+
}
|
|
1802
|
+
return s;
|
|
1803
|
+
}
|
|
1804
|
+
async startMicIfNeeded() {
|
|
1805
|
+
if (!(this.micStarted || this.destroyed)) {
|
|
1806
|
+
this.micStarted = !0;
|
|
1807
|
+
try {
|
|
1808
|
+
await this.audio.startMic();
|
|
1809
|
+
} catch (t) {
|
|
1810
|
+
this.emit("error", t instanceof Error ? t : new Error(String(t)));
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1813
|
+
}
|
|
1814
|
+
}
|
|
1815
|
+
const lt = { NV12: 0, I420: 1, RGB24: 2, RGBA: 3, H264: 100 }, dt = { Unknown: 0, Normal: 1, Rotate90: 2, Rotate180: 3, Rotate270: 4 };
|
|
1816
|
+
function ct(c) {
|
|
1817
|
+
return new D(c);
|
|
1818
|
+
}
|
|
1819
|
+
const ht = {
|
|
1820
|
+
init: ct,
|
|
1821
|
+
Client: D
|
|
1822
|
+
};
|
|
1823
|
+
export {
|
|
1824
|
+
lt as VideoFormat,
|
|
1825
|
+
dt as VideoOrientation,
|
|
1826
|
+
ht as ZAPICall,
|
|
1827
|
+
D as ZAPICallClient,
|
|
1828
|
+
ct as init
|
|
1829
|
+
};
|
|
1830
|
+
//# sourceMappingURL=z-api-call.mjs.map
|