How to handle audio stream in JsSIP?

I’m creating React application that use JsSIP library to answer calls made via VoIP SIP provider.

I’ve already created a page that have two buttons (Accept and Reject). It successfully register SIP client on SIP-server. It also successfully receive call and I can answer it. But I don’t hear anything while answering call.

Registering JsSIP client (in willReceiveProps because I have information for connection after props changing):

const socketHost = 'wss://' + + ':' + contactCenter.port
const socket = new JsSIP.WebSocketInterface(socketHost)
const configuration = {
    sockets: [socket],
    uri: 'sip:' + contactCenter.login + '@' +,
    password: contactCenter.password,
    socketHost: socketHost,

const coolPhone = new JsSIP.UA(configuration)

coolPhone.on('connected', (e: any) => {
    const messages = ServiceContainer.get<MessageManagerInterface>(ServiceTypes.Messages)
    messages.addSuccess('SIP connected')

coolPhone.on('newRTCSession', (e: any) => {
    const messages = ServiceContainer.get<MessageManagerInterface>(ServiceTypes.Messages)
    messages.addAlert('New call')

    const session = e.session

    session.on('failed', this.resetLocalState)
    session.on('ended', this.resetLocalState)

    const numberRegexp = /"(d+)"/
    const fromNumber = (numberRegexp.exec(e.request.headers.From[0].raw))[1]
    const toNumber = (numberRegexp.exec(e.request.headers.Contact[0].raw))[1].slice(1)

        callReceived: true,
        callSession: session,
        fromNumber: fromNumber,
        toNumber: toNumber,


Method that handles answer button click:

private answerCall = () => {
    const messages = ServiceContainer.get<MessageManagerInterface>(ServiceTypes.Messages)
    messages.addSuccess('Call answered')

    const callOptions = {
        mediaConstraints: {
            audio: true, // only audio calls
            video: false
        pcConfig: {
            iceServers: [
                { urls: [""] }
            iceTransportPolicy: "all",
            rtcpMuxPolicy: "negotiate"


    this.state.callSession.connection.addEventListener('addstream', (event: any) => {
        this.audioElement.srcObject =

        callAnswered: true,
        callReceived: false,

What did I do wrong?


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

I solved the problem.

The problem was in the position of line.

I moved it to the callback on addstream event:

this.state.callSession.connection.addEventListener('addstream', (event: any) => {
    this.audioElement.srcObject =

Now it works fine. Hope you also find it useful.

Method 2

You can use react-sip npm library which simplifies usage of jssip inside React apps:

You will just need to pass your connection settings as props to <SipProvider/>, which will be somewhere near the top of your react tree.
This will allow you to perform basic start/stop/answer operations and watch the status of your call in the context!

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x