Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

recordingXMLUtils.js 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /**
  2. * A collection of utility functions for taking in XML and parsing it to return
  3. * certain values.
  4. */
  5. export default {
  6. /**
  7. * Parses the presence update of the focus and returns an object with the
  8. * statuses related to recording.
  9. *
  10. * @param {Node} presence - An XMPP presence update.
  11. * @returns {Object} The current presence values related to recording.
  12. */
  13. getFocusRecordingUpdate(presence) {
  14. const jibriStatus = presence
  15. && presence.getElementsByTagName('jibri-recording-status')[0];
  16. if (!jibriStatus) {
  17. return;
  18. }
  19. return {
  20. error: jibriStatus.getAttribute('failure_reason'),
  21. recordingMode: jibriStatus.getAttribute('recording_mode'),
  22. sessionID: jibriStatus.getAttribute('session_id'),
  23. status: jibriStatus.getAttribute('status')
  24. };
  25. },
  26. /**
  27. * Parses the presence update from a hidden domain participant and returns
  28. * an object with the statuses related to recording.
  29. *
  30. * @param {Node} presence - An XMPP presence update.
  31. * @returns {Object} The current presence values related to recording.
  32. */
  33. getHiddenDomainUpdate(presence) {
  34. const liveStreamViewURLContainer
  35. = presence.getElementsByTagName('live-stream-view-url')[0];
  36. const liveStreamViewURL = liveStreamViewURLContainer
  37. && liveStreamViewURLContainer.textContent;
  38. const modeContainer
  39. = presence.getElementsByTagName('mode')[0];
  40. const mode = modeContainer
  41. && modeContainer.textContent
  42. && modeContainer.textContent.toLowerCase();
  43. const sessionIDContainer
  44. = presence.getElementsByTagName('session_id')[0];
  45. const sessionID
  46. = sessionIDContainer && sessionIDContainer.textContent;
  47. return {
  48. liveStreamViewURL,
  49. mode,
  50. sessionID
  51. };
  52. },
  53. /**
  54. * Returns the recording session ID from a successful IQ.
  55. *
  56. * @param {Node} response - The response from the IQ.
  57. * @returns {string} The session ID of the recording session.
  58. */
  59. getSessionIdFromIq(response) {
  60. const jibri = response && response.getElementsByTagName('jibri')[0];
  61. return jibri && jibri.getAttribute('session_id');
  62. },
  63. /**
  64. * Returns the recording session ID from a presence, if it exists.
  65. *
  66. * @param {Node} presence - An XMPP presence update.
  67. * @returns {string|undefined} The session ID of the recording session.
  68. */
  69. getSessionId(presence) {
  70. const sessionIdContainer
  71. = presence.getElementsByTagName('session_id')[0];
  72. const sessionId = sessionIdContainer && sessionIdContainer.textContent;
  73. return sessionId;
  74. },
  75. /**
  76. * Returns whether or not a presence is from the focus.
  77. *
  78. * @param {Node} presence - An XMPP presence update.
  79. * @returns {boolean} True if the presence is from the focus.
  80. */
  81. isFromFocus(presence) {
  82. return presence.getAttribute('from').includes('focus');
  83. }
  84. };