您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

actions.native.ts 3.3KB

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