使用Jssip的Webrtc客户端 - 使用Free开关和chrome

时间:2015-09-09 13:16:17

标签: javascript webrtc jssip

我正在使用JsSip 0.7x api来建立webrtc的客户端。 用于测试的铬。 使用网关终止对pstn的呼叫。 在index.html中使用audio元素并在事件上添加远程流 'addstream' 初始注册邀请等交换消息,收到200 ok。

日志显示已添加远程流 但双方的音频都没有响起。 媒体流活动:true,结束:false

有人可以提出可能的问题吗

  • 的index.html < audio id ='remoteVideo'控制autoplay =“autoplay”>不支持          

-testjssip.js

var localStream, remoteStream = null;

var remoteVideo = document.getElementById('remoteVideo');
var ua, session = null;

var eventHandlers;
var configuration = {
    'ws_servers': '******',
    'uri': '******',
    'password': '*****'
};

// Register callbacks to desired call events 

eventHandlers = {

    'peerconnection': function (e) {

        console.trace("fired for outgoing calls but before sdp generation in peerconnection ");

    },
    'connecting': function (e) { 

    },
    'progress': function (e) {

        console.trace('call is in progress', e);

    },
    'failed': function (e) {
        console.trace('call failed with cause: ', e);
    },
    'ended': function (e) {

        console.trace('call ended with cause: ', e);
    },
    'confirmed': function (e) {
    },
    'accepted': function (e) {
        console.trace(" call accepted ");
    },
    'addstream': function (e) {

 if(session.connection.getRemoteStreams().length > 0)
 {

    console.trace('remote stream added ' +e.stream.getAudioTracks().length);

    console.trace('remote stream added ' + e.stream.getTracks());

   remoteVideo = JsSIP.rtcninja.attachMediaStream(remoteVideo,e.stream);
        }
      }
};

var options = {

    'eventHandlers': eventHandlers,
    'extraHeaders': ['X-Foo: foo', 'X-Bar: bar'],
    'mediaConstraints': {'audio': true, 'video':false},
    'rtcOfferConstraints' : {'offerToReceiveAudio' : true } ,

    mandatory: [{
                OfferToReceiveAudio: true,
                OfferToReceiveVideo: false
            },{'DtlsSrtpKeyAgreement': true} ]

};
init();

function init() {

    console.trace("intializing user agent");
    ua = new JsSIP.UA(configuration);
    ua.start();
    console.trace("is registered : " + ua.isRegistered());
    uaEventHandling();
}
;


function uaEventHandling() {

    //events of UA class with their callbacks
    ua.on('registered', function (e) {
        console.trace("registered", e);
    });

    ua.on('unregistered', function (e) {
        console.trace("ua has been unregistered periodic registeration fails or ua.unregister()", e);
    });

    ua.on('registrationFailed', function (e) {
        console.trace("register failed", e);
    });
    ua.on('connected', function (e) {
        console.trace("connected to websocket");
    });
    ua.on('disconnected', function (e) {
        console.trace("disconnected");
        ua.stop();
    });

    ua.on('newRTCSession', function (e) {
        console.trace('new rtc session created - incoming or outgoing call');
        session = e.session;
        if (e.originator === 'local') {
            console.trace(e.request + ' outgoing session');

        }
        else {
            console.trace(e.request + ' incoming session answering a call');
            e.session.answer(options);
        }
    });

    ua.on('newMessage', function (e) {
        if (e.originator === 'local')
            console.trace(' outgoing MESSAGE request ', e);
        else
            console.trace(' incoming MESSAGE request ', e);
    });
};

ua.call('sip:********', options);

3 个答案:

答案 0 :(得分:2)

我刚刚解决了同样的问题。要将流添加到音频元素,我找到了解决方法:

var phone = new JsSIP.UA(config);
var session = phone.call(contact, options);
if (session) {
  session.connection.addEventListener(''addstream', (e) => {
    var audio = document.createElement('audio');
    audio.srcObject = e.stream;
    audio.play();  
  });
}   

答案 1 :(得分:0)

我将感激不尽。 几天来,我都为脑筋动了脑筋。 我觉得JsSIP一定有问题,不问在哪里玩? 下面是我添加的代码:

$('textarea').on('keyup', function(e) {
    validateTextarea();
});

答案 2 :(得分:0)

要回答您的问题,应在接听或发出电话后将其添加。 此示例用于接听来电:

sipSession.answer({
      mediaConstraints: {audio: true, video: false}
});

 
sipSession.connection.onaddstream = (e) => {
  var audio:any = document.getElementById('audio_remote');
  audio.srcObject = e.stream;
  audio.play();
};