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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 remove a local participant.
  69. *
  70. * @returns {Function}
  71. */
  72. export function localParticipantLeft() {
  73. return (dispatch, getState) => {
  74. const participant = getLocalParticipant(getState);
  75. if (participant) {
  76. return dispatch(participantLeft(participant.id));
  77. }
  78. };
  79. }
  80. /**
  81. * Action to signal that a participant has joined.
  82. *
  83. * @param {Participant} participant - Information about participant.
  84. * @returns {{
  85. * type: PARTICIPANT_JOINED,
  86. * participant: Participant
  87. * }}
  88. */
  89. export function participantJoined(participant) {
  90. return {
  91. type: PARTICIPANT_JOINED,
  92. participant
  93. };
  94. }
  95. /**
  96. * Action to signal that a participant has left.
  97. *
  98. * @param {string} id - Participant's ID.
  99. * @returns {{
  100. * type: PARTICIPANT_LEFT,
  101. * participant: {
  102. * id: string
  103. * }
  104. * }}
  105. */
  106. export function participantLeft(id) {
  107. return {
  108. type: PARTICIPANT_LEFT,
  109. participant: {
  110. id
  111. }
  112. };
  113. }
  114. /**
  115. * Action to signal that a participant's role has changed.
  116. *
  117. * @param {string} id - Participant's ID.
  118. * @param {PARTICIPANT_ROLE} role - Participant's new role.
  119. * @returns {{
  120. * type: PARTICIPANT_UPDATED,
  121. * participant: {
  122. * id: string,
  123. * role: PARTICIPANT_ROLE
  124. * }
  125. * }}
  126. */
  127. export function participantRoleChanged(id, role) {
  128. return participantUpdated({
  129. id,
  130. role
  131. });
  132. }
  133. /**
  134. * Action to signal that some of participant properties has been changed.
  135. *
  136. * @param {Participant} participant={} - Information about participant. To
  137. * identify the participant the object should contain either property id with
  138. * value the id of the participant or property local with value true (if the
  139. * local participant hasn't joined the conference yet).
  140. * @returns {{
  141. * type: PARTICIPANT_UPDATED,
  142. * participant: Participant
  143. * }}
  144. */
  145. export function participantUpdated(participant = {}) {
  146. return {
  147. type: PARTICIPANT_UPDATED,
  148. participant
  149. };
  150. }
  151. /**
  152. * Create an action which pins a conference participant.
  153. *
  154. * @param {string|null} id - The ID of the conference participant to pin or null
  155. * if none of the conference's participants are to be pinned.
  156. * @returns {{
  157. * type: PIN_PARTICIPANT,
  158. * participant: {
  159. * id: string
  160. * }
  161. * }}
  162. */
  163. export function pinParticipant(id) {
  164. return {
  165. type: PIN_PARTICIPANT,
  166. participant: {
  167. id
  168. }
  169. };
  170. }