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.6KB

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