JsSIP interface to

View the Project on GitHub callstats-io/callstats-jssip



The main module callstatsjssip is a function that receives a JsSIP.UA instance and parameters for callstats.initialize().

The main module also exports a setCallstatsModule() function.

callstatsjssip(ua, AppID, AppSecretOrTokenGenerator, localUserID, csInitCallback, csStatsCallback, configParams)

Params Argument Type Description
ua Required JsSIP.UA JsSIP UA instance.

The rest of parameters match those in callstats.initialize(), with a small difference:


Params Argument Type Description
module Required function The callstats main module.

By default this library uses window.callstats (assuming that the library has been previously loaded via a <script> tag.

However, the library can also be loaded using loaders such as require.js meaning that it may be not exposed as a global window.callstats. In that case, callstatsjssip.setCallstatsModule() can be used to provide the callstats-jssip library with the main module.

SessionHandler class

When a JsSIP RTCSession is created, the callstats-jssip library creates an instance of SessionHandler and stores it into to make it available to the application.

The SessionHandler class provides a wrapper over the API exposed by the callstats object, making it simpler by not requiring some parameters such as the pcObject or conferenceID.


A getter that provides the already initialized callstats object.

sessionHandler.associateMstWithUserID(userID, SSRC, usageLabel, associatedVideoTag)

Arguments match those in callstats.associateMstWithUserID().

sessionHandler.reportUserIDChange(newUserID, userIDType)

Arguments match those in callstats.reportUserIDChange().

sessionHandler.sendUserFeedback(feedback, pcCallback)

Arguments match those in callstats.sendUserFeedback().


Custom conferenceID value

By default, when a new JsSIP.RTCSession is created, the Call-ID value of the incoming/outgoing INVITE request is used as callstats’s conferenceID. This won’t work in case the SIP server is a B2BUA that handles a different Call-ID for each peer within the same call/conference. In that case, the application can set a custom conferenceID by setting as follows:

// Create a JsSIP.UA instance
var ua = new JsSIP.UA(config);

// Run it

// Set custom conferenceID for created sessions
ua.on('newRTCSession', function(data) {
  var session = data.session;

  // Read our desired conferenceID from a custom X-Conference-ID set by the server = session.getHeader('X-Conference-ID');

// Run the callstats-jssip library for this UA
callstatsjssip(ua, AppID, AppSecret);