modified lib-jitsi-meet dev repo
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 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  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 for a Jingle-related event.
  303. * @param action the action of the event
  304. * @param attributes attributes to add to the event.
  305. */
  306. export const createJingleEvent = function(action, attributes = {}) {
  307. return {
  308. type: TYPE_OPERATIONAL,
  309. action,
  310. source: 'jingle',
  311. attributes
  312. };
  313. };
  314. /**
  315. * Creates an event which indicates that a local track was not able to read
  316. * data from its source (a camera or a microphone).
  317. *
  318. * @param mediaType {String} the media type of the local track ('audio' or
  319. * 'video').
  320. */
  321. export const createNoDataFromSourceEvent = function(mediaType, value) {
  322. return {
  323. attributes: {
  324. 'media_type': mediaType,
  325. value
  326. },
  327. action: 'track.no.data.from.source',
  328. type: TYPE_OPERATIONAL
  329. };
  330. };
  331. /**
  332. * Creates an event for a p2p-related event.
  333. * @param action the action of the event
  334. * @param attributes attributes to add to the event.
  335. */
  336. export const createP2PEvent = function(action, attributes = {}) {
  337. return {
  338. type: TYPE_OPERATIONAL,
  339. action,
  340. source: 'p2p',
  341. attributes
  342. };
  343. };
  344. /**
  345. * Indicates that we received a remote command to mute.
  346. */
  347. export const createRemotelyMutedEvent = function() {
  348. return {
  349. type: TYPE_OPERATIONAL,
  350. action: 'remotely.muted'
  351. };
  352. };
  353. /**
  354. * Creates an event which contains RTP statistics such as RTT and packet loss.
  355. *
  356. * All average RTP stats are currently reported under 1 event name, but with
  357. * different properties that allows to distinguish between a P2P call, a
  358. * call relayed through TURN or the JVB, and multiparty vs 1:1.
  359. *
  360. * The structure of the event is:
  361. *
  362. * {
  363. * p2p: true,
  364. * conferenceSize: 2,
  365. * localCandidateType: "relay",
  366. * remoteCandidateType: "relay",
  367. * transportType: "udp",
  368. *
  369. * // Average RTT of 200ms
  370. * "rtt.avg": 200,
  371. * "rtt.samples": "[100, 200, 300]",
  372. *
  373. * // Average packet loss of 10%
  374. * "packet.loss.avg": 10,
  375. * "packet.loss.samples": '[5, 10, 15]'
  376. *
  377. * // Difference in milliseconds in the end-to-end RTT between p2p and jvb.
  378. * // The e2e RTT through jvb is 15ms shorter:
  379. * "rtt.diff": 15,
  380. *
  381. * // End-to-end RTT through JVB is ms.
  382. * "end2end.rtt.avg" = 100
  383. * }
  384. *
  385. * Note that the value of the "samples" properties are (JSON encoded) strings,
  386. * and not JSON arrays, as events' attributes can not be nested. The samples are
  387. * currently included for debug purposes only and can be removed anytime soon
  388. * from the structure.
  389. *
  390. * Also note that not all of values are present in each event, as values are
  391. * obtained and calculated as part of different process/event pipe. For example
  392. * {@link ConnectionAvgStats} instances are doing the reports for each
  393. * {@link TraceablePeerConnection} and work independently from the main stats
  394. * pipe.
  395. */
  396. export const createRtpStatsEvent = function(attributes) {
  397. return {
  398. type: TYPE_OPERATIONAL,
  399. action: 'rtp.stats',
  400. attributes
  401. };
  402. };
  403. /**
  404. * Creates an event which contains the round trip time (RTT) to a set of
  405. * regions.
  406. *
  407. * @param attributes
  408. * @returns {{type: string, action: string, attributes: *}}
  409. */
  410. export const createRttByRegionEvent = function(attributes) {
  411. return {
  412. type: TYPE_OPERATIONAL,
  413. action: 'rtt.by.region',
  414. attributes
  415. };
  416. };
  417. /**
  418. * Creates an event which contains an information related to the bridge channel close event.
  419. *
  420. * @param {string} code - A code from {@link https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent}
  421. * @param {string} reason - A string which describes the reason for closing the bridge channel.
  422. * @returns {{type: string, action: string, attributes: { code: string, reason: string }}}
  423. */
  424. export const createBridgeChannelClosedEvent = function(code, reason) {
  425. return {
  426. type: TYPE_OPERATIONAL,
  427. action: 'bridge-channel.error',
  428. attributes: {
  429. code,
  430. reason
  431. }
  432. };
  433. };
  434. /**
  435. * Creates an event which indicates the Time To First Media (TTFM).
  436. * It is measured in milliseconds relative to the beginning of the document's
  437. * lifetime (i.e. the origin used by window.performance.now()), and it excludes
  438. * the following:
  439. * 1. The delay due to getUserMedia()
  440. * 2. The period between the MUC being joined and the reception of the Jingle
  441. * session-initiate from jicofo. This is because jicofo will not start a Jingle
  442. * session until there are at least 2 participants in the room.
  443. *
  444. * @param attributes the attributes to add to the event. Currently used fields:
  445. * mediaType: the media type of the local track ('audio' or 'video').
  446. * muted: whether the track has ever been muted (?)
  447. * value: the TTMF in milliseconds.
  448. */
  449. export const createTtfmEvent = function(attributes) {
  450. return createConnectionStageReachedEvent('ttfm', attributes);
  451. };