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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import { JitsiTrackErrors } from '../lib-jitsi-meet';
  2. import { toState } from '../redux';
  3. /**
  4. * Attach a set of local tracks to a conference.
  5. *
  6. * @param {JitsiConference} conference - Conference instance.
  7. * @param {JitsiLocalTrack[]} localTracks - List of local media tracks.
  8. * @protected
  9. * @returns {Promise}
  10. */
  11. export function _addLocalTracksToConference(conference, localTracks) {
  12. const conferenceLocalTracks = conference.getLocalTracks();
  13. const promises = [];
  14. for (const track of localTracks) {
  15. // XXX The library lib-jitsi-meet may be draconian, for example, when
  16. // adding one and the same video track multiple times.
  17. if (conferenceLocalTracks.indexOf(track) === -1) {
  18. promises.push(
  19. conference.addTrack(track).catch(err => {
  20. _reportError(
  21. 'Failed to add local track to conference',
  22. err);
  23. }));
  24. }
  25. }
  26. return Promise.all(promises);
  27. }
  28. /**
  29. * Returns the current {@code JitsiConference} which is joining or joined and is
  30. * not leaving. Please note the contrast with merely reading the
  31. * {@code conference} state of the feature base/conference which is not joining
  32. * but may be leaving already.
  33. *
  34. * @param {Function|Object} stateful - The redux store, state, or
  35. * {@code getState} function.
  36. * @returns {JitsiConference|undefined}
  37. */
  38. export function getCurrentConference(stateful) {
  39. const { conference, joining, leaving }
  40. = toState(stateful)['features/base/conference'];
  41. return (
  42. conference
  43. ? conference === leaving ? undefined : conference
  44. : joining);
  45. }
  46. /**
  47. * Handle an error thrown by the backend (i.e. lib-jitsi-meet) while
  48. * manipulating a conference participant (e.g. pin or select participant).
  49. *
  50. * @param {Error} err - The Error which was thrown by the backend while
  51. * manipulating a conference participant and which is to be handled.
  52. * @protected
  53. * @returns {void}
  54. */
  55. export function _handleParticipantError(err) {
  56. // XXX DataChannels are initialized at some later point when the conference
  57. // has multiple participants, but code that pins or selects a participant
  58. // might be executed before. So here we're swallowing a particular error.
  59. // TODO Lib-jitsi-meet should be fixed to not throw such an exception in
  60. // these scenarios.
  61. if (err.message !== 'Data channels support is disabled!') {
  62. throw err;
  63. }
  64. }
  65. /**
  66. * Determines whether a specific string is a valid room name.
  67. *
  68. * @param {(string|undefined)} room - The name of the conference room to check
  69. * for validity.
  70. * @returns {boolean} If the specified room name is valid, then true; otherwise,
  71. * false.
  72. */
  73. export function isRoomValid(room) {
  74. return typeof room === 'string' && room !== '';
  75. }
  76. /**
  77. * Remove a set of local tracks from a conference.
  78. *
  79. * @param {JitsiConference} conference - Conference instance.
  80. * @param {JitsiLocalTrack[]} localTracks - List of local media tracks.
  81. * @protected
  82. * @returns {Promise}
  83. */
  84. export function _removeLocalTracksFromConference(conference, localTracks) {
  85. return Promise.all(localTracks.map(track =>
  86. conference.removeTrack(track)
  87. .catch(err => {
  88. // Local track might be already disposed by direct
  89. // JitsiTrack#dispose() call. So we should ignore this error
  90. // here.
  91. if (err.name !== JitsiTrackErrors.TRACK_IS_DISPOSED) {
  92. _reportError(
  93. 'Failed to remove local track from conference',
  94. err);
  95. }
  96. })
  97. ));
  98. }
  99. /**
  100. * Reports a specific Error with a specific error message. While the
  101. * implementation merely logs the specified msg and err via the console at the
  102. * time of this writing, the intention of the function is to abstract the
  103. * reporting of errors and facilitate elaborating on it in the future.
  104. *
  105. * @param {string} msg - The error message to report.
  106. * @param {Error} err - The Error to report.
  107. * @private
  108. * @returns {void}
  109. */
  110. function _reportError(msg, err) {
  111. // TODO This is a good point to call some global error handler when we have
  112. // one.
  113. console.error(msg, err);
  114. }