ue-softphone-sdk 3.0.15 → 3.0.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.
- package/dist/lib/types/index.d.ts +5 -0
- package/dist/lib/ue-soft-phone.min.js +2 -2
- package/dist/types/index.d.ts +5 -0
- package/dist/ue-softphone-sdk.js +2 -2
- package/index.html/index.html +13 -3
- package/package.json +1 -1
- package/sdkdemo/img/wifi1.b7af5ed5.svg +10 -0
- package/sdkdemo/img/wifi2.1648a543.svg +4 -0
- package/sdkdemo/img/wifi3.ec030889.svg +4 -0
- package/sdkdemo/img/wifi4.101d572a.svg +4 -0
- package/sdkdemo/ue-load.min.js +60 -60
- package/sdkdemo/ue.lib.css +1 -1
- package/sdkdemo/ue.min.js +19 -5
- package/sdkdemo/webphone_ez.html +76 -0
- package/src/index.ts +171 -52
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
* @Author: Wangtao
|
|
3
|
+
* @Date: 2024-02-04 15:32:27
|
|
4
|
+
* @LastEditors: Wangtao
|
|
5
|
+
* @LastEditTime: 2024-02-05 19:32:44
|
|
6
|
+
-->
|
|
7
|
+
<!DOCTYPE html>
|
|
8
|
+
<html>
|
|
9
|
+
<script type="text/javascript"></script>
|
|
10
|
+
<!-- <script src="./ue-load.min.js"></script> -->
|
|
11
|
+
<script src="https://softphone-dev.useasy.cn/ue-load.min.js"></script>
|
|
12
|
+
<!-- <script src="https://softphone-dev.useasy.cn/ue-load.min.js"></script> -->
|
|
13
|
+
|
|
14
|
+
<body>
|
|
15
|
+
<div>
|
|
16
|
+
<div id="button">
|
|
17
|
+
<button id="SHOP_CART_ADD_SKU" onclick="callout();">外呼</button>
|
|
18
|
+
<button id="SHOP_CHECKOUT_CREATE" onclick="hangup();">挂断</button>
|
|
19
|
+
<button id="SHOP_CHECKOUT_CREATE" onclick="loadjs();">动态加js</button>
|
|
20
|
+
<button id="SHOP_CHECKOUT_CREATE" onclick="init();">初始化</button>
|
|
21
|
+
</div>
|
|
22
|
+
</div>
|
|
23
|
+
</body>
|
|
24
|
+
|
|
25
|
+
<script type="text/javascript">
|
|
26
|
+
/* 动态加载js */
|
|
27
|
+
function loadjs () {
|
|
28
|
+
const script = document.createElement('script')
|
|
29
|
+
script.type = 'text/javascript'
|
|
30
|
+
script.src = 'https://softphone.useasy.cn/ue-load.min.js'
|
|
31
|
+
document.body.appendChild(script)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
window.ueSimpleSoftphone.init({
|
|
35
|
+
accountId: 'uecs1',
|
|
36
|
+
agentNumber: '8005',
|
|
37
|
+
password: 'Aa132456@',
|
|
38
|
+
loginType: 'WEBRTC',
|
|
39
|
+
isOpenCallQueue: false,
|
|
40
|
+
isOpenNetwork: true,
|
|
41
|
+
openNlsTranslation: true,
|
|
42
|
+
server: 'https://dev1.useasy.cn/api',
|
|
43
|
+
listenCallEvent: function (event) {
|
|
44
|
+
console.log('外部事件接收:', event)
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
/* 初始化 */
|
|
48
|
+
function init () {
|
|
49
|
+
window.ueSimpleSoftphone.init({
|
|
50
|
+
accountId: 'uecs1',
|
|
51
|
+
agentNumber: '8005',
|
|
52
|
+
password: 'Aa132456@',
|
|
53
|
+
loginType: 'WEBRTC',
|
|
54
|
+
isOpenCallQueue: false,
|
|
55
|
+
isOpenNetwork: true,
|
|
56
|
+
openNlsTranslation: true,
|
|
57
|
+
server: 'https://dev1.useasy.cn/api',
|
|
58
|
+
listenCallEvent: function (event) {
|
|
59
|
+
console.log('外部事件接收:', event)
|
|
60
|
+
}
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/* function callout(){
|
|
65
|
+
ue.call.callout(Object object);
|
|
66
|
+
console.log("外呼");
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
}
|
|
70
|
+
function hangup(){
|
|
71
|
+
ue.call.hangup(Object object)
|
|
72
|
+
console.log("挂断");
|
|
73
|
+
} */
|
|
74
|
+
</script>
|
|
75
|
+
|
|
76
|
+
</html>
|
package/src/index.ts
CHANGED
|
@@ -50,6 +50,7 @@ interface InitOptions {
|
|
|
50
50
|
pushHangupStatistics?: boolean;
|
|
51
51
|
pushCallinRingStatistics?: boolean;
|
|
52
52
|
isOpenCallQueue?: boolean; //是否开启呼叫队列推送
|
|
53
|
+
openNlsTranslation?: boolean; //是否开启电话条监听实时转译
|
|
53
54
|
}
|
|
54
55
|
interface SocketMonitorOptions {
|
|
55
56
|
transport: String;
|
|
@@ -255,6 +256,7 @@ export default class ueSoftphone {
|
|
|
255
256
|
static Socketinstance: any = null;
|
|
256
257
|
static AudioTask: any = null
|
|
257
258
|
static MonitorSocketinstance: any = null;
|
|
259
|
+
static UserConfig: any = null
|
|
258
260
|
static noop(): void {}
|
|
259
261
|
static debug: (msg: any) => void;
|
|
260
262
|
static log: (msg: any) => void;
|
|
@@ -268,6 +270,8 @@ export default class ueSoftphone {
|
|
|
268
270
|
|
|
269
271
|
private attachMonitorEventCallbacks: any;
|
|
270
272
|
|
|
273
|
+
private attachNlsTranslationEventCallbacks: any;
|
|
274
|
+
|
|
271
275
|
constructor(options: InitOptions = {}) {
|
|
272
276
|
options.error = typeof options.error == "function" ? options.error : ueSoftphone.noop;
|
|
273
277
|
options.success = typeof options.success == "function" ? options.success : ueSoftphone.noop;
|
|
@@ -355,7 +359,7 @@ export default class ueSoftphone {
|
|
|
355
359
|
|
|
356
360
|
private async login(options: InitOptions) {
|
|
357
361
|
console.log(options,"options");
|
|
358
|
-
|
|
362
|
+
ueSoftphone.UserConfig = options
|
|
359
363
|
const server = options.server || ueSoftphone.callApiUrl;
|
|
360
364
|
const loginName = options.agentNumber + "@" + options.accountId;
|
|
361
365
|
const loginType = options.loginType;
|
|
@@ -364,6 +368,7 @@ export default class ueSoftphone {
|
|
|
364
368
|
|
|
365
369
|
const isOpenNetwork = options.isOpenNetwork || false; // 是否开启网络检测,若需要则会挂监控网络状态,并将值回吐给客户
|
|
366
370
|
const isOpenCallQueue = options.isOpenCallQueue || false; // 是否开启呼叫队列推送,若需要则会挂呼叫队列socket,并将事件回吐给客户
|
|
371
|
+
const openNlsTranslation = options.openNlsTranslation || false; // 是否开启电话条监听实时转译,若需要则会挂呼叫队列socket,并将事件回吐给客户
|
|
367
372
|
let actionData = {
|
|
368
373
|
loginName: loginName,
|
|
369
374
|
loginType: loginType,
|
|
@@ -433,8 +438,8 @@ export default class ueSoftphone {
|
|
|
433
438
|
this.initnNetworkMonitoring(loginInfo.data.pushServer,'')
|
|
434
439
|
}
|
|
435
440
|
|
|
436
|
-
// 是否开启呼叫队列推送
|
|
437
|
-
if(isOpenCallQueue) {
|
|
441
|
+
// 是否开启呼叫队列推送(开启呼叫队列或者开启电话条监听都会开启)
|
|
442
|
+
if(isOpenCallQueue||openNlsTranslation) {
|
|
438
443
|
// 呼叫队列推送
|
|
439
444
|
this.initAgentQueue(
|
|
440
445
|
server,
|
|
@@ -443,6 +448,8 @@ export default class ueSoftphone {
|
|
|
443
448
|
loginInfo.data.agent,
|
|
444
449
|
options.success
|
|
445
450
|
);
|
|
451
|
+
}
|
|
452
|
+
if(isOpenCallQueue){
|
|
446
453
|
// 初始化获取呼叫队列数据
|
|
447
454
|
this.initQueue(server);
|
|
448
455
|
}
|
|
@@ -493,7 +500,6 @@ export default class ueSoftphone {
|
|
|
493
500
|
}
|
|
494
501
|
});
|
|
495
502
|
}
|
|
496
|
-
|
|
497
503
|
static createEventHandle(callbacks: any = {}) {
|
|
498
504
|
callbacks.success =
|
|
499
505
|
typeof callbacks.success == "function" ? callbacks.success : ueSoftphone.noop;
|
|
@@ -565,6 +571,7 @@ export default class ueSoftphone {
|
|
|
565
571
|
if (event.subType === "KICK_OFF") {
|
|
566
572
|
if (event.data.kickoff === true) {
|
|
567
573
|
this.Socketinstance.disconnect();
|
|
574
|
+
ueSoftphone.loginToken = 'KICK_OFF'
|
|
568
575
|
try {
|
|
569
576
|
ueSoftphone.webPhone.disconnect();
|
|
570
577
|
console.log(event,"互踢")
|
|
@@ -611,16 +618,6 @@ export default class ueSoftphone {
|
|
|
611
618
|
// // ueSoftphone.initOptions.sdkMonitorType || [];
|
|
612
619
|
// this.attachMonitorEventCallbacks.SocketOptions = {
|
|
613
620
|
// query: {
|
|
614
|
-
// transport: "websocket",
|
|
615
|
-
// sessionid: userOptions._id,
|
|
616
|
-
// logintoken: userOptions.loginToken
|
|
617
|
-
// },
|
|
618
|
-
// reconnectionDelay: 3000,
|
|
619
|
-
// "force new connection": true
|
|
620
|
-
// };
|
|
621
|
-
// ueSoftphone.createQueueMonitorEventHandle(this.attachMonitorEventCallbacks);
|
|
622
|
-
// }
|
|
623
|
-
// };
|
|
624
621
|
// 电话条事件回调
|
|
625
622
|
private initAttachEvent = (
|
|
626
623
|
server: any,
|
|
@@ -745,7 +742,7 @@ export default class ueSoftphone {
|
|
|
745
742
|
userOptions: any,
|
|
746
743
|
suc: any
|
|
747
744
|
) => {
|
|
748
|
-
if (this.attachMonitorEventCallbacks) {
|
|
745
|
+
if (this.attachMonitorEventCallbacks||this.attachNlsTranslationEventCallbacks) {
|
|
749
746
|
// 每次创建链接的时候,要获取最新的ws token
|
|
750
747
|
ueSoftphone.request(server + "/platform/action/refreshWsToken", {
|
|
751
748
|
verb: "GET",
|
|
@@ -759,28 +756,54 @@ export default class ueSoftphone {
|
|
|
759
756
|
serverUrl = item.url;
|
|
760
757
|
}
|
|
761
758
|
});
|
|
762
|
-
this.attachMonitorEventCallbacks.
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
759
|
+
if(this.attachMonitorEventCallbacks&&ueSoftphone.UserConfig.isOpenCallQueue){
|
|
760
|
+
this.attachMonitorEventCallbacks.serve = serverUrl;
|
|
761
|
+
this.attachMonitorEventCallbacks.SocketOptions = {
|
|
762
|
+
query: {
|
|
763
|
+
accountId: userOptions.accountId,
|
|
764
|
+
agentNumber: userOptions.agentNumber,
|
|
765
|
+
agentId: userOptions._id,
|
|
766
|
+
token: res.data.wsToken,
|
|
767
|
+
wsExtra: JSON.stringify({
|
|
768
|
+
loginType: loginType,
|
|
769
|
+
channelType: "SDK",
|
|
770
|
+
ability: ["call"]
|
|
771
|
+
}),
|
|
772
|
+
timestamp: res.data.timestamp,
|
|
773
|
+
clientType: 3
|
|
774
|
+
},
|
|
775
|
+
reconnectionDelay: 3000,
|
|
776
|
+
"force new connection": true,
|
|
777
|
+
transports: ["websocket"],
|
|
778
|
+
timeout: 5000
|
|
779
|
+
};
|
|
780
|
+
this.attachMonitorEventCallbacks.suc = suc;
|
|
781
|
+
ueSoftphone.createQueueMonitorEventHandle(this.attachMonitorEventCallbacks);
|
|
782
|
+
}
|
|
783
|
+
if(this.attachNlsTranslationEventCallbacks&&ueSoftphone.UserConfig.openNlsTranslation){
|
|
784
|
+
this.attachNlsTranslationEventCallbacks.serve = serverUrl;
|
|
785
|
+
this.attachNlsTranslationEventCallbacks.SocketOptions = {
|
|
786
|
+
query: {
|
|
787
|
+
accountId: userOptions.accountId,
|
|
788
|
+
agentNumber: userOptions.agentNumber,
|
|
789
|
+
agentId: userOptions._id,
|
|
790
|
+
token: res.data.wsToken,
|
|
791
|
+
wsExtra: JSON.stringify({
|
|
792
|
+
loginType: loginType,
|
|
793
|
+
channelType: "SDK",
|
|
794
|
+
ability: ["call"]
|
|
795
|
+
}),
|
|
796
|
+
timestamp: res.data.timestamp,
|
|
797
|
+
clientType: 3
|
|
798
|
+
},
|
|
799
|
+
reconnectionDelay: 3000,
|
|
800
|
+
"force new connection": true,
|
|
801
|
+
transports: ["websocket"],
|
|
802
|
+
timeout: 5000
|
|
803
|
+
};
|
|
804
|
+
this.attachNlsTranslationEventCallbacks.suc = suc;
|
|
805
|
+
ueSoftphone.createopenNlsTransEventHandle(this.attachNlsTranslationEventCallbacks);
|
|
806
|
+
}
|
|
784
807
|
}
|
|
785
808
|
},
|
|
786
809
|
error: (error: any) => {
|
|
@@ -830,18 +853,18 @@ export default class ueSoftphone {
|
|
|
830
853
|
callbacks.SocketOptions = {};
|
|
831
854
|
ueSoftphone.error({ message: "login response error!" });
|
|
832
855
|
}
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
856
|
+
if(this.MonitorSocketinstance===null){
|
|
857
|
+
this.MonitorSocketinstance = ueSoftphone.newWebSocket(
|
|
858
|
+
callbacks.server,
|
|
859
|
+
callbacks.SocketOptions
|
|
860
|
+
)
|
|
861
|
+
}
|
|
838
862
|
|
|
839
863
|
this.MonitorSocketinstance.on("connect", () => {
|
|
840
864
|
callbacks.success("connect event serve success!");
|
|
841
865
|
callbacks.suc();
|
|
842
866
|
ueSoftphone.log("监控connect========");
|
|
843
867
|
});
|
|
844
|
-
|
|
845
868
|
this.MonitorSocketinstance.on("error", (error: string, fn: Function) => {
|
|
846
869
|
callbacks.error({
|
|
847
870
|
type: "socketError",
|
|
@@ -851,17 +874,33 @@ export default class ueSoftphone {
|
|
|
851
874
|
fn("error");
|
|
852
875
|
}
|
|
853
876
|
});
|
|
854
|
-
|
|
855
|
-
this.MonitorSocketinstance.on("message", (event, m) => {
|
|
856
|
-
// callbacks.message(event);
|
|
857
|
-
callbacks.message({
|
|
858
|
-
subtype: event.subType,
|
|
859
|
-
data: event.data
|
|
860
|
-
});
|
|
861
|
-
});
|
|
877
|
+
|
|
862
878
|
this.MonitorSocketinstance.on("event", (event, m) => {
|
|
879
|
+
// 互踢逻辑
|
|
880
|
+
if (event.subType === "KICK_OFF") {
|
|
881
|
+
if (event.data.kickoff === true) {
|
|
882
|
+
this.MonitorSocketinstance.disconnect();
|
|
883
|
+
try {
|
|
884
|
+
ueSoftphone.webPhone.disconnect();
|
|
885
|
+
} catch (error) {}
|
|
886
|
+
callbacks.message({
|
|
887
|
+
message: "坐席账户在其他地方登录",
|
|
888
|
+
data: event
|
|
889
|
+
});
|
|
890
|
+
}
|
|
891
|
+
}
|
|
863
892
|
callbacks.message(event);
|
|
864
893
|
});
|
|
894
|
+
|
|
895
|
+
this.MonitorSocketinstance.on("call", (event, m) => {
|
|
896
|
+
if(event.subType=='queue'&&ueSoftphone.UserConfig.isOpenCallQueue){
|
|
897
|
+
callbacks.message({
|
|
898
|
+
subtype: event.subType,
|
|
899
|
+
data: event.data
|
|
900
|
+
});
|
|
901
|
+
}
|
|
902
|
+
});
|
|
903
|
+
|
|
865
904
|
// if (callbacks.sdkMonitorType) {
|
|
866
905
|
// const sdkMonitorTypeArr = callbacks.sdkMonitorType || [];
|
|
867
906
|
// if (Array.isArray(sdkMonitorTypeArr)) {
|
|
@@ -875,12 +914,83 @@ export default class ueSoftphone {
|
|
|
875
914
|
// }
|
|
876
915
|
// }
|
|
877
916
|
}
|
|
917
|
+
// 更新转译socket消息推送
|
|
918
|
+
static createopenNlsTransEventHandle(callbacks: any = {}) {
|
|
919
|
+
callbacks.success =
|
|
920
|
+
typeof callbacks.success == "function" ? callbacks.success : ueSoftphone.noop;
|
|
921
|
+
callbacks.error = typeof callbacks.error == "function" ? callbacks.error : ueSoftphone.noop;
|
|
922
|
+
callbacks.message =
|
|
923
|
+
typeof callbacks.message == "function" ? callbacks.message : ueSoftphone.noop;
|
|
924
|
+
callbacks.server =
|
|
925
|
+
callbacks.serve === null || callbacks.serve === undefined
|
|
926
|
+
? "ue-dev1.useasy.cn"
|
|
927
|
+
: callbacks.serve;
|
|
928
|
+
|
|
929
|
+
if (callbacks.SocketOptions === null || callbacks.SocketOptions === undefined) {
|
|
930
|
+
callbacks.SocketOptions = {};
|
|
931
|
+
ueSoftphone.error({ message: "login response error!" });
|
|
932
|
+
}
|
|
933
|
+
if(this.MonitorSocketinstance===null){
|
|
934
|
+
this.MonitorSocketinstance = ueSoftphone.newWebSocket(
|
|
935
|
+
callbacks.server,
|
|
936
|
+
callbacks.SocketOptions
|
|
937
|
+
)
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
this.MonitorSocketinstance.on("connect", () => {
|
|
941
|
+
callbacks.success("转译connect event serve success!");
|
|
942
|
+
callbacks.suc();
|
|
943
|
+
ueSoftphone.log("转译监控connect========");
|
|
944
|
+
});
|
|
945
|
+
this.MonitorSocketinstance.on("error", (error: string, fn: Function) => {
|
|
946
|
+
callbacks.error({
|
|
947
|
+
type: "socketError",
|
|
948
|
+
error: error
|
|
949
|
+
});
|
|
950
|
+
if (fn && typeof fn === "function") {
|
|
951
|
+
fn("error");
|
|
952
|
+
}
|
|
953
|
+
});
|
|
954
|
+
|
|
955
|
+
this.MonitorSocketinstance.on("event", (event, m) => {
|
|
956
|
+
// 互踢逻辑
|
|
957
|
+
if (event.subType === "KICK_OFF") {
|
|
958
|
+
if (event.data.kickoff === true) {
|
|
959
|
+
this.MonitorSocketinstance.disconnect();
|
|
960
|
+
try {
|
|
961
|
+
ueSoftphone.webPhone.disconnect();
|
|
962
|
+
} catch (error) {}
|
|
963
|
+
callbacks.message({
|
|
964
|
+
message: "坐席账户在其他地方登录",
|
|
965
|
+
data: event
|
|
966
|
+
});
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
callbacks.message(event);
|
|
970
|
+
});
|
|
971
|
+
|
|
972
|
+
this.MonitorSocketinstance.on("call", (event, m) => {
|
|
973
|
+
// 转译
|
|
974
|
+
if(event.subType=='translation'&&ueSoftphone.UserConfig.openNlsTranslation){
|
|
975
|
+
callbacks.message({
|
|
976
|
+
subtype: event.subType,
|
|
977
|
+
data: event.data
|
|
978
|
+
});
|
|
979
|
+
}
|
|
980
|
+
});
|
|
981
|
+
}
|
|
878
982
|
// 对外暴露监听呼叫队列socket方法
|
|
879
983
|
public listenCallQueueEvent = (callbacks: any) => {
|
|
880
984
|
// 若客户对接的demo中无attachMonitorEventCallbacks回调,则无法接收到监控的事件回吐
|
|
881
985
|
this.attachMonitorEventCallbacks = callbacks;
|
|
882
986
|
};
|
|
883
987
|
|
|
988
|
+
// 电话条监听实时转译socket事件
|
|
989
|
+
public listenTranslationEvent = (callbacks: any) => {
|
|
990
|
+
// 若客户对接的demo中无attachNlsTranslationEventCallbacks回调,则无法接收到监控的事件回吐
|
|
991
|
+
this.attachNlsTranslationEventCallbacks = callbacks;
|
|
992
|
+
};
|
|
993
|
+
|
|
884
994
|
static useDefaultDependencies(deps: any) {
|
|
885
995
|
const f = (deps && deps.fetch) || fetch;
|
|
886
996
|
const p = (deps && deps.Promise) || Promise;
|
|
@@ -1070,6 +1180,13 @@ export default class ueSoftphone {
|
|
|
1070
1180
|
});
|
|
1071
1181
|
return;
|
|
1072
1182
|
}
|
|
1183
|
+
if (ueSoftphone.loginToken === 'KICK_OFF') {
|
|
1184
|
+
params.fail({
|
|
1185
|
+
success: false,
|
|
1186
|
+
message: "您的座席账号正在别处登录,当前页面电话条已退出。"
|
|
1187
|
+
});
|
|
1188
|
+
return;
|
|
1189
|
+
}
|
|
1073
1190
|
// if (params.encryptionAlgorithm) {
|
|
1074
1191
|
// encryptionAlgorithm = params.encryptionAlgorithm;
|
|
1075
1192
|
// }
|
|
@@ -2298,11 +2415,13 @@ class ueWebsocket {
|
|
|
2298
2415
|
if (type === "event") {
|
|
2299
2416
|
this.ws.on("event", callback);
|
|
2300
2417
|
}
|
|
2418
|
+
if (type === "call") {
|
|
2419
|
+
this.ws.on("call", callback);
|
|
2420
|
+
}
|
|
2301
2421
|
}
|
|
2302
2422
|
public emit(type: string, params: any, callback: Function) {
|
|
2303
2423
|
this.ws.emit(type, params, callback);
|
|
2304
2424
|
}
|
|
2305
|
-
|
|
2306
2425
|
public disconnect() {
|
|
2307
2426
|
this.ws.disconnect();
|
|
2308
2427
|
}
|