jssip可用demo html+jssip-3.10.0.js

需要将语音系统的拨打功能,集成到办公CRM系统。实现办公OA,在浏览器中拨打,接听电话功能。

需求改造如下:落地移动IMS,增加了媒体服务器双机负载。网页拨打电话使用开源的Opensips+Rtpengine(当然现在很多厂商的新版SBC都带webrtc功能,价格参考 50并发≈3万rmb)。

Opensips+Rtpengine为此花了一些时间补充了一版, oepnsips搭建指南填坑版。(opensips教程基本是不可用的)。jssip demo, 99%发布的都是不可用的。jssip可用demo

html+jssip-3.10.0.js,后面基于demo开发了web拨号盘,通过网页悬浮框拨打电话。webrtc 谷歌插件。

<!DOCTYPE html>
<html>
<head>
  <title>JsSIP + WebRTC </title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta name="Author" content="foruok" />
  <meta name="description" content="JsSIP based example web application." />
  <script src="jssip-3.10.0.js" type="text/javascript"></script>
  <style type="text/css">
  </style>
</head>


<body> 
  <div id="login-page" style="width: 424px; height: 260px; background-color: #f2f4f4; border: 1px solid grey; padding-top: 4px">
    <table border="0" frame="void" width="418px">
      <tr>
        <td class="td_label" width="160px" align="right"><label for="sip_uri">SIP URI:</label></td>
        <td width="258px"><input style="width:250px" id="sip_uri" type="text" placeholder="SIP URI (i.e: sip:alice@example.com)" value="sip:8003@example.com"/></td>
      </tr>
      <tr>
        <td class="td_label"  align="right"><label for="sip_password">分机密码:</label></td>
        <td><input style="width:250px" id="sip_password" type="password" placeholder="SIP password" value="a123456789"/></td>
      </tr>
      <tr>
        <td class="td_label" align="right"><label for="ws_uri">WSS URI:</label></td>
        <td><input style="width:250px" id="ws_uri" class="last unset" type="text" placeholder="WSS URI (i.e: wss://example.com)" value="wss://example.com:1443/wss"/></td>
      </tr>
      <tr>
        <td class="td_label"  align="right"><label class="input_label" for="sip_phone_number">被叫号码:</label></td>
        <td><input style="width:250px" id="sip_phone_number" type="text" placeholder="sip:3000@example.com" value="9001"></td>
      </tr>
      <tr>
        <td colspan="2" align="center"><button onclick="testStart()"> 登录 </button></td>
      </tr>
      <tr>
        <td colspan="2" align="center"><button onclick="testCall()"> 呼叫 </button></td>
      </tr>
      <tr  hidden="true">
        <td  colspan="2" align="center"><button onclick="captureLocalMedia()"> Capture Local Media</button></td>
      </tr>
    </table>
	<audio id="audioElement"></audio>
  </div>

  <div hidden="true" style="width: 424px; height: 324px;background-color: #333333; border: 2px solid blue; padding:0px; margin-top: 4px;">
        <video id="videoView" width="420px" height="320px" autoplay ></video>
  </div>

</body>
  <script type="text/javascript">
    var outgoingSession = null;
    var incomingSession = null;
    var currentSession = null;
    var videoView = document.getElementById('videoView');

    var constraints = {
      audio: true,
      video: false,     
      mandatory: {
        maxWidth: 640,
        maxHeight: 360
      }
    };
    URL = window.URL || window.webkitURL;

    var localStream = null;
    var userAgent = null;

    function gotLocalMedia(stream) {
      console.info('Received local media stream');
      localStream = stream;
      videoView.src = URL.createObjectURL(stream);
    }

    function captureLocalMedia() {
      console.info('Requesting local video & audio');
      navigator.webkitGetUserMedia(constraints, gotLocalMedia, function(e){
        alert('getUserMedia() error: ' + e.name);
      });
    }

    function testStart(){

      var sip_uri_ = document.getElementById("sip_uri").value.toString();
      var sip_password_ = document.getElementById("sip_password").value.toString();
      var ws_uri_ = document.getElementById("ws_uri").value.toString();

      console.info("get input info: sip_uri = ", sip_uri_, " sip_password = ", sip_password_, " ws_uri = ", ws_uri_);

	   
      var socket = new JsSIP.WebSocketInterface(ws_uri_);
      var configuration = {
        sockets: [ socket ],
        //outbound_proxy_set: ws_uri_,
        uri: sip_uri_,
        password: sip_password_,
        //register: true,
        //session_timers: false
		session_timers: false, // 启用会话计时器(根据RFC 4028)
        user_agent: "Aegis WebRTC v1.0",
        contact_uri: sip_uri_,
        // outbound_proxy_set: wsUri,
        // display_name: String(phone),
        autostart: true, // 自动连接
        register: true, // 自动就绪
      }; 
	  
	  

      userAgent = new JsSIP.UA(configuration);

	 userAgent.on("connecting", (args) => {
        // this.$notify({
        //   title: "提示",
        //   message: "开始尝试连接",
        //   duration: 500,
        // });
        console.info("开始尝试连接", args);
      });
      userAgent.on('registered', function(data){
        console.info("registered: ", data.response.status_code, ",", data.response.reason_phrase);
      });

      userAgent.on('registrationFailed', function(data){
        console.log("registrationFailed, ", data);
        //console.warn("registrationFailed, ", data.response.status_code, ",", data.response.reason_phrase, " cause - ", data.cause);
      });

      userAgent.on('registrationExpiring', function(){
        console.warn("registrationExpiring");
      });

      userAgent.on('newRTCSession', function(e){
			console.log(`新的${e.originator === "local" ? "外呼" : "来电"}`, e);
        const session = e.session;
        this.session = session;
        const peerconnection = session.connection;
        if (e.originator === "local") {
          // 打电话
          peerconnection.addEventListener("addstream", (event) => {
            const audio = document.querySelector(".audio");
            audio.srcObject = event.stream;
          });
         
        } else {
          //document.getElementById("localVideo").play();
          // 接电话
          this.dialogVisible = true;
          this.isg = true;
          this.callers = session.remote_identity.uri.user;
        }
        // 接通,在这一步可以处理音频播放
        // 接通并不代表对方已经接受,接通代表 滴 滴 滴
        session.on("confirmed", () => {
          console.info("接通中");
          // peerconnection.addEventListener("track", (event) => {
          //   const audioView = document.querySelector("#conversation");
          //   audioView.srcObject = event.streams[0];
          //   audioView.play();
          //   audioView.volume = 1;
          // });
          const audioElement = document.getElementById("audioElement");
          audioElement.autoplay = true;
          const stream = new MediaStream();
          const receivers = session.connection.getReceivers();
          if (receivers)
            receivers.forEach((receiver) => stream.addTrack(receiver.track));
          audioElement.srcObject = stream;
          // 最后都要播放
          audioElement.play();
        });

        // 接听失败
        session.on("failed", (mdata) => {
          const myAuto = document.getElementById("localVideo");
          myAuto.pause();
          myAuto.load();
          
          console.info("来电的时候 拒接或者 还没接听对方自己就挂断了");
        });

        // 接听成功
        session.on("accepted", (response, cause) => {
          // 嘟嘟嘟
          //const conversation = document.getElementById("conversation");
          //conversation.pause();
          //conversation.load();
          //this.Answering = true;
          console.info("接听成功");
          
        });
        // 接听成功后 挂断
        session.on("ended", () => {
          

          this.dialogVisible = false;
          this.InCall = false;
        });
        // 通话被挂起
        session.on("hold", (data) => {
          const org = data.originator;
          if (org === "local") {
            log("通话被本地挂起:", org);
          } else {
            // log("通话被远程挂起:", org);
          }
        });
        // 通话被继续
        session.on("unhold", (data) => {
          const org = data.originator;
          if (org === "local") {
            // );
          } else {
            // log("通话被远程继续:", org);
          }
        });
		});

      userAgent.on('newMessage', function(data){
        if(data.originator == 'local'){
          console.info('onNewMessage , OutgoingRequest - ', data.request);
        }else{
          console.info('onNewMessage , IncomingRequest - ', data.request);
        }
      });

      console.info("call register");
      userAgent.start();
    };

    // Register callbacks to desired call events
    var eventHandlers = {
      'progress': function(e) {
          console.log('call is in progress');
        },
      'failed': function(e) {
          console.log('call failed: ', e);
      },
      'ended': function(e) {
          console.log('call ended : ', e);
      },
      'confirmed': function(e) {
        console.log('call confirmed');
      }
    };

    function testCall(){
			var sip_phone_number_ = document.getElementById("sip_phone_number").value.toString();

			var options = {
              'pcConfig': {
                'rtcpMuxPolicy': "negotiate",
              },
              'rtcOfferConstraints': {
                'offerToReceiveAudio': '1',
                'offerToReceiveVideo': '0',
              },
              'eventHandlers': eventHandlers,
              'mediaConstraints': {
                'audio': true,
                'video': false,
              },
            };
        //outgoingSession = userAgent.call('sip:3000@192.168.40.96:5060', options);
         outgoingSession = userAgent.call(sip_phone_number_, options);
	  }
  </script>
</html>

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
### 回答1: kernel-headers-3.10.0-957.1.3是指Linux内核的头文件,用于开发和构建内核模块。头文件包含了内核的函数、宏定义和结构体等信息,可以让开发者在编写内核模块时调用内核的功能。这个特定版本的头文件是针对Linux内核版本3.10.0-957.1.3的,对应着特定的内核版本。 内核头文件是Linux内核的重要组成部分,它们提供了与内核核心功能的接口。在编写内核模块时,我们需要包含这些头文件,以访问内核中已定义的函数和数据结构。这些头文件中包含了大量的定义,例如进程管理、内存管理、文件系统、网络等。 安装kernel-headers-3.10.0-957.1.3包可以方便开发者在特定的Linux内核版本上进行内核模块的开发与调试。它们通常与内核源代码的完整版本完全兼容,因此使用这些头文件可以确保我们所编写的内核模块与我们正在运行的内核版本兼容。 通过包管理工具可以安装kernel-headers-3.10.0-957.1.3,然后在编写内核模块时使用对应的头文件。它们提供了对内核功能的访问和使用,同时也规定了内核模块的接口规范。这样,在编译和加载内核模块时,编译器可以正确地解析我们所使用的内核函数和数据结构。 总之,kernel-headers-3.10.0-957.1.3是Linux内核的头文件,提供了访问内核功能的接口和定义,方便开发者在特定内核版本下进行内核模块的开发和调试。 ### 回答2: kernel-headers-3.10.0-957.1.3 是一个Linux内核的头文件包。Linux内核是操作系统的核心部分,它控制和管理计算机的硬件和软件资源。头文件是用于编程的文件,它包含了变量、函数和宏的声明,使得开发者能够使用并访问Linux内核的功能。 kernel-headers-3.10.0-957.1.3 是特定版本的内核头文件包。版本号"3.10.0-957.1.3"表示该内核及其相应的头文件包是Linux 3.10.0内核系列的第957.1.3补丁级别的版本。 使用这个头文件包,开发者可以编写应用程序、设备驱动或其他内核模块,来与Linux 3.10.0-957.1.3 版本内核进行交互。这些头文件包含了内核的接口和数据结构的定义,在编程过程中能提供必要的信息和函数的声明。 为了能够编译和链接针对该版本内核的代码,这个头文件包需要在开发环境中安装。它提供用于编译的必要文件和工具,允许开发者使用特定内核版本的API和函数来访问内核服务和功能。 总之,kernel-headers-3.10.0-957.1.3 是一个特定版本Linux内核的头文件包,开发者可以使用它来编写与该版本内核进行交互的应用程序、设备驱动或其他内核模块。它是开发环境中的一个重要组件,提供了访问内核服务和功能的必要接口和声明。
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值