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.

recordingXMLUtils.js 3.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. initiator: jibriStatus.getAttribute('initiator'),
  22. recordingMode: jibriStatus.getAttribute('recording_mode'),
  23. sessionID: jibriStatus.getAttribute('session_id'),
  24. status: jibriStatus.getAttribute('status')
  25. };
  26. },
  27. /**
  28. * Parses the presence update from a hidden domain participant and returns
  29. * an object with the statuses related to recording.
  30. *
  31. * @param {Node} presence - An XMPP presence update.
  32. * @returns {Object} The current presence values related to recording.
  33. */
  34. getHiddenDomainUpdate(presence) {
  35. const liveStreamViewURLContainer
  36. = presence.getElementsByTagName('live-stream-view-url')[0];
  37. const liveStreamViewURL = liveStreamViewURLContainer
  38. && liveStreamViewURLContainer.textContent;
  39. const modeContainer
  40. = presence.getElementsByTagName('mode')[0];
  41. const mode = modeContainer
  42. && modeContainer.textContent
  43. && modeContainer.textContent.toLowerCase();
  44. const sessionIDContainer
  45. = presence.getElementsByTagName('session_id')[0];
  46. const sessionID
  47. = sessionIDContainer && sessionIDContainer.textContent;
  48. return {
  49. liveStreamViewURL,
  50. mode,
  51. sessionID
  52. };
  53. },
  54. /**
  55. * Returns the recording session ID from a successful IQ.
  56. *
  57. * @param {Node} response - The response from the IQ.
  58. * @returns {string} The session ID of the recording session.
  59. */
  60. getSessionIdFromIq(response) {
  61. const jibri = response && response.getElementsByTagName('jibri')[0];
  62. return jibri && jibri.getAttribute('session_id');
  63. },
  64. /**
  65. * Returns the recording session ID from a presence, if it exists.
  66. *
  67. * @param {Node} presence - An XMPP presence update.
  68. * @returns {string|undefined} The session ID of the recording session.
  69. */
  70. getSessionId(presence) {
  71. const sessionIdContainer
  72. = presence.getElementsByTagName('session_id')[0];
  73. const sessionId = sessionIdContainer && sessionIdContainer.textContent;
  74. return sessionId;
  75. },
  76. /**
  77. * Returns whether or not a presence is from the focus.
  78. *
  79. * @param {Node} presence - An XMPP presence update.
  80. * @returns {boolean} True if the presence is from the focus.
  81. */
  82. isFromFocus(presence) {
  83. return presence.getAttribute('from').includes('focus');
  84. }
  85. };