1

我正在使用 JsSip 0.7x api 来制作 webrtc 的客户端。使用 chrome 进行测试。使用网关终止 pstn 上的呼叫。使用 index.html 中的音频元素并在事件“addstream”上添加远程流初始注册邀请等消息交换并收到 200 ok。

日志显示已添加远程流但双方都没有音频,甚至没有响铃。媒体流活动:真,结束:假

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

  • 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);
4

3 回答 3

5

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

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();  
  });
}   

于 2018-12-19T08:28:13.703 回答
2

我将无法感谢你。几天来我一直在琢磨单向音频的故事是什么。我觉得JsSIP没有问任何地方在哪里玩一定有什么问题?下面是我添加的代码:

//This untouched, only so you can easily locate where to add the code:
key: "_createRTCConnection",
value: function _createRTCConnection(pcConfig, rtcConstraints) {
var _this12 = this;

this._connection = new RTCPeerConnection(pcConfig, rtcConstraints);

/*THIS IS MINE*/
this._connection.onaddstream = function(e) {
var oA = document.getElementById("audio_remote")
oA.srcObject = e.stream;
oA.play()}
/*THIS IS MINE*/
于 2019-02-28T10:25:01.120 回答
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();
};

于 2020-09-10T12:38:09.380 回答