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.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. import './middleware';
  11. import './reducer';
  12. /**
  13. * Action to update a participant's email.
  14. *
  15. * @param {string} id - Participant's id.
  16. * @param {string} email - Participant's email.
  17. * @returns {{
  18. * type: PARTICIPANT_UPDATED,
  19. * participant: {
  20. * id: string,
  21. * avatar: string,
  22. * email: string
  23. * }
  24. * }}
  25. */
  26. export function changeParticipantEmail(id, email) {
  27. return {
  28. type: PARTICIPANT_UPDATED,
  29. participant: {
  30. id,
  31. email
  32. }
  33. };
  34. }
  35. /**
  36. * Create an action for when dominant speaker changes.
  37. *
  38. * @param {string} id - Participant id.
  39. * @returns {{
  40. * type: DOMINANT_SPEAKER_CHANGED,
  41. * participant: {
  42. * id: string
  43. * }
  44. * }}
  45. */
  46. export function dominantSpeakerChanged(id) {
  47. return {
  48. type: DOMINANT_SPEAKER_CHANGED,
  49. participant: {
  50. id
  51. }
  52. };
  53. }
  54. /**
  55. * Action to signal that ID of local participant has changed. This happens when
  56. * local participant joins a new conference or quits one.
  57. *
  58. * @param {string} id - New ID for local participant.
  59. * @returns {{
  60. * type: PARTICIPANT_ID_CHANGED,
  61. * newValue: string,
  62. * oldValue: string
  63. * }}
  64. */
  65. export function localParticipantIdChanged(id) {
  66. return (dispatch, getState) => {
  67. const participant = getLocalParticipant(getState);
  68. if (participant) {
  69. return dispatch({
  70. type: PARTICIPANT_ID_CHANGED,
  71. newValue: id,
  72. oldValue: participant.id
  73. });
  74. }
  75. };
  76. }
  77. /**
  78. * Action to signal that a local participant has joined.
  79. *
  80. * @param {Participant} participant={} - Information about participant.
  81. * @returns {{
  82. * type: PARTICIPANT_JOINED,
  83. * participant: Participant
  84. * }}
  85. */
  86. export function localParticipantJoined(participant = {}) {
  87. return participantJoined({
  88. ...participant,
  89. local: true
  90. });
  91. }
  92. /**
  93. * Action to remove a local participant.
  94. *
  95. * @returns {Function}
  96. */
  97. export function localParticipantLeft() {
  98. return (dispatch, getState) => {
  99. const participant = getLocalParticipant(getState);
  100. if (participant) {
  101. return dispatch(participantLeft(participant.id));
  102. }
  103. };
  104. }
  105. /**
  106. * Action to signal that a participant has joined.
  107. *
  108. * @param {Participant} participant - Information about participant.
  109. * @returns {{
  110. * type: PARTICIPANT_JOINED,
  111. * participant: Participant
  112. * }}
  113. */
  114. export function participantJoined(participant) {
  115. return {
  116. type: PARTICIPANT_JOINED,
  117. participant
  118. };
  119. }
  120. /**
  121. * Action to handle case when participant lefts.
  122. *
  123. * @param {string} id - Participant id.
  124. * @returns {{
  125. * type: PARTICIPANT_LEFT,
  126. * participant: {
  127. * id: string
  128. * }
  129. * }}
  130. */
  131. export function participantLeft(id) {
  132. return {
  133. type: PARTICIPANT_LEFT,
  134. participant: {
  135. id
  136. }
  137. };
  138. }
  139. /**
  140. * Action to handle case when participant's role changes.
  141. *
  142. * @param {string} id - Participant id.
  143. * @param {PARTICIPANT_ROLE} role - Participant's new role.
  144. * @returns {{
  145. * type: PARTICIPANT_UPDATED,
  146. * participant: {
  147. * id: string,
  148. * role: PARTICIPANT_ROLE
  149. * }
  150. * }}
  151. */
  152. export function participantRoleChanged(id, role) {
  153. return {
  154. type: PARTICIPANT_UPDATED,
  155. participant: {
  156. id,
  157. role
  158. }
  159. };
  160. }
  161. /**
  162. * Create an action which pins a conference participant.
  163. *
  164. * @param {string|null} id - The ID of the conference participant to pin or null
  165. * if none of the conference's participants are to be pinned.
  166. * @returns {{
  167. * type: PIN_PARTICIPANT,
  168. * participant: {
  169. * id: string
  170. * }
  171. * }}
  172. */
  173. export function pinParticipant(id) {
  174. return {
  175. type: PIN_PARTICIPANT,
  176. participant: {
  177. id
  178. }
  179. };
  180. }