Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

AnalyticsEvents.js 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  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 a track was unmuted (?).
  190. *
  191. * Properties:
  192. * mediaType: the media type of the local track ('audio' or 'video').
  193. * trackType: the type of the track ('local' or 'remote').
  194. * value: TODO: document
  195. */
  196. export const TRACK_UNMUTED = 'track.unmuted';
  197. /**
  198. * Creates an operational event which indicates that we have received a
  199. * "bridge down" event from jicofo.
  200. */
  201. export const createBridgeDownEvent = function() {
  202. const bridgeDown = 'bridge.down';
  203. return {
  204. action: bridgeDown,
  205. actionSubject: bridgeDown,
  206. type: TYPE_OPERATIONAL
  207. };
  208. };
  209. /**
  210. * Creates an event which indicates that the XMPP connection failed
  211. * @param errorType TODO
  212. * @param errorMessage TODO
  213. * @param detail connection failed details.
  214. */
  215. export const createConnectionFailedEvent
  216. = function(errorType, errorMessage, details) {
  217. return {
  218. type: TYPE_OPERATIONAL,
  219. action: 'connection.failed',
  220. attributes: {
  221. 'error_type': errorType,
  222. 'error_message': errorMessage,
  223. ...details
  224. }
  225. };
  226. };
  227. /**
  228. * Creates an operational event which indicates that a particular connection
  229. * stage was reached (i.e. the XMPP connection transitioned to the "connected"
  230. * state).
  231. *
  232. * @param stage the stage which was reached
  233. * @param attributes additional attributes for the event. This should be an
  234. * object with a "value" property indicating a timestamp in milliseconds
  235. * relative to the beginning of the document's lifetime.
  236. *
  237. */
  238. export const createConnectionStageReachedEvent = function(stage, attributes) {
  239. const action = 'connection.stage.reached';
  240. return {
  241. action,
  242. actionSubject: stage,
  243. attributes,
  244. source: action,
  245. type: TYPE_OPERATIONAL
  246. };
  247. };
  248. /**
  249. * Creates an operational event for the end-to-end round trip time to a
  250. * specific remote participant.
  251. * @param participantId the ID of the remote participant.
  252. * @param region the region of the remote participant
  253. * @param rtt the rtt
  254. */
  255. export const createE2eRttEvent = function(participantId, region, rtt) {
  256. const attributes = {
  257. 'participant_id': participantId,
  258. region,
  259. rtt
  260. };
  261. return {
  262. attributes,
  263. name: 'e2e_rtt',
  264. type: TYPE_OPERATIONAL
  265. };
  266. };
  267. /**
  268. * Creates an event which indicates that the focus has left the MUC.
  269. */
  270. export const createFocusLeftEvent = function() {
  271. const action = 'focus.left';
  272. return {
  273. action,
  274. actionSubject: action,
  275. type: TYPE_OPERATIONAL
  276. };
  277. };
  278. /**
  279. * Creates an event related to a getUserMedia call.
  280. *
  281. * @param action the type of the result that the event represents: 'error',
  282. * 'success', 'warning', etc.
  283. * @param attributes the attributes to attach to the event.
  284. * @returns {{type: string, source: string, name: string}}
  285. */
  286. export const createGetUserMediaEvent = function(action, attributes = {}) {
  287. return {
  288. type: TYPE_OPERATIONAL,
  289. source: 'get.user.media',
  290. action,
  291. attributes
  292. };
  293. };
  294. /**
  295. * Creates an event for a Jingle-related event.
  296. * @param action the action of the event
  297. * @param attributes attributes to add to the event.
  298. */
  299. export const createJingleEvent = function(action, attributes = {}) {
  300. return {
  301. type: TYPE_OPERATIONAL,
  302. action,
  303. source: 'jingle',
  304. attributes
  305. };
  306. };
  307. /**
  308. * Creates an event which indicates that a local track was not able to read
  309. * data from its source (a camera or a microphone).
  310. *
  311. * @param mediaType {String} the media type of the local track ('audio' or
  312. * 'video').
  313. */
  314. export const createNoDataFromSourceEvent = function(mediaType) {
  315. return {
  316. attributes: { 'media_type': mediaType },
  317. action: 'track.no.data.from.source',
  318. type: TYPE_OPERATIONAL
  319. };
  320. };
  321. /**
  322. * Creates an event for a p2p-related event.
  323. * @param action the action of the event
  324. * @param attributes attributes to add to the event.
  325. */
  326. export const createP2PEvent = function(action, attributes = {}) {
  327. return {
  328. type: TYPE_OPERATIONAL,
  329. action,
  330. source: 'p2p',
  331. attributes
  332. };
  333. };
  334. /**
  335. * Indicates that we received a remote command to mute.
  336. */
  337. export const createRemotelyMutedEvent = function() {
  338. return {
  339. type: TYPE_OPERATIONAL,
  340. action: 'remotely.muted'
  341. };
  342. };
  343. /**
  344. * Creates an event which contains RTP statistics such as RTT and packet loss.
  345. *
  346. * All average RTP stats are currently reported under 1 event name, but with
  347. * different properties that allows to distinguish between a P2P call, a
  348. * call relayed through TURN or the JVB, and multiparty vs 1:1.
  349. *
  350. * The structure of the event is:
  351. *
  352. * {
  353. * p2p: true,
  354. * conferenceSize: 2,
  355. * localCandidateType: "relay",
  356. * remoteCandidateType: "relay",
  357. * transportType: "udp",
  358. *
  359. * // Average RTT of 200ms
  360. * "rtt.avg": 200,
  361. * "rtt.samples": "[100, 200, 300]",
  362. *
  363. * // Average packet loss of 10%
  364. * "packet.loss.avg": 10,
  365. * "packet.loss.samples": '[5, 10, 15]'
  366. *
  367. * // Difference in milliseconds in the end-to-end RTT between p2p and jvb.
  368. * // The e2e RTT through jvb is 15ms shorter:
  369. * "rtt.diff": 15,
  370. *
  371. * // End-to-end RTT through JVB is ms.
  372. * "end2end.rtt.avg" = 100
  373. * }
  374. *
  375. * Note that the value of the "samples" properties are (JSON encoded) strings,
  376. * and not JSON arrays, as events' attributes can not be nested. The samples are
  377. * currently included for debug purposes only and can be removed anytime soon
  378. * from the structure.
  379. *
  380. * Also note that not all of values are present in each event, as values are
  381. * obtained and calculated as part of different process/event pipe. For example
  382. * {@link ConnectionAvgStats} instances are doing the reports for each
  383. * {@link TraceablePeerConnection} and work independently from the main stats
  384. * pipe.
  385. */
  386. export const createRtpStatsEvent = function(attributes) {
  387. return {
  388. type: TYPE_OPERATIONAL,
  389. action: 'rtp.stats',
  390. attributes
  391. };
  392. };
  393. /**
  394. * Creates an event which contains the round trip time (RTT) to a set of
  395. * regions.
  396. *
  397. * @param attributes
  398. * @returns {{type: string, action: string, attributes: *}}
  399. */
  400. export const createRttByRegionEvent = function(attributes) {
  401. return {
  402. type: TYPE_OPERATIONAL,
  403. action: 'rtt.by.region',
  404. attributes
  405. };
  406. };
  407. /**
  408. * Creates an event which contains an information related to the bridge channel close event.
  409. *
  410. * @param {string} code - A code from {@link https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent}
  411. * @param {string} reason - A string which describes the reason for closing the bridge channel.
  412. * @returns {{type: string, action: string, attributes: { code: string, reason: string }}}
  413. */
  414. export const createBridgeChannelClosedEvent = function(code, reason) {
  415. return {
  416. type: TYPE_OPERATIONAL,
  417. action: 'bridge-channel.error',
  418. attributes: {
  419. code,
  420. reason
  421. }
  422. };
  423. };
  424. /**
  425. * Creates an event which indicates the Time To First Media (TTFM).
  426. * It is measured in milliseconds relative to the beginning of the document's
  427. * lifetime (i.e. the origin used by window.performance.now()), and it excludes
  428. * the following:
  429. * 1. The delay due to getUserMedia()
  430. * 2. The period between the MUC being joined and the reception of the Jingle
  431. * session-initiate from jicofo. This is because jicofo will not start a Jingle
  432. * session until there are at least 2 participants in the room.
  433. *
  434. * @param attributes the attributes to add to the event. Currently used fields:
  435. * mediaType: the media type of the local track ('audio' or 'video').
  436. * muted: whether the track has ever been muted (?)
  437. * value: the TTMF in milliseconds.
  438. */
  439. export const createTtfmEvent = function(attributes) {
  440. return createConnectionStageReachedEvent('ttfm', attributes);
  441. };