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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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.unbundled;
  22. if(config.useBundle)
  23. usage = callStats.fabricUsage.multiplex;
  24. callStats.addNewFabric(this.peerconnection,
  25. Strophe.getResourceFromJid(jingleSession.peerjid),
  26. usage,
  27. this.confID,
  28. this.pcCallback.bind(this));
  29. },
  30. pcCallback: function (err, msg) {
  31. if(!callStats)
  32. return;
  33. console.log("Monitoring status: "+ err + " msg: " + msg);
  34. callStats.sendFabricEvent(this.peerconnection,
  35. callStats.fabricEvent.fabricSetup, this.confID);
  36. },
  37. sendMuteEvent: function (mute, type) {
  38. if(!callStats)
  39. return;
  40. var event = null;
  41. if(type === "video")
  42. {
  43. event = (mute? callStats.fabricEvent.videoPause :
  44. callStats.fabricEvent.videoResume);
  45. }
  46. else
  47. {
  48. event = (mute? callStats.fabricEvent.audioMute :
  49. callStats.fabricEvent.audioUnmute);
  50. }
  51. callStats.sendFabricEvent(this.peerconnection, event, this.confID);
  52. },
  53. sendTerminateEvent: function () {
  54. if(!callStats)
  55. return;
  56. callStats.sendFabricEvent(this.peerconnection,
  57. callStats.fabricEvent.fabricTerminated, this.confID);
  58. },
  59. sendSetupFailedEvent: function () {
  60. if(!callStats)
  61. return;
  62. callStats.sendFabricEvent(this.peerconnection,
  63. callStats.fabricEvent.fabricSetupFailed, this.confID);
  64. }
  65. };
  66. module.exports = CallStats;