webRTC:jssip登录freeswitch的正确办法及代码

简介: webRTC:jssip登录freeswitch的正确办法及代码

https://quantum6.blog.csdn.net/article/details/106031371


在这一篇文章中,没有登录成功,自然也无法呼叫。经过痛苦的过程,终于找到了正确办法:


freeswitch需要wss证书。

参考:


正确填写登录信息

端口不要改,使用默认的。


image.png


查看登录结果

image.png


登录代码

不知道从哪里复制来的,非常感谢。确实登录成功。


<!DOCTYPE html>
<html>
<head>
  <title>JsSIP + WebRTC + freeSWITCH</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.4.4.min.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:1011@192.168.1.111:5060" /></td>
      </tr>
      <tr>
        <td class="td_label"  align="right"><label for="sip_password">SIP Password:</label></td>
        <td><input style="width:250px" id="sip_password" type="password" placeholder="SIP password"
          value="1234" /></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://192.168.1.111:7443" /></td>
      </tr>
      <tr>
        <td class="td_label"  align="right"><label class="input_label" for="sip_phone_number">SIP Phone Info:</label></td>
        <td><input style="width:250px" id="sip_phone_number" type="text" placeholder="sip:3000@192.168.40.96:5060"
          value="sip:1001@192.168.1.111:5060" ></td>
      </tr>
      <tr>
        <td colspan="2" align="center"><button onclick="testStart()"> Initialize </button></td>
      </tr>
      <tr>
        <td colspan="2" align="center"><button onclick="testCall()"> Call </button></td>
      </tr>
      <tr>
        <td  colspan="2" align="center"><button onclick="captureLocalMedia()"> Capture Local Media</button></td>
      </tr>
    </table>
  </div>
  <div 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: true,     
      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
      };
      userAgent = new JsSIP.UA(configuration);
      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(data){
        console.info('onNewRTCSession: ', data);
        if(data.originator == 'remote'){ //incoming call
          console.info("incomingSession, answer the call");
          incomingSession = data.session;
          data.session.answer({'mediaConstraints' : { 'audio': true, 'video': true,       mandatory: { maxWidth: 640, maxHeight: 360 } }, 'mediaStream': localStream});
        }else{
          console.info("outgoingSession");
          outgoingSession = data.session;
          outgoingSession.on('connecting', function(data){
            console.info('onConnecting - ', data.request);
            currentSession = outgoingSession;
            outgoingSession = null;
          });
        }
          data.session.on('accepted', function(data){
            console.info('onAccepted - ', data);
            if(data.originator == 'remote' && currentSession == null){
              currentSession = incomingSession;
              incomingSession = null;
              console.info("setCurrentSession - ", currentSession);
            }
          });
          data.session.on('confirmed', function(data){
            console.info('onConfirmed - ', data);
            if(data.originator == 'remote' && currentSession == null){
              currentSession = incomingSession;
              incomingSession = null;
              console.info("setCurrentSession - ", currentSession);
            }          
          });
        data.session.on('sdp', function(data){
          console.info('onSDP, type - ', data.type, ' sdp - ', data.sdp);
          //data.sdp = data.sdp.replace('UDP/TLS/RTP/SAVPF', 'RTP/SAVPF');
          //console.info('onSDP, changed sdp - ', data.sdp);
        });
        data.session.on('progress', function(data){
          console.info('onProgress - ', data.originator);
          if(data.originator == 'remote'){
            console.info('onProgress, response - ', data.response);
          }
        });
        data.session.on('peerconnection', function(data){
          console.info('onPeerconnection - ', data.peerconnection);
          data.peerconnection.onaddstream = function(ev){
              console.info('onaddstream from remote - ', ev);
              videoView.src = URL.createObjectURL(ev.stream);
          };
        });
      });
      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 = {
        'eventHandlers'    : eventHandlers,
        'mediaConstraints' : { 'audio': true, 'video': true , 
                               mandatory: { maxWidth: 640, maxHeight: 360 }
          },
        'mediaStream': localStream
      };
      //outgoingSession = userAgent.call('sip:3000@192.168.40.96:5060', options);
      outgoingSession = userAgent.call(sip_phone_number_, options);
    }
  </script>
</html>



目录
相关文章
|
Web App开发 存储 编解码
Freeswitch关于支持jsip的配置
1、freeswitch安装过程(安装过程省略,运行环境为centos7,freeswitch1.6.5)
1194 0
|
12月前
|
网络协议 Linux Shell
阿里云安装freeswitch的步骤总结
本文介绍在阿里云上安装freeswitch系统三种安装方式:脚本、镜像及Docker。支持多种Linux系统,推荐最小化安装,提供下载地址、一键安装命令及卸载方法。安装后访问IP即可登录,默认账号密码为admin/admin,初始化需等待5-10分钟。
1468 5
|
存储 Ubuntu 数据安全/隐私保护
Ubuntu 24.04 安装 Docker
本文详细介绍在 VMware 中的 Ubuntu 24.04 服务器上安装 Docker 的完整流程,包括环境准备、配置阿里云镜像源、添加国内加速器及用户权限配置,确保高效、安全地部署并使用 Docker。
6168 4
Ubuntu 24.04 安装 Docker
|
Ubuntu Linux 数据安全/隐私保护
Windows中安装WSL 2和Ubuntu系统的教程
回看这一路,有趣吧?你已经跨界成为了一个Windows和Linux的桥梁。期待在代码的世界里,把一切玩得风生水起!
710 1
|
SQL Java 数据库连接
MyBatisPlus-聚合查询、分组查询及等值查询
MyBatisPlus-聚合查询、分组查询及等值查询
3651 0
|
网络协议 Linux
CentOS 7 上使用Certbot申请通配符证书
本文记录下申请RSA和ECDSA通配符证书的过程。 1. 安装Certbot 签署通配符证书需要Certbot 0.22以上。如果以前安装过certbot,一般是直接yum update即可。如果是全新安装,则如下: 先升级: yum update -y 查看系统版本: cat /etc/cen.
7430 1
|
监控 程序员 数据库
分享一个 .NET Core Console 项目中应用 NLog 写日志的详细例子
分享一个 .NET Core Console 项目中应用 NLog 写日志的详细例子
703 0
|
缓存 小程序 IDE
【每周一个小技巧】支付宝小程序自定义tabbar效果
【每周一个小技巧】支付宝小程序自定义tabbar效果
1152 2
|
Web App开发 应用服务中间件 Linux
freeswitch使用sip集成网页电话,nginx配置https协议
文章目录 网页集成软电话 配置freeswitch开启wss nginx配置自签名https域名 页面集成软电话开发 网页集成软电话 网页集成软电话需要使用https协议,页面与freeswitch平台建立websocket长连接。使用jssip库进行相关开发
1889 0
|
存储 XML Java
Flowable:ProcessEngin(引擎)与Service(服务接口)讲解
Flowable:ProcessEngin(引擎)与Service(服务接口)讲解
1603 0