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

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