@94ai/softphone 5.0.15 → 5.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.
@@ -0,0 +1 @@
1
+ !function(t,e){"object"==typeof exports?module.exports=e():"function"==typeof define&&define.amd?define([],e):t.Draggable=e()}(this,function(){"use strict";var t={grid:0,filterTarget:null,limit:{x:null,y:null},threshold:0,setCursor:!1,setPosition:!0,smoothDrag:!0,useGPU:!0,onDrag:u,onDragStart:u,onDragEnd:u},e={transform:function(){for(var t=" -o- -ms- -moz- -webkit-".split(" "),e=document.body.style,n=t.length;n--;){var o=t[n]+"transform";if(o in e)return o}}()},n={assign:function(){for(var t=arguments[0],e=arguments.length,n=1;n<e;n++){var o=arguments[n];for(var i in o)t[i]=o[i]}return t},bind:function(t,e){return function(){t.apply(e,arguments)}},on:function(t,e,o){if(e&&o)n.addEvent(t,e,o);else if(e)for(var i in e)n.addEvent(t,i,e[i])},off:function(t,e,o){if(e&&o)n.removeEvent(t,e,o);else if(e)for(var i in e)n.removeEvent(t,i,e[i])},limit:function(t,e){return e instanceof Array?t<(e=[+e[0],+e[1]])[0]?t=e[0]:t>e[1]&&(t=e[1]):t=+e,t},addEvent:"attachEvent"in Element.prototype?function(t,e,n){t.attachEvent("on"+e,n)}:function(t,e,n){t.addEventListener(e,n,!1)},removeEvent:"attachEvent"in Element.prototype?function(t,e,n){t.detachEvent("on"+e,n)}:function(t,e,n){t.removeEventListener(e,n)}};function o(e,o){var i=this,r=n.bind(i.start,i),s=n.bind(i.drag,i),u=n.bind(i.stop,i);if(!a(e))throw new TypeError("Draggable expects argument 0 to be an Element");o=n.assign({},t,o),n.assign(i,{element:e,handle:o.handle&&a(o.handle)?o.handle:e,handlers:{start:{mousedown:r,touchstart:r},move:{mousemove:s,mouseup:u,touchmove:s,touchend:u}},options:o}),i.initialize()}function i(t){return parseInt(t,10)}function r(t){return"currentStyle"in t?t.currentStyle:getComputedStyle(t)}function s(t){return null!=t}function a(t){return t instanceof Element||"undefined"!=typeof HTMLDocument&&t instanceof HTMLDocument}function u(){}return n.assign(o.prototype,{setOption:function(t,e){var n=this;return n.options[t]=e,n.initialize(),n},get:function(){var t=this.dragEvent;return{x:t.x,y:t.y}},set:function(t,e){var n=this.dragEvent;return n.original={x:n.x,y:n.y},this.move(t,e),this},dragEvent:{started:!1,x:0,y:0},initialize:function(){var t,o=this,i=o.element,s=(o.handle,i.style),a=r(i),u=o.options,f=e.transform,l=o._dimensions={height:i.offsetHeight,left:i.offsetLeft,top:i.offsetTop,width:i.offsetWidth};u.useGPU&&f&&("none"===(t=a[f])&&(t=""),s[f]=t+" translate3d(0,0,0)"),u.setPosition&&(s.display="block",s.left=l.left+"px",s.top=l.top+"px",s.width=l.width+"px",s.height=l.height+"px",s.bottom=s.right="auto",s.margin=0,s.position="absolute"),u.setCursor&&(s.cursor="move"),o.setLimit(u.limit),n.assign(o.dragEvent,{x:l.left,y:l.top}),n.on(o.handle,o.handlers.start)},start:function(t){var e=this,o=e.getCursor(t),i=e.element;e.useTarget(t.target||t.srcElement)&&(t.preventDefault&&!t.target.getAttribute("contenteditable")?t.preventDefault():t.target.getAttribute("contenteditable")||(t.returnValue=!1),e.dragEvent.oldZindex=i.style.zIndex,i.style.zIndex=1e4,e.setCursor(o),e.setPosition(),e.setZoom(),n.on(document,e.handlers.move))},drag:function(t){var e=this,n=e.dragEvent,o=e.element,i=e._cursor,r=e._dimensions,s=e.options,a=r.zoom,u=e.getCursor(t),f=s.threshold,l=(u.x-i.x)/a+r.left,d=(u.y-i.y)/a+r.top;!n.started&&f&&Math.abs(i.x-u.x)<f&&Math.abs(i.y-u.y)<f||(n.original||(n.original={x:l,y:d}),n.started||(s.onDragStart(o,l,d,t),n.started=!0),e.move(l,d)&&s.onDrag(o,n.x,n.y,t))},move:function(t,e){var n=this,o=n.dragEvent,i=n.options,r=i.grid,s=n.element.style,a=n.limit(t,e,o.original.x,o.original.y);return!i.smoothDrag&&r&&(a=n.round(a,r)),(a.x!==o.x||a.y!==o.y)&&(o.x=a.x,o.y=a.y,s.left=a.x+"px",s.top=a.y+"px",!0)},stop:function(t){var e,o=this,i=o.dragEvent,r=o.element,s=o.options,a=s.grid;n.off(document,o.handlers.move),r.style.zIndex=i.oldZindex,s.smoothDrag&&a&&(e=o.round({x:i.x,y:i.y},a),o.move(e.x,e.y),n.assign(o.dragEvent,e)),o.dragEvent.started&&s.onDragEnd(r,i.x,i.y,t),o.reset()},reset:function(){this.dragEvent.started=!1},round:function(t){var e=this.options.grid;return{x:e*Math.round(t.x/e),y:e*Math.round(t.y/e)}},getCursor:function(t){return{x:(t.targetTouches?t.targetTouches[0]:t).clientX,y:(t.targetTouches?t.targetTouches[0]:t).clientY}},setCursor:function(t){this._cursor=t},setLimit:function(t){var e=this,o=function(t,e){return{x:t,y:e}};if(t instanceof Function)e.limit=t;else if(a(t)){var i=e._dimensions,r=t.scrollHeight-i.height,u=t.scrollWidth-i.width;e.limit=function(t,e){return{x:n.limit(t,[0,u]),y:n.limit(e,[0,r])}}}else if(t){var f=s(t.x),l=s(t.y);e.limit=f||l?function(e,o){return{x:f?n.limit(e,t.x):e,y:l?n.limit(o,t.y):o}}:o}else e.limit=o},setPosition:function(){var t=this.element,e=t.style;n.assign(this._dimensions,{left:i(e.left)||t.offsetLeft,top:i(e.top)||t.offsetTop})},setZoom:function(){for(var t=this.element,e=1;t=t.offsetParent;){var n=r(t).zoom;if(n&&"normal"!==n){e=n;break}}this._dimensions.zoom=e},useTarget:function(t){var e=this.options.filterTarget;return!(e instanceof Function)||e(t)},destroy:function(){n.off(this.handle,this.handlers.start),n.off(document,this.handlers.move)}}),o});
@@ -8,7 +8,12 @@
8
8
  <title>microphone</title>
9
9
  </head>
10
10
  <body>
11
+ <br/>
11
12
  <div style="min-width: 700px;" id="softphone-container"></div> <!-- 👈 软电话容器 -->
13
+ <br/>
14
+ <button id="taskButton" style="margin-left: 20px">任务呼叫</button>
15
+ : <input id="taskCall" placeholder="请输入任务id, 空值用测试任务" style="width: 180px"/> <input id="taskPhoneCall" placeholder="请输入手机号, 空值用测试手机号" style="width: 180px"/>
16
+
12
17
  </body>
13
18
  <script src="./util.js"></script>
14
19
  <script src="./qiankun.js"></script>
@@ -33,6 +38,8 @@ document.addEventListener('DOMContentLoaded', async (event) => {
33
38
  const sha1 = CryptoJS.HmacSHA1(str, appSecret)
34
39
  sign = CryptoJS.enc.Base64.stringify(sha1)
35
40
 
41
+ let commonSoftphone // 软电话sdk实例
42
+
36
43
  /**
37
44
  👈 拿到实例后可以手动触发软电话实例的各种动作,如签入,签出,接听,忽略,挂断等等,注意这个实例不是软电话实例,是链接软电话通讯的实例
38
45
  */
@@ -53,11 +60,12 @@ document.addEventListener('DOMContentLoaded', async (event) => {
53
60
  /**
54
61
  * start - 海外特有参数
55
62
  */
56
- sgGateway: '1',
57
- sgBase: '1',
58
- sgOpen: '1',
59
- sgDomain: '1',
60
- env: 'sg',
63
+ sgGateway: '1', // 设置gatewayApi前缀调用地址, 默认undefined, 可选:'0'|'1'|string。示例: 'https://gateway.xxx.com'。 传'1'使用默认海外地址;传'0'或不传使用国内默认地址
64
+ sgBase: '1', // 设置baseApi前缀调用地址, 默认undefined, 可选:'0'|'1'|string。 示例: 'https://www.xxx.com/api'。 传'1'使用默认海外地址;传'0'或不传使用国内默认地址
65
+ sgOpen: '1', // 设置openApi前缀调用地址, 默认undefined, 可选:'0'|'1'|string。示例: 'https://www.xxx.com/openapi'。 传'1'使用默认海外地址;传'0'或不传使用国内默认地址
66
+
67
+ sgDomain: '1', // 切换海外环境代理, 默认undefined 可选:'0'|'1'。 传'1'切换海外;传'0'或不传使用国内
68
+ env: 'sg', // 切换海外环境微前端调用, 可选: 'dev' | 'test' | 'sg' | 'gray' | 'prod'
61
69
  /**
62
70
  * end - 海外特有参数
63
71
  */
@@ -65,15 +73,14 @@ document.addEventListener('DOMContentLoaded', async (event) => {
65
73
  extStatus: '1', // 👈 初始化是否处于小休状态, 非1 小休 1 在线
66
74
 
67
75
  softphoneConnectCallBack: async (data) => {
68
- console.log(await (await data.commonSoftphone.getUserAgentManager()).getAgentInfo())
69
- // const userAgent = await data.commonSoftphone.getUserAgentManager()
70
- // console.log(await userAgent.getAgentInfo())
71
- // console.log(await userAgent.requestOpenApi({
72
- // url: '/v1/agent/getAgent',
73
- // data: {
74
- // agentTag,
76
+ // if (data.status) {
77
+ // commonSoftphone = data.commonSoftphone
78
+ // const userAgentManager = await commonSoftphone.getUserAgentManager()
79
+ // const agentInfo = await userAgentManager.getAgentInfo()
80
+ // if (agentInfo.agentStatus != 1) {
81
+ // nfSoftPhoneInstance.seatsStatusChange(false)
75
82
  // }
76
- // }))
83
+ // }
77
84
  }, // 👈 签入签出回调
78
85
  softphoneAutoIgnoreCallback: (data) => {console.log('softphone-auto-ignore-callback', data)}, // 👈 自动忽略回调
79
86
  softphoneCallRefreshCallBack: (data) => {console.log('softphone-call-refresh', data)}, // 👈 来电刷新来电记录列表回调
@@ -84,7 +91,15 @@ document.addEventListener('DOMContentLoaded', async (event) => {
84
91
  softphoneSessionStateChangeCallBack: (data) => {console.log('softphone-session-state-change', data)},// 👈 会话状态改变回调
85
92
  softphoneIncomingCallBack: (data) => {console.log('softphone-incoming', data)},// 👈 来电回调
86
93
  softphoneSendDtmfCallBack: (data) => {console.log('softphone-send-dtmf', data)},// 👈 转人工回调
87
- softphoneConnectRegisteredCallBack: (data) => {console.log('softphone-connect-registered', data)},// 👈 动态绑定动作完成回调(在这之后才能执行动作类总线通讯)
94
+ softphoneConnectRegisteredCallBack: async (data) => {
95
+ // console.log('softphone-connect-registered', data)
96
+ // commonSoftphone = data.commonSoftphone
97
+ // const userAgentManager = await commonSoftphone.getUserAgentManager()
98
+ // const agentInfo = await userAgentManager.getAgentInfo()
99
+ // if (agentInfo.agentStatus != 1) {
100
+ // nfSoftPhoneInstance.seatsStatusChange(false)
101
+ // }
102
+ },// 👈 动态绑定动作完成回调(在这之后才能执行动作类总线通讯)
88
103
  softphoneSignOverduedCallBack: (done) => { // 👈 注册sign过期后重新刷新sign逻辑
89
104
  const timestamp = Date.now()
90
105
  done({
@@ -93,6 +108,41 @@ document.addEventListener('DOMContentLoaded', async (event) => {
93
108
  })
94
109
  },
95
110
  });
111
+
112
+ const taskButton = document.getElementById('taskButton')
113
+ const taskCall = document.getElementById('taskCall')
114
+ const taskPhoneCall = document.getElementById('taskPhoneCall')
115
+
116
+ // 任务外呼: 先桥接手机侧,手机侧接通后,再桥接坐席
117
+ const taskPhone = async () => {
118
+ const callInfo = await (await commonSoftphone.getUserAgentManager()).requestOpenApi({ // 任务外呼
119
+ url: '/v1/task/importTaskCustomer',
120
+ data: {
121
+ "requestId": generateUUID(), // 请求id,具有唯一性,用来做请求幂等处理,一个请求id有效期10分钟。不传则不做幂等处理
122
+ "taskId": taskCall.value || 93726, // 测试任务
123
+ "failReturn": 1, // 可选值:0,1,默认1。如导入的数据中有部分验证不通过数据:0表示导入验证成功的,返回失败的数据;1表示全部数据(包括验证成功及失败的)都不导入;
124
+ "customers":[
125
+ {
126
+ "tag": "xx", // 自定义透传参数,来电坐席电话端软电话sip头可以直接获取
127
+ "clientUrl": "xx", // 自定义来电弹屏显示的第三方页面,用来展示来电具体信息
128
+ "number": taskPhoneCall.value || 15018707394, // 外呼号码
129
+ "properties": { // 自定义透传参数,可以通过[挂断回调]回调给第三方后端,前端主动获取需要调用gateway接口
130
+ "尊称": "先生",
131
+ "姓名": "张三"
132
+ }
133
+ }
134
+ ]
135
+ }
136
+ })
137
+ if (callInfo.code === 200) { // 正确响应
138
+ alert('导号成功')
139
+ } else {
140
+ alert(callInfo.message)
141
+ }
142
+ }
143
+
144
+ taskButton.addEventListener('click', taskPhone) // 任务呼叫
145
+
96
146
  })
97
147
 
98
148
  document.addEventListener('unload', () => {
@@ -476,17 +476,17 @@ class SoftphoneManager {
476
476
  }
477
477
 
478
478
  seatsStatusChange(status) {
479
- this.microCommunicat('softphone-connect', {
479
+ this.microCommunicat('softphone-seats-status-change', {
480
480
  status
481
481
  })
482
482
  }
483
483
 
484
484
  accept() {
485
- this.microCommunicat('softphone-connect')
485
+ this.microCommunicat('oftphone-accept')
486
486
  }
487
487
 
488
488
  ignore() {
489
- this.microCommunicat('softphone-hangup')
489
+ this.microCommunicat('softphone-ignore')
490
490
  }
491
491
 
492
492
  hangup() {
@@ -510,20 +510,17 @@ class SoftphoneManager {
510
510
  const shared = new Shared('default')
511
511
  if (props.getOfflineInfo) {
512
512
  shared.getOfflineInfo = async (data) => {
513
- return await props.getOfflineInfo
514
- !(data)
513
+ return await props.getOfflineInfo(data)
515
514
  }
516
515
  }
517
516
  if (props.changeALittleRest) {
518
517
  shared.changeALittleRest = async (data) => {
519
- return await props.changeALittleRest
520
- !(data)
518
+ return await props.changeALittleRest(data)
521
519
  }
522
520
  }
523
521
  if (props.quickCallWin) {
524
522
  shared.quickCallWin = async (data) => {
525
- return await props.quickCallWin
526
- !(data)
523
+ return await props.quickCallWin(data)
527
524
  }
528
525
  }
529
526
  (Object.keys(props.envMap).reduce((res, currentValue) => {
@@ -18,3 +18,16 @@ function isDomainOrIP(str) {
18
18
  }
19
19
  return domainPattern.test(str)
20
20
  }
21
+
22
+ function generateUUID() { // Public Domain/MIT
23
+ var d = Date.now();
24
+ if (typeof performance !== 'undefined' && typeof performance.now === 'function'){
25
+ d += performance.now(); //use high-precision timer if available
26
+ }
27
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
28
+ var r = (d + Math.random() * 16) % 16 | 0;
29
+ d = Math.floor(d / 16);
30
+ return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
31
+ });
32
+ }
33
+