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 7.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. import {
  2. DOMINANT_SPEAKER_CHANGED,
  3. KICK_PARTICIPANT,
  4. MUTE_REMOTE_PARTICIPANT,
  5. PARTICIPANT_DISPLAY_NAME_CHANGED,
  6. PARTICIPANT_ID_CHANGED,
  7. PARTICIPANT_JOINED,
  8. PARTICIPANT_LEFT,
  9. PARTICIPANT_UPDATED,
  10. PIN_PARTICIPANT
  11. } from './actionTypes';
  12. import { MAX_DISPLAY_NAME_LENGTH } from './constants';
  13. import { getLocalParticipant } from './functions';
  14. /**
  15. * Create an action for when dominant speaker changes.
  16. *
  17. * @param {string} id - Participant's ID.
  18. * @returns {{
  19. * type: DOMINANT_SPEAKER_CHANGED,
  20. * participant: {
  21. * id: string
  22. * }
  23. * }}
  24. */
  25. export function dominantSpeakerChanged(id) {
  26. return {
  27. type: DOMINANT_SPEAKER_CHANGED,
  28. participant: {
  29. id
  30. }
  31. };
  32. }
  33. /**
  34. * Creates an action to signal the connection status of the local participant
  35. * has changed.
  36. *
  37. * @param {string} connectionStatus - The current connection status of the local
  38. * participant, as enumerated by the library's participantConnectionStatus
  39. * constants.
  40. * @returns {Function}
  41. */
  42. export function localParticipantConnectionStatusChanged(connectionStatus) {
  43. return (dispatch, getState) => {
  44. const participant = getLocalParticipant(getState);
  45. if (participant) {
  46. return dispatch(participantConnectionStatusChanged(
  47. participant.id, connectionStatus));
  48. }
  49. };
  50. }
  51. /**
  52. * Create an action for removing a participant from the conference.
  53. *
  54. * @param {string} id - Participant's ID.
  55. * @returns {{
  56. * type: KICK_PARTICIPANT,
  57. * id: string
  58. * }}
  59. */
  60. export function kickParticipant(id) {
  61. return {
  62. type: KICK_PARTICIPANT,
  63. id
  64. };
  65. }
  66. /**
  67. * Action to signal that the ID of local participant has changed. It happens
  68. * when the local participant joins a new conference or leaves an existing
  69. * conference.
  70. *
  71. * @param {string} id - New ID for local participant.
  72. * @returns {Function}
  73. */
  74. export function localParticipantIdChanged(id) {
  75. return (dispatch, getState) => {
  76. const participant = getLocalParticipant(getState);
  77. if (participant) {
  78. return dispatch({
  79. type: PARTICIPANT_ID_CHANGED,
  80. newValue: id,
  81. oldValue: participant.id
  82. });
  83. }
  84. };
  85. }
  86. /**
  87. * Action to signal that a local participant has joined.
  88. *
  89. * @param {Participant} participant={} - Information about participant.
  90. * @returns {{
  91. * type: PARTICIPANT_JOINED,
  92. * participant: Participant
  93. * }}
  94. */
  95. export function localParticipantJoined(participant = {}) {
  96. return participantJoined({
  97. ...participant,
  98. local: true
  99. });
  100. }
  101. /**
  102. * Action to signal the role of the local participant has changed. It can happen
  103. * when the participant has joined a conference, even before a non-default local
  104. * id has been set, or after a moderator leaves.
  105. *
  106. * @param {string} role - The new role of the local participant.
  107. * @returns {Function}
  108. */
  109. export function localParticipantRoleChanged(role) {
  110. return (dispatch, getState) => {
  111. const participant = getLocalParticipant(getState);
  112. if (participant) {
  113. return dispatch(participantRoleChanged(participant.id, role));
  114. }
  115. };
  116. }
  117. /**
  118. * Create an action for muting another participant in the conference.
  119. *
  120. * @param {string} id - Participant's ID.
  121. * @returns {{
  122. * type: MUTE_REMOTE_PARTICIPANT,
  123. * id: string
  124. * }}
  125. */
  126. export function muteRemoteParticipant(id) {
  127. return {
  128. type: MUTE_REMOTE_PARTICIPANT,
  129. id
  130. };
  131. }
  132. /**
  133. * Action to update a participant's connection status.
  134. *
  135. * @param {string} id - Participant's ID.
  136. * @param {string} connectionStatus - The new connection status of the
  137. * participant.
  138. * @returns {{
  139. * type: PARTICIPANT_UPDATED,
  140. * participant: {
  141. * connectionStatus: string,
  142. * id: string
  143. * }
  144. * }}
  145. */
  146. export function participantConnectionStatusChanged(id, connectionStatus) {
  147. return {
  148. type: PARTICIPANT_UPDATED,
  149. participant: {
  150. connectionStatus,
  151. id
  152. }
  153. };
  154. }
  155. /**
  156. * Action to remove a local participant.
  157. *
  158. * @returns {Function}
  159. */
  160. export function localParticipantLeft() {
  161. return (dispatch, getState) => {
  162. const participant = getLocalParticipant(getState);
  163. if (participant) {
  164. return dispatch(participantLeft(participant.id));
  165. }
  166. };
  167. }
  168. /**
  169. * Action to signal that a participant's display name has changed.
  170. *
  171. * @param {string} id - The id of the participant being changed.
  172. * @param {string} displayName - The new display name.
  173. * @returns {{
  174. * type: PARTICIPANT_DISPLAY_NAME_CHANGED,
  175. * id: string,
  176. * name: string
  177. * }}
  178. */
  179. export function participantDisplayNameChanged(id, displayName = '') {
  180. // FIXME Do not use this action over participantUpdated. This action exists
  181. // as a a bridge for local name updates. Once other components responsible
  182. // for updating the local user's display name are in react/redux, this
  183. // action should be replaceable with the participantUpdated action.
  184. return {
  185. type: PARTICIPANT_DISPLAY_NAME_CHANGED,
  186. id,
  187. name: displayName.substr(0, MAX_DISPLAY_NAME_LENGTH)
  188. };
  189. }
  190. /**
  191. * Action to signal that a participant has joined.
  192. *
  193. * @param {Participant} participant - Information about participant.
  194. * @returns {{
  195. * type: PARTICIPANT_JOINED,
  196. * participant: Participant
  197. * }}
  198. */
  199. export function participantJoined(participant) {
  200. return {
  201. type: PARTICIPANT_JOINED,
  202. participant
  203. };
  204. }
  205. /**
  206. * Action to signal that a participant has left.
  207. *
  208. * @param {string} id - Participant's ID.
  209. * @returns {{
  210. * type: PARTICIPANT_LEFT,
  211. * participant: {
  212. * id: string
  213. * }
  214. * }}
  215. */
  216. export function participantLeft(id) {
  217. return {
  218. type: PARTICIPANT_LEFT,
  219. participant: {
  220. id
  221. }
  222. };
  223. }
  224. /**
  225. * Action to signal that a participant's presence status has changed.
  226. *
  227. * @param {string} id - Participant's ID.
  228. * @param {string} presence - Participant's new presence status.
  229. * @returns {{
  230. * type: PARTICIPANT_UPDATED,
  231. * participant: {
  232. * id: string,
  233. * presence: string
  234. * }
  235. * }}
  236. */
  237. export function participantPresenceChanged(id, presence) {
  238. return participantUpdated({
  239. id,
  240. presence
  241. });
  242. }
  243. /**
  244. * Action to signal that a participant's role has changed.
  245. *
  246. * @param {string} id - Participant's ID.
  247. * @param {PARTICIPANT_ROLE} role - Participant's new role.
  248. * @returns {{
  249. * type: PARTICIPANT_UPDATED,
  250. * participant: {
  251. * id: string,
  252. * role: PARTICIPANT_ROLE
  253. * }
  254. * }}
  255. */
  256. export function participantRoleChanged(id, role) {
  257. return participantUpdated({
  258. id,
  259. role
  260. });
  261. }
  262. /**
  263. * Action to signal that some of participant properties has been changed.
  264. *
  265. * @param {Participant} participant={} - Information about participant. To
  266. * identify the participant the object should contain either property id with
  267. * value the id of the participant or property local with value true (if the
  268. * local participant hasn't joined the conference yet).
  269. * @returns {{
  270. * type: PARTICIPANT_UPDATED,
  271. * participant: Participant
  272. * }}
  273. */
  274. export function participantUpdated(participant = {}) {
  275. return {
  276. type: PARTICIPANT_UPDATED,
  277. participant
  278. };
  279. }
  280. /**
  281. * Create an action which pins a conference participant.
  282. *
  283. * @param {string|null} id - The ID of the conference participant to pin or null
  284. * if none of the conference's participants are to be pinned.
  285. * @returns {{
  286. * type: PIN_PARTICIPANT,
  287. * participant: {
  288. * id: string
  289. * }
  290. * }}
  291. */
  292. export function pinParticipant(id) {
  293. return {
  294. type: PIN_PARTICIPANT,
  295. participant: {
  296. id
  297. }
  298. };
  299. }