You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

actions.js 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. import {
  2. DOMINANT_SPEAKER_CHANGED,
  3. PARTICIPANT_ID_CHANGED,
  4. PARTICIPANT_JOINED,
  5. PARTICIPANT_LEFT,
  6. PARTICIPANT_UPDATED,
  7. PIN_PARTICIPANT
  8. } from './actionTypes';
  9. import { getLocalParticipant } from './functions';
  10. /**
  11. * Action to update a participant's avatar ID.
  12. *
  13. * @param {string} id - Participant's ID.
  14. * @param {string} avatarID - Participant's avatar ID.
  15. * @returns {{
  16. * type: PARTICIPANT_UPDATED,
  17. * participant: {
  18. * id: string,
  19. * avatarID: string,
  20. * }
  21. * }}
  22. */
  23. export function changeParticipantAvatarID(id, avatarID) {
  24. return {
  25. type: PARTICIPANT_UPDATED,
  26. participant: {
  27. id,
  28. avatarID
  29. }
  30. };
  31. }
  32. /**
  33. * Action to update a participant's avatar URL.
  34. *
  35. * @param {string} id - Participant's ID.
  36. * @param {string} avatarURL - Participant's avatar URL.
  37. * @returns {{
  38. * type: PARTICIPANT_UPDATED,
  39. * participant: {
  40. * id: string,
  41. * avatarURL: string,
  42. * }
  43. * }}
  44. */
  45. export function changeParticipantAvatarURL(id, avatarURL) {
  46. return {
  47. type: PARTICIPANT_UPDATED,
  48. participant: {
  49. id,
  50. avatarURL
  51. }
  52. };
  53. }
  54. /**
  55. * Action to update a participant's email.
  56. *
  57. * @param {string} id - Participant's ID.
  58. * @param {string} email - Participant's email.
  59. * @returns {{
  60. * type: PARTICIPANT_UPDATED,
  61. * participant: {
  62. * id: string,
  63. * email: string
  64. * }
  65. * }}
  66. */
  67. export function changeParticipantEmail(id, email) {
  68. return {
  69. type: PARTICIPANT_UPDATED,
  70. participant: {
  71. id,
  72. email
  73. }
  74. };
  75. }
  76. /**
  77. * Create an action for when dominant speaker changes.
  78. *
  79. * @param {string} id - Participant's ID.
  80. * @returns {{
  81. * type: DOMINANT_SPEAKER_CHANGED,
  82. * participant: {
  83. * id: string
  84. * }
  85. * }}
  86. */
  87. export function dominantSpeakerChanged(id) {
  88. return {
  89. type: DOMINANT_SPEAKER_CHANGED,
  90. participant: {
  91. id
  92. }
  93. };
  94. }
  95. /**
  96. * Action to signal that ID of local participant has changed. This happens when
  97. * local participant joins a new conference or quits one.
  98. *
  99. * @param {string} id - New ID for local participant.
  100. * @returns {{
  101. * type: PARTICIPANT_ID_CHANGED,
  102. * newValue: string,
  103. * oldValue: string
  104. * }}
  105. */
  106. export function localParticipantIdChanged(id) {
  107. return (dispatch, getState) => {
  108. const participant = getLocalParticipant(getState);
  109. if (participant) {
  110. return dispatch({
  111. type: PARTICIPANT_ID_CHANGED,
  112. newValue: id,
  113. oldValue: participant.id
  114. });
  115. }
  116. };
  117. }
  118. /**
  119. * Action to signal that a local participant has joined.
  120. *
  121. * @param {Participant} participant={} - Information about participant.
  122. * @returns {{
  123. * type: PARTICIPANT_JOINED,
  124. * participant: Participant
  125. * }}
  126. */
  127. export function localParticipantJoined(participant = {}) {
  128. return participantJoined({
  129. ...participant,
  130. local: true
  131. });
  132. }
  133. /**
  134. * Action to remove a local participant.
  135. *
  136. * @returns {Function}
  137. */
  138. export function localParticipantLeft() {
  139. return (dispatch, getState) => {
  140. const participant = getLocalParticipant(getState);
  141. if (participant) {
  142. return dispatch(participantLeft(participant.id));
  143. }
  144. };
  145. }
  146. /**
  147. * Action to signal that a participant has joined.
  148. *
  149. * @param {Participant} participant - Information about participant.
  150. * @returns {{
  151. * type: PARTICIPANT_JOINED,
  152. * participant: Participant
  153. * }}
  154. */
  155. export function participantJoined(participant) {
  156. return {
  157. type: PARTICIPANT_JOINED,
  158. participant
  159. };
  160. }
  161. /**
  162. * Action to signal that a participant has left.
  163. *
  164. * @param {string} id - Participant's ID.
  165. * @returns {{
  166. * type: PARTICIPANT_LEFT,
  167. * participant: {
  168. * id: string
  169. * }
  170. * }}
  171. */
  172. export function participantLeft(id) {
  173. return {
  174. type: PARTICIPANT_LEFT,
  175. participant: {
  176. id
  177. }
  178. };
  179. }
  180. /**
  181. * Action to signal that a participant's role has changed.
  182. *
  183. * @param {string} id - Participant's ID.
  184. * @param {PARTICIPANT_ROLE} role - Participant's new role.
  185. * @returns {{
  186. * type: PARTICIPANT_UPDATED,
  187. * participant: {
  188. * id: string,
  189. * role: PARTICIPANT_ROLE
  190. * }
  191. * }}
  192. */
  193. export function participantRoleChanged(id, role) {
  194. return {
  195. type: PARTICIPANT_UPDATED,
  196. participant: {
  197. id,
  198. role
  199. }
  200. };
  201. }
  202. /**
  203. * Create an action which pins a conference participant.
  204. *
  205. * @param {string|null} id - The ID of the conference participant to pin or null
  206. * if none of the conference's participants are to be pinned.
  207. * @returns {{
  208. * type: PIN_PARTICIPANT,
  209. * participant: {
  210. * id: string
  211. * }
  212. * }}
  213. */
  214. export function pinParticipant(id) {
  215. return {
  216. type: PIN_PARTICIPANT,
  217. participant: {
  218. id
  219. }
  220. };
  221. }