freeswitch 使用sipjs 、jssip webrtc網頁音視頻通話

關於linphone手機端開發參考https://blog.csdn.net/Java_lilin/article/details/80539116

配置幫助羣:261074724 

sipjs 官網http://sipjs.com/

參考官網說明 寫法如下:

<body>
  <div id="id_msg"></div>
  <input id="id_to" value="10000"/>
  <button οnclick="call()">call</button>
  <button οnclick="gua()">gua</button> 
  <br/> 
    <video id="remoteVideo" style="width:200px;height:400px;"></video>
    <video id="localVideo"  muted="muted"></video>

    <script src="sip-0.13.6.min.js"></script>
    <script src="vconsole.min.js"></script>
    <script type="text/javascript">
    var vConsole = new VConsole();
var config = {
  // Replace this IP address with your FreeSWITCH IP address
  uri: '10001@xx:9060',

  // Replace this IP address with your FreeSWITCH IP address
  // and replace the port with your FreeSWITCH ws port
  transportOptions: {
    wsServers: ['wss://xx:7443'] 
  },
  // FreeSWITCH Default Username
  authorizationUser: '10001',

  // FreeSWITCH Default Password
  password: 'test1'
};

var userAgent = new SIP.UA(config);

var remoteVideo = document.getElementById('remoteVideo');
var localVideo = document.getElementById('localVideo');
var sipsession = null;
userAgent.on('registered', function () {
    document.getElementById('id_msg').innerText="ok";
});
userAgent.on('invite', function(session) {
    var url = session.remoteIdentity.uri.toString()+"--->call";
  var isaccept = confirm(url);
  if(isaccept)
  { 
      //接受來電
      session.accept({
        sessionDescriptionHandlerOptions: {
          constraints: {
            audio: true,
            video: true
          }
        }
      });
      sipsession = session;  
      session.on('accepted', function() {//
          // We need to check the peer connection to determine which track was added
            
          var pc = session.sessionDescriptionHandler.peerConnection;
          console.log(pc);
           console.log(pc.getLocalStreams());
          // Gets remote tracks
          var remoteStream = new MediaStream();
          pc.getReceivers().forEach(function(receiver) { 
            remoteStream.addTrack(receiver.track);
          });
          remoteVideo.srcObject = remoteStream;
          remoteVideo.play();
          
         if(pc.getSenders() ){
              var localStream = new MediaStream();
              pc.getSenders().forEach(function(sender) {
                localStream.addTrack(sender.track);
              });
              localVideo.srcObject = localStream;
              localVideo.play();
          }
          
     });
  }
  else
  {
      //拒絕來電
      session.reject();
  } 
} );

function gua(){
    sipsession.terminate();
}
function  call( ){ 
var to =document.getElementById('id_to').value;
sipsession = userAgent.invite(to+'@xx:7443',{
    sessionDescriptionHandlerOptions: {
      constraints: {
        audio: true,  video: true
      }
    }
  });

sipsession.on('accepted', function() {
  // We need to check the peer connection to determine which track was added

  var pc = sipsession.sessionDescriptionHandler.peerConnection;

  // Gets remote tracks
  var remoteStream = new MediaStream(); 
  pc.getReceivers().forEach(function(receiver) { 
    remoteStream.addTrack(receiver.track);261074724
  });
  remoteVideo.srcObject = remoteStream;
  remoteVideo.play(); 

  // Gets local tracks
  if(pc.getSenders() ){
      var localStream = new MediaStream();
      pc.getSenders().forEach(function(sender) {
        localStream.addTrack(sender.track);
      });
      localVideo.srcObject = localStream;
      localVideo.play();
  }
});

}


    </script>
 
</body>

................

測試結果如下

  局域網 外網(nat ok) 音視頻 linphone 正常接聽
pc瀏覽器 支持 支持 支持 支持 ok
手機瀏覽器 支持 支持 支持 支持 ok
微信網頁 支持 支持 支持 支持 ok

手機端須改動一點地方 可以加羣討論:261074724

測試挺好的這個

/////////////////////////////////

jssip 官網https://jssip.net/

頁面參考

https://blog.csdn.net/foruok/article/details/74321214

經個人測試 jssip 在內網效果很好

在外網配置turn後呼叫有點慢 接通好像有點問題

和linphone集成的交流羣 :261074724 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章