| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- var outgoingSession = null,incomingSession = null,currentSession = null,
- timeStrart=false,thjsTel=false,timeReg,signState,
- videoView = document.getElementById('videoView'),
- localStream = null,userAgent = null,
- constraints = {
- audio: true,
- video: false,
- mandatory: {
- maxWidth: 640,
- maxHeight: 360
- }
- };
- URL = window.URL || window.webkitURL;
- function testStart() {
- var sip_uri_ = huayi.config.sip_uri_.toString();
- var sip_password_ = huayi.config.sip_password_.toString();
- var ws_uri_ = huayi.config.ws_uri_.toString();
- console.log(sip_uri_+'-'+sip_password_+'-'+ws_uri_)
- console.info("get input info: sip_uri = ", sip_uri_, " sip_password = ", sip_password_, " ws_uri = ", ws_uri_);
- JsSIP.C.SESSION_EXPIRES = 120, JsSIP.C.MIN_SESSION_EXPIRES = 120;
- 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: true,
- contact_uri: 'sip:'+$.cookie("extno")+'@'+huayi.config.socket_ip+';transport=ws',
- authorization:$.cookie("extno"),
- display_name:$.cookie("extno")
- };
- userAgent = new JsSIP.UA(configuration);
- //注册成功
- userAgent.on('registered', function(data) {
- if (!timeStrart) {
- $(".tooltip_text").text("初始化成功...");
- $(".td-call").hide();
- }
- timeStrart=false;
- //setTimeout(function(){$(".tooltip_text").text("分机号:"+$.cookie("extno")"); }, 3000);
- console.info("registered: ", data.response.status_code, ",", data.response.reason_phrase);
- });
- //注册失败
- userAgent.on('registrationFailed', function(data) {
- if (!timeStrart) {
- $(".tooltip_text").text("注册失败...")
- }
- timeStrart=false;
- console.log("registrationFailed, ", data);
- //console.warn("registrationFailed, ", data.response.status_code, ",", data.response.reason_phrase, " cause - ", data.cause);
- });
- //注册超时
- userAgent.on('registrationExpiring', function() {
- if (!timeStrart) {
- //$(".tooltip_text").text("注册超时...")
- }
- timeStrart=false;
- console.warn("registrationExpiring");
- });
- userAgent.on('newRTCSession', function(data) {
- console.info('onNewRTCSession: ', data);
- //通话呼入
- if(data.originator == 'remote') {
- // if(data.request.data.split("Extension ")[1]){
- // var stringHr_1=data.request.data.split("Extension ")[1].split('"')[0]
- // }
- console.info("incomingSession, answer the call----------------------");
- incomingSession = data.session;
- } 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;
- //layer.msg("setCurrentSession - ", currentSession);
- }
- });
- data.session.on('confirmed', function(data) {
- $(".tooltip_text").text("通话中...") //呼入建立
- if (signState) {
- $(".hwzt").text('通话中');
- }
- thjsTel=true;
- //calling();
- // if(stringHr_1){
- // var p = '<a href="javascript:;" class="active J_menuTab" data-id="./callScreen/callScreen.html?Number=' + stringHr_1+'">来电弹屏<i class="fa fa-times-circle"></i></a>';
- // $(".J_menuTab").removeClass("active");
- // var nif = '<iframe class="J_iframe J_iframeNew" name="iframe" width="100%" height="100%" src="./callScreen/callScreen.html?Number=' + stringHr_1+'"></iframe>';
- // $(".J_mainContent").find("iframe.J_iframe").hide().parents(".J_mainContent").append(nif);
- // $(".J_menuTabs .page-tabs-content").append(p);
- // }
- console.info('onConfirmed - ', data);
- if(data.originator == 'remote' && currentSession == null) {
- currentSession = incomingSession;
- incomingSession = null;
- //layer.msg("setCurrentSession - ", currentSession);
- }
- });
- data.session.on('sdp', function(data) {
- console.info('onSDP, type - ', data.type, ' sdp - ', data.sdp);
- });
- data.session.on('progress', function(data) {
- $(".tooltip_text").text("振铃中...")
- thjsTel=true;
- //layer.msg('onProgress - ', data.originator);
- if(data.originator == 'remote') {
- //layer.msg('onProgress, response - ', data.response);
- }
- });
- data.session.on('peerconnection', function(data) {
- $(".tooltip_text").text("呼叫建立...")//呼入建立
- //layer.msg('onPeerconnection - ', data.peerconnection);
- data.peerconnection.onaddstream = function(ev) {
- //layer.msg('onaddstream from remote ----------- ', ev);
- //<!-- videoView.src = URL.createObjectURL(ev.stream); -->
- videoView.srcObject = ev.stream;
- };
- });
- });
- userAgent.on('newMessage', function(data) {
- if(data.originator == 'local') {
- console.info('onNewMessage , OutgoingRequest - ', data.request);
- } else {
- console.info('onNewMessage , IncomingRequest - ', data.request);
- }
- });
- userAgent.start();
- }
- //外呼状态
- var eventHandlers = {
- 'progress': function(e) {
- $(".tooltip_text").text("呼出振铃...");
- },
- 'failed': function(e) {
- $(".tooltip_text").text("呼叫失败...");
- },
- 'ended': function(e) {
- clearInter();
- $(".tooltip_text").text("通话结束...");
- },
- 'confirmed': function(e) {
- $(".tooltip_text").text("呼叫建立...");
- }
- };
- function inCall () {
- if (incomingSession) {
- incomingSession.answer({
- 'mediaConstraints': {
- 'audio': true,
- 'video': false,
- mandatory: {
- maxWidth: 640,
- maxHeight: 360
- }
- },
- 'mediaStream': localStream
- });
- incomingSession = null;
- }
-
- }
- function testCall() {
- // 外呼拨打
- var sip_phone_number_ = document.getElementById("sip_phone_number").value.toString();
- var options = {
- 'eventHandlers': eventHandlers,
- 'mediaConstraints': {
- 'audio': true,
- 'video': false,
- mandatory: {
- maxWidth: 640,
- maxHeight: 360
- }
- },
- 'mediaStream': localStream
- };
- outgoingSession = userAgent.call(sip_phone_number_, options);
-
- var p = '<a style="background: #24c792; color: #FFFFFF;" href="javascript:;" class="active J_menuTab" data-id="./callScreen/OutCallScreen.html?Number=' + sip_phone_number_+'">外呼弹屏<i class="fa fa-times-circle"></i></a>';
- $(".J_menuTab").removeClass("active");
- var nif = '<iframe class="J_iframe J_iframeNew" name="iframe" width="100%" height="100%" src="./callScreen/OutCallScreen.html?Number=' + sip_phone_number_+'"></iframe>';
- $(".J_mainContent").find("iframe.J_iframe").hide().parents(".J_mainContent").append(nif);
- $(".J_menuTabs .page-tabs-content").append(p);
-
- }
- function reg() {
- if (!timeReg) {
- $(".td-call").hide();
- $(".tooltip_text").text("注册成功...");
- }
- timeReg=false;
- console.log('register----------->');
- userAgent.register();
- }
- //定时注册
- //regTime();
- function regTime(){
- setInterval(function() {
- timeStrart=true;
- timeReg=true;
- reg();
- }, 1000*60);
- }
- //注销
- function unReg() {
- $(".td-call").hide();
- $(".tooltip_text").text("注销...");
- //console.log('unregister----------->');
- userAgent.unregister(true);
- }
- //挂断
- function hangup() {
- //window.frames[1].clearInter();
- $(".tooltip_text").text("挂断...");
- obj.Type = "DropCall";
- Send();
- userAgent.terminateSessions();
- }
-
|