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

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