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.

subscriber.js 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. // @flow
  2. import { StateListenerRegistry } from '../base/redux';
  3. import { getCurrentConference } from '../base/conference';
  4. import {
  5. getPinnedParticipant,
  6. isLocalParticipantModerator
  7. } from '../base/participants';
  8. import { FOLLOW_ME_COMMAND } from './constants';
  9. /**
  10. * Subscribes to changes to the Follow Me setting for the local participant to
  11. * notify remote participants of current user interface status.
  12. * Changing newSelectedValue param to off, when feature is turned of so we can
  13. * notify all listeners.
  14. */
  15. StateListenerRegistry.register(
  16. /* selector */ state => state['features/base/conference'].followMeEnabled,
  17. /* listener */ (newSelectedValue, store) => _sendFollowMeCommand(newSelectedValue || 'off', store));
  18. /**
  19. * Subscribes to changes to the currently pinned participant in the user
  20. * interface of the local participant.
  21. */
  22. StateListenerRegistry.register(
  23. /* selector */ state => {
  24. const pinnedParticipant = getPinnedParticipant(state);
  25. return pinnedParticipant ? pinnedParticipant.id : null;
  26. },
  27. /* listener */ _sendFollowMeCommand);
  28. /**
  29. * Subscribes to changes to the shared document (etherpad) visibility in the
  30. * user interface of the local participant.
  31. *
  32. * @param sharedDocumentVisible {Boolean} {true} if the shared document was
  33. * shown (as a result of the toggle) or {false} if it was hidden
  34. */
  35. StateListenerRegistry.register(
  36. /* selector */ state => state['features/etherpad'].editing,
  37. /* listener */ _sendFollowMeCommand);
  38. /**
  39. * Subscribes to changes to the filmstrip visibility in the user interface of
  40. * the local participant.
  41. */
  42. StateListenerRegistry.register(
  43. /* selector */ state => state['features/filmstrip'].visible,
  44. /* listener */ _sendFollowMeCommand);
  45. /**
  46. * Subscribes to changes to the tile view setting in the user interface of the
  47. * local participant.
  48. */
  49. StateListenerRegistry.register(
  50. /* selector */ state => state['features/video-layout'].tileViewEnabled,
  51. /* listener */ _sendFollowMeCommand);
  52. /**
  53. * Private selector for returning state from redux that should be respected by
  54. * other participants while follow me is enabled.
  55. *
  56. * @param {Object} state - The redux state.
  57. * @returns {Object}
  58. */
  59. function _getFollowMeState(state) {
  60. const pinnedParticipant = getPinnedParticipant(state);
  61. return {
  62. filmstripVisible: state['features/filmstrip'].visible,
  63. nextOnStage: pinnedParticipant && pinnedParticipant.id,
  64. sharedDocumentVisible: state['features/etherpad'].editing,
  65. tileViewEnabled: state['features/video-layout'].tileViewEnabled
  66. };
  67. }
  68. /**
  69. * Sends the follow-me command, when a local property change occurs.
  70. *
  71. * @param {*} newSelectedValue - The changed selected value from the selector.
  72. * @param {Object} store - The redux store.
  73. * @private
  74. * @returns {void}
  75. */
  76. function _sendFollowMeCommand(
  77. newSelectedValue, store) { // eslint-disable-line no-unused-vars
  78. const state = store.getState();
  79. const conference = getCurrentConference(state);
  80. if (!conference) {
  81. return;
  82. }
  83. // Only a moderator is allowed to send commands.
  84. if (!isLocalParticipantModerator(state)) {
  85. return;
  86. }
  87. if (newSelectedValue === 'off') {
  88. // if the change is to off, local user turned off follow me and
  89. // we want to signal this
  90. conference.sendCommandOnce(
  91. FOLLOW_ME_COMMAND,
  92. { attributes: { off: true } }
  93. );
  94. return;
  95. } else if (!state['features/base/conference'].followMeEnabled) {
  96. return;
  97. }
  98. conference.sendCommand(
  99. FOLLOW_ME_COMMAND,
  100. { attributes: _getFollowMeState(state) }
  101. );
  102. }