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 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. * Create an action for when dominant speaker changes.
  12. *
  13. * @param {string} id - Participant's ID.
  14. * @returns {{
  15. * type: DOMINANT_SPEAKER_CHANGED,
  16. * participant: {
  17. * id: string
  18. * }
  19. * }}
  20. */
  21. export function dominantSpeakerChanged(id) {
  22. return {
  23. type: DOMINANT_SPEAKER_CHANGED,
  24. participant: {
  25. id
  26. }
  27. };
  28. }
  29. /**
  30. * Action to signal that the ID of local participant has changed. It happens
  31. * when the local participant joins a new conference or leaves an existing
  32. * conference.
  33. *
  34. * @param {string} id - New ID for local participant.
  35. * @returns {Function}
  36. */
  37. export function localParticipantIdChanged(id) {
  38. return (dispatch, getState) => {
  39. const participant = getLocalParticipant(getState);
  40. if (participant) {
  41. return dispatch({
  42. type: PARTICIPANT_ID_CHANGED,
  43. newValue: id,
  44. oldValue: participant.id
  45. });
  46. }
  47. };
  48. }
  49. /**
  50. * Action to signal that a local participant has joined.
  51. *
  52. * @param {Participant} participant={} - Information about participant.
  53. * @returns {{
  54. * type: PARTICIPANT_JOINED,
  55. * participant: Participant
  56. * }}
  57. */
  58. export function localParticipantJoined(participant = {}) {
  59. return participantJoined({
  60. ...participant,
  61. local: true
  62. });
  63. }
  64. /**
  65. * Action to signal the role of the local participant has changed. It can happen
  66. * when the participant has joined a conference, even before a non-default local
  67. * id has been set, or after a moderator leaves.
  68. *
  69. * @param {string} role - The new role of the local participant.
  70. * @returns {Function}
  71. */
  72. export function localParticipantRoleChanged(role) {
  73. return (dispatch, getState) => {
  74. const participant = getLocalParticipant(getState);
  75. if (participant) {
  76. return dispatch(participantRoleChanged(participant.id, role));
  77. }
  78. };
  79. }
  80. /**
  81. * Action to update a participant's connection status.
  82. *
  83. * @param {string} id - Participant's ID.
  84. * @param {string} connectionStatus - The new connection status of the
  85. * participant.
  86. * @returns {{
  87. * type: PARTICIPANT_UPDATED,
  88. * participant: {
  89. * connectionStatus: string,
  90. * id: string
  91. * }
  92. * }}
  93. */
  94. export function participantConnectionStatusChanged(id, connectionStatus) {
  95. return {
  96. type: PARTICIPANT_UPDATED,
  97. participant: {
  98. connectionStatus,
  99. id
  100. }
  101. };
  102. }
  103. /**
  104. * Action to remove a local participant.
  105. *
  106. * @returns {Function}
  107. */
  108. export function localParticipantLeft() {
  109. return (dispatch, getState) => {
  110. const participant = getLocalParticipant(getState);
  111. if (participant) {
  112. return dispatch(participantLeft(participant.id));
  113. }
  114. };
  115. }
  116. /**
  117. * Action to signal that a participant has joined.
  118. *
  119. * @param {Participant} participant - Information about participant.
  120. * @returns {{
  121. * type: PARTICIPANT_JOINED,
  122. * participant: Participant
  123. * }}
  124. */
  125. export function participantJoined(participant) {
  126. return {
  127. type: PARTICIPANT_JOINED,
  128. participant
  129. };
  130. }
  131. /**
  132. * Action to signal that a participant has left.
  133. *
  134. * @param {string} id - Participant's ID.
  135. * @returns {{
  136. * type: PARTICIPANT_LEFT,
  137. * participant: {
  138. * id: string
  139. * }
  140. * }}
  141. */
  142. export function participantLeft(id) {
  143. return {
  144. type: PARTICIPANT_LEFT,
  145. participant: {
  146. id
  147. }
  148. };
  149. }
  150. /**
  151. * Action to signal that a participant's role has changed.
  152. *
  153. * @param {string} id - Participant's ID.
  154. * @param {PARTICIPANT_ROLE} role - Participant's new role.
  155. * @returns {{
  156. * type: PARTICIPANT_UPDATED,
  157. * participant: {
  158. * id: string,
  159. * role: PARTICIPANT_ROLE
  160. * }
  161. * }}
  162. */
  163. export function participantRoleChanged(id, role) {
  164. return participantUpdated({
  165. id,
  166. role
  167. });
  168. }
  169. /**
  170. * Action to signal that some of participant properties has been changed.
  171. *
  172. * @param {Participant} participant={} - Information about participant. To
  173. * identify the participant the object should contain either property id with
  174. * value the id of the participant or property local with value true (if the
  175. * local participant hasn't joined the conference yet).
  176. * @returns {{
  177. * type: PARTICIPANT_UPDATED,
  178. * participant: Participant
  179. * }}
  180. */
  181. export function participantUpdated(participant = {}) {
  182. return {
  183. type: PARTICIPANT_UPDATED,
  184. participant
  185. };
  186. }
  187. /**
  188. * Create an action which pins a conference participant.
  189. *
  190. * @param {string|null} id - The ID of the conference participant to pin or null
  191. * if none of the conference's participants are to be pinned.
  192. * @returns {{
  193. * type: PIN_PARTICIPANT,
  194. * participant: {
  195. * id: string
  196. * }
  197. * }}
  198. */
  199. export function pinParticipant(id) {
  200. return {
  201. type: PIN_PARTICIPANT,
  202. participant: {
  203. id
  204. }
  205. };
  206. }