Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

actions.js 7.7KB

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