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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 ID of local participant has changed. This happens when
  31. * local participant joins a new conference or quits one.
  32. *
  33. * @param {string} id - New ID for local participant.
  34. * @returns {{
  35. * type: PARTICIPANT_ID_CHANGED,
  36. * newValue: string,
  37. * oldValue: string
  38. * }}
  39. */
  40. export function localParticipantIdChanged(id) {
  41. return (dispatch, getState) => {
  42. const participant = getLocalParticipant(getState);
  43. if (participant) {
  44. return dispatch({
  45. type: PARTICIPANT_ID_CHANGED,
  46. newValue: id,
  47. oldValue: participant.id
  48. });
  49. }
  50. };
  51. }
  52. /**
  53. * Action to signal that a local participant has joined.
  54. *
  55. * @param {Participant} participant={} - Information about participant.
  56. * @returns {{
  57. * type: PARTICIPANT_JOINED,
  58. * participant: Participant
  59. * }}
  60. */
  61. export function localParticipantJoined(participant = {}) {
  62. return participantJoined({
  63. ...participant,
  64. local: true
  65. });
  66. }
  67. /**
  68. * Action to update a participant's connection status.
  69. *
  70. * @param {string} id - Participant's ID.
  71. * @param {string} connectionStatus - The new connection status of the
  72. * participant.
  73. * @returns {{
  74. * type: PARTICIPANT_UPDATED,
  75. * participant: {
  76. * connectionStatus: string,
  77. * id: string
  78. * }
  79. * }}
  80. */
  81. export function participantConnectionStatusChanged(id, connectionStatus) {
  82. return {
  83. type: PARTICIPANT_UPDATED,
  84. participant: {
  85. connectionStatus,
  86. id
  87. }
  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 signal that a participant has left.
  120. *
  121. * @param {string} id - Participant's 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 signal that a participant's role has changed.
  139. *
  140. * @param {string} id - Participant's 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 participantUpdated({
  152. id,
  153. role
  154. });
  155. }
  156. /**
  157. * Action to signal that some of participant properties has been changed.
  158. *
  159. * @param {Participant} participant={} - Information about participant. To
  160. * identify the participant the object should contain either property id with
  161. * value the id of the participant or property local with value true (if the
  162. * local participant hasn't joined the conference yet).
  163. * @returns {{
  164. * type: PARTICIPANT_UPDATED,
  165. * participant: Participant
  166. * }}
  167. */
  168. export function participantUpdated(participant = {}) {
  169. return {
  170. type: PARTICIPANT_UPDATED,
  171. participant
  172. };
  173. }
  174. /**
  175. * Create an action which pins a conference participant.
  176. *
  177. * @param {string|null} id - The ID of the conference participant to pin or null
  178. * if none of the conference's participants are to be pinned.
  179. * @returns {{
  180. * type: PIN_PARTICIPANT,
  181. * participant: {
  182. * id: string
  183. * }
  184. * }}
  185. */
  186. export function pinParticipant(id) {
  187. return {
  188. type: PIN_PARTICIPANT,
  189. participant: {
  190. id
  191. }
  192. };
  193. }