Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

actions.js 7.1KB

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