最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Webrtc Client using Jssip - No audio both ways using Free switch and chrome - Stack Overflow

programmeradmin1浏览0评论

I am using JsSip 0.7x api for making client side of webrtc. Used chrome for testing. Terminating call on a pstn using gateway. Using audio element in index.html and adding remote stream on event 'addstream' Initial Register Invite etc messages exchanged and 200 ok received.

Log shows remote stream has been added But no audio on both sides not even ringing. media stream active : true , ended : false

Can somebody suggest possible issues

  • index.html < audio id='remoteVideo' controls autoplay = "autoplay" > not supported

-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 - ining or outgoing call');
        session = e.session;
        if (e.originator === 'local') {
            console.trace(e.request + ' outgoing session');

        }
        else {
            console.trace(e.request + ' ining 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(' ining MESSAGE request ', e);
    });
};

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

I am using JsSip 0.7x api for making client side of webrtc. Used chrome for testing. Terminating call on a pstn using gateway. Using audio element in index.html and adding remote stream on event 'addstream' Initial Register Invite etc messages exchanged and 200 ok received.

Log shows remote stream has been added But no audio on both sides not even ringing. media stream active : true , ended : false

Can somebody suggest possible issues

  • index.html < audio id='remoteVideo' controls autoplay = "autoplay" > not supported

-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 - ining or outgoing call');
        session = e.session;
        if (e.originator === 'local') {
            console.trace(e.request + ' outgoing session');

        }
        else {
            console.trace(e.request + ' ining 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(' ining MESSAGE request ', e);
    });
};

ua.call('sip:********', options);
Share Improve this question edited May 26, 2017 at 3:08 Michael Sivolobov 13.3k5 gold badges46 silver badges67 bronze badges asked Sep 9, 2015 at 13:16 iridescentsiridescents 312 silver badges5 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 7

I've just solved same issue. To add stream to audio element I've found the solution:

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

I would not be able to thank you enough. I wracked my head for days what is the story of the one way audio. I felt that there must be something wrong that JsSIP not asking anywhere where to play? Below is the code I added:

//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*/

To answer your question, you should add this after answering or emitting the call. This example is for answering an ining call :

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

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

发布评论

评论列表(0)

  1. 暂无评论