選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

actions.js 12KB

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