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. /* global config, $, APP, Strophe, callstats */
  2. var callStats = null;
  3. function initCallback (err, msg) {
  4. console.log("Initializing Status: err="+err+" msg="+msg);
  5. }
  6. var CallStats = {
  7. init: function (jingleSession) {
  8. if(!config.callStatsID || !config.callStatsSecret || callStats !== null)
  9. return;
  10. callStats = new callstats($,io,jsSHA);
  11. this.session = jingleSession;
  12. this.peerconnection = jingleSession.peerconnection.peerconnection;
  13. this.userID = APP.xmpp.myResource();
  14. var location = window.location;
  15. this.confID = location.protocol + "//" +
  16. location.hostname + location.pathname;
  17. //userID is generated or given by the origin server
  18. callStats.initialize(config.callStatsID,
  19. config.callStatsSecret,
  20. this.userID,
  21. initCallback);
  22. var 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. event = (mute? callStats.fabricEvent.videoPause :
  42. callStats.fabricEvent.videoResume);
  43. }
  44. else {
  45. event = (mute? callStats.fabricEvent.audioMute :
  46. callStats.fabricEvent.audioUnmute);
  47. }
  48. callStats.sendFabricEvent(this.peerconnection, event, this.confID);
  49. },
  50. sendTerminateEvent: function () {
  51. if(!callStats) {
  52. return;
  53. }
  54. callStats.sendFabricEvent(this.peerconnection,
  55. callStats.fabricEvent.fabricTerminated, this.confID);
  56. },
  57. sendSetupFailedEvent: function () {
  58. if(!callStats) {
  59. return;
  60. }
  61. callStats.sendFabricEvent(this.peerconnection,
  62. callStats.fabricEvent.fabricSetupFailed, this.confID);
  63. }
  64. };
  65. module.exports = CallStats;