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

actions.js 4.0KB

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