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.web.ts 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { createLocalTrack } from '../base/lib-jitsi-meet/functions';
  2. export * from './functions.any';
  3. /**
  4. * Returns a promise which resolves with a list of objects containing
  5. * all the video jitsiTracks and appropriate errors for the given device ids.
  6. *
  7. * @param {string[]} ids - The list of the camera ids for which to create tracks.
  8. * @param {number} [timeout] - A timeout for the createLocalTrack function call.
  9. *
  10. * @returns {Promise<Object[]>}
  11. */
  12. export function createLocalVideoTracks(ids: string[], timeout?: number) {
  13. return Promise.all(ids.map(deviceId => createLocalTrack('video', deviceId, timeout)
  14. .then((jitsiTrack: any) => {
  15. return {
  16. jitsiTrack,
  17. deviceId
  18. };
  19. })
  20. .catch(() => {
  21. return {
  22. jitsiTrack: null,
  23. deviceId,
  24. error: 'deviceSelection.previewUnavailable'
  25. };
  26. })));
  27. }
  28. /**
  29. * Returns a promise which resolves with a list of objects containing
  30. * the audio track and the corresponding audio device information.
  31. *
  32. * @param {Object[]} devices - A list of microphone devices.
  33. * @param {number} [timeout] - A timeout for the createLocalTrack function call.
  34. * @returns {Promise<{
  35. * deviceId: string,
  36. * hasError: boolean,
  37. * jitsiTrack: Object,
  38. * label: string
  39. * }[]>}
  40. */
  41. export function createLocalAudioTracks(devices: Array<{ deviceId: string; label: string; }>, timeout?: number) {
  42. return Promise.all(
  43. devices.map(async ({ deviceId, label }) => {
  44. let jitsiTrack = null;
  45. let hasError = false;
  46. try {
  47. jitsiTrack = await createLocalTrack('audio', deviceId, timeout);
  48. } catch (err) {
  49. hasError = true;
  50. }
  51. return {
  52. deviceId,
  53. hasError,
  54. jitsiTrack,
  55. label
  56. };
  57. }));
  58. }