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.

AnalyticsEvents.js 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  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. * The "action" value for Jingle events which indicates that a session-initiate
  64. * not arrived within a timeout (the value is specified in
  65. * the {@link JingleSessionPC}.
  66. * @type {string}
  67. */
  68. export const ACTION_JINGLE_SI_TIMEOUT = 'session-initiate.timeout';
  69. /**
  70. * A constant for the "terminate" action for Jingle events. TODO: verify/fix
  71. * the documentation)
  72. * @type {string}
  73. */
  74. export const ACTION_JINGLE_TERMINATE = 'terminate';
  75. /**
  76. * The "action" value for Jingle events which indicates that a transport-replace
  77. * was received.
  78. * @type {string}
  79. */
  80. export const ACTION_JINGLE_TR_RECEIVED
  81. = 'transport-replace.received';
  82. /**
  83. * The "action" value for Jingle events which indicates that a transport-replace
  84. * succeeded (TODO: verify/fix the documentation)
  85. * @type {string}
  86. */
  87. export const ACTION_JINGLE_TR_SUCCESS
  88. = 'transport-replace.success';
  89. /**
  90. * The "action" value for P2P events which indicates that a connection was
  91. * established (TODO: verify/fix the documentation)
  92. * @type {string}
  93. */
  94. export const ACTION_P2P_ESTABLISHED = 'established';
  95. /**
  96. * The "action" value for P2P events which indicates that something failed.
  97. * @type {string}
  98. */
  99. export const ACTION_P2P_FAILED = 'failed';
  100. /**
  101. * The "action" value for P2P events which indicates that a switch to
  102. * jitsi-videobridge happened.
  103. * @type {string}
  104. */
  105. export const ACTION_P2P_SWITCH_TO_JVB = 'switch.to.jvb';
  106. /**
  107. * The name of an event which indicates an available device. We send one such
  108. * event per available device once when the available devices are first known,
  109. * and every time that they change
  110. * @type {string}
  111. *
  112. * Properties:
  113. * audio_input_device_count: the number of audio input devices available at
  114. * the time the event was sent.
  115. * audio_output_device_count: the number of audio output devices available
  116. * at the time the event was sent.
  117. * video_input_device_count: the number of video input devices available at
  118. * the time the event was sent.
  119. * video_output_device_count: the number of video output devices available
  120. * at the time the event was sent.
  121. * device_id: an identifier of the device described in this event.
  122. * device_group_id:
  123. * device_kind: one of 'audioinput', 'audiooutput', 'videoinput' or
  124. * 'videooutput'.
  125. * device_label: a string which describes the device.
  126. */
  127. export const AVAILABLE_DEVICE = 'available.device';
  128. /**
  129. * This appears to be fired only in certain cases when the XMPP connection
  130. * disconnects (and it was intentional?). It is currently never observed to
  131. * fire in production.
  132. *
  133. * TODO: document
  134. *
  135. * Properties:
  136. * message: an error message
  137. */
  138. export const CONNECTION_DISCONNECTED = 'connection.disconnected';
  139. /**
  140. * Indicates that the user of the application provided feedback in terms of a
  141. * rating (an integer from 1 to 5) and an optional comment.
  142. * Properties:
  143. * value: the user's rating (an integer from 1 to 5)
  144. * comment: the user's comment
  145. */
  146. export const FEEDBACK = 'feedback';
  147. /**
  148. * Indicates the duration of a particular phase of the ICE connectivity
  149. * establishment.
  150. *
  151. * Properties:
  152. * phase: the ICE phase (e.g. 'gathering', 'checking', 'establishment')
  153. * value: the duration in milliseconds.
  154. * p2p: whether the associated ICE connection is p2p or towards a
  155. * jitsi-videobridge
  156. * initiator: whether the local Jingle peer is the initiator or responder
  157. * in the Jingle session. XXX we probably actually care about the ICE
  158. * role (controlling vs controlled), and we assume that this correlates
  159. * with the Jingle initiator.
  160. */
  161. export const ICE_DURATION = 'ice.duration';
  162. /**
  163. * Indicates the difference in milliseconds between the ICE establishment time
  164. * for the P2P and JVB connections (e.g. a value of 10 would indicate that the
  165. * P2P connection took 10ms more than JVB connection to establish).
  166. *
  167. * Properties:
  168. * value: the difference in establishment durations in milliseconds.
  169. *
  170. */
  171. export const ICE_ESTABLISHMENT_DURATION_DIFF
  172. = 'ice.establishment.duration.diff';
  173. /**
  174. * Indicates that the ICE state has changed.
  175. *
  176. * Properties:
  177. * state: the ICE state which was entered (e.g. 'checking', 'connected',
  178. * 'completed', etc).
  179. * value: the time in milliseconds (as reported by
  180. * window.performance.now()) that the state change occurred.
  181. * p2p: whether the associated ICE connection is p2p or towards a
  182. * jitsi-videobridge
  183. * signalingState: The signaling state of the associated PeerConnection
  184. * reconnect: whether the associated Jingle session is in the process of
  185. * reconnecting (or is it ICE? TODO: verify/fix the documentation)
  186. */
  187. export const ICE_STATE_CHANGED = 'ice.state.changed';
  188. /**
  189. * Indicates that no bytes have been sent for the track.
  190. *
  191. * Properties:
  192. * mediaType: the media type of the local track ('audio' or 'video').
  193. */
  194. export const NO_BYTES_SENT = 'track.no-bytes-sent';
  195. /**
  196. * Indicates that a track was unmuted (?).
  197. *
  198. * Properties:
  199. * mediaType: the media type of the local track ('audio' or 'video').
  200. * trackType: the type of the track ('local' or 'remote').
  201. * value: TODO: document
  202. */
  203. export const TRACK_UNMUTED = 'track.unmuted';
  204. /**
  205. * Creates an operational event which indicates that we have received a
  206. * "bridge down" event from jicofo.
  207. */
  208. export const createBridgeDownEvent = function() {
  209. const bridgeDown = 'bridge.down';
  210. return {
  211. action: bridgeDown,
  212. actionSubject: bridgeDown,
  213. type: TYPE_OPERATIONAL
  214. };
  215. };
  216. /**
  217. * Creates an event which indicates that the XMPP connection failed
  218. * @param errorType TODO
  219. * @param errorMessage TODO
  220. * @param detail connection failed details.
  221. */
  222. export const createConnectionFailedEvent
  223. = function(errorType, errorMessage, details) {
  224. return {
  225. type: TYPE_OPERATIONAL,
  226. action: 'connection.failed',
  227. attributes: {
  228. 'error_type': errorType,
  229. 'error_message': errorMessage,
  230. ...details
  231. }
  232. };
  233. };
  234. /**
  235. * Creates an operational event which indicates that a particular connection
  236. * stage was reached (i.e. the XMPP connection transitioned to the "connected"
  237. * state).
  238. *
  239. * @param stage the stage which was reached
  240. * @param attributes additional attributes for the event. This should be an
  241. * object with a "value" property indicating a timestamp in milliseconds
  242. * relative to the beginning of the document's lifetime.
  243. *
  244. */
  245. export const createConnectionStageReachedEvent = function(stage, attributes) {
  246. const action = 'connection.stage.reached';
  247. return {
  248. action,
  249. actionSubject: stage,
  250. attributes,
  251. source: action,
  252. type: TYPE_OPERATIONAL
  253. };
  254. };
  255. /**
  256. * Creates an operational event for the end-to-end round trip time to a
  257. * specific remote participant.
  258. * @param participantId the ID of the remote participant.
  259. * @param region the region of the remote participant
  260. * @param rtt the rtt
  261. */
  262. export const createE2eRttEvent = function(participantId, region, rtt) {
  263. const attributes = {
  264. 'participant_id': participantId,
  265. region,
  266. rtt
  267. };
  268. return {
  269. attributes,
  270. name: 'e2e_rtt',
  271. type: TYPE_OPERATIONAL
  272. };
  273. };
  274. /**
  275. * Creates an event which indicates that the focus has left the MUC.
  276. */
  277. export const createFocusLeftEvent = function() {
  278. const action = 'focus.left';
  279. return {
  280. action,
  281. actionSubject: action,
  282. type: TYPE_OPERATIONAL
  283. };
  284. };
  285. /**
  286. * Creates an event related to a getUserMedia call.
  287. *
  288. * @param action the type of the result that the event represents: 'error',
  289. * 'success', 'warning', etc.
  290. * @param attributes the attributes to attach to the event.
  291. * @returns {{type: string, source: string, name: string}}
  292. */
  293. export const createGetUserMediaEvent = function(action, attributes = {}) {
  294. return {
  295. type: TYPE_OPERATIONAL,
  296. source: 'get.user.media',
  297. action,
  298. attributes
  299. };
  300. };
  301. /**
  302. * Creates an event related to remote participant connection status changes.
  303. *
  304. * @param attributes the attributes to attach to the event.
  305. * @returns {{type: string, source: string, name: string}}
  306. */
  307. export const createParticipantConnectionStatusEvent = function(attributes = {}) {
  308. const action = 'duration';
  309. return {
  310. type: TYPE_OPERATIONAL,
  311. source: 'peer.conn.status',
  312. action,
  313. attributes
  314. };
  315. };
  316. /**
  317. * Creates an event for a Jingle-related event.
  318. * @param action the action of the event
  319. * @param attributes attributes to add to the event.
  320. */
  321. export const createJingleEvent = function(action, attributes = {}) {
  322. return {
  323. type: TYPE_OPERATIONAL,
  324. action,
  325. source: 'jingle',
  326. attributes
  327. };
  328. };
  329. /**
  330. * Creates an event which indicates that a local track was not able to read
  331. * data from its source (a camera or a microphone).
  332. *
  333. * @param mediaType {String} the media type of the local track ('audio' or
  334. * 'video').
  335. */
  336. export const createNoDataFromSourceEvent = function(mediaType, value) {
  337. return {
  338. attributes: {
  339. 'media_type': mediaType,
  340. value
  341. },
  342. action: 'track.no.data.from.source',
  343. type: TYPE_OPERATIONAL
  344. };
  345. };
  346. /**
  347. * Creates an event for a p2p-related event.
  348. * @param action the action of the event
  349. * @param attributes attributes to add to the event.
  350. */
  351. export const createP2PEvent = function(action, attributes = {}) {
  352. return {
  353. type: TYPE_OPERATIONAL,
  354. action,
  355. source: 'p2p',
  356. attributes
  357. };
  358. };
  359. /**
  360. * Indicates that we received a remote command to mute.
  361. */
  362. export const createRemotelyMutedEvent = function() {
  363. return {
  364. type: TYPE_OPERATIONAL,
  365. action: 'remotely.muted'
  366. };
  367. };
  368. /**
  369. * Creates an event which contains RTP statistics such as RTT and packet loss.
  370. *
  371. * All average RTP stats are currently reported under 1 event name, but with
  372. * different properties that allows to distinguish between a P2P call, a
  373. * call relayed through TURN or the JVB, and multiparty vs 1:1.
  374. *
  375. * The structure of the event is:
  376. *
  377. * {
  378. * p2p: true,
  379. * conferenceSize: 2,
  380. * localCandidateType: "relay",
  381. * remoteCandidateType: "relay",
  382. * transportType: "udp",
  383. *
  384. * // Average RTT of 200ms
  385. * "rtt.avg": 200,
  386. * "rtt.samples": "[100, 200, 300]",
  387. *
  388. * // Average packet loss of 10%
  389. * "packet.loss.avg": 10,
  390. * "packet.loss.samples": '[5, 10, 15]'
  391. *
  392. * // Difference in milliseconds in the end-to-end RTT between p2p and jvb.
  393. * // The e2e RTT through jvb is 15ms shorter:
  394. * "rtt.diff": 15,
  395. *
  396. * // End-to-end RTT through JVB is ms.
  397. * "end2end.rtt.avg" = 100
  398. * }
  399. *
  400. * Note that the value of the "samples" properties are (JSON encoded) strings,
  401. * and not JSON arrays, as events' attributes can not be nested. The samples are
  402. * currently included for debug purposes only and can be removed anytime soon
  403. * from the structure.
  404. *
  405. * Also note that not all of values are present in each event, as values are
  406. * obtained and calculated as part of different process/event pipe. For example
  407. * {@link ConnectionAvgStats} instances are doing the reports for each
  408. * {@link TraceablePeerConnection} and work independently from the main stats
  409. * pipe.
  410. */
  411. export const createRtpStatsEvent = function(attributes) {
  412. return {
  413. type: TYPE_OPERATIONAL,
  414. action: 'rtp.stats',
  415. attributes
  416. };
  417. };
  418. /**
  419. * Creates an event which contains the round trip time (RTT) to a set of
  420. * regions.
  421. *
  422. * @param attributes
  423. * @returns {{type: string, action: string, attributes: *}}
  424. */
  425. export const createRttByRegionEvent = function(attributes) {
  426. return {
  427. type: TYPE_OPERATIONAL,
  428. action: 'rtt.by.region',
  429. attributes
  430. };
  431. };
  432. /**
  433. * Creates an event which contains information about the audio output problem (the user id of the affected participant,
  434. * the local audio levels and the remote audio levels that triggered the event).
  435. *
  436. * @param {string} userID - The user id of the affected participant.
  437. * @param {*} localAudioLevel - The local audio levels.
  438. * @param {*} remoteAudioLevels - The audio levels received from the participant.
  439. */
  440. export function createAudioOutputProblemEvent(userID, localAudioLevel, remoteAudioLevels) {
  441. return {
  442. type: TYPE_OPERATIONAL,
  443. action: 'audio.output.problem',
  444. attributes: {
  445. userID,
  446. localAudioLevel,
  447. remoteAudioLevels
  448. }
  449. };
  450. }
  451. /**
  452. * Creates an event which contains an information related to the bridge channel close event.
  453. *
  454. * @param {string} code - A code from {@link https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent}
  455. * @param {string} reason - A string which describes the reason for closing the bridge channel.
  456. * @returns {{type: string, action: string, attributes: { code: string, reason: string }}}
  457. */
  458. export const createBridgeChannelClosedEvent = function(code, reason) {
  459. return {
  460. type: TYPE_OPERATIONAL,
  461. action: 'bridge-channel.error',
  462. attributes: {
  463. code,
  464. reason
  465. }
  466. };
  467. };
  468. /**
  469. * Creates an event which indicates the Time To First Media (TTFM).
  470. * It is measured in milliseconds relative to the beginning of the document's
  471. * lifetime (i.e. the origin used by window.performance.now()), and it excludes
  472. * the following:
  473. * 1. The delay due to getUserMedia()
  474. * 2. The period between the MUC being joined and the reception of the Jingle
  475. * session-initiate from jicofo. This is because jicofo will not start a Jingle
  476. * session until there are at least 2 participants in the room.
  477. *
  478. * @param attributes the attributes to add to the event. Currently used fields:
  479. * mediaType: the media type of the local track ('audio' or 'video').
  480. * muted: whether the track has ever been muted (?)
  481. * value: the TTMF in milliseconds.
  482. */
  483. export const createTtfmEvent = function(attributes) {
  484. return createConnectionStageReachedEvent('ttfm', attributes);
  485. };