您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

actions.js 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. import {
  2. DOMINANT_SPEAKER_CHANGED,
  3. PARTICIPANT_DISPLAY_NAME_CHANGED,
  4. PARTICIPANT_ID_CHANGED,
  5. PARTICIPANT_JOINED,
  6. PARTICIPANT_LEFT,
  7. PARTICIPANT_UPDATED,
  8. PIN_PARTICIPANT
  9. } from './actionTypes';
  10. import { MAX_DISPLAY_NAME_LENGTH } from './constants';
  11. import { getLocalParticipant } from './functions';
  12. /**
  13. * Create an action for when dominant speaker changes.
  14. *
  15. * @param {string} id - Participant's ID.
  16. * @returns {{
  17. * type: DOMINANT_SPEAKER_CHANGED,
  18. * participant: {
  19. * id: string
  20. * }
  21. * }}
  22. */
  23. export function dominantSpeakerChanged(id) {
  24. return {
  25. type: DOMINANT_SPEAKER_CHANGED,
  26. participant: {
  27. id
  28. }
  29. };
  30. }
  31. /**
  32. * Action to signal that the ID of local participant has changed. It happens
  33. * when the local participant joins a new conference or leaves an existing
  34. * conference.
  35. *
  36. * @param {string} id - New ID for local participant.
  37. * @returns {Function}
  38. */
  39. export function localParticipantIdChanged(id) {
  40. return (dispatch, getState) => {
  41. const participant = getLocalParticipant(getState);
  42. if (participant) {
  43. return dispatch({
  44. type: PARTICIPANT_ID_CHANGED,
  45. newValue: id,
  46. oldValue: participant.id
  47. });
  48. }
  49. };
  50. }
  51. /**
  52. * Action to signal that a local participant has joined.
  53. *
  54. * @param {Participant} participant={} - Information about participant.
  55. * @returns {{
  56. * type: PARTICIPANT_JOINED,
  57. * participant: Participant
  58. * }}
  59. */
  60. export function localParticipantJoined(participant = {}) {
  61. return participantJoined({
  62. ...participant,
  63. local: true
  64. });
  65. }
  66. /**
  67. * Action to signal the role of the local participant has changed. It can happen
  68. * when the participant has joined a conference, even before a non-default local
  69. * id has been set, or after a moderator leaves.
  70. *
  71. * @param {string} role - The new role of the local participant.
  72. * @returns {Function}
  73. */
  74. export function localParticipantRoleChanged(role) {
  75. return (dispatch, getState) => {
  76. const participant = getLocalParticipant(getState);
  77. if (participant) {
  78. return dispatch(participantRoleChanged(participant.id, role));
  79. }
  80. };
  81. }
  82. /**
  83. * Action to update a participant's connection status.
  84. *
  85. * @param {string} id - Participant's ID.
  86. * @param {string} connectionStatus - The new connection status of the
  87. * participant.
  88. * @returns {{
  89. * type: PARTICIPANT_UPDATED,
  90. * participant: {
  91. * connectionStatus: string,
  92. * id: string
  93. * }
  94. * }}
  95. */
  96. export function participantConnectionStatusChanged(id, connectionStatus) {
  97. return {
  98. type: PARTICIPANT_UPDATED,
  99. participant: {
  100. connectionStatus,
  101. id
  102. }
  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 that a participant's display name has changed.
  120. *
  121. * @param {string} id - The id of the participant being changed.
  122. * @param {string} displayName - The new display name.
  123. * @returns {{
  124. * type: PARTICIPANT_DISPLAY_NAME_CHANGED,
  125. * id: string,
  126. * name: string
  127. * }}
  128. */
  129. export function participantDisplayNameChanged(id, displayName = '') {
  130. // FIXME Do not use this action over participantUpdated. This action exists
  131. // as a a bridge for local name updates. Once other components responsible
  132. // for updating the local user's display name are in react/redux, this
  133. // action should be replaceable with the participantUpdated action.
  134. return {
  135. type: PARTICIPANT_DISPLAY_NAME_CHANGED,
  136. id,
  137. name: displayName.substr(0, MAX_DISPLAY_NAME_LENGTH)
  138. };
  139. }
  140. /**
  141. * Action to signal that a participant has joined.
  142. *
  143. * @param {Participant} participant - Information about participant.
  144. * @returns {{
  145. * type: PARTICIPANT_JOINED,
  146. * participant: Participant
  147. * }}
  148. */
  149. export function participantJoined(participant) {
  150. return {
  151. type: PARTICIPANT_JOINED,
  152. participant
  153. };
  154. }
  155. /**
  156. * Action to signal that a participant has left.
  157. *
  158. * @param {string} id - Participant's ID.
  159. * @returns {{
  160. * type: PARTICIPANT_LEFT,
  161. * participant: {
  162. * id: string
  163. * }
  164. * }}
  165. */
  166. export function participantLeft(id) {
  167. return {
  168. type: PARTICIPANT_LEFT,
  169. participant: {
  170. id
  171. }
  172. };
  173. }
  174. /**
  175. * Action to signal that a participant's role has changed.
  176. *
  177. * @param {string} id - Participant's ID.
  178. * @param {PARTICIPANT_ROLE} role - Participant's new role.
  179. * @returns {{
  180. * type: PARTICIPANT_UPDATED,
  181. * participant: {
  182. * id: string,
  183. * role: PARTICIPANT_ROLE
  184. * }
  185. * }}
  186. */
  187. export function participantRoleChanged(id, role) {
  188. return participantUpdated({
  189. id,
  190. role
  191. });
  192. }
  193. /**
  194. * Action to signal that some of participant properties has been changed.
  195. *
  196. * @param {Participant} participant={} - Information about participant. To
  197. * identify the participant the object should contain either property id with
  198. * value the id of the participant or property local with value true (if the
  199. * local participant hasn't joined the conference yet).
  200. * @returns {{
  201. * type: PARTICIPANT_UPDATED,
  202. * participant: Participant
  203. * }}
  204. */
  205. export function participantUpdated(participant = {}) {
  206. return {
  207. type: PARTICIPANT_UPDATED,
  208. participant
  209. };
  210. }
  211. /**
  212. * Create an action which pins a conference participant.
  213. *
  214. * @param {string|null} id - The ID of the conference participant to pin or null
  215. * if none of the conference's participants are to be pinned.
  216. * @returns {{
  217. * type: PIN_PARTICIPANT,
  218. * participant: {
  219. * id: string
  220. * }
  221. * }}
  222. */
  223. export function pinParticipant(id) {
  224. return {
  225. type: PIN_PARTICIPANT,
  226. participant: {
  227. id
  228. }
  229. };
  230. }