Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

AnalyticsEvents.js 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. /**
  2. * This class exports constants and factory methods related to the analytics
  3. * API provided by AnalyticsAdapter. In order for entries in a database to be
  4. * somewhat easily traceable back to the code which produced them, events sent
  5. * through analytics should be defined here.
  6. *
  7. * Since the AnalyticsAdapter API can be used in different ways, for some events
  8. * it is more convenient to just define the event name as a constant. For other
  9. * events a factory function is easier.
  10. *
  11. * A general approach for adding a new event:
  12. * 1. Determine the event type: track, UI, page, or operational. If in doubt use
  13. * operational.
  14. * 2. Determine whether the event is related to other existing events, and
  15. * which fields are desired to be set: name, action, actionSubject, source.
  16. * 3. If the name is sufficient (the other fields are not important), use a
  17. * constant. Otherwise use a factory function.
  18. *
  19. * Note that the AnalyticsAdapter uses the events passed to its functions for
  20. * its own purposes, and might modify them. Because of this factory functions
  21. * should create new objects.
  22. *
  23. */
  24. /**
  25. * The constant which identifies an event of type "operational".
  26. * @type {string}
  27. */
  28. export const TYPE_OPERATIONAL = 'operational';
  29. /**
  30. * The constant which identifies an event of type "page".
  31. * @type {string}
  32. */
  33. export const TYPE_PAGE = 'page';
  34. /**
  35. * The constant which identifies an event of type "track".
  36. * @type {string}
  37. */
  38. export const TYPE_TRACK = 'track';
  39. /**
  40. * The constant which identifies an event of type "ui".
  41. * @type {string}
  42. */
  43. export const TYPE_UI = 'ui';
  44. /**
  45. * The "action" value for Jingle events which indicates that the Jingle session
  46. * was restarted (TODO: verify/fix the documentation)
  47. * @type {string}
  48. */
  49. export const ACTION_JINGLE_RESTART = 'restart';
  50. /**
  51. * The "action" value for Jingle events which indicates that a session-accept
  52. * timed out (TODO: verify/fix the documentation)
  53. * @type {string}
  54. */
  55. export const ACTION_JINGLE_SA_TIMEOUT = 'session-accept.timeout';
  56. /**
  57. * The "action" value for Jingle events which indicates that a session-initiate
  58. * was received.
  59. * @type {string}
  60. */
  61. export const ACTION_JINGLE_SI_RECEIVED = 'session-initiate.received';
  62. /**
  63. * A constant for the "terminate" action for Jingle events. TODO: verify/fix
  64. * the documentation)
  65. * @type {string}
  66. */
  67. export const ACTION_JINGLE_TERMINATE = 'terminate';
  68. /**
  69. * The "action" value for Jingle events which indicates that a transport-replace
  70. * was received.
  71. * @type {string}
  72. */
  73. export const ACTION_JINGLE_TR_RECEIVED
  74. = 'transport-replace.received';
  75. /**
  76. * The "action" value for Jingle events which indicates that a transport-replace
  77. * succeeded (TODO: verify/fix the documentation)
  78. * @type {string}
  79. */
  80. export const ACTION_JINGLE_TR_SUCCESS
  81. = 'transport-replace.success';
  82. /**
  83. * The "action" value for P2P events which indicates that a connection was
  84. * established (TODO: verify/fix the documentation)
  85. * @type {string}
  86. */
  87. export const ACTION_P2P_ESTABLISHED = 'established';
  88. /**
  89. * The "action" value for P2P events which indicates that something failed.
  90. * @type {string}
  91. */
  92. export const ACTION_P2P_FAILED = 'failed';
  93. /**
  94. * The "action" value for P2P events which indicates that a switch to
  95. * jitsi-videobridge happened.
  96. * @type {string}
  97. */
  98. export const ACTION_P2P_SWITCH_TO_JVB = 'switch.to.jvb';
  99. /**
  100. * The name of an event which indicates an available device. We send one such
  101. * event per available device once when the available devices are first known,
  102. * and every time that they change
  103. * @type {string}
  104. *
  105. * Properties:
  106. * audio_input_device_count: the number of audio input devices available at
  107. * the time the event was sent.
  108. * audio_output_device_count: the number of audio output devices available
  109. * at the time the event was sent.
  110. * video_input_device_count: the number of video input devices available at
  111. * the time the event was sent.
  112. * video_output_device_count: the number of video output devices available
  113. * at the time the event was sent.
  114. * device_id: an identifier of the device described in this event.
  115. * device_group_id:
  116. * device_kind: one of 'audioinput', 'audiooutput', 'videoinput' or
  117. * 'videooutput'.
  118. * device_label: a string which describes the device.
  119. */
  120. export const AVAILABLE_DEVICE = 'available.device';
  121. /**
  122. * This appears to be fired only in certain cases when the XMPP connection
  123. * disconnects (and it was intentional?). It is currently never observed to
  124. * fire in production.
  125. *
  126. * TODO: document
  127. *
  128. * Properties:
  129. * message: an error message
  130. */
  131. export const CONNECTION_DISCONNECTED = 'connection.disconnected';
  132. /**
  133. * Indicates that the user of the application provided feedback in terms of a
  134. * rating (an integer from 1 to 5) and an optional comment.
  135. * Properties:
  136. * value: the user's rating (an integer from 1 to 5)
  137. * comment: the user's comment
  138. */
  139. export const FEEDBACK = 'feedback';
  140. /**
  141. * Indicates the duration of a particular phase of the ICE connectivity
  142. * establishment.
  143. *
  144. * Properties:
  145. * phase: the ICE phase (e.g. 'gathering', 'checking', 'establishment')
  146. * value: the duration in milliseconds.
  147. * p2p: whether the associated ICE connection is p2p or towards a
  148. * jitsi-videobridge
  149. * initiator: whether the local Jingle peer is the initiator or responder
  150. * in the Jingle session. XXX we probably actually care about the ICE
  151. * role (controlling vs controlled), and we assume that this correlates
  152. * with the Jingle initiator.
  153. */
  154. export const ICE_DURATION = 'ice.duration';
  155. /**
  156. * Indicates the difference in milliseconds between the ICE establishment time
  157. * for the P2P and JVB connections (e.g. a value of 10 would indicate that the
  158. * P2P connection took 10ms more than JVB connection to establish).
  159. *
  160. * Properties:
  161. * value: the difference in establishment durations in milliseconds.
  162. *
  163. */
  164. export const ICE_ESTABLISHMENT_DURATION_DIFF
  165. = 'ice.establishment.duration.diff';
  166. /**
  167. * Indicates that the ICE state has changed.
  168. *
  169. * Properties:
  170. * state: the ICE state which was entered (e.g. 'checking', 'connected',
  171. * 'completed', etc).
  172. * value: the time in milliseconds (as reported by
  173. * window.performance.now()) that the state change occurred.
  174. * p2p: whether the associated ICE connection is p2p or towards a
  175. * jitsi-videobridge
  176. * signalingState: The signaling state of the associated PeerConnection
  177. * reconnect: whether the associated Jingle session is in the process of
  178. * reconnecting (or is it ICE? TODO: verify/fix the documentation)
  179. */
  180. export const ICE_STATE_CHANGED = 'ice.state.changed';
  181. /**
  182. * Indicates that a track was unmuted (?).
  183. *
  184. * Properties:
  185. * mediaType: the media type of the local track ('audio' or 'video').
  186. * trackType: the type of the track ('local' or 'remote').
  187. * value: TODO: document
  188. */
  189. export const TRACK_UNMUTED = 'track.unmuted';
  190. /**
  191. * Creates an operational event which indicates that we have received a
  192. * "bridge down" event from jicofo.
  193. */
  194. export const createBridgeDownEvent = function() {
  195. const bridgeDown = 'bridge.down';
  196. return {
  197. action: bridgeDown,
  198. actionSubject: bridgeDown,
  199. type: TYPE_OPERATIONAL
  200. };
  201. };
  202. /**
  203. * Creates an event which indicates that the XMPP connection failed
  204. * @param errorType TODO
  205. * @param errorMessage TODO
  206. * @param detail connection failed details.
  207. */
  208. export const createConnectionFailedEvent
  209. = function(errorType, errorMessage, details) {
  210. return {
  211. type: TYPE_OPERATIONAL,
  212. action: 'connection.failed',
  213. attributes: {
  214. 'error_type': errorType,
  215. 'error_message': errorMessage,
  216. ...details
  217. }
  218. };
  219. };
  220. /**
  221. * Creates an operational event which indicates that a particular connection
  222. * stage was reached (i.e. the XMPP connection transitioned to the "connected"
  223. * state).
  224. *
  225. * @param stage the stage which was reached
  226. * @param attributes additional attributes for the event. This should be an
  227. * object with a "value" property indicating a timestamp in milliseconds
  228. * relative to the beginning of the document's lifetime.
  229. *
  230. */
  231. export const createConnectionStageReachedEvent = function(stage, attributes) {
  232. const action = 'connection.stage.reached';
  233. return {
  234. action,
  235. actionSubject: stage,
  236. attributes,
  237. source: action,
  238. type: TYPE_OPERATIONAL
  239. };
  240. };
  241. /**
  242. * Creates an event which indicates that the focus has left the MUC.
  243. */
  244. export const createFocusLeftEvent = function() {
  245. const action = 'focus.left';
  246. return {
  247. action,
  248. actionSubject: action,
  249. type: TYPE_OPERATIONAL
  250. };
  251. };
  252. /**
  253. * Creates an event related to a getUserMedia call.
  254. *
  255. * @param action the type of the result that the event represents: 'error',
  256. * 'success', 'warning', etc.
  257. * @param attributes the attributes to attach to the event.
  258. * @returns {{type: string, source: string, name: string}}
  259. */
  260. export const createGetUserMediaEvent = function(action, attributes = {}) {
  261. return {
  262. type: TYPE_OPERATIONAL,
  263. source: 'get.user.media',
  264. action,
  265. attributes
  266. };
  267. };
  268. /**
  269. * Creates an event for a Jingle-related event.
  270. * @param action the action of the event
  271. * @param attributes attributes to add to the event.
  272. */
  273. export const createJingleEvent = function(action, attributes = {}) {
  274. return {
  275. type: TYPE_OPERATIONAL,
  276. action,
  277. source: 'jingle',
  278. attributes
  279. };
  280. };
  281. /**
  282. * Creates an event which indicates that a local track was not able to read
  283. * data from its source (a camera or a microphone).
  284. *
  285. * @param mediaType {String} the media type of the local track ('audio' or
  286. * 'video').
  287. */
  288. export const createNoDataFromSourceEvent = function(mediaType) {
  289. return {
  290. attributes: { 'media_type': mediaType },
  291. action: 'track.no.data.from.source',
  292. type: TYPE_OPERATIONAL
  293. };
  294. };
  295. /**
  296. * Creates an event for a p2p-related event.
  297. * @param action the action of the event
  298. * @param attributes attributes to add to the event.
  299. */
  300. export const createP2PEvent = function(action, attributes = {}) {
  301. return {
  302. type: TYPE_OPERATIONAL,
  303. action,
  304. source: 'p2p',
  305. attributes
  306. };
  307. };
  308. /**
  309. * Indicates that we received a remote command to mute.
  310. */
  311. export const createRemotelyMutedEvent = function() {
  312. return {
  313. type: TYPE_OPERATIONAL,
  314. action: 'remotely.muted'
  315. };
  316. };
  317. /**
  318. * Creates an event which contains RTP statistics such as RTT and packet loss.
  319. *
  320. * All average RTP stats are currently reported under 1 event name, but with
  321. * different properties that allows to distinguish between a P2P call, a
  322. * call relayed through TURN or the JVB, and multiparty vs 1:1.
  323. *
  324. * The structure of the event is:
  325. *
  326. * {
  327. * p2p: true,
  328. * conferenceSize: 2,
  329. * localCandidateType: "relay",
  330. * remoteCandidateType: "relay",
  331. * transportType: "udp",
  332. *
  333. * // Average RTT of 200ms
  334. * "rtt.avg": 200,
  335. * "rtt.samples": "[100, 200, 300]",
  336. *
  337. * // Average packet loss of 10%
  338. * "packet.loss.avg": 10,
  339. * "packet.loss.samples": '[5, 10, 15]'
  340. *
  341. * // Difference in milliseconds in the end-to-end RTT between p2p and jvb.
  342. * // The e2e RTT through jvb is 15ms shorter:
  343. * "rtt.diff": 15,
  344. *
  345. * // End-to-end RTT through JVB is ms.
  346. * "end2end.rtt.avg" = 100
  347. * }
  348. *
  349. * Note that the value of the "samples" properties are (JSON encoded) strings,
  350. * and not JSON arrays, as events' attributes can not be nested. The samples are
  351. * currently included for debug purposes only and can be removed anytime soon
  352. * from the structure.
  353. *
  354. * Also note that not all of values are present in each event, as values are
  355. * obtained and calculated as part of different process/event pipe. For example
  356. * {@link ConnectionAvgStats} instances are doing the reports for each
  357. * {@link TraceablePeerConnection} and work independently from the main stats
  358. * pipe.
  359. */
  360. export const createRtpStatsEvent = function(attributes) {
  361. return {
  362. type: TYPE_OPERATIONAL,
  363. action: 'rtp.stats',
  364. attributes
  365. };
  366. };
  367. /**
  368. * Creates an event which indicates the Time To First Media (TTFM).
  369. * It is measured in milliseconds relative to the beginning of the document's
  370. * lifetime (i.e. the origin used by window.performance.now()), and it excludes
  371. * the following:
  372. * 1. The delay due to getUserMedia()
  373. * 2. The period between the MUC being joined and the reception of the Jingle
  374. * session-initiate from jicofo. This is because jicofo will not start a Jingle
  375. * session until there are at least 2 participants in the room.
  376. *
  377. * @param attributes the attributes to add to the event. Currently used fields:
  378. * mediaType: the media type of the local track ('audio' or 'video').
  379. * muted: whether the track has ever been muted (?)
  380. * value: the TTMF in milliseconds.
  381. */
  382. export const createTtfmEvent = function(attributes) {
  383. return createConnectionStageReachedEvent('ttfm', attributes);
  384. };