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.

actions.native.ts 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import { IReduxState, IStore } from '../../app/types';
  2. // eslint-disable-next-line lines-around-comment
  3. // @ts-ignore
  4. import { setPictureInPictureEnabled } from '../../mobile/picture-in-picture/functions';
  5. import { showNotification } from '../../notifications/actions';
  6. import { NOTIFICATION_TIMEOUT_TYPE } from '../../notifications/constants';
  7. import JitsiMeetJS from '../lib-jitsi-meet';
  8. import {
  9. setScreenshareMuted,
  10. setVideoMuted
  11. } from '../media/actions';
  12. import { VIDEO_MUTISM_AUTHORITY } from '../media/constants';
  13. import { addLocalTrack, replaceLocalTrack } from './actions.any';
  14. import { getLocalDesktopTrack, getTrackState, isLocalVideoTrackDesktop } from './functions.native';
  15. export * from './actions.any';
  16. /* eslint-disable @typescript-eslint/no-unused-vars */
  17. /**
  18. * Signals that the local participant is ending screensharing or beginning the screensharing flow.
  19. *
  20. * @param {boolean} enabled - The state to toggle screen sharing to.
  21. * @param {boolean} _ignore1 - Ignored.
  22. * @param {any} _ignore2 - Ignored.
  23. * @returns {Function}
  24. */
  25. export function toggleScreensharing(enabled: boolean, _ignore1?: boolean, _ignore2?: any) {
  26. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  27. const state = getState();
  28. if (enabled) {
  29. const isSharing = isLocalVideoTrackDesktop(state);
  30. if (!isSharing) {
  31. _startScreenSharing(dispatch, state);
  32. }
  33. } else {
  34. dispatch(setScreenshareMuted(true));
  35. dispatch(setVideoMuted(false, VIDEO_MUTISM_AUTHORITY.SCREEN_SHARE));
  36. setPictureInPictureEnabled(true);
  37. }
  38. };
  39. }
  40. /* eslint-enable @typescript-eslint/no-unused-vars */
  41. /**
  42. * Creates desktop track and replaces the local one.
  43. *
  44. * @private
  45. * @param {Dispatch} dispatch - The redux {@code dispatch} function.
  46. * @param {Object} state - The redux state.
  47. * @returns {void}
  48. */
  49. async function _startScreenSharing(dispatch: Function, state: IReduxState) {
  50. setPictureInPictureEnabled(false);
  51. try {
  52. const tracks: any[] = await JitsiMeetJS.createLocalTracks({ devices: [ 'desktop' ] });
  53. const track = tracks[0];
  54. const currentLocalDesktopTrack = getLocalDesktopTrack(getTrackState(state));
  55. const currentJitsiTrack = currentLocalDesktopTrack?.jitsiTrack;
  56. // The first time the user shares the screen we add the track and create the transceiver.
  57. // Afterwards, we just replace the old track, so the transceiver will be reused.
  58. if (currentJitsiTrack) {
  59. dispatch(replaceLocalTrack(currentJitsiTrack, track));
  60. } else {
  61. dispatch(addLocalTrack(track));
  62. }
  63. dispatch(setVideoMuted(true, VIDEO_MUTISM_AUTHORITY.SCREEN_SHARE));
  64. const { enabled: audioOnly } = state['features/base/audio-only'];
  65. if (audioOnly) {
  66. dispatch(showNotification({
  67. titleKey: 'notify.screenSharingAudioOnlyTitle',
  68. descriptionKey: 'notify.screenSharingAudioOnlyDescription',
  69. maxLines: 3
  70. }, NOTIFICATION_TIMEOUT_TYPE.LONG));
  71. }
  72. } catch (error: any) {
  73. console.log('ERROR creating ScreeSharing stream ', error);
  74. setPictureInPictureEnabled(true);
  75. }
  76. }