2017-02-28 03:21:50 +00:00
|
|
|
import { JitsiConferenceEvents } from '../lib-jitsi-meet';
|
2016-10-05 14:36:59 +00:00
|
|
|
import {
|
|
|
|
changeParticipantEmail,
|
|
|
|
dominantSpeakerChanged,
|
|
|
|
participantJoined,
|
|
|
|
participantLeft,
|
|
|
|
participantRoleChanged
|
|
|
|
} from '../participants';
|
2016-12-05 15:14:50 +00:00
|
|
|
import { trackAdded, trackRemoved } from '../tracks';
|
2016-10-05 14:36:59 +00:00
|
|
|
|
|
|
|
import {
|
2016-12-12 01:02:50 +00:00
|
|
|
CONFERENCE_FAILED,
|
2016-10-05 14:36:59 +00:00
|
|
|
CONFERENCE_JOINED,
|
|
|
|
CONFERENCE_LEFT,
|
2017-01-18 19:28:52 +00:00
|
|
|
CONFERENCE_WILL_JOIN,
|
2016-10-05 14:36:59 +00:00
|
|
|
CONFERENCE_WILL_LEAVE,
|
2016-12-12 19:49:23 +00:00
|
|
|
LOCK_STATE_CHANGED,
|
2016-12-12 01:02:50 +00:00
|
|
|
SET_PASSWORD,
|
2016-10-05 14:36:59 +00:00
|
|
|
SET_ROOM
|
|
|
|
} from './actionTypes';
|
|
|
|
import { EMAIL_COMMAND } from './constants';
|
|
|
|
import { _addLocalTracksToConference } from './functions';
|
|
|
|
|
|
|
|
/**
|
2016-12-12 00:29:13 +00:00
|
|
|
* Adds conference (event) listeners.
|
2016-10-05 14:36:59 +00:00
|
|
|
*
|
2016-12-12 00:29:13 +00:00
|
|
|
* @param {JitsiConference} conference - The JitsiConference instance.
|
|
|
|
* @param {Dispatch} dispatch - The Redux dispatch function.
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
2016-10-05 14:36:59 +00:00
|
|
|
*/
|
2016-12-12 00:29:13 +00:00
|
|
|
function _addConferenceListeners(conference, dispatch) {
|
2016-12-12 01:02:50 +00:00
|
|
|
conference.on(
|
|
|
|
JitsiConferenceEvents.CONFERENCE_FAILED,
|
2017-01-31 20:58:48 +00:00
|
|
|
(...args) => dispatch(conferenceFailed(conference, ...args)));
|
2016-12-12 00:29:13 +00:00
|
|
|
conference.on(
|
|
|
|
JitsiConferenceEvents.CONFERENCE_JOINED,
|
|
|
|
(...args) => dispatch(_conferenceJoined(conference, ...args)));
|
|
|
|
conference.on(
|
|
|
|
JitsiConferenceEvents.CONFERENCE_LEFT,
|
|
|
|
(...args) => dispatch(_conferenceLeft(conference, ...args)));
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2016-12-12 00:29:13 +00:00
|
|
|
conference.on(
|
|
|
|
JitsiConferenceEvents.DOMINANT_SPEAKER_CHANGED,
|
|
|
|
(...args) => dispatch(dominantSpeakerChanged(...args)));
|
|
|
|
|
2016-12-12 19:49:23 +00:00
|
|
|
conference.on(
|
|
|
|
JitsiConferenceEvents.LOCK_STATE_CHANGED,
|
|
|
|
(...args) => dispatch(_lockStateChanged(conference, ...args)));
|
|
|
|
|
2016-12-12 00:29:13 +00:00
|
|
|
conference.on(
|
|
|
|
JitsiConferenceEvents.TRACK_ADDED,
|
|
|
|
t => t && !t.isLocal() && dispatch(trackAdded(t)));
|
|
|
|
conference.on(
|
|
|
|
JitsiConferenceEvents.TRACK_REMOVED,
|
|
|
|
t => t && !t.isLocal() && dispatch(trackRemoved(t)));
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2016-12-12 00:29:13 +00:00
|
|
|
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)));
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2016-12-12 00:29:13 +00:00
|
|
|
conference.addCommandListener(
|
|
|
|
EMAIL_COMMAND,
|
|
|
|
(data, id) => dispatch(changeParticipantEmail(id, data.value)));
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|
|
|
|
|
2016-12-12 01:02:50 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
* }}
|
2017-01-31 20:58:48 +00:00
|
|
|
* @public
|
2016-12-12 01:02:50 +00:00
|
|
|
*/
|
2017-01-31 20:58:48 +00:00
|
|
|
export function conferenceFailed(conference, error) {
|
2016-12-12 01:02:50 +00:00
|
|
|
return {
|
|
|
|
type: CONFERENCE_FAILED,
|
|
|
|
conference,
|
|
|
|
error
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
|
|
|
* 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}
|
|
|
|
*/
|
2016-12-05 15:14:50 +00:00
|
|
|
function _conferenceJoined(conference) {
|
2016-10-05 14:36:59 +00:00
|
|
|
return (dispatch, getState) => {
|
2016-12-05 15:14:50 +00:00
|
|
|
const localTracks
|
|
|
|
= getState()['features/base/tracks']
|
|
|
|
.filter(t => t.local)
|
|
|
|
.map(t => t.jitsiTrack);
|
2016-10-05 14:36:59 +00:00
|
|
|
|
|
|
|
if (localTracks.length) {
|
|
|
|
_addLocalTracksToConference(conference, localTracks);
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: CONFERENCE_JOINED,
|
2016-12-12 00:29:13 +00:00
|
|
|
conference
|
2016-10-05 14:36:59 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-01-18 19:28:52 +00:00
|
|
|
/**
|
2017-01-20 18:11:11 +00:00
|
|
|
* Signals that a specific conference has been left.
|
2017-01-18 19:28:52 +00:00
|
|
|
*
|
2017-01-20 18:11:11 +00:00
|
|
|
* @param {JitsiConference} conference - The JitsiConference instance which was
|
|
|
|
* left by the local participant.
|
2017-01-18 19:28:52 +00:00
|
|
|
* @returns {{
|
2017-01-20 18:11:11 +00:00
|
|
|
* type: CONFERENCE_LEFT,
|
|
|
|
* conference: JitsiConference
|
2017-01-18 19:28:52 +00:00
|
|
|
* }}
|
|
|
|
*/
|
2017-01-20 18:11:11 +00:00
|
|
|
function _conferenceLeft(conference) {
|
2017-01-18 19:28:52 +00:00
|
|
|
return {
|
2017-01-20 18:11:11 +00:00
|
|
|
type: CONFERENCE_LEFT,
|
|
|
|
conference
|
2017-01-18 19:28:52 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
2017-01-20 18:11:11 +00:00
|
|
|
* 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.
|
2016-10-05 14:36:59 +00:00
|
|
|
*
|
2017-01-20 18:11:11 +00:00
|
|
|
* @param {string} room - The room (name) which identifies the conference the
|
|
|
|
* local participant will (try to) join.
|
2016-10-05 14:36:59 +00:00
|
|
|
* @returns {{
|
2017-01-20 18:11:11 +00:00
|
|
|
* type: CONFERENCE_WILL_JOIN,
|
|
|
|
* room: string
|
2016-10-05 14:36:59 +00:00
|
|
|
* }}
|
|
|
|
*/
|
2017-01-20 18:11:11 +00:00
|
|
|
function _conferenceWillJoin(room) {
|
2016-10-05 14:36:59 +00:00
|
|
|
return {
|
2017-01-20 18:11:11 +00:00
|
|
|
type: CONFERENCE_WILL_JOIN,
|
|
|
|
room
|
2016-10-05 14:36:59 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-12-12 00:29:13 +00:00
|
|
|
* Signals the intention of the application to have the local participant leave
|
|
|
|
* a specific conference. Similar in fashion to CONFERENCE_LEFT. Contrary to it
|
2016-10-05 14:36:59 +00:00
|
|
|
* 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,
|
2016-12-12 00:29:13 +00:00
|
|
|
* conference: JitsiConference
|
2016-10-05 14:36:59 +00:00
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
export function conferenceWillLeave(conference) {
|
|
|
|
return {
|
|
|
|
type: CONFERENCE_WILL_LEAVE,
|
2016-12-12 00:29:13 +00:00
|
|
|
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');
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|
2016-12-12 00:29:13 +00:00
|
|
|
|
2016-12-12 01:02:50 +00:00
|
|
|
const { password, room } = state['features/base/conference'];
|
2016-12-12 00:29:13 +00:00
|
|
|
|
|
|
|
if (typeof room === 'undefined' || room === '') {
|
|
|
|
throw new Error('Cannot join conference without room name');
|
|
|
|
}
|
|
|
|
|
2017-01-20 18:11:11 +00:00
|
|
|
dispatch(_conferenceWillJoin(room));
|
2017-01-18 19:28:52 +00:00
|
|
|
|
2016-12-12 00:29:13 +00:00
|
|
|
// TODO Take options from config.
|
|
|
|
const conference
|
2017-01-15 19:05:17 +00:00
|
|
|
= connection.initJitsiConference(
|
2017-01-20 18:11:11 +00:00
|
|
|
|
2017-02-24 18:01:10 +00:00
|
|
|
// 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
|
|
|
|
});
|
2016-12-12 00:29:13 +00:00
|
|
|
|
|
|
|
_addConferenceListeners(conference, dispatch);
|
|
|
|
|
2016-12-12 01:02:50 +00:00
|
|
|
conference.join(password);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-12-12 19:49:23 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-12-12 01:02:50 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
2016-12-13 09:14:04 +00:00
|
|
|
* @returns {Function}
|
2016-12-12 01:02:50 +00:00
|
|
|
*/
|
|
|
|
export function setPassword(conference, method, password) {
|
2016-12-13 09:14:04 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
2016-10-05 14:36:59 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
};
|
|
|
|
}
|