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 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. // getUserMedia calls happen before CallStats init
  7. // so if there are any getUserMedia errors, we store them in this array
  8. // and send them to callstats on init
  9. var pendingUserMediaErrors = [];
  10. function initCallback (err, msg) {
  11. console.log("Initializing Status: err="+err+" msg="+msg);
  12. }
  13. var CallStats = {
  14. init: function (jingleSession) {
  15. if(!config.callStatsID || !config.callStatsSecret || callStats !== null)
  16. return;
  17. callStats = new callstats($, io, jsSHA);
  18. this.session = jingleSession;
  19. this.peerconnection = jingleSession.peerconnection.peerconnection;
  20. this.userID = Settings.getCallStatsUserName();
  21. var location = window.location;
  22. this.confID = location.hostname + location.pathname;
  23. //userID is generated or given by the origin server
  24. callStats.initialize(config.callStatsID,
  25. config.callStatsSecret,
  26. this.userID,
  27. initCallback);
  28. var usage = callStats.fabricUsage.multiplex;
  29. callStats.addNewFabric(this.peerconnection,
  30. Strophe.getResourceFromJid(jingleSession.peerjid),
  31. usage,
  32. this.confID,
  33. this.pcCallback.bind(this));
  34. // notify callstats about getUserMedia failures if there were any
  35. if (pendingUserMediaErrors.length) {
  36. pendingUserMediaErrors.forEach(this.sendGetUserMediaFailed, this);
  37. pendingUserMediaErrors.length = 0;
  38. }
  39. },
  40. pcCallback: function (err, msg) {
  41. if (!callStats) {
  42. return;
  43. }
  44. console.log("Monitoring status: "+ err + " msg: " + msg);
  45. callStats.sendFabricEvent(this.peerconnection,
  46. callStats.fabricEvent.fabricSetup, this.confID);
  47. },
  48. sendMuteEvent: function (mute, type) {
  49. if (!callStats) {
  50. return;
  51. }
  52. var event = null;
  53. if (type === "video") {
  54. event = (mute? callStats.fabricEvent.videoPause :
  55. callStats.fabricEvent.videoResume);
  56. }
  57. else {
  58. event = (mute? callStats.fabricEvent.audioMute :
  59. callStats.fabricEvent.audioUnmute);
  60. }
  61. callStats.sendFabricEvent(this.peerconnection, event, this.confID);
  62. },
  63. sendTerminateEvent: function () {
  64. if(!callStats) {
  65. return;
  66. }
  67. callStats.sendFabricEvent(this.peerconnection,
  68. callStats.fabricEvent.fabricTerminated, this.confID);
  69. },
  70. sendSetupFailedEvent: function () {
  71. if(!callStats) {
  72. return;
  73. }
  74. callStats.sendFabricEvent(this.peerconnection,
  75. callStats.fabricEvent.fabricSetupFailed, this.confID);
  76. },
  77. /**
  78. * Sends the given feedback through CallStats.
  79. *
  80. * @param overallFeedback an integer between 1 and 5 indicating the
  81. * user feedback
  82. * @param detailedFeedback detailed feedback from the user. Not yet used
  83. */
  84. sendFeedback: function(overallFeedback, detailedFeedback) {
  85. if(!callStats) {
  86. return;
  87. }
  88. var feedbackString = '{"userID":"' + this.userID + '"' +
  89. ', "overall":' + overallFeedback +
  90. ', "comment": "' + detailedFeedback + '"}';
  91. var feedbackJSON = JSON.parse(feedbackString);
  92. callStats.sendUserFeedback(
  93. this.confID, feedbackJSON);
  94. },
  95. /**
  96. * Notifies CallStats that getUserMedia failed.
  97. *
  98. * @param {Error} e error to send
  99. */
  100. sendGetUserMediaFailed: function (e) {
  101. if(!callStats) {
  102. pendingUserMediaErrors.push(e);
  103. return;
  104. }
  105. callStats.reportError(this.peerconnection, this.confID,
  106. callStats.webRTCFunctions.getUserMedia, e);
  107. },
  108. /**
  109. * Notifies CallStats that peer connection failed to create offer.
  110. *
  111. * @param {Error} e error to send
  112. */
  113. sendCreateOfferFailed: function (e) {
  114. if(!callStats) {
  115. return;
  116. }
  117. callStats.reportError(this.peerconnection, this.confID,
  118. callStats.webRTCFunctions.createOffer, e);
  119. },
  120. /**
  121. * Notifies CallStats that peer connection failed to create answer.
  122. *
  123. * @param {Error} e error to send
  124. */
  125. sendCreateAnswerFailed: function (e) {
  126. if(!callStats) {
  127. return;
  128. }
  129. callStats.reportError(this.peerconnection, this.confID,
  130. callStats.webRTCFunctions.createAnswer, e);
  131. },
  132. /**
  133. * Notifies CallStats that peer connection failed to set local description.
  134. *
  135. * @param {Error} e error to send
  136. */
  137. sendSetLocalDescFailed: function (e) {
  138. if(!callStats) {
  139. return;
  140. }
  141. callStats.reportError(this.peerconnection, this.confID,
  142. callStats.webRTCFunctions.setLocalDescription, e);
  143. },
  144. /**
  145. * Notifies CallStats that peer connection failed to set remote description.
  146. *
  147. * @param {Error} e error to send
  148. */
  149. sendSetRemoteDescFailed: function (e) {
  150. if(!callStats) {
  151. return;
  152. }
  153. callStats.reportError(
  154. this.peerconnection, this.confID,
  155. callStats.webRTCFunctions.setRemoteDescription, e);
  156. },
  157. /**
  158. * Notifies CallStats that peer connection failed to add ICE candidate.
  159. *
  160. * @param {Error} e error to send
  161. */
  162. sendAddIceCandidateFailed: function (e) {
  163. if(!callStats) {
  164. return;
  165. }
  166. callStats.reportError(this.peerconnection, this.confID,
  167. callStats.webRTCFunctions.addIceCandidate, e);
  168. }
  169. };
  170. module.exports = CallStats;