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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 location = window.location;
  14. this.confID = location.protocol + "//" +
  15. location.hostname + location.pathname;
  16. //userID is generated or given by the origin server
  17. callStats.initialize(config.callStatsID,
  18. config.callStatsSecret,
  19. this.userID,
  20. initCallback);
  21. var usage = callStats.fabricUsage.multiplex;
  22. callStats.addNewFabric(this.peerconnection,
  23. Strophe.getResourceFromJid(jingleSession.peerjid),
  24. usage,
  25. this.confID,
  26. this.pcCallback.bind(this));
  27. },
  28. pcCallback: function (err, msg) {
  29. if(!callStats)
  30. return;
  31. console.log("Monitoring status: "+ err + " msg: " + msg);
  32. callStats.sendFabricEvent(this.peerconnection,
  33. callStats.fabricEvent.fabricSetup, this.confID);
  34. },
  35. sendMuteEvent: function (mute, type) {
  36. if(!callStats)
  37. return;
  38. var event = null;
  39. if(type === "video")
  40. {
  41. event = (mute? callStats.fabricEvent.videoPause :
  42. callStats.fabricEvent.videoResume);
  43. }
  44. else
  45. {
  46. event = (mute? callStats.fabricEvent.audioMute :
  47. callStats.fabricEvent.audioUnmute);
  48. }
  49. callStats.sendFabricEvent(this.peerconnection, event, this.confID);
  50. },
  51. sendTerminateEvent: function () {
  52. if(!callStats)
  53. return;
  54. callStats.sendFabricEvent(this.peerconnection,
  55. callStats.fabricEvent.fabricTerminated, this.confID);
  56. },
  57. sendSetupFailedEvent: function () {
  58. if(!callStats)
  59. return;
  60. callStats.sendFabricEvent(this.peerconnection,
  61. callStats.fabricEvent.fabricSetupFailed, this.confID);
  62. }
  63. };
  64. module.exports = CallStats;