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.

functions.js 3.7KB

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