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.js 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. import { NOTIFICATION_TIMEOUT, showNotification } from '../../notifications';
  2. import { set } from '../redux';
  3. import {
  4. DOMINANT_SPEAKER_CHANGED,
  5. HIDDEN_PARTICIPANT_JOINED,
  6. HIDDEN_PARTICIPANT_LEFT,
  7. GRANT_MODERATOR,
  8. KICK_PARTICIPANT,
  9. MUTE_REMOTE_PARTICIPANT,
  10. PARTICIPANT_ID_CHANGED,
  11. PARTICIPANT_JOINED,
  12. PARTICIPANT_KICKED,
  13. PARTICIPANT_LEFT,
  14. PARTICIPANT_UPDATED,
  15. PIN_PARTICIPANT,
  16. SET_LOADABLE_AVATAR_URL
  17. } from './actionTypes';
  18. import {
  19. getLocalParticipant,
  20. getNormalizedDisplayName,
  21. getParticipantDisplayName,
  22. figureOutMutedWhileDisconnectedStatus
  23. } from './functions';
  24. /**
  25. * Create an action for when dominant speaker changes.
  26. *
  27. * @param {string} id - Participant's ID.
  28. * @param {JitsiConference} conference - The {@code JitsiConference} associated
  29. * with the participant identified by the specified {@code id}. Only the local
  30. * participant is allowed to not specify an associated {@code JitsiConference}
  31. * instance.
  32. * @returns {{
  33. * type: DOMINANT_SPEAKER_CHANGED,
  34. * participant: {
  35. * conference: JitsiConference,
  36. * id: string
  37. * }
  38. * }}
  39. */
  40. export function dominantSpeakerChanged(id, conference) {
  41. return {
  42. type: DOMINANT_SPEAKER_CHANGED,
  43. participant: {
  44. conference,
  45. id
  46. }
  47. };
  48. }
  49. /**
  50. * Create an action for granting moderator to a participant.
  51. *
  52. * @param {string} id - Participant's ID.
  53. * @returns {{
  54. * type: GRANT_MODERATOR,
  55. * id: string
  56. * }}
  57. */
  58. export function grantModerator(id) {
  59. return {
  60. type: GRANT_MODERATOR,
  61. id
  62. };
  63. }
  64. /**
  65. * Create an action for removing a participant from the conference.
  66. *
  67. * @param {string} id - Participant's ID.
  68. * @returns {{
  69. * type: KICK_PARTICIPANT,
  70. * id: string
  71. * }}
  72. */
  73. export function kickParticipant(id) {
  74. return {
  75. type: KICK_PARTICIPANT,
  76. id
  77. };
  78. }
  79. /**
  80. * Creates an action to signal the connection status of the local participant
  81. * has changed.
  82. *
  83. * @param {string} connectionStatus - The current connection status of the local
  84. * participant, as enumerated by the library's participantConnectionStatus
  85. * constants.
  86. * @returns {Function}
  87. */
  88. export function localParticipantConnectionStatusChanged(connectionStatus) {
  89. return (dispatch, getState) => {
  90. const participant = getLocalParticipant(getState);
  91. if (participant) {
  92. return dispatch(participantConnectionStatusChanged(
  93. participant.id,
  94. connectionStatus));
  95. }
  96. };
  97. }
  98. /**
  99. * Action to signal that the ID of local participant has changed. It happens
  100. * when the local participant joins a new conference or leaves an existing
  101. * conference.
  102. *
  103. * @param {string} id - New ID for local participant.
  104. * @returns {Function}
  105. */
  106. export function localParticipantIdChanged(id) {
  107. return (dispatch, getState) => {
  108. const participant = getLocalParticipant(getState);
  109. if (participant) {
  110. return dispatch({
  111. type: PARTICIPANT_ID_CHANGED,
  112. // XXX A participant is identified by an id-conference pair.
  113. // Only the local participant is with an undefined conference.
  114. conference: undefined,
  115. newValue: id,
  116. oldValue: participant.id
  117. });
  118. }
  119. };
  120. }
  121. /**
  122. * Action to signal that a local participant has joined.
  123. *
  124. * @param {Participant} participant={} - Information about participant.
  125. * @returns {{
  126. * type: PARTICIPANT_JOINED,
  127. * participant: Participant
  128. * }}
  129. */
  130. export function localParticipantJoined(participant = {}) {
  131. return participantJoined(set(participant, 'local', true));
  132. }
  133. /**
  134. * Action to remove a local participant.
  135. *
  136. * @returns {Function}
  137. */
  138. export function localParticipantLeft() {
  139. return (dispatch, getState) => {
  140. const participant = getLocalParticipant(getState);
  141. if (participant) {
  142. return (
  143. dispatch(
  144. participantLeft(
  145. participant.id,
  146. // XXX Only the local participant is allowed to leave
  147. // without stating the JitsiConference instance because
  148. // the local participant is uniquely identified by the
  149. // very fact that there is only one local participant
  150. // (and the fact that the local participant "joins" at
  151. // the beginning of the app and "leaves" at the end of
  152. // the app).
  153. undefined)));
  154. }
  155. };
  156. }
  157. /**
  158. * Action to signal the role of the local participant has changed. It can happen
  159. * when the participant has joined a conference, even before a non-default local
  160. * id has been set, or after a moderator leaves.
  161. *
  162. * @param {string} role - The new role of the local participant.
  163. * @returns {Function}
  164. */
  165. export function localParticipantRoleChanged(role) {
  166. return (dispatch, getState) => {
  167. const participant = getLocalParticipant(getState);
  168. if (participant) {
  169. return dispatch(participantRoleChanged(participant.id, role));
  170. }
  171. };
  172. }
  173. /**
  174. * Create an action for muting another participant in the conference.
  175. *
  176. * @param {string} id - Participant's ID.
  177. * @returns {{
  178. * type: MUTE_REMOTE_PARTICIPANT,
  179. * id: string
  180. * }}
  181. */
  182. export function muteRemoteParticipant(id) {
  183. return {
  184. type: MUTE_REMOTE_PARTICIPANT,
  185. id
  186. };
  187. }
  188. /**
  189. * Action to update a participant's connection status.
  190. *
  191. * @param {string} id - Participant's ID.
  192. * @param {string} connectionStatus - The new connection status of the
  193. * participant.
  194. * @returns {{
  195. * type: PARTICIPANT_UPDATED,
  196. * participant: {
  197. * connectionStatus: string,
  198. * id: string
  199. * }
  200. * }}
  201. */
  202. export function participantConnectionStatusChanged(id, connectionStatus) {
  203. return (dispatch, getState) => {
  204. dispatch({
  205. type: PARTICIPANT_UPDATED,
  206. participant: {
  207. connectionStatus,
  208. id,
  209. mutedWhileDisconnected: figureOutMutedWhileDisconnectedStatus(getState(), id, connectionStatus)
  210. }
  211. });
  212. };
  213. }
  214. /**
  215. * Action to signal that a participant has joined.
  216. *
  217. * @param {Participant} participant - Information about participant.
  218. * @returns {{
  219. * type: PARTICIPANT_JOINED,
  220. * participant: Participant
  221. * }}
  222. */
  223. export function participantJoined(participant) {
  224. // Only the local participant is not identified with an id-conference pair.
  225. if (participant.local) {
  226. return {
  227. type: PARTICIPANT_JOINED,
  228. participant
  229. };
  230. }
  231. // In other words, a remote participant is identified with an id-conference
  232. // pair.
  233. const { conference } = participant;
  234. if (!conference) {
  235. throw Error(
  236. 'A remote participant must be associated with a JitsiConference!');
  237. }
  238. return (dispatch, getState) => {
  239. // A remote participant is only expected to join in a joined or joining
  240. // conference. The following check is really necessary because a
  241. // JitsiConference may have moved into leaving but may still manage to
  242. // sneak a PARTICIPANT_JOINED in if its leave is delayed for any purpose
  243. // (which is not outragous given that leaving involves network
  244. // requests.)
  245. const stateFeaturesBaseConference
  246. = getState()['features/base/conference'];
  247. if (conference === stateFeaturesBaseConference.conference
  248. || conference === stateFeaturesBaseConference.joining) {
  249. return dispatch({
  250. type: PARTICIPANT_JOINED,
  251. participant
  252. });
  253. }
  254. };
  255. }
  256. /**
  257. * Action to signal that a hidden participant has joined the conference.
  258. *
  259. * @param {string} id - The id of the participant.
  260. * @param {string} displayName - The display name, or undefined when
  261. * unknown.
  262. * @returns {{
  263. * type: HIDDEN_PARTICIPANT_JOINED,
  264. * displayName: string,
  265. * id: string
  266. * }}
  267. */
  268. export function hiddenParticipantJoined(id, displayName) {
  269. return {
  270. type: HIDDEN_PARTICIPANT_JOINED,
  271. id,
  272. displayName
  273. };
  274. }
  275. /**
  276. * Action to signal that a hidden participant has left the conference.
  277. *
  278. * @param {string} id - The id of the participant.
  279. * @returns {{
  280. * type: HIDDEN_PARTICIPANT_LEFT,
  281. * id: string
  282. * }}
  283. */
  284. export function hiddenParticipantLeft(id) {
  285. return {
  286. type: HIDDEN_PARTICIPANT_LEFT,
  287. id
  288. };
  289. }
  290. /**
  291. * Action to signal that a participant has left.
  292. *
  293. * @param {string} id - Participant's ID.
  294. * @param {JitsiConference} conference - The {@code JitsiConference} associated
  295. * with the participant identified by the specified {@code id}. Only the local
  296. * participant is allowed to not specify an associated {@code JitsiConference}
  297. * instance.
  298. * @returns {{
  299. * type: PARTICIPANT_LEFT,
  300. * participant: {
  301. * conference: JitsiConference,
  302. * id: string
  303. * }
  304. * }}
  305. */
  306. export function participantLeft(id, conference) {
  307. return {
  308. type: PARTICIPANT_LEFT,
  309. participant: {
  310. conference,
  311. id
  312. }
  313. };
  314. }
  315. /**
  316. * Action to signal that a participant's presence status has changed.
  317. *
  318. * @param {string} id - Participant's ID.
  319. * @param {string} presence - Participant's new presence status.
  320. * @returns {{
  321. * type: PARTICIPANT_UPDATED,
  322. * participant: {
  323. * id: string,
  324. * presence: string
  325. * }
  326. * }}
  327. */
  328. export function participantPresenceChanged(id, presence) {
  329. return participantUpdated({
  330. id,
  331. presence
  332. });
  333. }
  334. /**
  335. * Action to signal that a participant's role has changed.
  336. *
  337. * @param {string} id - Participant's ID.
  338. * @param {PARTICIPANT_ROLE} role - Participant's new role.
  339. * @returns {{
  340. * type: PARTICIPANT_UPDATED,
  341. * participant: {
  342. * id: string,
  343. * role: PARTICIPANT_ROLE
  344. * }
  345. * }}
  346. */
  347. export function participantRoleChanged(id, role) {
  348. return participantUpdated({
  349. id,
  350. role
  351. });
  352. }
  353. /**
  354. * Action to signal that some of participant properties has been changed.
  355. *
  356. * @param {Participant} participant={} - Information about participant. To
  357. * identify the participant the object should contain either property id with
  358. * value the id of the participant or property local with value true (if the
  359. * local participant hasn't joined the conference yet).
  360. * @returns {{
  361. * type: PARTICIPANT_UPDATED,
  362. * participant: Participant
  363. * }}
  364. */
  365. export function participantUpdated(participant = {}) {
  366. const participantToUpdate = {
  367. ...participant
  368. };
  369. if (participant.name) {
  370. participantToUpdate.name = getNormalizedDisplayName(participant.name);
  371. }
  372. return {
  373. type: PARTICIPANT_UPDATED,
  374. participant: participantToUpdate
  375. };
  376. }
  377. /**
  378. * Action to signal that a participant has muted us.
  379. *
  380. * @param {JitsiParticipant} participant - Information about participant.
  381. * @returns {Promise}
  382. */
  383. export function participantMutedUs(participant) {
  384. return (dispatch, getState) => {
  385. if (!participant) {
  386. return;
  387. }
  388. dispatch(showNotification({
  389. descriptionKey: 'notify.mutedRemotelyDescription',
  390. titleKey: 'notify.mutedRemotelyTitle',
  391. titleArguments: {
  392. participantDisplayName:
  393. getParticipantDisplayName(getState, participant.getId())
  394. }
  395. }));
  396. };
  397. }
  398. /**
  399. * Action to signal that a participant had been kicked.
  400. *
  401. * @param {JitsiParticipant} kicker - Information about participant performing the kick.
  402. * @param {JitsiParticipant} kicked - Information about participant that was kicked.
  403. * @returns {Promise}
  404. */
  405. export function participantKicked(kicker, kicked) {
  406. return (dispatch, getState) => {
  407. dispatch({
  408. type: PARTICIPANT_KICKED,
  409. kicked: kicked.getId(),
  410. kicker: kicker.getId()
  411. });
  412. dispatch(showNotification({
  413. titleArguments: {
  414. kicked:
  415. getParticipantDisplayName(getState, kicked.getId()),
  416. kicker:
  417. getParticipantDisplayName(getState, kicker.getId())
  418. },
  419. titleKey: 'notify.kickParticipant'
  420. }, NOTIFICATION_TIMEOUT * 2)); // leave more time for this
  421. };
  422. }
  423. /**
  424. * Create an action which pins a conference participant.
  425. *
  426. * @param {string|null} id - The ID of the conference participant to pin or null
  427. * if none of the conference's participants are to be pinned.
  428. * @returns {{
  429. * type: PIN_PARTICIPANT,
  430. * participant: {
  431. * id: string
  432. * }
  433. * }}
  434. */
  435. export function pinParticipant(id) {
  436. return {
  437. type: PIN_PARTICIPANT,
  438. participant: {
  439. id
  440. }
  441. };
  442. }
  443. /**
  444. * Creates an action which notifies the app that the loadable URL of the avatar of a participant got updated.
  445. *
  446. * @param {string} participantId - The ID of the participant.
  447. * @param {string} url - The new URL.
  448. * @returns {{
  449. * type: SET_LOADABLE_AVATAR_URL,
  450. * participant: {
  451. * id: string,
  452. * loadableAvatarUrl: string
  453. * }
  454. * }}
  455. */
  456. export function setLoadableAvatarUrl(participantId, url) {
  457. return {
  458. type: SET_LOADABLE_AVATAR_URL,
  459. participant: {
  460. id: participantId,
  461. loadableAvatarUrl: url
  462. }
  463. };
  464. }