123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423 |
- import { JitsiConferenceEvents } from '../lib-jitsi-meet';
- import {
- changeParticipantLastNStatus,
- dominantSpeakerChanged,
- getLocalParticipant,
- participantJoined,
- participantLeft,
- participantRoleChanged,
- participantUpdated
- } from '../participants';
- import { trackAdded, trackRemoved } from '../tracks';
-
- import {
- CONFERENCE_FAILED,
- CONFERENCE_JOINED,
- CONFERENCE_LEFT,
- CONFERENCE_WILL_JOIN,
- CONFERENCE_WILL_LEAVE,
- LOCK_STATE_CHANGED,
- SET_LASTN,
- SET_PASSWORD,
- SET_ROOM
- } from './actionTypes';
- import {
- AVATAR_ID_COMMAND,
- AVATAR_URL_COMMAND,
- EMAIL_COMMAND
- } from './constants';
- import { _addLocalTracksToConference } from './functions';
-
- import type { Dispatch } from 'redux';
-
- /**
- * Adds conference (event) listeners.
- *
- * @param {JitsiConference} conference - The JitsiConference instance.
- * @param {Dispatch} dispatch - The Redux dispatch function.
- * @private
- * @returns {void}
- */
- function _addConferenceListeners(conference, dispatch) {
- conference.on(
- JitsiConferenceEvents.CONFERENCE_FAILED,
- (...args) => dispatch(conferenceFailed(conference, ...args)));
- conference.on(
- JitsiConferenceEvents.CONFERENCE_JOINED,
- (...args) => dispatch(conferenceJoined(conference, ...args)));
- conference.on(
- JitsiConferenceEvents.CONFERENCE_LEFT,
- (...args) => dispatch(conferenceLeft(conference, ...args)));
-
- conference.on(
- JitsiConferenceEvents.DOMINANT_SPEAKER_CHANGED,
- (...args) => dispatch(dominantSpeakerChanged(...args)));
-
- conference.on(
- JitsiConferenceEvents.LAST_N_ENDPOINTS_CHANGED,
- (...args) => _lastNEndpointsChanged(dispatch, ...args));
-
- conference.on(
- JitsiConferenceEvents.LOCK_STATE_CHANGED,
- (...args) => dispatch(_lockStateChanged(conference, ...args)));
-
- conference.on(
- JitsiConferenceEvents.TRACK_ADDED,
- t => t && !t.isLocal() && dispatch(trackAdded(t)));
- conference.on(
- JitsiConferenceEvents.TRACK_REMOVED,
- t => t && !t.isLocal() && dispatch(trackRemoved(t)));
-
- conference.on(
- JitsiConferenceEvents.USER_JOINED,
- (id, user) => dispatch(participantJoined({
- id,
- name: user.getDisplayName(),
- role: user.getRole()
- })));
- conference.on(
- JitsiConferenceEvents.USER_LEFT,
- (...args) => dispatch(participantLeft(...args)));
- conference.on(
- JitsiConferenceEvents.USER_ROLE_CHANGED,
- (...args) => dispatch(participantRoleChanged(...args)));
-
- conference.addCommandListener(
- AVATAR_ID_COMMAND,
- (data, id) => dispatch(participantUpdated({
- id,
- avatarID: data.value
- })));
- conference.addCommandListener(
- AVATAR_URL_COMMAND,
- (data, id) => dispatch(participantUpdated({
- id,
- avatarURL: data.value
- })));
- conference.addCommandListener(
- EMAIL_COMMAND,
- (data, id) => dispatch(participantUpdated({
- id,
- email: data.value
- })));
- }
-
- /**
- * Sets the data for the local participant to the conference.
- *
- * @param {JitsiConference} conference - The JitsiConference instance.
- * @param {Object} state - The Redux state.
- * @returns {void}
- */
- function _setLocalParticipantData(conference, state) {
- const localParticipant
- = getLocalParticipant(state['features/base/participants']);
-
- conference.removeCommand(AVATAR_ID_COMMAND);
- conference.sendCommand(AVATAR_ID_COMMAND, {
- value: localParticipant.avatarID
- });
- }
-
- /**
- * Signals that a specific conference has failed.
- *
- * @param {JitsiConference} conference - The JitsiConference that has failed.
- * @param {string} error - The error describing/detailing the cause of the
- * failure.
- * @returns {{
- * type: CONFERENCE_FAILED,
- * conference: JitsiConference,
- * error: string
- * }}
- * @public
- */
- export function conferenceFailed(conference, error) {
- return {
- type: CONFERENCE_FAILED,
- conference,
- error
- };
- }
-
- /**
- * Attach any pre-existing local media to the conference once the conference has
- * been joined.
- *
- * @param {JitsiConference} conference - The JitsiConference instance which was
- * joined by the local participant.
- * @returns {Function}
- */
- export function conferenceJoined(conference) {
- return (dispatch, getState) => {
- const localTracks
- = getState()['features/base/tracks']
- .filter(t => t.local)
- .map(t => t.jitsiTrack);
-
- if (localTracks.length) {
- _addLocalTracksToConference(conference, localTracks);
- }
-
- dispatch({
- type: CONFERENCE_JOINED,
- conference
- });
- };
- }
-
- /**
- * Signals that a specific conference has been left.
- *
- * @param {JitsiConference} conference - The JitsiConference instance which was
- * left by the local participant.
- * @returns {{
- * type: CONFERENCE_LEFT,
- * conference: JitsiConference
- * }}
- */
- export function conferenceLeft(conference) {
- return {
- type: CONFERENCE_LEFT,
- conference
- };
- }
-
- /**
- * Signals the intention of the application to have the local participant join a
- * conference with a specific room (name). Similar in fashion
- * to CONFERENCE_JOINED.
- *
- * @param {string} room - The room (name) which identifies the conference the
- * local participant will (try to) join.
- * @returns {{
- * type: CONFERENCE_WILL_JOIN,
- * room: string
- * }}
- */
- function _conferenceWillJoin(room) {
- return {
- type: CONFERENCE_WILL_JOIN,
- room
- };
- }
-
- /**
- * Signals the intention of the application to have the local participant leave
- * a specific conference. Similar in fashion to CONFERENCE_LEFT. Contrary to it
- * though, it's not guaranteed because CONFERENCE_LEFT may be triggered by
- * lib-jitsi-meet and not the application.
- *
- * @param {JitsiConference} conference - The JitsiConference instance which will
- * be left by the local participant.
- * @returns {{
- * type: CONFERENCE_LEFT,
- * conference: JitsiConference
- * }}
- */
- export function conferenceWillLeave(conference) {
- return {
- type: CONFERENCE_WILL_LEAVE,
- conference
- };
- }
-
- /**
- * Initializes a new conference.
- *
- * @returns {Function}
- */
- export function createConference() {
- return (dispatch, getState) => {
- const state = getState();
- const connection = state['features/base/connection'].connection;
-
- if (!connection) {
- throw new Error('Cannot create conference without connection');
- }
-
- const { password, room } = state['features/base/conference'];
-
- if (typeof room === 'undefined' || room === '') {
- throw new Error('Cannot join conference without room name');
- }
-
- dispatch(_conferenceWillJoin(room));
-
- // TODO Take options from config.
- const conference
- = connection.initJitsiConference(
-
- // XXX Lib-jitsi-meet does not accept uppercase letters.
- room.toLowerCase(),
- {
- openSctp: true
-
- // FIXME I tested H.264 from iPhone 6S during a morning
- // standup but, unfortunately, the other participants who
- // happened to be running the Web app saw only black.
- //
- // preferH264: true
- });
-
- _addConferenceListeners(conference, dispatch);
-
- _setLocalParticipantData(conference, state);
-
- conference.join(password);
- };
- }
-
- /**
- * Handles the lastN status changes for participants in the current conference.
- * Signals that a participant's lastN status has changed, for each participant
- * who entered or left the last N set.
- *
- * @param {Dispatch} dispatch - Redux dispatch function.
- * @param {Array} leavingIds - Ids of participants who are leaving the last N
- * set.
- * @param {Array} enteringIds - Ids of participants who are entering the last N
- * set.
- * @returns {void}
- *
- * @private
- */
- function _lastNEndpointsChanged(dispatch, leavingIds = [], enteringIds = []) {
- for (const id of leavingIds) {
- dispatch(changeParticipantLastNStatus(id, false));
- }
-
- for (const id of enteringIds) {
- dispatch(changeParticipantLastNStatus(id, true));
- }
- }
-
- /**
- * Signals that the lock state of a specific JitsiConference changed.
- *
- * @param {JitsiConference} conference - The JitsiConference which had its lock
- * state changed.
- * @param {boolean} locked - If the specified conference became locked, true;
- * otherwise, false.
- * @returns {{
- * type: LOCK_STATE_CHANGED,
- * conference: JitsiConference,
- * locked: boolean
- * }}
- */
- function _lockStateChanged(conference, locked) {
- return {
- type: LOCK_STATE_CHANGED,
- conference,
- locked
- };
- }
-
- /**
- * Sets the video channel's last N (value) of the current conference. A value of
- * undefined shall be used to reset it to the default value.
- *
- * @param {(number|undefined)} lastN - The last N value to be set.
- * @returns {Function}
- */
- export function setLastN(lastN: ?number) {
- return (dispatch: Dispatch<*>, getState: Function) => {
- if (typeof lastN === 'undefined') {
- const { config } = getState()['features/base/lib-jitsi-meet'];
-
- /* eslint-disable no-param-reassign */
-
- lastN = config.channelLastN;
- if (typeof lastN === 'undefined') {
- lastN = -1;
- }
-
- /* eslint-enable no-param-reassign */
- }
-
- dispatch({
- type: SET_LASTN,
- lastN
- });
- };
- }
-
- /**
- * Sets the password to join or lock a specific JitsiConference.
- *
- * @param {JitsiConference} conference - The JitsiConference which requires a
- * password to join or is to be locked with the specified password.
- * @param {Function} method - The JitsiConference method of password protection
- * such as join or lock.
- * @param {string} password - The password with which the specified conference
- * is to be joined or locked.
- * @returns {Function}
- */
- export function setPassword(conference, method, password) {
- return (dispatch, getState) => {
- switch (method) {
- case conference.join: {
- let state = getState()['features/base/conference'];
-
- // Make sure that the action will set a password for a conference
- // that the application wants joined.
- if (state.passwordRequired === conference) {
- dispatch({
- type: SET_PASSWORD,
- conference,
- method,
- password
- });
-
- // Join the conference with the newly-set password.
-
- // Make sure that the action did set the password.
- state = getState()['features/base/conference'];
- if (state.password === password
- && !state.passwordRequired
-
- // Make sure that the application still wants the
- // conference joined.
- && !state.conference) {
- method.call(conference, password);
- }
- }
- break;
- }
-
- case conference.lock: {
- const state = getState()['features/base/conference'];
-
- if (state.conference === conference) {
- return (
- method.call(conference, password)
- .then(() => dispatch({
- type: SET_PASSWORD,
- conference,
- method,
- password
- })));
- }
-
- return Promise.reject();
- }
- }
- };
- }
-
- /**
- * Sets (the name of) the room of the conference to be joined.
- *
- * @param {(string|undefined)} room - The name of the room of the conference to
- * be joined.
- * @returns {{
- * type: SET_ROOM,
- * room: string
- * }}
- */
- export function setRoom(room) {
- return {
- type: SET_ROOM,
- room
- };
- }
|