Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

actions.js 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. /* global interfaceConfig */
  2. import throttle from 'lodash/throttle';
  3. import { showNotification } from '../../notifications';
  4. import {
  5. DOMINANT_SPEAKER_CHANGED,
  6. KICK_PARTICIPANT,
  7. MUTE_REMOTE_PARTICIPANT,
  8. PARTICIPANT_DISPLAY_NAME_CHANGED,
  9. PARTICIPANT_ID_CHANGED,
  10. PARTICIPANT_JOINED,
  11. PARTICIPANT_LEFT,
  12. PARTICIPANT_UPDATED,
  13. PIN_PARTICIPANT
  14. } from './actionTypes';
  15. import { MAX_DISPLAY_NAME_LENGTH } from './constants';
  16. import { getLocalParticipant } from './functions';
  17. /**
  18. * Create an action for when dominant speaker changes.
  19. *
  20. * @param {string} id - Participant's ID.
  21. * @returns {{
  22. * type: DOMINANT_SPEAKER_CHANGED,
  23. * participant: {
  24. * id: string
  25. * }
  26. * }}
  27. */
  28. export function dominantSpeakerChanged(id) {
  29. return {
  30. type: DOMINANT_SPEAKER_CHANGED,
  31. participant: {
  32. id
  33. }
  34. };
  35. }
  36. /**
  37. * Create an action for removing a participant from the conference.
  38. *
  39. * @param {string} id - Participant's ID.
  40. * @returns {{
  41. * type: KICK_PARTICIPANT,
  42. * id: string
  43. * }}
  44. */
  45. export function kickParticipant(id) {
  46. return {
  47. type: KICK_PARTICIPANT,
  48. id
  49. };
  50. }
  51. /**
  52. * Creates an action to signal the connection status of the local participant
  53. * has changed.
  54. *
  55. * @param {string} connectionStatus - The current connection status of the local
  56. * participant, as enumerated by the library's participantConnectionStatus
  57. * constants.
  58. * @returns {Function}
  59. */
  60. export function localParticipantConnectionStatusChanged(connectionStatus) {
  61. return (dispatch, getState) => {
  62. const participant = getLocalParticipant(getState);
  63. if (participant) {
  64. return dispatch(participantConnectionStatusChanged(
  65. participant.id,
  66. connectionStatus));
  67. }
  68. };
  69. }
  70. /**
  71. * Action to signal that the ID of local participant has changed. It happens
  72. * when the local participant joins a new conference or leaves an existing
  73. * conference.
  74. *
  75. * @param {string} id - New ID for local participant.
  76. * @returns {Function}
  77. */
  78. export function localParticipantIdChanged(id) {
  79. return (dispatch, getState) => {
  80. const participant = getLocalParticipant(getState);
  81. if (participant) {
  82. return dispatch({
  83. type: PARTICIPANT_ID_CHANGED,
  84. newValue: id,
  85. oldValue: participant.id
  86. });
  87. }
  88. };
  89. }
  90. /**
  91. * Action to signal that a local participant has joined.
  92. *
  93. * @param {Participant} participant={} - Information about participant.
  94. * @returns {{
  95. * type: PARTICIPANT_JOINED,
  96. * participant: Participant
  97. * }}
  98. */
  99. export function localParticipantJoined(participant = {}) {
  100. return participantJoined({
  101. ...participant,
  102. local: true
  103. });
  104. }
  105. /**
  106. * Action to remove a local participant.
  107. *
  108. * @returns {Function}
  109. */
  110. export function localParticipantLeft() {
  111. return (dispatch, getState) => {
  112. const participant = getLocalParticipant(getState);
  113. if (participant) {
  114. return dispatch(participantLeft(participant.id));
  115. }
  116. };
  117. }
  118. /**
  119. * Action to signal the role of the local participant has changed. It can happen
  120. * when the participant has joined a conference, even before a non-default local
  121. * id has been set, or after a moderator leaves.
  122. *
  123. * @param {string} role - The new role of the local participant.
  124. * @returns {Function}
  125. */
  126. export function localParticipantRoleChanged(role) {
  127. return (dispatch, getState) => {
  128. const participant = getLocalParticipant(getState);
  129. if (participant) {
  130. return dispatch(participantRoleChanged(participant.id, role));
  131. }
  132. };
  133. }
  134. /**
  135. * Create an action for muting another participant in the conference.
  136. *
  137. * @param {string} id - Participant's ID.
  138. * @returns {{
  139. * type: MUTE_REMOTE_PARTICIPANT,
  140. * id: string
  141. * }}
  142. */
  143. export function muteRemoteParticipant(id) {
  144. return {
  145. type: MUTE_REMOTE_PARTICIPANT,
  146. id
  147. };
  148. }
  149. /**
  150. * Action to update a participant's connection status.
  151. *
  152. * @param {string} id - Participant's ID.
  153. * @param {string} connectionStatus - The new connection status of the
  154. * participant.
  155. * @returns {{
  156. * type: PARTICIPANT_UPDATED,
  157. * participant: {
  158. * connectionStatus: string,
  159. * id: string
  160. * }
  161. * }}
  162. */
  163. export function participantConnectionStatusChanged(id, connectionStatus) {
  164. return {
  165. type: PARTICIPANT_UPDATED,
  166. participant: {
  167. connectionStatus,
  168. id
  169. }
  170. };
  171. }
  172. /**
  173. * Action to signal that a participant's display name has changed.
  174. *
  175. * @param {string} id - The id of the participant being changed.
  176. * @param {string} displayName - The new display name.
  177. * @returns {{
  178. * type: PARTICIPANT_DISPLAY_NAME_CHANGED,
  179. * id: string,
  180. * name: string
  181. * }}
  182. */
  183. export function participantDisplayNameChanged(id, displayName = '') {
  184. // FIXME Do not use this action over participantUpdated. This action exists
  185. // as a a bridge for local name updates. Once other components responsible
  186. // for updating the local user's display name are in react/redux, this
  187. // action should be replaceable with the participantUpdated action.
  188. return {
  189. type: PARTICIPANT_DISPLAY_NAME_CHANGED,
  190. id,
  191. name: displayName.substr(0, MAX_DISPLAY_NAME_LENGTH)
  192. };
  193. }
  194. /**
  195. * Action to signal that a participant has joined.
  196. *
  197. * @param {Participant} participant - Information about participant.
  198. * @returns {{
  199. * type: PARTICIPANT_JOINED,
  200. * participant: Participant
  201. * }}
  202. */
  203. export function participantJoined(participant) {
  204. if (!participant.local && !participant.conference) {
  205. throw Error(
  206. 'A remote participant must be associated with a JitsiConference!');
  207. }
  208. return {
  209. type: PARTICIPANT_JOINED,
  210. participant
  211. };
  212. }
  213. /**
  214. * Action to signal that a participant has left.
  215. *
  216. * @param {string} id - Participant's ID.
  217. * @returns {{
  218. * type: PARTICIPANT_LEFT,
  219. * participant: {
  220. * id: string
  221. * }
  222. * }}
  223. */
  224. export function participantLeft(id) {
  225. return {
  226. type: PARTICIPANT_LEFT,
  227. participant: {
  228. id
  229. }
  230. };
  231. }
  232. /**
  233. * Action to signal that a participant's presence status has changed.
  234. *
  235. * @param {string} id - Participant's ID.
  236. * @param {string} presence - Participant's new presence status.
  237. * @returns {{
  238. * type: PARTICIPANT_UPDATED,
  239. * participant: {
  240. * id: string,
  241. * presence: string
  242. * }
  243. * }}
  244. */
  245. export function participantPresenceChanged(id, presence) {
  246. return participantUpdated({
  247. id,
  248. presence
  249. });
  250. }
  251. /**
  252. * Action to signal that a participant's role has changed.
  253. *
  254. * @param {string} id - Participant's ID.
  255. * @param {PARTICIPANT_ROLE} role - Participant's new role.
  256. * @returns {{
  257. * type: PARTICIPANT_UPDATED,
  258. * participant: {
  259. * id: string,
  260. * role: PARTICIPANT_ROLE
  261. * }
  262. * }}
  263. */
  264. export function participantRoleChanged(id, role) {
  265. return participantUpdated({
  266. id,
  267. role
  268. });
  269. }
  270. /**
  271. * Action to signal that some of participant properties has been changed.
  272. *
  273. * @param {Participant} participant={} - Information about participant. To
  274. * identify the participant the object should contain either property id with
  275. * value the id of the participant or property local with value true (if the
  276. * local participant hasn't joined the conference yet).
  277. * @returns {{
  278. * type: PARTICIPANT_UPDATED,
  279. * participant: Participant
  280. * }}
  281. */
  282. export function participantUpdated(participant = {}) {
  283. return {
  284. type: PARTICIPANT_UPDATED,
  285. participant
  286. };
  287. }
  288. /**
  289. * Create an action which pins a conference participant.
  290. *
  291. * @param {string|null} id - The ID of the conference participant to pin or null
  292. * if none of the conference's participants are to be pinned.
  293. * @returns {{
  294. * type: PIN_PARTICIPANT,
  295. * participant: {
  296. * id: string
  297. * }
  298. * }}
  299. */
  300. export function pinParticipant(id) {
  301. return {
  302. type: PIN_PARTICIPANT,
  303. participant: {
  304. id
  305. }
  306. };
  307. }
  308. /**
  309. * An array of names of participants that have joined the conference. The array
  310. * is replaced with an empty array as notifications are displayed.
  311. *
  312. * @private
  313. * @type {string[]}
  314. */
  315. let joinedParticipantsNames = [];
  316. /**
  317. * A throttled internal function that takes the internal list of participant
  318. * names, {@code joinedParticipantsNames}, and triggers the display of a
  319. * notification informing of their joining.
  320. *
  321. * @private
  322. * @type {Function}
  323. */
  324. const _throttledNotifyParticipantConnected = throttle(dispatch => {
  325. const joinedParticipantsCount = joinedParticipantsNames.length;
  326. let notificationProps;
  327. if (joinedParticipantsCount >= 3) {
  328. notificationProps = {
  329. titleArguments: {
  330. name: joinedParticipantsNames[0],
  331. count: joinedParticipantsCount - 1
  332. },
  333. titleKey: 'notify.connectedThreePlusMembers'
  334. };
  335. } else if (joinedParticipantsCount === 2) {
  336. notificationProps = {
  337. titleArguments: {
  338. first: joinedParticipantsNames[0],
  339. second: joinedParticipantsNames[1]
  340. },
  341. titleKey: 'notify.connectedTwoMembers'
  342. };
  343. } else if (joinedParticipantsCount) {
  344. notificationProps = {
  345. titleArguments: {
  346. name: joinedParticipantsNames[0]
  347. },
  348. titleKey: 'notify.connectedOneMember'
  349. };
  350. }
  351. if (notificationProps) {
  352. dispatch(
  353. showNotification(notificationProps, 2500));
  354. }
  355. joinedParticipantsNames = [];
  356. }, 500, { leading: false });
  357. /**
  358. * Queues the display of a notification of a participant having connected to
  359. * the meeting. The notifications are batched so that quick consecutive
  360. * connection events are shown in one notification.
  361. *
  362. * @param {string} displayName - The name of the participant that connected.
  363. * @returns {Function}
  364. */
  365. export function showParticipantJoinedNotification(displayName) {
  366. joinedParticipantsNames.push(
  367. displayName || interfaceConfig.DEFAULT_REMOTE_DISPLAY_NAME);
  368. return dispatch => _throttledNotifyParticipantConnected(dispatch);
  369. }