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.5KB

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