@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.
Files changed (46) hide show
  1. package/lib/softphone.umd.min.js +1 -1
  2. package/package.json +1 -1
  3. package/.yarnrc.yml +0 -19
  4. package/html-softphone-demo/CryptoJS.js +0 -3
  5. package/html-softphone-demo/README.md +0 -10
  6. package/html-softphone-demo/RootCA.pem +0 -20
  7. package/html-softphone-demo/WebrtcDiver.js +0 -320
  8. package/html-softphone-demo/antique_phone.mp3 +0 -0
  9. package/html-softphone-demo/cert.pem +0 -21
  10. package/html-softphone-demo/embed-ui/index.html +0 -123
  11. package/html-softphone-demo/embed-ui/softphone.js +0 -533
  12. package/html-softphone-demo/embed-ui/util.js +0 -123
  13. package/html-softphone-demo/fp.umd.min.js +0 -9
  14. package/html-softphone-demo/gg.xccjh.top.key +0 -27
  15. package/html-softphone-demo/gg.xccjh.top.pem +0 -61
  16. package/html-softphone-demo/index-channel.html +0 -904
  17. package/html-softphone-demo/index-local.html +0 -586
  18. package/html-softphone-demo/index-open.html +0 -617
  19. package/html-softphone-demo/index-switch-pcm.html +0 -613
  20. package/html-softphone-demo/index-test.html +0 -593
  21. package/html-softphone-demo/index-voice.html +0 -720
  22. package/html-softphone-demo/index.html +0 -1090
  23. package/html-softphone-demo/localhost.crt +0 -21
  24. package/html-softphone-demo/localhost.key +0 -28
  25. package/html-softphone-demo/micro-call-ui/CryptoJS.js +0 -3
  26. package/html-softphone-demo/micro-call-ui/draggable.html +0 -168
  27. package/html-softphone-demo/micro-call-ui/draggable.js +0 -1
  28. package/html-softphone-demo/micro-call-ui/index.html +0 -153
  29. package/html-softphone-demo/micro-call-ui/microphone.js +0 -824
  30. package/html-softphone-demo/micro-call-ui/qiankun.js +0 -2
  31. package/html-softphone-demo/micro-call-ui/util.js +0 -33
  32. package/html-softphone-demo/micro-call-ui/wujie.js +0 -3
  33. package/html-softphone-demo/pcm-player.js +0 -131
  34. package/html-softphone-demo/pcm-server/16bit-44100.pcm +0 -0
  35. package/html-softphone-demo/pcm-server/index.html +0 -110
  36. package/html-softphone-demo/pcm-server/server.js +0 -54
  37. package/html-softphone-demo/private.key +0 -28
  38. package/html-softphone-demo/softphone.umd.min.js +0 -2
  39. package/html-softphone-demo/tapd_35238004_base64_1695010473_859.gif +0 -0
  40. package/html-softphone-demo/test.html +0 -190
  41. package/html-softphone-demo/vue-esm-ui/common-ui.es.browser.js +0 -56545
  42. package/html-softphone-demo/vue-esm-ui/vue-esm.html +0 -2043
  43. package/html-softphone-demo/vue-sfc-ui/CryptoJS.js +0 -3
  44. package/html-softphone-demo/vue-sfc-ui/vue-sfc.html +0 -1858
  45. package/html-softphone-demo/vue-umd-ui/common-ui.umd.browser.js +0 -338
  46. package/html-softphone-demo/vue-umd-ui/vue-umd.html +0 -1978
@@ -1,720 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8" />
5
- <meta name="viewport"
6
- content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no" />
7
- <title>softphone</title>
8
- <style>
9
- #softphone-app {
10
- padding-top: 50px;
11
- overflow: hidden;
12
- }
13
- </style>
14
- </head>
15
- <body>
16
- <div id="softphone-app">
17
- <div style="float: left;margin-left: 20px">
18
- <div style="margin-bottom: 15px">
19
- 一、当前坐席信息:
20
- </div>
21
- <pre id="info"></pre>
22
- <div>
23
- 2. 当前坐席交流传递到远端的音量大小:<span id="volumn">0.00</span>
24
- <div>- (强度比例0.00~1.00,用以实现如下音量反馈效果)</div>
25
- <img src="./tapd_35238004_base64_1695010473_859.gif" style="width: 460px" />
26
- </div>
27
- <div style="margin-bottom: 15px">
28
- 3. 当前浏览器状态(通过权限网络检测获取):
29
- </div>
30
- <pre id="browserSoftphoneEnv"></pre>
31
- </div>
32
- <div style="float: left;margin-left: 10px">
33
- <div style="margin-bottom: 15px">
34
- 二、调试步骤:
35
- </div>
36
- <div>1. 获取坐席是否在线
37
- <div>
38
- - agentStatus === 1 -> 在线
39
- </div>
40
- <div>
41
- - agentStatus === 3 -> 小休
42
- </div>
43
- <div>
44
- - tip: 能外呼的条件是:
45
- <div style="margin-left: 20px;">
46
- <div>
47
- 1. 软电话签入
48
- </div>
49
- <div>
50
- 2. 坐席在线
51
- </div>
52
- <div>
53
- 3. 同时确保坐席所在企业配置 【坐席外呼依赖】配置项 是【标识】 (默认是【登录】)
54
- </div>
55
- <div style="margin-left: 20px;">
56
- - 配置项 【登录】:只有登录了94决策系统才可外呼。
57
- </div>
58
- <div style="margin-left: 30px;">
59
- (tip: 如果不确定联系94运维在管理后台查看以及配置)
60
- </div>
61
- </div>
62
- </div>
63
-
64
- </div>
65
- <div>2. 设置坐席在线</div>
66
- <div>3. 连接外呼服务器(软电话签入)</div>
67
- <div>4. 手动呼叫或任务外呼</div>
68
- <div>- 手动呼叫,外呼服务器会先呼叫坐席,坐席接听后才会正式呼叫用户</div>
69
- <div>- 任务外呼,外呼服务器会先呼叫用户,用户接听后才会正式呼叫坐席,坐席接听前有ai和用户对话</div>
70
- <div>5. 接听 </div>
71
- <div>6. 转人工(根据任务的配置:是否是监听任务,手动外呼不是任务外呼,不用转人工) </div>
72
- <div>- tip:监听任务:接听后只可以听到ai和用户的对话,转人工后才可以和用户直接对话 </div>
73
- <div>7. 挂断</div>
74
- </div>
75
- <div style="float: left;margin-left: 20px">
76
- <div style="margin-bottom: 15px">
77
- 三、具体步骤:
78
- </div>
79
- <button id="nap">设置当前坐席进入小休状态</button>
80
- <br>
81
- <br>
82
- <button id="online">1. 设置当前坐席在线</button>
83
- <br>
84
- <br>
85
- <button id="connectToServer">2. 连接外呼服务器</button>
86
- <br>
87
- <br>
88
- <button id="disconnect" disabled>断开连接服务器</button>
89
- <br>
90
- <br>
91
- <button id="callButton">3. 手动呼叫</button>
92
- : <input id="call" />
93
- <br>
94
- <br>
95
- <button id="ignore" disabled>忽略</button>
96
- <br>
97
- <br>
98
- <button id="answer" disabled>4. 接听</button>
99
- <br>
100
- <br>
101
- <button id="hangUp" disabled>5. 挂断</button>
102
- <br>
103
- <br>
104
- <button id="sendStarDTMF" disabled>按*转人工</button>
105
- <br>
106
- <br>
107
- <button id="localVoiceAccess" disabled>本地声音接入(默认接入)</button>
108
- <br>
109
- <br>
110
- <button id="remoteSoundAccess" disabled>远程声音接入(默认接入)</button>
111
- <br>
112
- <br>
113
- <button id="localSoundDisconnection" disabled>本地声音断开</button>
114
- <br>
115
- <br>
116
- <button id="remoteSoundDisconnection" disabled>远程声音断开</button>
117
- <br>
118
- <br>
119
- <button id="check">权限网络检测</button>
120
- <br>
121
- <br>
122
- <audio
123
- id="remoteAudio"
124
- controls
125
- style="display:none"
126
- >
127
- <p>Your browser doesn't support HTML5 audio - remoteAudio</p>
128
- </audio>
129
- <audio
130
- id="localAudio"
131
- style="display:none"
132
- src="./antique_phone.mp3"
133
- controls
134
- loop
135
- >
136
- <p>Your browser doesn't support HTML5 audio - localAudio</p>
137
- </audio>
138
- </div>
139
- </div>
140
- <div>
141
- 四、当前聊天记录信息:
142
- <pre id="chatInfo">
143
- </pre>
144
- </div>
145
-
146
- <script src="./fp.umd.min.js"></script>
147
- <script src="./CryptoJS.js"></script>
148
- <script src="./softphone.umd.min.js"></script>
149
- <script src="./pcm-player.js"></script>
150
- <!--<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.3.2.js"></script>-->
151
-
152
- <script>
153
- // const buffer = new ArrayBuffer(8);
154
- // wx.miniProgram.postMessage({ data: {foo: wx.arrayBufferToBase64(arrayBuffer) } })
155
- // const pc = new RTCPeerConnection();
156
- // pc.createOffer({offerToReceiveAudio: true}).then(offer => console.log(offer.sdp, 'RTCPeerConnection supports sdp'))
157
- let audioContext;
158
- let audioContextGain;
159
- let startTime
160
- let recorder
161
- let dest
162
- let gainNode
163
- let samples = new Float32Array();
164
- let interval
165
- let numberOfChannels
166
- function flush() {
167
- // console.log(samples, 'samples')
168
- if (!samples.length) return;
169
- const bufferSource = audioContextGain.createBufferSource()
170
- const length = samples.length / numberOfChannels
171
- const audioBuffer = audioContextGain.createBuffer(numberOfChannels, length, audioContextGain.sampleRate)
172
-
173
- let audioData
174
- let channel
175
- let offset
176
- let i
177
- let decrement
178
-
179
- for (channel = 0; channel < numberOfChannels; channel++) {
180
- audioData = audioBuffer.getChannelData(channel);
181
- offset = channel;
182
- decrement = 50;
183
- for (i = 0; i < length; i++) {
184
- audioData[i] = samples[offset];
185
- /* fadein */
186
- if (i < 50) {
187
- audioData[i] = (audioData[i] * i) / 50;
188
- }
189
- /* fadeout*/
190
- if (i >= (length - 51)) {
191
- audioData[i] = (audioData[i] * decrement--) / 50;
192
- }
193
- offset += numberOfChannels;
194
- }
195
- }
196
- if (startTime < audioContextGain.currentTime) {
197
- startTime = audioContextGain.currentTime;
198
- }
199
- console.log('start vs current '+startTime+' vs '+audioContextGain.currentTime+' duration: '+audioBuffer.duration);
200
- bufferSource.buffer = audioBuffer;
201
- bufferSource.connect(gainNode);
202
- bufferSource.start(startTime);
203
- startTime += audioBuffer.duration;
204
- samples = new Float32Array();
205
- }
206
-
207
- // 创建一个AudioBuffer,并填充音频数据
208
- function bufferToWave(channelData) {
209
- const audioBuffer = audioContext.createBuffer(1, channelData.length, audioContext.sampleRate);
210
- const audioData = audioBuffer.getChannelData(0);
211
- audioData.set(channelData);
212
-
213
- // 转换为ArrayBuffer
214
- const buffer = new ArrayBuffer(audioData.length * 2);
215
- const view = new DataView(buffer);
216
- for (let i = 0; i < audioData.length; i++) {
217
- view.setInt16(i * 2, audioData[i] * 0x7FFF, true);
218
- }
219
-
220
- return buffer;
221
- }
222
-
223
- document.addEventListener('DOMContentLoaded', async (event) => {
224
- const phoneRing = './antique_phone.mp3'
225
-
226
- /**
227
- * 开启电话响铃
228
- */
229
- const phoneRings = () => {
230
- remoteAudio.src = phoneRing
231
- playMedia('localAudio')
232
- }
233
-
234
- /**
235
- * 关闭电话响铃
236
- */
237
- const stopPhoneRings = () => {
238
- remoteAudio.src = ''
239
- pauseMedia('localAudio')
240
- }
241
-
242
- /**
243
- * 获取dom
244
- */
245
- const info = document.getElementById('info')
246
- const ignore = document.getElementById('ignore')
247
- const answer = document.getElementById('answer')
248
- const hangUp = document.getElementById('hangUp')
249
- const connectToServer = document.getElementById('connectToServer')
250
- const call = document.getElementById('call')
251
- const callButton = document.getElementById('callButton')
252
- const nap = document.getElementById('nap')
253
- const chatInfo = document.getElementById('chatInfo')
254
- const online = document.getElementById('online')
255
- const disconnect = document.getElementById('disconnect')
256
- const sendStarDTMF = document.getElementById('sendStarDTMF')
257
- const localVoiceAccess = document.getElementById('localVoiceAccess')
258
- const remoteSoundAccess = document.getElementById('remoteSoundAccess')
259
- const localSoundDisconnection = document.getElementById('localSoundDisconnection')
260
- const remoteSoundDisconnection = document.getElementById('remoteSoundDisconnection')
261
- const check = document.getElementById('check')
262
- const volumn = document.getElementById('volumn')
263
- const browserSoftphoneEnv = document.getElementById('browserSoftphoneEnv')
264
- const localAudio = document.getElementById('localAudio')
265
- const remoteAudio = document.getElementById('remoteAudio')
266
-
267
- const {
268
- UserAgentFactory,
269
- UserAgent,
270
- playMedia,
271
- pauseMedia,
272
- SessionState,
273
- getMedia
274
- } = softphone // 👈 sdk
275
-
276
- /**
277
- * 获取软电话代理实例
278
- */
279
- const userAgentManager = UserAgentFactory.getUserAgentManager({
280
- agentTag: '15018707394', // 生产线 坐席维度定位
281
- appKey: '032d44009bff1752', // 生产线 企业维度定位
282
- appSecret: '4c7304c94c5e8725613516d4d6db679b', // 生产线 企业维度定位
283
- refreshSpeekVolumn(value) { // 当来电接通时,实时查看坐席说话的音量实际传送到给对方的音量大小
284
- volumn.innerText = value
285
- },
286
- refreshRequirementCheck(value) { // 权限网络检测
287
- browserSoftphoneEnv.innerText = JSON.stringify(value, null, 2)
288
- },
289
- refreshChat(info) { // 刷新会话记录
290
- chatInfo.innerText = JSON.stringify(info, null, 2)
291
- },
292
- refreshChatErrorCallback(e) {
293
- console.log(e)
294
- },
295
- enableChatInfoPush: true // 开启会话记录实时推送,开启后,当任务外呼时,可以实时获取通话记录信息,实时回调到refreshChat,中途出现任何异常会回调refreshChatErrorCallback
296
- })
297
-
298
- /**
299
- * 获取坐席当前状态信息(注意牵扯到openAPI的信息需要angentId,即方式一。如果通过方式二需要手动使用userAgentManager.requestOpenApi获取,即上述example3
300
- */
301
- const angentInfo = await userAgentManager.getAgentInfo()
302
- if (angentInfo.code === 200) { // 正确响应
303
- info.innerText = `1. ${JSON.stringify(angentInfo.data, null, 2)}`
304
- if (angentInfo.data.agentStatus === 1) { // 页面按钮的禁用状态
305
- nap.disabled = false
306
- online.disabled = true // 可切换在线
307
- } else {
308
- nap.disabled = true // 可切换小休
309
- online.disabled = false
310
- }
311
- } else {
312
- alert(angentInfo.message)
313
- throw new Error(angentInfo)
314
- }
315
-
316
-
317
- /**
318
- * 签入
319
- */
320
- const connect = async () => {
321
- try {
322
- await userAgentManager.prepareUserAgent(
323
- { // config
324
- refresh(path, value) { // 当软电话状态变化时会实时刷新这个方法
325
- console.log(path, value)
326
- },
327
- registererOptions: { // 设置会话多长时间过期,然后自动重签, 单位秒
328
- expires: 10 * 60
329
- }
330
- },
331
- { // event
332
- onInvite(invitation) { // 当有外呼过来
333
- // const info = userAgentManager.getCallNumberDetail({
334
- // id: Number(userAgentManager.businessAttribute.numberId), // 根据你需要哪通电话来,这里在来电时获取当前来电详情
335
- // taskId: userAgentManager.businessAttribute.taskId, // 如果不是任务外呼不用传
336
- // })
337
- // console.log(info, '========')
338
- setTimeout(() => {
339
- acceptInvite()
340
- }, 0)
341
- console.log(userAgentManager.businessAttribute)
342
- phoneRings() // 播放模拟来电响铃
343
- invitation.stateChange.addListener((state) => { // 一旦接听(执行accept),监听会话的生命周期
344
- switch (state) {
345
- case SessionState.Initial:
346
- break
347
- case SessionState.Establishing:
348
- break
349
- case SessionState.Established: // session建立后就可拿到webrtc的各种基础api,如userAgentManager.getPeerConnection(),如userAgentManager.getSenders()等等
350
- // const mediaElement1 = getMedia('remoteAudio')
351
- // mediaElement1.srcObject = userAgentManager.getStream() // 获取流
352
- // mediaElement1.play() // 把softphone流导入到audio接入用户语音
353
-
354
- // 创建一个录音器
355
- audioContext = new (window.AudioContext || window.webkitAudioContext)();
356
- audioContextGain = new (window.AudioContext || window.webkitAudioContext)();
357
- audioContext.resume();
358
- audioContextGain.resume();
359
- audioContext.onstatechange = () => console.log(audioContext.state);
360
- audioContextGain.onstatechange = () => console.log(audioContextGain.state);
361
- startTime = audioContextGain.currentTime
362
- recorder = audioContext.createScriptProcessor(4096, 1, 1);
363
- dest = audioContext.createMediaStreamDestination();
364
- gainNode = audioContextGain.createGain();
365
- gainNode.gain.value = 1;
366
- gainNode.connect(audioContextGain.destination)
367
- const audioSource = audioContext.createMediaStreamSource(userAgentManager.getPeerConnection().getRemoteAudioTrack()[0]);
368
- audioSource.connect(recorder);
369
- // gainNode.connect(recorder);
370
- recorder.connect(audioContext.destination);
371
-
372
- // 监听音频数据
373
- recorder.onaudioprocess = function(audioProcessingEvent) {
374
- //输入流位置
375
- const inputBuffer = audioProcessingEvent.inputBuffer;
376
- numberOfChannels = inputBuffer.numberOfChannels
377
- //输出流位置
378
- // const outputBuffer = audioProcessingEvent.outputBuffer;
379
- // //遍历通道处理数据,当前只有1个输入1个输出
380
- // for (let channel = 0; channel < outputBuffer.numberOfChannels; channel++) {
381
- // const inputData = inputBuffer.getChannelData(channel);
382
- // const outputData = outputBuffer.getChannelData(channel);
383
- // //用按钮控制是否记录流信息
384
- // for (let i = 0; i < inputData.length; i = i + 1) {
385
- // //直接将输入的数据传给输出通道
386
- // outputData[i] = inputData[i];
387
- // }
388
- // }
389
- // console.log('onaudioprocess', inputBuffer.numberOfChannels)
390
- const channelData = inputBuffer.getChannelData(0);
391
- console.log(channelData, 'channelDatachannelDatachannelDatachannelData')
392
- // // 将音频数据转换为ArrayBuffer
393
- const arrayBuffer = bufferToWave(channelData);
394
- // // 在这里使用arrayBuffer进行后续处理
395
- const uint8ArrayData = new Uint8Array(arrayBuffer)
396
- const int16Array = new Int16Array(uint8ArrayData.buffer)
397
- const float32 = new Float32Array(uint8ArrayData.length)
398
- let j
399
- for (j = 0; j < int16Array.length; j++) {
400
- float32[j] = int16Array[j] / 32768;
401
- }
402
- const tmp = new Float32Array(samples.length + float32.length);
403
- tmp.set(samples, 0);
404
- tmp.set(float32, samples.length);
405
- samples = tmp;
406
- if (!interval) {
407
- interval = setInterval(flush, 1000)
408
- }
409
- };
410
- hangUp.disabled = false
411
- break
412
- case SessionState.Terminating:
413
- case SessionState.Terminated: // 在挂断电话时候会执行
414
- interval = undefined
415
- clearInterval(interval)
416
- gainNode.disconnect()
417
- recorder.disconnect()
418
- dest.disconnect()
419
- audioContext.close()
420
- audioContextGain.close()
421
- const mediaElement2 = getMedia('remoteAudio') // 获取audio dom
422
- mediaElement2.srcObject = null
423
- mediaElement2.pause() // 释放audio
424
- stopPhoneRings()
425
-
426
- ignore.disabled = true
427
- answer.disabled = true
428
- hangUp.disabled = true
429
- localSoundDisconnection.disabled = true
430
- remoteSoundDisconnection.disabled = true
431
- localVoiceAccess.disabled = true
432
- remoteSoundAccess.disabled = true
433
- break
434
- default:
435
- throw new Error('Unknown session state.')
436
- }
437
- })
438
- ignore.disabled = false
439
- answer.disabled = false
440
- localSoundDisconnection.disabled = false
441
- remoteSoundDisconnection.disabled = false
442
- }
443
- }
444
- ) // 👈 一键签入
445
- } catch (errorInfo) { // 签入容错提示处理
446
- if (errorInfo.message.indexOf('Invalid WebSocket Server URL') > -1
447
- || errorInfo.message.indexOf('Invalid scheme in WebSocket Server URL') > -1) {
448
- alert('签入配置地址不正确,无法连通完成签入')
449
- } else if (errorInfo.message === 'sip register fail with code 503' ||
450
- (errorInfo.message.indexOf('WebSocket closed') > -1 && errorInfo.message.indexOf('code: 1006') > -1)) {
451
- alert('软电话服务器不可用,签入失败')
452
- } else {
453
- alert(errorInfo.message)
454
- }
455
- throw errorInfo
456
- }
457
- disconnect.disabled = false
458
- connectToServer.disabled = true
459
- ignore.disabled = true
460
- answer.disabled = true
461
- hangUp.disabled = true
462
- localSoundDisconnection.disabled = true
463
- remoteSoundDisconnection.disabled = true
464
- localVoiceAccess.disabled = true
465
- remoteSoundAccess.disabled = true
466
- }
467
-
468
- /**
469
- * 签出
470
- */
471
- const disConnect = async () => {
472
- await userAgentManager.dispose() // 👈 一个方法安全销毁,一键签出
473
- connectToServer.disabled = false
474
- disconnect.disabled = true
475
- ignore.disabled = true
476
- answer.disabled = true
477
- hangUp.disabled = true
478
- localSoundDisconnection.disabled = true
479
- remoteSoundDisconnection.disabled = true
480
- localVoiceAccess.disabled = true
481
- remoteSoundAccess.disabled = true
482
- }
483
-
484
- /**
485
- * 按*号转人工,返回promise,可以做loading效果做点击锁
486
- */
487
-
488
- const sendStarDtmf = async () => {
489
- // 由于 【坐席外呼类型】 没有配置要不要转人工的入口
490
- // 而:【坐席快速外呼】 不需要 转人工;【坐席ai外呼】 一定要 转人工;其他外呼类型根据userAgentManager.notNeedSendStarDtmf(true不需要,false需要,即本质是根据配置),如任务类型外呼根据任务的配置
491
- // userAgentManager.getFastOutboundCall判断是否坐席快速外呼(true是false否)
492
- // userAgentManager.getSitOutboundCall判断是否坐席ai外呼(true是false否)
493
- if ((!userAgentManager.notNeedSendStarDtmf() && !userAgentManager.getFastOutboundCall()) || userAgentManager.getSitOutboundCall()) {
494
- await new Promise((resolve, reject) => {
495
- const fn = async () => {
496
- await userAgentManager.sendStarDtmf({
497
- requestDelegate: {
498
- onAccept () { // 👈 转人工响应成功
499
- resolve(true)
500
- },
501
- async onReject (info) { //👈 转人工响应超时或失败
502
- alert('转人工响应失败:' + info.message?.statusCode + ':' + info.message?.reasonPhrase)
503
- reject(new Error(info.message.statusCode + ':' + info.message.reasonPhrase))
504
- }
505
- }
506
- }) // 👈 一键转人工,await的下行代码被执行说明成功发出转人工信令
507
- sendStarDTMF.disabled = true
508
- }
509
- fn()
510
- })
511
- }
512
- }
513
-
514
- /**
515
- * 挂断
516
- */
517
- const hangUpInvite = async () => {
518
- await new Promise((resolve, reject) => {
519
- const fn = async () => {
520
- await userAgentManager.hangUpInvite({
521
- scoutResponse: true, // 标识是手动挂断,手动挂断无需等待响应,信号成功发出立即重置会话状态。
522
- byeOptions: {
523
- requestDelegate: {
524
- onAccept (response) { // 👈 挂断响应成功
525
- resolve(response)
526
- },
527
- onReject: (response) => { // 👈 挂断响应超时或失败
528
- alert('挂断响应失败: ' + response?.message?.statusCode + ': ' + response?.message?.reasonPhrase) // 会话终止
529
- reject(new Error(response?.message?.statusCode + ': ' + response?.message?.reasonPhrase))
530
- }
531
- }
532
- },
533
- }) // 👈 一键挂断, 下行代码执行,说明挂端信令成功发出
534
- stopPhoneRings() // 暂停来电铃声,正常挂断不需要处理铃声(因为已经接听,会话已建立,才能挂断),这里做个兜底
535
- ignore.disabled = true
536
- answer.disabled = true
537
- hangUp.disabled = true
538
- localSoundDisconnection.disabled = true
539
- remoteSoundDisconnection.disabled = true
540
- localVoiceAccess.disabled = true
541
- remoteSoundAccess.disabled = true
542
- }
543
- fn()
544
- })
545
- }
546
- /**
547
- * 忽略
548
- */
549
- const ignoreInvite = async () => {
550
- stopPhoneRings() // 暂停来电铃声
551
- await userAgentManager.ignoreInvite() // 👈 一键忽略,下行代码被执行说明忽略信令成功发出
552
- ignore.disabled = true
553
- answer.disabled = true
554
- hangUp.disabled = true
555
- localSoundDisconnection.disabled = true
556
- remoteSoundDisconnection.disabled = true
557
- localVoiceAccess.disabled = true
558
- remoteSoundAccess.disabled = true
559
- }
560
- /**
561
- * 接听
562
- */
563
- const acceptInvite = async () => {
564
- stopPhoneRings() // 暂停来电铃声
565
- try {
566
- await new Promise((resolve, reject) => {
567
- const fn = async () => {
568
- await userAgentManager.acceptInvite({
569
- onAck (info) { // 👈 接听响应成功
570
- resolve(info)
571
- },
572
- onAckTimeout () { // 👈 接听响应失败
573
- reject(new Error('接听响应失败'))
574
- }
575
- }) // 👈 一键接听,下行代码被执行说明接听信令被成功发出
576
- console.log('接听信令被成功发出')
577
- }
578
- fn()
579
- })
580
- // 接听信令不能被发出,可能原因如下:
581
- } catch (error) { // 接听容错提示处理
582
- if (error.message === 'Requested device not found'
583
- || error.message === 'The object can not be found here.') { // 设备问题
584
- alert('未检测到耳麦设备,已自动断开来电')
585
- throw error
586
- } else if (error.message === 'The request is not allowed by the user agent or the platform in the current context.'
587
- || error.message === 'Media devices not available in insecure contexts.') { // 设备权限和浏览器api权限问题
588
- if (navigator.userAgent.indexOf('Firefox') > -1) {
589
- alert('软电话功能需要获取麦克风权限,如果没有麦克风权限或者http域名未配置insecure contexts都会引起连接会话立即终止,如果当前浏览器访问的地址是https协议,大部分连接会话终止的原因是没有麦克风权限')
590
- } else {
591
- alert('浏览器webrtc功能默认需要网站域名升级到https,如果当前域名为http,请配置浏览器insecure以指定域名白名单使用webrtc api,此时才可获取设备等权限以使用软电话功能')
592
- }
593
- throw error
594
- } else if (error.message === 'Permission denied') { // 麦克风权限问题
595
- alert('没有麦克风权限,请开启')
596
- throw error
597
- } else if (error.message === 'RTCPeerConnection is not defined') { // 浏览器版本问题
598
- alert('当前浏览器版本过低不支持webrtc,推荐使用新版的谷歌或360或edge浏览器')
599
- throw error
600
- }
601
- throw error
602
- }
603
- // 由于 【坐席外呼类型】 没有配置要不要转人工的入口
604
- // 而:【坐席快速外呼】 不需要 转人工;【坐席ai外呼】 一定要 转人工;其他外呼类型根据userAgentManager.notNeedSendStarDtmf(true不需要,false需要,根据配置),如任务类型外呼根据任务配置
605
- // userAgentManager.getFastOutboundCall判断是否坐席快速外呼(true是false否)
606
- // userAgentManager.getSitOutboundCall判断是否坐席ai外呼(true是false否)
607
- if ((!userAgentManager.notNeedSendStarDtmf() && !userAgentManager.getFastOutboundCall()) || userAgentManager.getSitOutboundCall()) {
608
- sendStarDTMF.disabled = false // 打开页面转人工功能
609
- }
610
- hangUp.disabled = false
611
- answer.disabled = true
612
- ignore.disabled = true
613
- }
614
-
615
- /**
616
- * 本地声音推流通道 -> 默认开
617
- * 手动打开 本地声音推流通道(打开本地声音发送)
618
- */
619
- const unMuteLocalAudio = () => {
620
- localVoiceAccess.disabled = true
621
- localSoundDisconnection.disabled = false
622
- userAgentManager.unMuteLocalAudio() // 👈 一键
623
- }
624
- /**
625
- * 本地声音推流通道 -> 默认开
626
- * 手动关闭 本地声音推流通道(关闭本地声音发送)
627
- */
628
- const muteLocalAudio = () => {
629
- remoteSoundAccess.disabled = true
630
- remoteSoundDisconnection.disabled = false
631
- userAgentManager.muteLocalAudio() // 👈 一键
632
- }
633
- /**
634
- * 远端声音拉流通道 -> 默认开
635
- * 手动打开 远端声音拉流通道(用以打开远端声音接收)
636
- */
637
- const unMuteRemoteAudio = () => {
638
- localSoundDisconnection.disabled = true
639
- localVoiceAccess.disabled = false
640
- userAgentManager.unMuteRemoteAudio() // 👈 一键
641
- }
642
- /**
643
- * 远端声音拉流通道 -> 默认开
644
- * 手动关闭 远端声音拉流通道(用以关闭远端声音接收)
645
- */
646
- const muteRemoteAudio = () => {
647
- remoteSoundDisconnection.disabled = true
648
- remoteSoundAccess.disabled = false
649
- userAgentManager.muteRemoteAudio() // 👈 一键
650
- }
651
-
652
- /**
653
- * 呼叫
654
- */
655
- const callPhone = async () => {
656
- const callInfo = await userAgentManager.callNumber(call.value) // 👈 一键
657
- if (callInfo.code === 200) { // 正确响应
658
- alert('呼叫成功')
659
- } else {
660
- alert(callInfo.message)
661
- }
662
- }
663
-
664
- /**
665
- * 切换坐席进入小休
666
- */
667
- const toggleNap = async () => {
668
- const napInfo = await userAgentManager.toggleNap(true) // 👈 一键
669
- if (napInfo.code === 200) { // 正确响应
670
- nap.disabled = true
671
- online.disabled = false
672
- alert('进入小休成功')
673
- } else {
674
- alert(napInfo.message)
675
- }
676
- }
677
-
678
- /**
679
- * 切换坐席进入在线
680
- */
681
- const toggleOnline = async () => {
682
- const napInfo = await userAgentManager.toggleNap(false) // 👈 一键
683
- if (napInfo.code === 200) { // 正确响应
684
- nap.disabled = false
685
- online.disabled = true
686
- alert('设置坐席在线成功')
687
- } else {
688
- alert(napInfo.message)
689
- }
690
- }
691
-
692
- /**
693
- * 环境检测
694
- */
695
- const envCheck = () => {
696
- userAgentManager.softphoneEnvCheck() // 👈 一键检测,检测出结果后会回调在生成软电话实例时注册的钩子 refreshRequirementCheck
697
- }
698
-
699
- /** 各种操作按钮 注册事件开始 */
700
- ignore.addEventListener('click', ignoreInvite) // 忽略
701
- answer.addEventListener('click', acceptInvite) // 接听
702
- hangUp.addEventListener('click', hangUpInvite) // 挂断
703
- connectToServer.addEventListener('click', connect) // 签入
704
- disconnect.addEventListener('click', disConnect) // 签出
705
- sendStarDTMF.addEventListener('click', sendStarDtmf) // 转人工
706
- localVoiceAccess.addEventListener('click', unMuteLocalAudio) // 打开本地声音发送
707
- remoteSoundAccess.addEventListener('click', muteLocalAudio) // 关闭本地声音发送
708
- localSoundDisconnection.addEventListener('click', unMuteRemoteAudio) // 打开远端声音接收
709
- remoteSoundDisconnection.addEventListener('click', muteRemoteAudio) // 关闭远端声音接收
710
- callButton.addEventListener('click', callPhone) // 呼叫
711
- nap.addEventListener('click', toggleNap) // 切换坐席进入小休
712
- online.addEventListener('click', toggleOnline) // 切换坐席进入在线
713
- check.addEventListener('click', envCheck) // 执行软电话必备的权限&网络环境检测
714
- /** 注册事件结束 */
715
- })
716
-
717
-
718
- </script>
719
- </body>
720
- </html>