@94ai/nf-softphone 3.3.17

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.
@@ -0,0 +1,566 @@
1
+ "use strict";
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ const vueDemi = require("vue-demi");
4
+ const commonUtils = require("@94ai/common-utils");
5
+ const vue2RuntimeHelpers = require("@94ai/vue2-runtime-helpers");
6
+ const __sfc_main = vueDemi.defineComponent({
7
+ name: "nf-softphone"
8
+ });
9
+ __sfc_main.props = {
10
+ scrollview: {
11
+ key: "scrollview",
12
+ required: false,
13
+ type: String,
14
+ default: void 0
15
+ },
16
+ envMap: {
17
+ key: "envMap",
18
+ required: false,
19
+ type: Object,
20
+ default: () => ({
21
+ test: "http://softphone.test.k8s.com",
22
+ dev: "http://softphone.dev.k8s.com",
23
+ sg: "https://seatsg.94ai.com",
24
+ gray: "http://softphone.gray.94ai.com",
25
+ prod: "https://seat.94ai.com"
26
+ })
27
+ },
28
+ env: {
29
+ key: "env",
30
+ required: false,
31
+ type: null,
32
+ default: "test"
33
+ },
34
+ selector: {
35
+ key: "selector",
36
+ required: false,
37
+ type: String,
38
+ default: void 0
39
+ },
40
+ el: {
41
+ key: "el",
42
+ required: false,
43
+ type: String
44
+ },
45
+ agentId: {
46
+ key: "agentId",
47
+ required: false,
48
+ type: String,
49
+ default: void 0
50
+ },
51
+ agentTag: {
52
+ key: "agentTag",
53
+ required: false,
54
+ type: String,
55
+ default: void 0
56
+ },
57
+ appKey: {
58
+ key: "appKey",
59
+ required: false,
60
+ type: String,
61
+ default: void 0
62
+ },
63
+ appSecret: {
64
+ key: "appSecret",
65
+ required: false,
66
+ type: String,
67
+ default: void 0
68
+ },
69
+ extStatus: {
70
+ key: "extStatus",
71
+ required: false,
72
+ type: String,
73
+ default: "0"
74
+ },
75
+ origin: {
76
+ key: "origin",
77
+ required: false,
78
+ type: String,
79
+ default: "nf-softphone"
80
+ },
81
+ ancestorOrigin: {
82
+ key: "ancestorOrigin",
83
+ required: false,
84
+ type: String,
85
+ default: "nf-softphone"
86
+ }
87
+ };
88
+ __sfc_main.setup = (__props, __ctx) => {
89
+ var _a;
90
+ const props = __props;
91
+ const emit = __ctx.emit;
92
+ const container = vueDemi.ref();
93
+ const iframeContainer = vueDemi.ref();
94
+ const iframe2 = vueDemi.ref();
95
+ const instance = (_a = vueDemi.getCurrentInstance()) == null ? void 0 : _a.proxy;
96
+ const getContextDomElement = (el) => {
97
+ const parent = (instance == null ? void 0 : instance.$el) || document;
98
+ return (props.selector ? parent.querySelector(props.selector) ?? document.querySelector(props.selector) ?? parent : parent).querySelector(el);
99
+ };
100
+ const handlingCommunication = (e) => {
101
+ const iframe3 = getContextDomElement(".nf-softphone-iframe");
102
+ if (iframe3) {
103
+ let data = {};
104
+ try {
105
+ data = JSON.parse(e.data);
106
+ } catch (e2) {
107
+ }
108
+ if (data.type === "softphone-expand") {
109
+ if (data.data === "expand") {
110
+ iframe3.setAttribute("style", "position: fixed;z-index:999;");
111
+ } else if (data.data === "shrink") {
112
+ iframe3.removeAttribute("style");
113
+ }
114
+ return;
115
+ }
116
+ if (data.origin === "ai-softphone") {
117
+ if (data.type === "softphone-connect") {
118
+ emit("softphone-connect", data);
119
+ } else if (data.type === "softphone-call-refresh") {
120
+ emit("softphone-call-refresh", data);
121
+ } else if (data.type === "softphone-seats-status-change") {
122
+ emit("softphone-seats-status-change", data);
123
+ } else if (data.type === "softphone-accept") {
124
+ emit("softphone-accept", data);
125
+ } else if (data.type === "softphone-ignore") {
126
+ emit("softphone-ignore", data);
127
+ } else if (data.type === "softphone-hangup") {
128
+ emit("softphone-hangup", data);
129
+ } else if (data.type === "softphone-session-state-change") {
130
+ emit("softphone-session-state-change", data);
131
+ } else if (data.type === "softphone-incoming") {
132
+ emit("softphone-incoming", data);
133
+ } else if (data.type === "softphone-send-dtmf") {
134
+ emit("softphone-send-dtmf", data);
135
+ } else if (data.type === "softphone-connect-registered") {
136
+ emit("softphone-connect-registered", data);
137
+ }
138
+ }
139
+ }
140
+ };
141
+ let timer;
142
+ const refreshStyle = async () => {
143
+ clearTimeout(timer);
144
+ timer = void 0;
145
+ const containerStyle = container.value.getAttribute("style");
146
+ const iframeContainerStyle = iframeContainer.value.getAttribute("style");
147
+ container.value.removeAttribute("style");
148
+ iframeContainer.value.removeAttribute("style");
149
+ const leftMargin = getComputedStyle(container.value).marginLeft;
150
+ const top = container.value.getBoundingClientRect().top;
151
+ if (top <= 0) {
152
+ container.value.setAttribute("style", containerStyle);
153
+ iframeContainer.value.setAttribute("style", iframeContainerStyle);
154
+ return {
155
+ top: 0,
156
+ left: 0
157
+ };
158
+ }
159
+ const left = container.value.getBoundingClientRect().left;
160
+ if (left <= 0) {
161
+ container.value.setAttribute("style", containerStyle);
162
+ iframeContainer.value.setAttribute("style", iframeContainerStyle);
163
+ return {
164
+ top: 0,
165
+ left: 0
166
+ };
167
+ }
168
+ container.value.setAttribute("style", `margin-top:${top}px;margin-left:${leftMargin};margin-bottom:${top}px;`);
169
+ iframeContainer.value.setAttribute("style", `margin-top:-${2 * top}px;margin-left:-${left}px;`);
170
+ timer = setTimeout(() => {
171
+ clearTimeout(timer);
172
+ timer = void 0;
173
+ containerScrolling.value = false;
174
+ }, 100);
175
+ return {
176
+ leftMargin,
177
+ top,
178
+ left
179
+ };
180
+ };
181
+ const containerScrolling = vueDemi.ref();
182
+ const handlingScrollTransparent = () => {
183
+ containerScrolling.value = true;
184
+ };
185
+ const handlingScroll = commonUtils.debounce(async () => {
186
+ var _a2;
187
+ const {
188
+ top,
189
+ left
190
+ } = await refreshStyle() || {};
191
+ if (top && left) {
192
+ (_a2 = iframe2.value) == null ? void 0 : _a2.contentWindow.postMessage(JSON.stringify({
193
+ type: "softphone-scroll",
194
+ origin: props.origin,
195
+ ancestorOrigin: props.ancestorOrigin,
196
+ data: {
197
+ paddingTop: top + "px"
198
+ }
199
+ }), "*");
200
+ }
201
+ }, 500, false);
202
+ vueDemi.onMounted(async () => {
203
+ var _a2, _b;
204
+ const {
205
+ top,
206
+ left
207
+ } = await refreshStyle();
208
+ const {
209
+ envMap,
210
+ env,
211
+ agentTag,
212
+ agentId,
213
+ appSecret,
214
+ extStatus,
215
+ appKey
216
+ } = props;
217
+ let url = `${(envMap == null ? void 0 : envMap[env]) ?? env}/#/?cross=1&open=1`;
218
+ url += agentTag ? `&agentTag=${agentTag}` : "";
219
+ url += agentId ? `&agentId=${agentId}` : "";
220
+ url += `&appKey=${appKey}&appSecret=${appSecret}&extStatus=${extStatus}&paddingTop=${top}px&paddingLeft=${left}px`;
221
+ iframe2.value.src = url;
222
+ window.addEventListener("message", handlingCommunication, false);
223
+ if (props.scrollview) {
224
+ (_a2 = document.querySelector(props.scrollview)) == null ? void 0 : _a2.addEventListener("scroll", handlingScroll);
225
+ (_b = document.querySelector(props.scrollview)) == null ? void 0 : _b.addEventListener("scroll", handlingScrollTransparent);
226
+ }
227
+ });
228
+ vueDemi.onUnmounted(() => {
229
+ var _a2, _b;
230
+ window.removeEventListener("message", handlingCommunication, false);
231
+ if (props.scrollview) {
232
+ (_a2 = document.querySelector(props.scrollview)) == null ? void 0 : _a2.removeEventListener("scroll", handlingScroll);
233
+ (_b = document.querySelector(props.scrollview)) == null ? void 0 : _b.removeEventListener("scroll", handlingScrollTransparent);
234
+ }
235
+ });
236
+ const postMessageCommunicate = (type, status) => {
237
+ var _a2;
238
+ (_a2 = iframe2.value) == null ? void 0 : _a2.contentWindow.postMessage(JSON.stringify({
239
+ origin: props.origin,
240
+ ancestorOrigin: props.ancestorOrigin,
241
+ type,
242
+ data: {
243
+ status,
244
+ type: "manual"
245
+ }
246
+ }), "*");
247
+ };
248
+ const connect = () => {
249
+ postMessageCommunicate("softphone-connect", true);
250
+ };
251
+ const disconnect = () => {
252
+ postMessageCommunicate("softphone-connect", false);
253
+ };
254
+ const seatsStatusChange = (status) => {
255
+ postMessageCommunicate("softphone-seats-status-change", status);
256
+ };
257
+ const accept = () => {
258
+ postMessageCommunicate("softphone-accept");
259
+ };
260
+ const ignore = () => {
261
+ postMessageCommunicate("softphone-ignore");
262
+ };
263
+ const hangup = () => {
264
+ postMessageCommunicate("softphone-hangup");
265
+ };
266
+ const sendDtmf = () => {
267
+ postMessageCommunicate("softphone-send-dtmf");
268
+ };
269
+ return Object.assign({
270
+ container,
271
+ iframeContainer,
272
+ iframe: iframe2,
273
+ containerScrolling
274
+ }, {
275
+ connect,
276
+ disconnect,
277
+ seatsStatusChange,
278
+ accept,
279
+ ignore,
280
+ hangup,
281
+ sendDtmf,
282
+ iframe: iframe2,
283
+ containerScrolling
284
+ });
285
+ };
286
+ __sfc_main.components = Object.assign({
287
+ iframe
288
+ }, __sfc_main.components);
289
+ var _sfc_render = function render() {
290
+ var _vm = this, _c = _vm._self._c;
291
+ _vm._self._setupProxy;
292
+ return _c("div", {
293
+ staticClass: "nf-softphone"
294
+ }, [_c("div", {
295
+ ref: "container",
296
+ staticClass: "nf-softphone-container",
297
+ class: {
298
+ "nf-transparent": _vm.containerScrolling === true
299
+ }
300
+ }, [_c("div", {
301
+ ref: "iframeContainer",
302
+ staticClass: "nf-softphone-iframe-container"
303
+ }, [_c("iframe", {
304
+ ref: "iframe",
305
+ staticClass: "nf-softphone-iframe",
306
+ attrs: {
307
+ "src": "",
308
+ "frameborder": "0",
309
+ "scrolling": "no",
310
+ "allow": "camera *; microphone *"
311
+ }
312
+ })])]), _c("div", {
313
+ class: {
314
+ "nf-softphone-text": true
315
+ },
316
+ style: {
317
+ "display": _vm.containerScrolling === true ? "block" : "none"
318
+ }
319
+ }, [_vm._v("正在滚动中...")])]);
320
+ };
321
+ var _sfc_staticRenderFns = [];
322
+ var __component__ = /* @__PURE__ */ vue2RuntimeHelpers.normalizeComponent(__sfc_main, _sfc_render, _sfc_staticRenderFns, false, null, null, null, null);
323
+ const NfSoftphone = __component__.exports;
324
+ class SoftphoneManager {
325
+ constructor() {
326
+ this.option = {
327
+ origin: "nf-softphone",
328
+ ancestorOrigin: "nf-softphone",
329
+ envMap: {
330
+ test: "http://softphone.test.k8s.com",
331
+ dev: "http://softphone.dev.k8s.com",
332
+ sg: "https://seatsg.94ai.com",
333
+ gray: "http://softphone.gray.94ai.com",
334
+ prod: "https://seat.94ai.com"
335
+ },
336
+ env: "test",
337
+ selector: void 0,
338
+ el: void 0,
339
+ agentId: void 0,
340
+ agentTag: void 0,
341
+ appKey: void 0,
342
+ appSecret: void 0,
343
+ extStatus: "0",
344
+ instanceMap: {},
345
+ softphoneConnectCallBack: () => {
346
+ console.log("softphone-connect");
347
+ },
348
+ softphoneCallRefreshCallBack: () => {
349
+ console.log("softphone-call-refresh");
350
+ },
351
+ softphoneSeatStatusChangeCallBack: () => {
352
+ console.log("softphone-seats-status-change");
353
+ },
354
+ softphoneAcceptCallBack: () => {
355
+ console.log("softphone-accept");
356
+ },
357
+ softphoneIgnoreCallBack: () => {
358
+ console.log("softphone-ignore");
359
+ },
360
+ softphoneHangupCallBack: () => {
361
+ console.log("softphone-hangup");
362
+ },
363
+ softphoneSessionStateChangeCallBack: () => {
364
+ console.log("softphone-session-state-change");
365
+ },
366
+ softphoneIncomingCallBack: () => {
367
+ console.log("softphone-incoming");
368
+ },
369
+ softphoneSendDtmfCallBack: () => {
370
+ console.log("softphone-send-dtmf");
371
+ },
372
+ softphoneConnectRegisteredCallBack: () => {
373
+ console.log("softphone-connect-registered");
374
+ }
375
+ };
376
+ this.loadCssCode = (code) => {
377
+ if (!document.getElementById("nf-softphone")) {
378
+ const style = document.createElement("style");
379
+ style.id = "nf-softphone";
380
+ style.type = "text/css";
381
+ style.rel = "stylesheet";
382
+ style.appendChild(document.createTextNode(code));
383
+ const head = document.getElementsByTagName("head")[0];
384
+ head.appendChild(style);
385
+ }
386
+ };
387
+ this.removeCssCode = () => {
388
+ const css = document.getElementById("nf-softphone");
389
+ if (css) {
390
+ if (css.parentNode) {
391
+ css.parentNode.removeChild(css);
392
+ }
393
+ }
394
+ };
395
+ this.getContextDomElement = (el) => {
396
+ return (this.option.selector ? document.querySelector(this.option.selector) ?? document : document).querySelector(el);
397
+ };
398
+ this.handlingCommunication = (e) => {
399
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
400
+ const iframe2 = this.getContextDomElement(".nf-softphone-iframe");
401
+ if (iframe2) {
402
+ let data = {};
403
+ try {
404
+ data = JSON.parse(e.data);
405
+ } catch (e2) {
406
+ }
407
+ if (data.type === "softphone-expand") {
408
+ if (data.data === "expand") {
409
+ iframe2.setAttribute("style", "position: fixed;z-index:999;");
410
+ } else if (data.data === "shrink") {
411
+ iframe2.removeAttribute("style");
412
+ }
413
+ return;
414
+ }
415
+ if (data.origin === "ai-softphone") {
416
+ if (data.type === "softphone-connect") {
417
+ (_b = (_a = this.option).softphoneConnectCallBack) == null ? void 0 : _b.call(_a, data);
418
+ } else if (data.type === "softphone-call-refresh") {
419
+ (_d = (_c = this.option).softphoneCallRefreshCallBack) == null ? void 0 : _d.call(_c, data);
420
+ } else if (data.type === "softphone-seats-status-change") {
421
+ (_f = (_e = this.option).softphoneSeatStatusChangeCallBack) == null ? void 0 : _f.call(_e, data);
422
+ } else if (data.type === "softphone-accept") {
423
+ (_h = (_g = this.option).softphoneAcceptCallBack) == null ? void 0 : _h.call(_g, data);
424
+ } else if (data.type === "softphone-ignore") {
425
+ (_j = (_i = this.option).softphoneIgnoreCallBack) == null ? void 0 : _j.call(_i, data);
426
+ } else if (data.type === "softphone-hangup") {
427
+ (_l = (_k = this.option).softphoneHangupCallBack) == null ? void 0 : _l.call(_k, data);
428
+ } else if (data.type === "softphone-session-state-change") {
429
+ (_n = (_m = this.option).softphoneSessionStateChangeCallBack) == null ? void 0 : _n.call(_m, data);
430
+ } else if (data.type === "softphone-incoming") {
431
+ (_p = (_o = this.option).softphoneIncomingCallBack) == null ? void 0 : _p.call(_o, data);
432
+ } else if (data.type === "softphone-send-dtmf") {
433
+ (_r = (_q = this.option).softphoneSendDtmfCallBack) == null ? void 0 : _r.call(_q, data);
434
+ } else if (data.type === "softphone-connect-registered") {
435
+ (_t = (_s = this.option).softphoneConnectRegisteredCallBack) == null ? void 0 : _t.call(_s, data);
436
+ }
437
+ }
438
+ }
439
+ };
440
+ this.handlerInteractive = () => {
441
+ window.addEventListener("message", this.handlingCommunication, false);
442
+ this.loadCssCode(`
443
+ body,html {
444
+ overflow: hidden;
445
+ }
446
+ .nf-softphone-container {
447
+ margin-left: 10px;
448
+ height: 32px;
449
+ min-width: 600px;
450
+ }
451
+ .nf-softphone-iframe-container {
452
+ height: 32px;
453
+ width: 100%;
454
+ overflow: visible;
455
+ }
456
+ .nf-softphone-iframe {
457
+ width: 100vw;
458
+ height: 100vh;
459
+ top: 0;
460
+ left: 0;
461
+ }
462
+ `);
463
+ };
464
+ this.handlerDomRemove = () => {
465
+ Object.keys(this.option.instanceMap).forEach((key) => {
466
+ const el = document.getElementById(key);
467
+ if (el && el.parentNode) {
468
+ el.parentNode.removeChild(el);
469
+ }
470
+ });
471
+ };
472
+ this.handlerDomGenerater = () => {
473
+ const container = document.createElement("div");
474
+ const iframeContainer = document.createElement("div");
475
+ const iframe2 = document.createElement("iframe");
476
+ const uuid = commonUtils.generateUUID();
477
+ this.option.instanceMap[uuid] = container;
478
+ container.setAttribute("id", uuid);
479
+ container.setAttribute("class", "nf-softphone-container");
480
+ iframeContainer.setAttribute("class", "nf-softphone-iframe-container");
481
+ iframe2.setAttribute("class", "nf-softphone-iframe");
482
+ iframe2.setAttribute("src", "");
483
+ iframe2.setAttribute("frameborder", "0");
484
+ iframe2.setAttribute("scrolling", "no");
485
+ iframe2.setAttribute("allow", "camera *; microphone *");
486
+ iframeContainer.appendChild(iframe2);
487
+ container.appendChild(iframeContainer);
488
+ const destination = this.option.el ? this.getContextDomElement(this.option.el) ?? document.body : document.body;
489
+ destination.appendChild(container);
490
+ const leftMargin = getComputedStyle(container).marginLeft;
491
+ const top = container.getBoundingClientRect().top;
492
+ const left = container.getBoundingClientRect().left;
493
+ container.setAttribute("style", `margin-top:${top}px;margin-left:${leftMargin};margin-bottom:${top}px;`);
494
+ iframeContainer.setAttribute("style", `margin-top:-${2 * top}px;margin-left:-${left}px;`);
495
+ const {
496
+ envMap,
497
+ env,
498
+ agentTag,
499
+ agentId,
500
+ appSecret,
501
+ extStatus,
502
+ appKey
503
+ } = this.option;
504
+ let url = `${(envMap == null ? void 0 : envMap[env]) ?? env}/#/?cross=1&open=1`;
505
+ url += agentTag ? `&agentTag=${agentTag}` : "";
506
+ url += agentId ? `&agentId=${agentId}` : "";
507
+ url += `&appKey=${appKey}&appSecret=${appSecret}&extStatus=${extStatus}&paddingTop=${top}px&paddingLeft=${left}px`;
508
+ iframe2.src = url;
509
+ };
510
+ this.initSoftphone = (option) => {
511
+ this.option = option ? { ...this.option, ...option } : this.option;
512
+ this.handlerInteractive();
513
+ this.handlerDomGenerater();
514
+ return this;
515
+ };
516
+ this.postMessageCommunicate = (type, status) => {
517
+ const iframe2 = this.getContextDomElement(".nf-softphone-iframe");
518
+ if (iframe2) {
519
+ iframe2.contentWindow.postMessage(JSON.stringify({
520
+ origin: this.option.origin,
521
+ ancestorOrigin: this.option.ancestorOrigin,
522
+ type,
523
+ data: {
524
+ status,
525
+ type: "manual"
526
+ }
527
+ }), "*");
528
+ }
529
+ };
530
+ this.connect = () => {
531
+ this.postMessageCommunicate("softphone-connect", true);
532
+ };
533
+ this.disconnect = () => {
534
+ this.postMessageCommunicate("softphone-connect", false);
535
+ };
536
+ this.seatsStatusChange = (status) => {
537
+ this.postMessageCommunicate("softphone-seats-status-change", status);
538
+ };
539
+ this.accept = () => {
540
+ this.postMessageCommunicate("softphone-accept");
541
+ };
542
+ this.ignore = () => {
543
+ this.postMessageCommunicate("softphone-ignore");
544
+ };
545
+ this.hangup = () => {
546
+ this.postMessageCommunicate("softphone-hangup");
547
+ };
548
+ this.sendDtmf = () => {
549
+ this.postMessageCommunicate("softphone-send-dtmf");
550
+ };
551
+ this.destroy = () => {
552
+ window.removeEventListener("message", this.handlingCommunication, false);
553
+ this.removeCssCode();
554
+ this.handlerDomRemove();
555
+ };
556
+ }
557
+ }
558
+ const softphoneManager = new SoftphoneManager();
559
+ NfSoftphone.install = (app) => {
560
+ app.prototype.$softphoneManager = softphoneManager;
561
+ NfSoftphone.$softphoneManager = softphoneManager;
562
+ app.component("nf-softphone", NfSoftphone);
563
+ };
564
+ exports.SoftphoneManager = SoftphoneManager;
565
+ exports.default = NfSoftphone;
566
+ exports.softphoneManager = softphoneManager;