You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CallStats.js 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. var callStats = null;
  2. function initCallback (err, msg) {
  3. console.log("Initializing Status: err="+err+" msg="+msg);
  4. }
  5. var CallStats = {
  6. init: function (jingleSession) {
  7. if(!config.callStatsID || !config.callStatsSecret || callStats !== null)
  8. return;
  9. callStats = new callstats($,io,jsSHA);
  10. this.session = jingleSession;
  11. this.peerconnection = jingleSession.peerconnection.peerconnection;
  12. this.userID = APP.xmpp.myResource();
  13. var roomJid = APP.UI.getRoomName();
  14. this.confID = roomJid? Strophe.getNodeFromJid(roomJid) : null;
  15. //userID is generated or given by the origin server
  16. callStats.initialize(config.callStatsID,
  17. config.callStatsSecret,
  18. this.userID,
  19. initCallback);
  20. var usage = callStats.fabricUsage.unbundled;
  21. if(config.useBundle)
  22. usage = callStats.fabricUsage.multiplex;
  23. callStats.addNewFabric(this.peerconnection,
  24. Strophe.getResourceFromJid(jingleSession.peerjid),
  25. usage,
  26. this.confID,
  27. this.pcCallback.bind(this));
  28. },
  29. pcCallback: function (err, msg) {
  30. if(!callStats)
  31. return;
  32. console.log("Monitoring status: "+ err + " msg: " + msg);
  33. callStats.sendFabricEvent(this.peerconnection,
  34. callStats.fabricEvent.fabricSetup, this.confID);
  35. },
  36. sendMuteEvent: function (mute, type) {
  37. if(!callStats)
  38. return;
  39. var event = null;
  40. if(type === "video")
  41. {
  42. event = (mute? callStats.fabricEvent.videoPause :
  43. callStats.fabricEvent.videoResume);
  44. }
  45. else
  46. {
  47. event = (mute? callStats.fabricEvent.audioMute :
  48. callStats.fabricEvent.audioUnmute);
  49. }
  50. callStats.sendFabricEvent(this.peerconnection, event, this.confID);
  51. },
  52. sendTerminateEvent: function () {
  53. if(!callStats)
  54. return;
  55. callStats.sendFabricEvent(this.peerconnection,
  56. callStats.fabricEvent.fabricTerminated, this.confID);
  57. },
  58. sendSetupFailedEvent: function () {
  59. if(!callStats)
  60. return;
  61. callStats.sendFabricEvent(this.peerconnection,
  62. callStats.fabricEvent.fabricSetupFailed, this.confID);
  63. }
  64. };
  65. module.exports = CallStats;