第一步 拉取jssip

npm i jssip-for-node

第二步
点击签入的时候,要判断当前浏览器是否支持麦克风

  • 打开谷歌 右击属性 更改目标--unsafely-treat-insecure-origin-as-secure=" http://电脑ip"
  • 关闭当其浏览器 再次打开
  • 粘贴以下代码
<el-button @click="signinApi('signin')">签入</el-button>



// 判断是否插入麦克风
      asdas(value) {
        navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
        const that = this;
        if (navigator.getUserMedia) {
          console.log("接入录音设备");
          navigator.getUserMedia({audio: true},
            function onSuccess(stream) {
              console.log("已点击允许,开启成功");
              //后台接口  返回 jssip 需要的参数  {
					 //"code": "0",
					   // "result": {
					     //   "wsUrl": "wss://sip.fanlp.cn:7443",
					      //  "uri": "sip:2002@sip.fanlp.cn:7443",
					       // "password": "1234"
					    //},
					    //"message": "操作成功"
					//}
              let json = {}
              json.opt = value
              json.taskId = that.ruleFrom.taskId[1]
              that.hwyStatusOpt(json)
            },
            function onError(error) {
              that.$message.error("拒绝麦克风授权,请重新签入");
            }
          );
        } else {
          // 不支持
          console.log("请接入麦克风设备在迁入");
          that.$message.error("请接入麦克风设备再签入");
        }
      },

第三布 配置jssip

//sip 配置 注册
      callPhone(obj) {
        debugger
        // 配置信息
        if (this.ua) {
          this.ua.stop();
        }
        const socket = new this.JsSIP.WebSocketInterface(obj.wsUrl);
        const configuration = {
          sockets: [socket],
          uri: obj.uri,
          password: obj.password
        };
        // 创建UA
        this.ua = new this.JsSIP.UA(configuration);
        // 状态回调
        this.ua.on("connected", function (e) {
          console.log("--------已连接---------");
        });
        this.ua.on("disconnected", function (e) {
          console.log("-------未连接--------");
        });
        this.ua.on("registered", function (e) {
          console.log("--------已注册-------");
        });
        this.ua.on("unregistered", function (e) {
          console.log("------未注册--------");
        });
        this.ua.on("registrationFailed", e => {
          this.$message.error("SIP注册失败,请联系管理员");
        });
        //改变按钮状态
        this.signIn = true
        this.startwork = false
        //客户接到了电话才会走这里
        this.ua.on("newRTCSession", e => {
          console.log("newRTCSession");
          console.log(e);
          this.nextCallIntervalTimerEvent = e;
          console.log("Callid=" + e.request.headers["X-Callid"][0].raw + "------------------Phone=" + e.request.headers["X-Phone"][0].raw);
          const Taskid = e.request.headers["X-Taskid"][0].raw;
          const Phone = e.request.headers["X-Phone"][0].raw;
          const callId = e.request.headers["X-Callid"][0].raw;

            e.session.on("confirmed", e => {
              console.log("--------------------------电话接通,开始通话");
            });
            e.session.on("ended", e => {
              console.log("---------------------------电话已挂断,开始问卷");
              //挂机后 嘟一声挂断了
              this.$refs.hangMusic.play();
            });
            //绑定回调后先给坐席‘滴’一声   
            this.$refs.tipMusic.play();
            e.session.answer();
        });
        // 登陆
        this.ua.start();
        // 登出
        // ua.stop();
      },

	//挂断、接通、执行的录音
	<audio id="audio" src autoplay/>
    <audio ref="tipMusic" :src="tipMusic"/>
    <audio ref="hangMusic" :src="hangMusic"/>
Logo

前往低代码交流专区

更多推荐