Browse Source

外呼切换账号

ct 2 ngày trước cách đây
mục cha
commit
895c35045e
3 tập tin đã thay đổi với 69 bổ sung54 xóa
  1. 12 3
      src/store/modules/user.js
  2. 54 44
      src/utils/call.js
  3. 3 7
      src/views/crm/customer/my.vue

+ 12 - 3
src/store/modules/user.js

@@ -37,7 +37,7 @@ const user = {
       state.user = user
     },
     SET_CALL_USER: (state, callUser) => {
-      console.log(callUser)
+      console.log("1231-----------------------------",callUser)
       state.callUser = callUser
     },
     SET_CALL_REALM: (state, callRealm) => {
@@ -50,9 +50,18 @@ const user = {
       state.isCall = call
     },
     SET_CALL_STATUS: (state, title) => {
-      console.log(title)
+      console.log("1232-----------------------------",title)
       state.callTitle = title
     },
+    //清除外呼信息
+    CLEAR_SIP_ACCOUNT: (state) => {
+      console.log("5555555555555555555")
+      state.callUser = null
+      state.callRealm = null
+      state.callHa1 = null
+      state.isCall = false
+      state.callTitle = null
+    },
   },
 
   actions: {
@@ -87,7 +96,7 @@ const user = {
     GetSipAccount({ commit, state },param) {
       return new Promise((resolve, reject) => {
         getSipAccount(param).then(res => {
-          console.log(res)
+          console.log("1230-----------------------------",res)
           if(res.code==200){
             commit('SET_CALL_USER', res.data.data.response.data.user)
             commit('SET_CALL_REALM', res.data.data.response.data.realm)

+ 54 - 44
src/utils/call.js

@@ -32,61 +32,71 @@ export function callNumber(customerId,contactsId,orderId,callerLine){
 	const callHa1 = store.getters && store.getters.callHa1
     JsSIP.C.SESSION_EXPIRES=120,JsSIP.C.MIN_SESSION_EXPIRES=360;
 
-	console.log(callUser)
-	console.log(callRealm)
-	console.log(callHa1)
-	if(_phone==null){
-		
-		_phone = new WebPhoneSDK({
-				lib: JsSIP,
-				debug: true,
-				debugLib: true,
-				user: callUser,
-				ha1: callHa1,
-				realm: callRealm,
-				server: server,
-				audioElement: document.getElementById('remoteAudio'),
-				httpsConfirmFrame: 'httpsConfirmFrame',
-				pcConfig:{"iceServers":[{"urls":["stun:211.159.161.254"]}]},
-				events: {
-					'ua.connecting': (type, data) => webphoneHandle(type, data),
-					'ua.connected': (type, data) => webphoneHandle(type, data), //WEBPHONE链接OK
-					'ua.disconnected': (type, data) => webphoneHandle(type, data), //WEBPHONE链接断开
-					'reg.registered': (type, data) => webphoneHandle(type, data),  //WEBPHONE 分机注册
-					'reg.unregistered': (type, data) => webphoneHandle(type, data), //WEBPHONE 分机取消注册
-					'reg.failed': (type, data) => webphoneHandle(type, data),  //WEBPHONE 注册失败
-					'incoming.notify': (type, data, options) => webphoneHandle(type, data, options),  //有电话进来了
-					'incoming.failed': (type, data, options) => webphoneHandle(type, data, options),//WEBPHONE 有电话进来,然后处理失败了(如,我们拒绝了,或者客户侧直接挂断了)
-					'incoming.ended': (type, options) => webphoneHandle(type, options),// WEBPHONE 有电话进来了,呼叫正常结束了
-					'incoming.accecpted': (type, options) => webphoneHandle(type, options),//有电话进来了,呼叫接听了额
-					'outgoing.connecting': (type, options) => webphoneHandle(type, options),//WEBPHONE正在尝试呼出
-					'outgoing.progress': (type, options) => webphoneHandle(type, options),//WEBPHONE开始振铃了
-					'outgoing.failed': (type, data, options) => webphoneHandle(type, data, options),//WEBPHONE呼出失败了,如被叫拒绝了,线路异常呼出失败了
-					'outgoing.ended': (type, options) => webphoneHandle(type, options),  //呼出正常结束
-					'outgoing.accecpted': (type, data, options) => webphoneHandle(type, data, options),  //呼出被叫接听
-					'call.hold': (type, data) => webphoneHandle(type, data), //呼叫保持
-					'call.unhold': (type, data) => webphoneHandle(type, data),  //呼叫解除保持
-				}
-			})
-			_phone.start({});
+	
+  
+	// 2. 销毁旧实例
+	if (_phone) {
+	  try {
+		_phone.stop && _phone.stop()
+	  } catch (e) {
+		console.warn('旧 _phone 停止失败', e)
+	  }
+	  _phone = null
 	}
+  
+	// 3. 新建实例
+	_phone = new WebPhoneSDK({
+		lib: JsSIP,
+		debug: true,
+		debugLib: true,
+		user: callUser,
+		ha1: callHa1,
+		realm: callRealm,
+		server: server,
+		audioElement: document.getElementById('remoteAudio'),
+		httpsConfirmFrame: 'httpsConfirmFrame',
+		pcConfig:{"iceServers":[{"urls":["stun:211.159.161.254"]}]},
+		events: {
+			'ua.connecting': (type, data) => webphoneHandle(type, data),
+			'ua.connected': (type, data) => webphoneHandle(type, data), //WEBPHONE链接OK
+			'ua.disconnected': (type, data) => webphoneHandle(type, data), //WEBPHONE链接断开
+			'reg.registered': (type, data) => webphoneHandle(type, data),  //WEBPHONE 分机注册
+			'reg.unregistered': (type, data) => webphoneHandle(type, data), //WEBPHONE 分机取消注册
+			'reg.failed': (type, data) => webphoneHandle(type, data),  //WEBPHONE 注册失败
+			'incoming.notify': (type, data, options) => webphoneHandle(type, data, options),  //有电话进来了
+			'incoming.failed': (type, data, options) => webphoneHandle(type, data, options),//WEBPHONE 有电话进来,然后处理失败了(如,我们拒绝了,或者客户侧直接挂断了)
+			'incoming.ended': (type, options) => webphoneHandle(type, options),// WEBPHONE 有电话进来了,呼叫正常结束了
+			'incoming.accecpted': (type, options) => webphoneHandle(type, options),//有电话进来了,呼叫接听了额
+			'outgoing.connecting': (type, options) => webphoneHandle(type, options),//WEBPHONE正在尝试呼出
+			'outgoing.progress': (type, options) => webphoneHandle(type, options),//WEBPHONE开始振铃了
+			'outgoing.failed': (type, data, options) => webphoneHandle(type, data, options),//WEBPHONE呼出失败了,如被叫拒绝了,线路异常呼出失败了
+			'outgoing.ended': (type, options) => webphoneHandle(type, options),  //呼出正常结束
+			'outgoing.accecpted': (type, data, options) => webphoneHandle(type, data, options),  //呼出被叫接听
+			'call.hold': (type, data) => webphoneHandle(type, data), //呼叫保持
+			'call.unhold': (type, data) => webphoneHandle(type, data),  //呼叫解除保持
+		}
+	})
+
 	
+  
+	_phone.start({}) // 必须重新启动
+  
 	var data={customerId:customerId,contactsId:contactsId,orderId:orderId,callerId:callerLine};
-	
+  
 	this.callMobile(data).then(response => {
         if(response.code==200){
 			_phone.call(response.mobile,{userdata:response.logs.sessionId});
 			this.$store.dispatch('Call', {
-				mobile: response.displayMobile,
-				sessionId: response.logs.sessionId
-			})
+		  mobile: response.displayMobile,
+		  sessionId: response.logs.sessionId
+		})
         }
         else{
 			that.$notify.error({
-				title: response.msg,
-				showClose: false
+		  title: response.msg,
+		  showClose: false
 			});
-        }
+	  }
     });
   }
   export function callOff(){

+ 3 - 7
src/views/crm/customer/my.vue

@@ -370,7 +370,6 @@ import addVisitStatus from '../components/addVisitStatus.vue';
 import addPackage from "@/views/store/components/addOrder";
 import addOrderOffline from "@/views/store/components/addOrderOffline";
 import {getMyCallerApiList} from "@/api/company/companyVoiceCaller"
-import { getSipAccount } from "@/api/company/companyVoiceApi"
 export default {
   name: "Customer",
   components: {addPackage,addOrderOffline,addVisitStatus,addCustomerType,addRemark,addTag,assignUser,assistUser,addOrEditCustomer,editSource, addBatchSms,customerDetails,addVisit },
@@ -558,13 +557,10 @@ export default {
       });
     },
     changeCallerLine(){
-      const param = {callerId:this.selectedCallerLine}
-      // getSipAccount(param)
-      this.$store.dispatch('GetSipAccount',param).then(() => {
+      const param = { callerId: this.selectedCallerLine }
 
-      }).catch(err => {
-
-      });
+      this.$store.commit('CLEAR_SIP_ACCOUNT')
+      this.$store.dispatch('GetSipAccount', param)
 
     },
     handleCommand(command){