@94ai/softphone 6.0.5 → 6.0.6
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/lib/softphone.umd.min.js +1 -1
- package/package.json +1 -1
- package/.yarnrc.yml +0 -19
- package/html-softphone-demo/CryptoJS.js +0 -3
- package/html-softphone-demo/README.md +0 -10
- package/html-softphone-demo/RootCA.pem +0 -20
- package/html-softphone-demo/WebrtcDiver.js +0 -320
- package/html-softphone-demo/antique_phone.mp3 +0 -0
- package/html-softphone-demo/cert.pem +0 -21
- package/html-softphone-demo/embed-ui/index.html +0 -123
- package/html-softphone-demo/embed-ui/softphone.js +0 -533
- package/html-softphone-demo/embed-ui/util.js +0 -123
- package/html-softphone-demo/fp.umd.min.js +0 -9
- package/html-softphone-demo/gg.xccjh.top.key +0 -27
- package/html-softphone-demo/gg.xccjh.top.pem +0 -61
- package/html-softphone-demo/index-channel.html +0 -904
- package/html-softphone-demo/index-local.html +0 -586
- package/html-softphone-demo/index-open.html +0 -617
- package/html-softphone-demo/index-switch-pcm.html +0 -613
- package/html-softphone-demo/index-test.html +0 -593
- package/html-softphone-demo/index-voice.html +0 -720
- package/html-softphone-demo/index.html +0 -1090
- package/html-softphone-demo/localhost.crt +0 -21
- package/html-softphone-demo/localhost.key +0 -28
- package/html-softphone-demo/micro-call-ui/CryptoJS.js +0 -3
- package/html-softphone-demo/micro-call-ui/draggable.html +0 -168
- package/html-softphone-demo/micro-call-ui/draggable.js +0 -1
- package/html-softphone-demo/micro-call-ui/index.html +0 -153
- package/html-softphone-demo/micro-call-ui/microphone.js +0 -824
- package/html-softphone-demo/micro-call-ui/qiankun.js +0 -2
- package/html-softphone-demo/micro-call-ui/util.js +0 -33
- package/html-softphone-demo/micro-call-ui/wujie.js +0 -3
- package/html-softphone-demo/pcm-player.js +0 -131
- package/html-softphone-demo/pcm-server/16bit-44100.pcm +0 -0
- package/html-softphone-demo/pcm-server/index.html +0 -110
- package/html-softphone-demo/pcm-server/server.js +0 -54
- package/html-softphone-demo/private.key +0 -28
- package/html-softphone-demo/softphone.umd.min.js +0 -2
- package/html-softphone-demo/tapd_35238004_base64_1695010473_859.gif +0 -0
- package/html-softphone-demo/test.html +0 -190
- package/html-softphone-demo/vue-esm-ui/common-ui.es.browser.js +0 -56545
- package/html-softphone-demo/vue-esm-ui/vue-esm.html +0 -2043
- package/html-softphone-demo/vue-sfc-ui/CryptoJS.js +0 -3
- package/html-softphone-demo/vue-sfc-ui/vue-sfc.html +0 -1858
- package/html-softphone-demo/vue-umd-ui/common-ui.umd.browser.js +0 -338
- package/html-softphone-demo/vue-umd-ui/vue-umd.html +0 -1978
|
@@ -1,533 +0,0 @@
|
|
|
1
|
-
class SoftphoneManager {
|
|
2
|
-
|
|
3
|
-
id
|
|
4
|
-
timer
|
|
5
|
-
|
|
6
|
-
constructor() {
|
|
7
|
-
/**
|
|
8
|
-
* 隔离链接实例
|
|
9
|
-
*/
|
|
10
|
-
this.id = generateUUID()
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
option = {
|
|
14
|
-
origin: 'ai-softphone',
|
|
15
|
-
ancestorOrigin: 'nf-softphone',
|
|
16
|
-
destinationOrigin: '*',
|
|
17
|
-
|
|
18
|
-
scrollview: undefined,
|
|
19
|
-
scrollingText: '正在滚动中...',
|
|
20
|
-
|
|
21
|
-
envMap: {
|
|
22
|
-
test: 'http://softphone.test.k8s.com',
|
|
23
|
-
dev: 'http://softphone.dev.k8s.com',
|
|
24
|
-
sg: 'https://seat.teleai.com',
|
|
25
|
-
gray: 'http://softphone.gray.94ai.com',
|
|
26
|
-
prod: 'https://seat.94ai.com',
|
|
27
|
-
},
|
|
28
|
-
env: 'prod',
|
|
29
|
-
selector: undefined,
|
|
30
|
-
el: undefined,
|
|
31
|
-
|
|
32
|
-
agentId: undefined,
|
|
33
|
-
agentTag: undefined,
|
|
34
|
-
appKey: undefined,
|
|
35
|
-
appSecret: undefined,
|
|
36
|
-
|
|
37
|
-
sgGateway: undefined,
|
|
38
|
-
sgBase: undefined,
|
|
39
|
-
sgOpen: undefined,
|
|
40
|
-
sgDomain: undefined,
|
|
41
|
-
|
|
42
|
-
timestamp: undefined,
|
|
43
|
-
sign: undefined,
|
|
44
|
-
|
|
45
|
-
extStatus: '0',
|
|
46
|
-
|
|
47
|
-
callShow: '1',
|
|
48
|
-
transferToLaborShow: '1',
|
|
49
|
-
restShow: '1',
|
|
50
|
-
networkDetectShow: '1',
|
|
51
|
-
muteShow: '1',
|
|
52
|
-
logShow: '1',
|
|
53
|
-
timingShow: '1',
|
|
54
|
-
signShow: '1',
|
|
55
|
-
|
|
56
|
-
instanceMap: {},
|
|
57
|
-
|
|
58
|
-
requestOpenApiCallBackMap: {},
|
|
59
|
-
|
|
60
|
-
softphoneConnectCallBack: () => {console.log('softphone-connect')},
|
|
61
|
-
softphoneCallRefreshCallBack: () => {console.log('softphone-call-refresh')},
|
|
62
|
-
softphoneSeatStatusChangeCallBack: () => {console.log('softphone-seats-status-change')},
|
|
63
|
-
softphoneAcceptCallBack: () => {console.log('softphone-accept')},
|
|
64
|
-
softphoneIgnoreCallBack: () => {console.log('softphone-ignore')},
|
|
65
|
-
softphoneHangupCallBack: () => {console.log('softphone-hangup')},
|
|
66
|
-
softphoneAutoIgnoreCallback: () => {console.log('softphone-auto-ignore-callback')},
|
|
67
|
-
softphoneSessionStateChangeCallBack: () => {console.log('softphone-session-state-change')},
|
|
68
|
-
softphoneIncomingCallBack: () => {console.log('softphone-incoming')},
|
|
69
|
-
softphoneSendDtmfCallBack: () => {console.log('softphone-send-dtmf')},
|
|
70
|
-
softphoneConnectRegisteredCallBack: () => {console.log('softphone-connect-registered')},
|
|
71
|
-
softphoneSignOverduedCallBack: (done) => {
|
|
72
|
-
done({
|
|
73
|
-
timestamp: undefined,
|
|
74
|
-
sign: undefined
|
|
75
|
-
})
|
|
76
|
-
},
|
|
77
|
-
softphoneRequestOpenApiCallBack: async (data) => {
|
|
78
|
-
// data: {
|
|
79
|
-
// origin
|
|
80
|
-
// ancestorOrigin
|
|
81
|
-
// destinationOrigin
|
|
82
|
-
// type: 'softphone-request-open-api'
|
|
83
|
-
// uuid
|
|
84
|
-
// code
|
|
85
|
-
// message
|
|
86
|
-
// data: {
|
|
87
|
-
// type: 'manual',
|
|
88
|
-
// param,
|
|
89
|
-
// res
|
|
90
|
-
// }
|
|
91
|
-
// }
|
|
92
|
-
await this.option.requestOpenApiCallBackMap[data.uuid](data)
|
|
93
|
-
},
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
loadCssCode = (code) => {
|
|
98
|
-
const styleId = 'nf-softphone'
|
|
99
|
-
if (!document.getElementById(styleId)) {
|
|
100
|
-
const style = document.createElement('style');
|
|
101
|
-
style.id = styleId
|
|
102
|
-
style.type = 'text/css';
|
|
103
|
-
// @ts-ignore
|
|
104
|
-
style.rel = 'stylesheet';
|
|
105
|
-
//for Chrome Firefox Opera Safari
|
|
106
|
-
style.appendChild(document.createTextNode(code));
|
|
107
|
-
//for IE
|
|
108
|
-
//style.styleSheet.cssText = code;
|
|
109
|
-
const head = document.getElementsByTagName('head')[0];
|
|
110
|
-
head.appendChild(style);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
removeCssCode = () => {
|
|
115
|
-
const styleId = 'nf-softphone'
|
|
116
|
-
const css = document.getElementById(styleId)
|
|
117
|
-
if (css) {
|
|
118
|
-
if (css.parentNode) {
|
|
119
|
-
css.parentNode.removeChild(css);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* 隔离软电话容器
|
|
126
|
-
*/
|
|
127
|
-
getContextDomElement = (el) => {
|
|
128
|
-
return (this.option.selector ? (document.querySelector(this.option.selector) ?? document) : document).querySelector(el)
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* 隔离软电话容器内容
|
|
132
|
-
*/
|
|
133
|
-
getSoftphoneDomElement = (el) => {
|
|
134
|
-
return this.getContextDomElement(this.option.el).querySelector(el) || this.getContextDomElement(el) || document.querySelector(el)
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
signOverdued = (data) => {
|
|
138
|
-
const iframe = this.getSoftphoneDomElement('.nf-softphone-iframe')
|
|
139
|
-
iframe?.contentWindow?.postMessage(JSON.stringify({
|
|
140
|
-
origin: 'nf-softphone',
|
|
141
|
-
ancestorOrigin: this.option.ancestorOrigin,
|
|
142
|
-
destinationOrigin: 'ai-softphone',
|
|
143
|
-
type: 'softphone-sign-overdued',
|
|
144
|
-
data
|
|
145
|
-
}), '*')
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
handlingCommunication = (e) => {
|
|
149
|
-
const iframe = this.getSoftphoneDomElement('.nf-softphone-iframe')
|
|
150
|
-
if (iframe) {
|
|
151
|
-
let data = {}
|
|
152
|
-
try {
|
|
153
|
-
data = JSON.parse(e.data)
|
|
154
|
-
} catch (e) {}
|
|
155
|
-
if ((data.ancestorOrigin === this.option.ancestorOrigin && data.origin !== this.option.ancestorOrigin) ||
|
|
156
|
-
(data.ancestorOrigin === this.option.origin && data.origin === this.option.origin)) {
|
|
157
|
-
if (data.destinationOrigin === '*' || data.destinationOrigin === this.option.destinationOrigin) {
|
|
158
|
-
if (data.type === 'softphone-expand') {
|
|
159
|
-
if (data.data === 'expand') {
|
|
160
|
-
iframe.setAttribute('style', 'position: fixed;z-index:999;');
|
|
161
|
-
} else if (data.data === 'shrink') {
|
|
162
|
-
iframe.removeAttribute('style');
|
|
163
|
-
}
|
|
164
|
-
return
|
|
165
|
-
}
|
|
166
|
-
if (data.type === 'softphone-connect') {
|
|
167
|
-
this.option.softphoneConnectCallBack?.(data)
|
|
168
|
-
} else if (data.type === 'softphone-call-refresh') {
|
|
169
|
-
this.option.softphoneCallRefreshCallBack?.(data)
|
|
170
|
-
} else if (data.type === 'softphone-seats-status-change') {
|
|
171
|
-
this.option.softphoneSeatStatusChangeCallBack?.(data)
|
|
172
|
-
} else if (data.type === 'softphone-accept') {
|
|
173
|
-
this.option.softphoneAcceptCallBack?.(data)
|
|
174
|
-
} else if (data.type === 'softphone-ignore') {
|
|
175
|
-
this.option.softphoneIgnoreCallBack?.(data)
|
|
176
|
-
} else if (data.type === 'softphone-hangup') {
|
|
177
|
-
this.option.softphoneHangupCallBack?.(data)
|
|
178
|
-
} else if (data.type === 'softphone-auto-ignore-callback') {
|
|
179
|
-
this.option.softphoneAutoIgnoreCallback?.(data)
|
|
180
|
-
} else if (data.type === 'softphone-session-state-change') {
|
|
181
|
-
this.option.softphoneSessionStateChangeCallBack?.(data)
|
|
182
|
-
} else if (data.type === 'softphone-incoming') {
|
|
183
|
-
this.option.softphoneIncomingCallBack?.(data)
|
|
184
|
-
} else if (data.type === 'softphone-send-dtmf') {
|
|
185
|
-
this.option.softphoneSendDtmfCallBack?.(data)
|
|
186
|
-
} else if (data.type === 'softphone-connect-registered') {
|
|
187
|
-
this.option.softphoneConnectRegisteredCallBack?.(data)
|
|
188
|
-
} else if (data.type === 'softphone-request-open-api') {
|
|
189
|
-
this.option.softphoneRequestOpenApiCallBack?.(data)
|
|
190
|
-
} else if (data.type === 'softphone-sign-overdued') {
|
|
191
|
-
const done = (data) => {
|
|
192
|
-
const {
|
|
193
|
-
sign,
|
|
194
|
-
timestamp
|
|
195
|
-
} = data
|
|
196
|
-
this.signOverdued({
|
|
197
|
-
sign,
|
|
198
|
-
timestamp
|
|
199
|
-
})
|
|
200
|
-
}
|
|
201
|
-
this.option.softphoneSignOverduedCallBack?.(done)
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
handlingScroll = debounce(async () => {
|
|
209
|
-
const {
|
|
210
|
-
top,
|
|
211
|
-
left,
|
|
212
|
-
} = (await this.refreshStyle() || {})
|
|
213
|
-
if (top && left) {
|
|
214
|
-
(this.getSoftphoneDomElement('.nf-softphone-iframe')).contentWindow.postMessage(JSON.stringify({
|
|
215
|
-
type: 'softphone-scroll',
|
|
216
|
-
origin: this.option.origin,
|
|
217
|
-
ancestorOrigin: this.option.ancestorOrigin,
|
|
218
|
-
destinationOrigin: this.option.destinationOrigin,
|
|
219
|
-
data: {
|
|
220
|
-
paddingTop: top + 'px',
|
|
221
|
-
}
|
|
222
|
-
}), '*')
|
|
223
|
-
}
|
|
224
|
-
}, 500, false)
|
|
225
|
-
|
|
226
|
-
handlerInteractive = () => {
|
|
227
|
-
/**
|
|
228
|
-
* 实时处理层级
|
|
229
|
-
*/
|
|
230
|
-
window.addEventListener('message', this.handlingCommunication, false);
|
|
231
|
-
if (this.option.scrollview) {
|
|
232
|
-
document.querySelector(this.option.scrollview)?.addEventListener('scroll', this.handlingScroll)
|
|
233
|
-
document.querySelector(this.option.scrollview)?.addEventListener('scroll', this.handlingScrollTransparent)
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
this.loadCssCode(`
|
|
237
|
-
.nf-transparent {
|
|
238
|
-
visibility: hidden;
|
|
239
|
-
}
|
|
240
|
-
.nf-softphone-text {
|
|
241
|
-
text-align: center;
|
|
242
|
-
line-height: 32px;
|
|
243
|
-
margin-top: -32px;
|
|
244
|
-
}
|
|
245
|
-
.nf-softphone-container {
|
|
246
|
-
margin-left: 10px;
|
|
247
|
-
height: 32px;
|
|
248
|
-
min-width: 600px;
|
|
249
|
-
}
|
|
250
|
-
.nf-softphone-iframe-container {
|
|
251
|
-
height: 32px;
|
|
252
|
-
width: 100%;
|
|
253
|
-
overflow: visible;
|
|
254
|
-
}
|
|
255
|
-
.nf-softphone-iframe {
|
|
256
|
-
width: 100vw;
|
|
257
|
-
height: 100vh;
|
|
258
|
-
top: 0;
|
|
259
|
-
left: 0;
|
|
260
|
-
}
|
|
261
|
-
`);
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
handlerDomRemove = () => {
|
|
265
|
-
Object.keys(this.option.instanceMap).forEach(key => {
|
|
266
|
-
const el = document.getElementById(key)
|
|
267
|
-
if (el && el.parentNode) {
|
|
268
|
-
if (el instanceof HTMLIFrameElement) {
|
|
269
|
-
el.remove()
|
|
270
|
-
} else {
|
|
271
|
-
el.parentNode.removeChild(el)
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
})
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
_containerScrolling
|
|
278
|
-
|
|
279
|
-
get containerScrolling() {
|
|
280
|
-
return this._containerScrolling
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
set containerScrolling(value) {
|
|
284
|
-
if (this.containerScrolling !== value) {
|
|
285
|
-
this._containerScrolling = value
|
|
286
|
-
const nfSoftphoneContainer = this.getSoftphoneDomElement('.nf-softphone-container')
|
|
287
|
-
const nfSoftphoneText = this.getSoftphoneDomElement('.nf-softphone-text')
|
|
288
|
-
nfSoftphoneContainer?.setAttribute('class', `nf-softphone-container ${value === true ? 'nf-transparent' : ''}`)
|
|
289
|
-
nfSoftphoneText?.setAttribute('style', `display: ${value === true ? 'block' : 'none'}`)
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
handlingScrollTransparent = () => {
|
|
294
|
-
this.containerScrolling = true
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
refreshStyle = async () => {
|
|
298
|
-
clearTimeout(this.timer)
|
|
299
|
-
this.timer = undefined
|
|
300
|
-
const nfSoftphoneContainer = this.getSoftphoneDomElement('.nf-softphone-container')
|
|
301
|
-
const nfSoftphoneIframeContainer = this.getSoftphoneDomElement('.nf-softphone-iframe-container')
|
|
302
|
-
if (nfSoftphoneContainer && nfSoftphoneIframeContainer) {
|
|
303
|
-
const containerStyle = nfSoftphoneContainer.getAttribute('style')
|
|
304
|
-
const iframeContainerStyle = nfSoftphoneIframeContainer.getAttribute('style')
|
|
305
|
-
nfSoftphoneContainer.removeAttribute('style')
|
|
306
|
-
nfSoftphoneIframeContainer.removeAttribute('style')
|
|
307
|
-
const leftMargin = getComputedStyle(nfSoftphoneContainer).marginLeft
|
|
308
|
-
const top = nfSoftphoneContainer.getBoundingClientRect().top
|
|
309
|
-
if (top <= 0) {
|
|
310
|
-
nfSoftphoneContainer.setAttribute('style', containerStyle)
|
|
311
|
-
nfSoftphoneIframeContainer.setAttribute('style', iframeContainerStyle)
|
|
312
|
-
return {
|
|
313
|
-
top: 0,
|
|
314
|
-
left: 0,
|
|
315
|
-
leftMargin
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
const left = nfSoftphoneContainer.getBoundingClientRect().left
|
|
319
|
-
if (left <= 0) {
|
|
320
|
-
nfSoftphoneContainer.setAttribute('style', containerStyle)
|
|
321
|
-
nfSoftphoneIframeContainer.setAttribute('style', iframeContainerStyle)
|
|
322
|
-
return {
|
|
323
|
-
top: 0,
|
|
324
|
-
left: 0,
|
|
325
|
-
leftMargin
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
nfSoftphoneContainer.setAttribute('style', `margin-top:${top}px;margin-left:${leftMargin};margin-bottom:${top}px;`)
|
|
329
|
-
nfSoftphoneIframeContainer.setAttribute('style', `margin-top:-${2 * top}px;margin-left:-${left}px;`)
|
|
330
|
-
this.timer = setTimeout(() => {
|
|
331
|
-
clearTimeout(this.timer)
|
|
332
|
-
this.timer = undefined
|
|
333
|
-
this.containerScrolling = false
|
|
334
|
-
}, 100)
|
|
335
|
-
return {
|
|
336
|
-
leftMargin,
|
|
337
|
-
top,
|
|
338
|
-
left
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
return {
|
|
342
|
-
leftMargin: 0,
|
|
343
|
-
top: 0,
|
|
344
|
-
left: 0
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
handlerDomGenerater = async () => {
|
|
349
|
-
const nfSoftphone = document.createElement('div');
|
|
350
|
-
const nfSoftphoneText = document.createElement('div');
|
|
351
|
-
nfSoftphoneText.innerText = this.option.scrollingText || '正在滚动中...'
|
|
352
|
-
|
|
353
|
-
const nfSoftphoneContainer = document.createElement('div');
|
|
354
|
-
const iframeContainer = document.createElement('div');
|
|
355
|
-
const iframe = document.createElement('iframe');
|
|
356
|
-
|
|
357
|
-
const uuid = this.id + '-container'
|
|
358
|
-
this.option.instanceMap[uuid] = nfSoftphone
|
|
359
|
-
nfSoftphone.setAttribute('id', uuid)
|
|
360
|
-
nfSoftphone.setAttribute('class', 'nf-softphone')
|
|
361
|
-
nfSoftphoneText.setAttribute('class', 'nf-softphone-text')
|
|
362
|
-
nfSoftphoneText.setAttribute('style', "display: none;")
|
|
363
|
-
nfSoftphoneContainer.setAttribute('class', "nf-softphone-container")
|
|
364
|
-
iframeContainer.setAttribute('class', "nf-softphone-iframe-container")
|
|
365
|
-
iframe.setAttribute('class', "nf-softphone-iframe")
|
|
366
|
-
iframe.setAttribute('src', "")
|
|
367
|
-
iframe.setAttribute('frameborder', "0")
|
|
368
|
-
iframe.setAttribute('scrolling', "no")
|
|
369
|
-
iframe.setAttribute('allow', "camera *; microphone *")
|
|
370
|
-
iframeContainer.appendChild(iframe)
|
|
371
|
-
nfSoftphoneContainer.appendChild(iframeContainer)
|
|
372
|
-
nfSoftphone.appendChild(nfSoftphoneContainer)
|
|
373
|
-
nfSoftphone.appendChild(nfSoftphoneText)
|
|
374
|
-
const destination = (this.option.el ? this.getSoftphoneDomElement(this.option.el) ?? document.body : document.body)
|
|
375
|
-
destination.appendChild(nfSoftphone)
|
|
376
|
-
await nextTick()
|
|
377
|
-
const {
|
|
378
|
-
top,
|
|
379
|
-
left,
|
|
380
|
-
} = await this.refreshStyle()
|
|
381
|
-
const {
|
|
382
|
-
envMap,
|
|
383
|
-
env,
|
|
384
|
-
agentTag,
|
|
385
|
-
agentId,
|
|
386
|
-
appSecret,
|
|
387
|
-
extStatus,
|
|
388
|
-
appKey,
|
|
389
|
-
ancestorOrigin,
|
|
390
|
-
destinationOrigin,
|
|
391
|
-
callShow,
|
|
392
|
-
transferToLaborShow,
|
|
393
|
-
restShow,
|
|
394
|
-
networkDetectShow,
|
|
395
|
-
muteShow,
|
|
396
|
-
logShow,
|
|
397
|
-
timingShow,
|
|
398
|
-
signShow,
|
|
399
|
-
sign,
|
|
400
|
-
timestamp,
|
|
401
|
-
sgGateway,
|
|
402
|
-
sgBase,
|
|
403
|
-
sgOpen,
|
|
404
|
-
sgDomain,
|
|
405
|
-
} = this.option
|
|
406
|
-
let url = `${ envMap?.[env] ?? env }/#/?cross=1&open=1`
|
|
407
|
-
url += agentTag ? `&agentTag=${agentTag}` : ''
|
|
408
|
-
url += agentId ? `&agentId=${agentId}` : ''
|
|
409
|
-
url += appSecret ? `&appSecret=${appSecret}` : ''
|
|
410
|
-
url += sign ? `&sign=${sign}` : ''
|
|
411
|
-
url += timestamp ? `×tamp=${timestamp}` : ''
|
|
412
|
-
url += sgGateway ? `&sgGateway=${sgGateway}` : ''
|
|
413
|
-
url += sgBase ? `&sgBase=${sgBase}` : ''
|
|
414
|
-
url += sgOpen ? `&sgOpen=${sgOpen}` : ''
|
|
415
|
-
url += sgDomain ? `&sgDomain=${sgDomain}` : ''
|
|
416
|
-
url += `&appKey=${appKey}&extStatus=${extStatus}&paddingTop=${top}px&paddingLeft=${left}px&ancestorOrigin=${ancestorOrigin}&destinationOrigin=${destinationOrigin}`
|
|
417
|
-
url += `&callShow=${callShow}`
|
|
418
|
-
url += `&transferToLaborShow=${transferToLaborShow}`
|
|
419
|
-
url += `&restShow=${restShow}`
|
|
420
|
-
url += `&networkDetectShow=${networkDetectShow}`
|
|
421
|
-
url += `&muteShow=${muteShow}`
|
|
422
|
-
url += `&logShow=${logShow}`
|
|
423
|
-
url += `&timingShow=${timingShow}`
|
|
424
|
-
url += `&signShow=${signShow}`
|
|
425
|
-
iframe.src = url
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
initSoftphone = (option) => {
|
|
429
|
-
this.option = option ? { ...this.option, ...option } :this.option
|
|
430
|
-
this.handlerInteractive()
|
|
431
|
-
this.handlerDomGenerater()
|
|
432
|
-
return this
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
postMessageCommunicate = (type, status, param) => {
|
|
436
|
-
const iframe = this.getSoftphoneDomElement('.nf-softphone-iframe')
|
|
437
|
-
if (iframe) {
|
|
438
|
-
iframe.contentWindow.postMessage(JSON.stringify({
|
|
439
|
-
origin: 'nf-softphone',
|
|
440
|
-
ancestorOrigin: this.option.ancestorOrigin,
|
|
441
|
-
destinationOrigin: this.option.destinationOrigin,
|
|
442
|
-
type,
|
|
443
|
-
data: {
|
|
444
|
-
status,
|
|
445
|
-
type: 'manual',
|
|
446
|
-
param,
|
|
447
|
-
}
|
|
448
|
-
}), '*')
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
connect = () => {
|
|
452
|
-
this.postMessageCommunicate('softphone-connect', true)
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
disconnect = () => {
|
|
457
|
-
this.postMessageCommunicate('softphone-connect', false)
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
seatsStatusChange = (status) => {
|
|
461
|
-
this.postMessageCommunicate('softphone-seats-status-change', status)
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
accept = () => {
|
|
465
|
-
this.postMessageCommunicate('softphone-accept')
|
|
466
|
-
}
|
|
467
|
-
ignore = () => {
|
|
468
|
-
this.postMessageCommunicate('softphone-ignore')
|
|
469
|
-
}
|
|
470
|
-
hangup = () => {
|
|
471
|
-
this.postMessageCommunicate('softphone-hangup')
|
|
472
|
-
}
|
|
473
|
-
sendDtmf = () => {
|
|
474
|
-
this.postMessageCommunicate('softphone-send-dtmf')
|
|
475
|
-
}
|
|
476
|
-
requestOpenApi = async (param) => {
|
|
477
|
-
return new Promise(((resolve, reject) => {
|
|
478
|
-
const uuid = generateUUID()
|
|
479
|
-
this.option.requestOpenApiCallBackMap[uuid] = async (result) => {
|
|
480
|
-
// result: {
|
|
481
|
-
// origin
|
|
482
|
-
// ancestorOrigin
|
|
483
|
-
// destinationOrigin
|
|
484
|
-
// type: 'softphone-request-open-api'
|
|
485
|
-
// uuid
|
|
486
|
-
// code: 200,
|
|
487
|
-
// message: '成功',
|
|
488
|
-
// data: {
|
|
489
|
-
// type: 'manual',
|
|
490
|
-
// param: {}, // 请求参数
|
|
491
|
-
// res // 响应结果
|
|
492
|
-
// }
|
|
493
|
-
// }
|
|
494
|
-
if (result.code === 200) {
|
|
495
|
-
resolve(result.data.res)
|
|
496
|
-
} else {
|
|
497
|
-
reject(result)
|
|
498
|
-
}
|
|
499
|
-
delete this.option.requestOpenApiCallBackMap[uuid]
|
|
500
|
-
}
|
|
501
|
-
this.postMessageCommunicate('softphone-request-open-api', undefined, {
|
|
502
|
-
uuid,
|
|
503
|
-
param
|
|
504
|
-
})
|
|
505
|
-
}))
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
removeTimer = () => {
|
|
509
|
-
clearTimeout(this.timer)
|
|
510
|
-
this.timer = undefined
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
destroy = async () => {
|
|
514
|
-
return new Promise((resolve) => {
|
|
515
|
-
this.disconnect()
|
|
516
|
-
let timer = setTimeout(() => {
|
|
517
|
-
clearTimeout(timer)
|
|
518
|
-
timer = undefined
|
|
519
|
-
window.removeEventListener('message', this.handlingCommunication, false);
|
|
520
|
-
if (this.option.scrollview) {
|
|
521
|
-
document.querySelector(this.option.scrollview)?.removeEventListener('scroll', this.handlingScroll)
|
|
522
|
-
document.querySelector(this.option.scrollview)?.removeEventListener('scroll', this.handlingScrollTransparent)
|
|
523
|
-
}
|
|
524
|
-
this.removeCssCode()
|
|
525
|
-
this.handlerDomRemove()
|
|
526
|
-
this.removeTimer()
|
|
527
|
-
resolve()
|
|
528
|
-
})
|
|
529
|
-
})
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
const softphoneManager = new SoftphoneManager()
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
function generateUUID() { // Public Domain/MIT
|
|
2
|
-
let d = Date.now();
|
|
3
|
-
if (typeof performance !== 'undefined' && typeof performance.now === 'function'){
|
|
4
|
-
d += performance.now(); //use high-precision timer if available
|
|
5
|
-
}
|
|
6
|
-
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
7
|
-
const r = (d + Math.random() * 16) % 16 | 0;
|
|
8
|
-
d = Math.floor(d / 16);
|
|
9
|
-
return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function debounce(func, wait, immediate) {
|
|
14
|
-
let timeout, args, context, timestamp, result
|
|
15
|
-
|
|
16
|
-
const later = function() {
|
|
17
|
-
// 据上一次触发时间间隔
|
|
18
|
-
const last = +new Date() - timestamp
|
|
19
|
-
|
|
20
|
-
// 上次被包装函数被调用时间间隔last小于设定时间间隔wait
|
|
21
|
-
if (last < wait && last > 0) {
|
|
22
|
-
timeout = setTimeout(later, wait - last)
|
|
23
|
-
} else {
|
|
24
|
-
timeout = null
|
|
25
|
-
// 如果设定为immediate===true,因为开始边界已经调用过了此处无需调用
|
|
26
|
-
if (!immediate) {
|
|
27
|
-
result = func.apply(context, args)
|
|
28
|
-
if (!timeout) context = args = null
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return function(...args) {
|
|
34
|
-
// @ts-ignore
|
|
35
|
-
context = this
|
|
36
|
-
timestamp = +new Date()
|
|
37
|
-
const callNow = immediate && !timeout
|
|
38
|
-
// 如果延时不存在,重新设定延时
|
|
39
|
-
if (!timeout) timeout = setTimeout(later, wait)
|
|
40
|
-
if (callNow) {
|
|
41
|
-
result = func.apply(context, args)
|
|
42
|
-
// @ts-ignore
|
|
43
|
-
context = args = null
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return result
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// 用于存储传入 nextTick 的回调函数
|
|
51
|
-
const callbacks = [];
|
|
52
|
-
// 标记是否已经安排了回调函数的执行
|
|
53
|
-
let pending = false;
|
|
54
|
-
|
|
55
|
-
// 执行队列中的所有回调函数
|
|
56
|
-
function flushCallbacks() {
|
|
57
|
-
pending = false;
|
|
58
|
-
// 复制一份当前的回调队列,避免在执行过程中添加新的回调影响循环
|
|
59
|
-
const copies = callbacks.slice(0);
|
|
60
|
-
callbacks.length = 0;
|
|
61
|
-
// 依次执行每个回调函数,并处理可能出现的异常
|
|
62
|
-
for (let i = 0; i < copies.length; i++) {
|
|
63
|
-
try {
|
|
64
|
-
copies[i]();
|
|
65
|
-
} catch (e) {
|
|
66
|
-
console.error('Error in nextTick callback:', e);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// 根据浏览器支持情况选择合适的异步执行方式
|
|
72
|
-
let timerFunc;
|
|
73
|
-
if (typeof Promise !== 'undefined') {
|
|
74
|
-
// 如果支持 Promise,使用 Promise 的 then 方法创建微任务
|
|
75
|
-
const p = Promise.resolve();
|
|
76
|
-
timerFunc = () => {
|
|
77
|
-
p.then(flushCallbacks);
|
|
78
|
-
};
|
|
79
|
-
} else if (typeof MutationObserver !== 'undefined') {
|
|
80
|
-
// 如果支持 MutationObserver,使用它创建微任务
|
|
81
|
-
let counter = 1;
|
|
82
|
-
const observer = new MutationObserver(flushCallbacks);
|
|
83
|
-
const textNode = document.createTextNode(String(counter));
|
|
84
|
-
observer.observe(textNode, {
|
|
85
|
-
characterData: true
|
|
86
|
-
});
|
|
87
|
-
timerFunc = () => {
|
|
88
|
-
counter = (counter + 1) % 2;
|
|
89
|
-
textNode.data = String(counter);
|
|
90
|
-
};
|
|
91
|
-
} else if (typeof setImmediate !== 'undefined') {
|
|
92
|
-
// 如果支持 setImmediate,使用它创建宏任务
|
|
93
|
-
timerFunc = () => {
|
|
94
|
-
setImmediate(flushCallbacks);
|
|
95
|
-
};
|
|
96
|
-
} else {
|
|
97
|
-
// 最后使用 setTimeout 作为兜底方案创建宏任务
|
|
98
|
-
timerFunc = () => {
|
|
99
|
-
setTimeout(flushCallbacks, 0);
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
// 实现 nextTick 函数,支持传入回调函数或返回 Promise
|
|
103
|
-
async function nextTick(cb) {
|
|
104
|
-
return new Promise((resolve) => {
|
|
105
|
-
// 将回调函数和 resolve 函数封装成一个新的回调
|
|
106
|
-
callbacks.push(() => {
|
|
107
|
-
if (cb) {
|
|
108
|
-
try {
|
|
109
|
-
cb();
|
|
110
|
-
} catch (e) {
|
|
111
|
-
console.error('Error in nextTick callback:', e);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
// 当回调执行完毕后,resolve Promise
|
|
115
|
-
resolve(true);
|
|
116
|
-
});
|
|
117
|
-
// 如果当前没有正在执行的回调安排,安排一次新的执行
|
|
118
|
-
if (!pending) {
|
|
119
|
-
pending = true;
|
|
120
|
-
timerFunc();
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
}
|