Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

actions.js 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. import JitsiMeetJS from '../lib-jitsi-meet';
  2. import {
  3. changeParticipantEmail,
  4. dominantSpeakerChanged,
  5. participantJoined,
  6. participantLeft,
  7. participantRoleChanged
  8. } from '../participants';
  9. import { trackAdded, trackRemoved } from '../tracks';
  10. import {
  11. CONFERENCE_FAILED,
  12. CONFERENCE_JOINED,
  13. CONFERENCE_LEFT,
  14. CONFERENCE_WILL_LEAVE,
  15. SET_PASSWORD,
  16. SET_ROOM
  17. } from './actionTypes';
  18. import { EMAIL_COMMAND } from './constants';
  19. import { _addLocalTracksToConference } from './functions';
  20. import './middleware';
  21. import './reducer';
  22. /**
  23. * Adds conference (event) listeners.
  24. *
  25. * @param {JitsiConference} conference - The JitsiConference instance.
  26. * @param {Dispatch} dispatch - The Redux dispatch function.
  27. * @private
  28. * @returns {void}
  29. */
  30. function _addConferenceListeners(conference, dispatch) {
  31. const JitsiConferenceEvents = JitsiMeetJS.events.conference;
  32. conference.on(
  33. JitsiConferenceEvents.CONFERENCE_FAILED,
  34. (...args) => dispatch(_conferenceFailed(conference, ...args)));
  35. conference.on(
  36. JitsiConferenceEvents.CONFERENCE_JOINED,
  37. (...args) => dispatch(_conferenceJoined(conference, ...args)));
  38. conference.on(
  39. JitsiConferenceEvents.CONFERENCE_LEFT,
  40. (...args) => dispatch(_conferenceLeft(conference, ...args)));
  41. conference.on(
  42. JitsiConferenceEvents.DOMINANT_SPEAKER_CHANGED,
  43. (...args) => dispatch(dominantSpeakerChanged(...args)));
  44. conference.on(
  45. JitsiConferenceEvents.TRACK_ADDED,
  46. t => t && !t.isLocal() && dispatch(trackAdded(t)));
  47. conference.on(
  48. JitsiConferenceEvents.TRACK_REMOVED,
  49. t => t && !t.isLocal() && dispatch(trackRemoved(t)));
  50. conference.on(
  51. JitsiConferenceEvents.USER_JOINED,
  52. (id, user) => dispatch(participantJoined({
  53. id,
  54. name: user.getDisplayName(),
  55. role: user.getRole()
  56. })));
  57. conference.on(
  58. JitsiConferenceEvents.USER_LEFT,
  59. (...args) => dispatch(participantLeft(...args)));
  60. conference.on(
  61. JitsiConferenceEvents.USER_ROLE_CHANGED,
  62. (...args) => dispatch(participantRoleChanged(...args)));
  63. conference.addCommandListener(
  64. EMAIL_COMMAND,
  65. (data, id) => dispatch(changeParticipantEmail(id, data.value)));
  66. }
  67. /**
  68. * Signals that a specific conference has failed.
  69. *
  70. * @param {JitsiConference} conference - The JitsiConference that has failed.
  71. * @param {string} error - The error describing/detailing the cause of the
  72. * failure.
  73. * @returns {{
  74. * type: CONFERENCE_FAILED,
  75. * conference: JitsiConference,
  76. * error: string
  77. * }}
  78. */
  79. function _conferenceFailed(conference, error) {
  80. return {
  81. type: CONFERENCE_FAILED,
  82. conference,
  83. error
  84. };
  85. }
  86. /**
  87. * Attach any pre-existing local media to the conference once the conference has
  88. * been joined.
  89. *
  90. * @param {JitsiConference} conference - The JitsiConference instance which was
  91. * joined by the local participant.
  92. * @returns {Function}
  93. */
  94. function _conferenceJoined(conference) {
  95. return (dispatch, getState) => {
  96. const localTracks
  97. = getState()['features/base/tracks']
  98. .filter(t => t.local)
  99. .map(t => t.jitsiTrack);
  100. if (localTracks.length) {
  101. _addLocalTracksToConference(conference, localTracks);
  102. }
  103. dispatch({
  104. type: CONFERENCE_JOINED,
  105. conference
  106. });
  107. };
  108. }
  109. /**
  110. * Signals that a specific conference has been left.
  111. *
  112. * @param {JitsiConference} conference - The JitsiConference instance which was
  113. * left by the local participant.
  114. * @returns {{
  115. * type: CONFERENCE_LEFT,
  116. * conference: JitsiConference
  117. * }}
  118. */
  119. function _conferenceLeft(conference) {
  120. return {
  121. type: CONFERENCE_LEFT,
  122. conference
  123. };
  124. }
  125. /**
  126. * Signals the intention of the application to have the local participant leave
  127. * a specific conference. Similar in fashion to CONFERENCE_LEFT. Contrary to it
  128. * though, it's not guaranteed because CONFERENCE_LEFT may be triggered by
  129. * lib-jitsi-meet and not the application.
  130. *
  131. * @param {JitsiConference} conference - The JitsiConference instance which will
  132. * be left by the local participant.
  133. * @returns {{
  134. * type: CONFERENCE_LEFT,
  135. * conference: JitsiConference
  136. * }}
  137. */
  138. export function conferenceWillLeave(conference) {
  139. return {
  140. type: CONFERENCE_WILL_LEAVE,
  141. conference
  142. };
  143. }
  144. /**
  145. * Initializes a new conference.
  146. *
  147. * @returns {Function}
  148. */
  149. export function createConference() {
  150. return (dispatch, getState) => {
  151. const state = getState();
  152. const connection = state['features/base/connection'].connection;
  153. if (!connection) {
  154. throw new Error('Cannot create conference without connection');
  155. }
  156. const { password, room } = state['features/base/conference'];
  157. if (typeof room === 'undefined' || room === '') {
  158. throw new Error('Cannot join conference without room name');
  159. }
  160. // TODO Take options from config.
  161. const conference
  162. = connection.initJitsiConference(room, { openSctp: true });
  163. _addConferenceListeners(conference, dispatch);
  164. conference.join(password);
  165. };
  166. }
  167. /**
  168. * Sets the password to join or lock a specific JitsiConference.
  169. *
  170. * @param {JitsiConference} conference - The JitsiConference which requires a
  171. * password to join or is to be locked with the specified password.
  172. * @param {Function} method - The JitsiConference method of password protection
  173. * such as join or lock.
  174. * @param {string} password - The password with which the specified conference
  175. * is to be joined or locked.
  176. * @returns {{
  177. * type: SET_PASSWORD,
  178. * conference: JitsiConference,
  179. * method: Function,
  180. * password: string
  181. * }}
  182. */
  183. export function setPassword(conference, method, password) {
  184. return {
  185. type: SET_PASSWORD,
  186. conference,
  187. method,
  188. password
  189. };
  190. }
  191. /**
  192. * Sets (the name of) the room of the conference to be joined.
  193. *
  194. * @param {(string|undefined)} room - The name of the room of the conference to
  195. * be joined.
  196. * @returns {{
  197. * type: SET_ROOM,
  198. * room: string
  199. * }}
  200. */
  201. export function setRoom(room) {
  202. return {
  203. type: SET_ROOM,
  204. room
  205. };
  206. }