2020-04-16 10:47:10 +00:00
|
|
|
// @flow
|
|
|
|
|
2020-05-14 12:30:24 +00:00
|
|
|
import uuid from 'uuid';
|
|
|
|
|
|
|
|
import { getRoomName } from '../base/conference';
|
2020-05-20 10:57:03 +00:00
|
|
|
import { getDialOutStatusUrl, getDialOutUrl } from '../base/config/functions';
|
|
|
|
import { createLocalTrack } from '../base/lib-jitsi-meet';
|
2020-06-19 07:03:26 +00:00
|
|
|
import {
|
|
|
|
getLocalAudioTrack,
|
|
|
|
getLocalVideoTrack,
|
|
|
|
trackAdded,
|
|
|
|
replaceLocalTrack
|
|
|
|
} from '../base/tracks';
|
2020-05-20 10:57:03 +00:00
|
|
|
import { openURLInBrowser } from '../base/util';
|
|
|
|
import { executeDialOutRequest, executeDialOutStatusRequest, getDialInfoPageURL } from '../invite/functions';
|
|
|
|
import { showErrorNotification } from '../notifications';
|
|
|
|
|
2020-04-16 10:47:10 +00:00
|
|
|
import {
|
|
|
|
PREJOIN_START_CONFERENCE,
|
|
|
|
SET_DEVICE_STATUS,
|
2020-05-14 12:30:24 +00:00
|
|
|
SET_DIALOUT_COUNTRY,
|
|
|
|
SET_DIALOUT_NUMBER,
|
|
|
|
SET_DIALOUT_STATUS,
|
2020-07-02 09:18:38 +00:00
|
|
|
SET_PREJOIN_DISPLAY_NAME_REQUIRED,
|
2020-05-07 07:42:55 +00:00
|
|
|
SET_SKIP_PREJOIN,
|
2020-04-16 10:47:10 +00:00
|
|
|
SET_JOIN_BY_PHONE_DIALOG_VISIBLITY,
|
|
|
|
SET_PREJOIN_DEVICE_ERRORS,
|
2020-06-19 07:03:26 +00:00
|
|
|
SET_PREJOIN_PAGE_VISIBILITY
|
2020-04-16 10:47:10 +00:00
|
|
|
} from './actionTypes';
|
2020-05-14 12:30:24 +00:00
|
|
|
import {
|
|
|
|
getFullDialOutNumber,
|
|
|
|
getDialOutConferenceUrl,
|
|
|
|
getDialOutCountry,
|
|
|
|
isJoinByPhoneDialogVisible
|
|
|
|
} from './functions';
|
2020-05-20 10:57:03 +00:00
|
|
|
import logger from './logger';
|
2020-05-14 12:30:24 +00:00
|
|
|
|
|
|
|
const dialOutStatusToKeyMap = {
|
|
|
|
INITIATED: 'presenceStatus.calling',
|
|
|
|
RINGING: 'presenceStatus.ringing'
|
|
|
|
};
|
|
|
|
|
|
|
|
const DIAL_OUT_STATUS = {
|
|
|
|
INITIATED: 'INITIATED',
|
|
|
|
RINGING: 'RINGING',
|
|
|
|
CONNECTED: 'CONNECTED',
|
|
|
|
DISCONNECTED: 'DISCONNECTED',
|
|
|
|
FAILED: 'FAILED'
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The time interval used between requests while polling for dial out status.
|
|
|
|
*/
|
|
|
|
const STATUS_REQ_FREQUENCY = 2000;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The maximum number of retries while polling for dial out status.
|
|
|
|
*/
|
|
|
|
const STATUS_REQ_CAP = 45;
|
2020-04-16 10:47:10 +00:00
|
|
|
|
2020-05-14 12:30:24 +00:00
|
|
|
/**
|
|
|
|
* Polls for status change after dial out.
|
|
|
|
* Changes dialog message based on response, closes the dialog if there is an error,
|
|
|
|
* joins the meeting when CONNECTED.
|
|
|
|
*
|
|
|
|
* @param {string} reqId - The request id used to correlate the dial out request with this one.
|
|
|
|
* @param {Function} onSuccess - Success handler.
|
|
|
|
* @param {Function} onFail - Fail handler.
|
|
|
|
* @param {number} count - The number of retried calls. When it hits STATUS_REQ_CAP it should no longer make requests.
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
function pollForStatus(
|
|
|
|
reqId: string,
|
|
|
|
onSuccess: Function,
|
|
|
|
onFail: Function,
|
|
|
|
count = 0) {
|
|
|
|
return async function(dispatch: Function, getState: Function) {
|
|
|
|
const state = getState();
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (!isJoinByPhoneDialogVisible(state)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const res = await executeDialOutStatusRequest(getDialOutStatusUrl(state), reqId);
|
|
|
|
|
|
|
|
switch (res) {
|
|
|
|
case DIAL_OUT_STATUS.INITIATED:
|
|
|
|
case DIAL_OUT_STATUS.RINGING: {
|
|
|
|
dispatch(setDialOutStatus(dialOutStatusToKeyMap[res]));
|
|
|
|
|
|
|
|
if (count < STATUS_REQ_CAP) {
|
|
|
|
return setTimeout(() => {
|
|
|
|
dispatch(pollForStatus(reqId, onSuccess, onFail, count + 1));
|
|
|
|
}, STATUS_REQ_FREQUENCY);
|
|
|
|
}
|
|
|
|
|
|
|
|
return onFail();
|
|
|
|
}
|
|
|
|
|
|
|
|
case DIAL_OUT_STATUS.CONNECTED: {
|
|
|
|
return onSuccess();
|
|
|
|
}
|
|
|
|
|
|
|
|
case DIAL_OUT_STATUS.DISCONNECTED: {
|
|
|
|
dispatch(showErrorNotification({
|
|
|
|
titleKey: 'prejoin.errorDialOutDisconnected'
|
|
|
|
}));
|
|
|
|
|
|
|
|
return onFail();
|
|
|
|
}
|
|
|
|
|
|
|
|
case DIAL_OUT_STATUS.FAILED: {
|
|
|
|
dispatch(showErrorNotification({
|
|
|
|
titleKey: 'prejoin.errorDialOutFailed'
|
|
|
|
}));
|
|
|
|
|
|
|
|
return onFail();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
dispatch(showErrorNotification({
|
|
|
|
titleKey: 'prejoin.errorDialOutStatus'
|
|
|
|
}));
|
|
|
|
logger.error('Error getting dial out status', err);
|
|
|
|
onFail();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Action used for joining the meeting with phone audio.
|
|
|
|
* A dial out connection is tried and a polling mechanism is used for getting the status.
|
|
|
|
* If the connection succeeds the `onSuccess` callback is executed.
|
|
|
|
* If the phone connection fails or the number is invalid the `onFail` callback is executed.
|
|
|
|
*
|
|
|
|
* @param {Function} onSuccess - Success handler.
|
|
|
|
* @param {Function} onFail - Fail handler.
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
export function dialOut(onSuccess: Function, onFail: Function) {
|
|
|
|
return async function(dispatch: Function, getState: Function) {
|
|
|
|
const state = getState();
|
|
|
|
const reqId = uuid.v4();
|
|
|
|
const url = getDialOutUrl(state);
|
|
|
|
const conferenceUrl = getDialOutConferenceUrl(state);
|
|
|
|
const phoneNumber = getFullDialOutNumber(state);
|
|
|
|
const countryCode = getDialOutCountry(state).code.toUpperCase();
|
|
|
|
|
|
|
|
const body = {
|
|
|
|
conferenceUrl,
|
|
|
|
countryCode,
|
|
|
|
name: phoneNumber,
|
|
|
|
phoneNumber
|
|
|
|
};
|
|
|
|
|
|
|
|
try {
|
|
|
|
await executeDialOutRequest(url, body, reqId);
|
|
|
|
|
|
|
|
dispatch(pollForStatus(reqId, onSuccess, onFail));
|
|
|
|
} catch (err) {
|
|
|
|
const notification = {
|
|
|
|
titleKey: 'prejoin.errorDialOut',
|
|
|
|
titleArguments: undefined
|
|
|
|
};
|
|
|
|
|
|
|
|
if (err.status) {
|
|
|
|
if (err.messageKey === 'validation.failed') {
|
|
|
|
notification.titleKey = 'prejoin.errorValidation';
|
|
|
|
} else {
|
|
|
|
notification.titleKey = 'prejoin.errorStatusCode';
|
|
|
|
notification.titleArguments = { status: err.status };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch(showErrorNotification(notification));
|
|
|
|
logger.error('Error dialing out', err);
|
|
|
|
onFail();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-04-16 10:47:10 +00:00
|
|
|
/**
|
|
|
|
* Adds all the newly created tracks to store on init.
|
|
|
|
*
|
|
|
|
* @param {Object[]} tracks - The newly created tracks.
|
|
|
|
* @param {Object} errors - The errors from creating the tracks.
|
|
|
|
*
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
export function initPrejoin(tracks: Object[], errors: Object) {
|
|
|
|
return async function(dispatch: Function) {
|
|
|
|
dispatch(setPrejoinDeviceErrors(errors));
|
|
|
|
|
|
|
|
|
2020-06-19 07:03:26 +00:00
|
|
|
tracks.forEach(track => dispatch(trackAdded(track)));
|
2020-04-16 10:47:10 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-07-08 09:59:46 +00:00
|
|
|
* Action used to start the conference.
|
2020-04-16 10:47:10 +00:00
|
|
|
*
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
export function joinConference() {
|
2020-07-08 09:59:46 +00:00
|
|
|
return {
|
|
|
|
type: PREJOIN_START_CONFERENCE
|
2020-04-16 10:47:10 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Joins the conference without audio.
|
|
|
|
*
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
export function joinConferenceWithoutAudio() {
|
|
|
|
return async function(dispatch: Function, getState: Function) {
|
2020-06-19 07:03:26 +00:00
|
|
|
const tracks = getState()['features/base/tracks'];
|
|
|
|
const audioTrack = getLocalAudioTrack(tracks)?.jitsiTrack;
|
2020-04-16 10:47:10 +00:00
|
|
|
|
|
|
|
if (audioTrack) {
|
2020-06-19 07:03:26 +00:00
|
|
|
await dispatch(replaceLocalTrack(audioTrack, null));
|
2020-04-16 10:47:10 +00:00
|
|
|
}
|
|
|
|
dispatch(joinConference());
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-05-14 12:30:24 +00:00
|
|
|
/**
|
|
|
|
* Opens an external page with all the dial in numbers.
|
|
|
|
*
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
export function openDialInPage() {
|
|
|
|
return function(dispatch: Function, getState: Function) {
|
|
|
|
const state = getState();
|
|
|
|
const locationURL = state['features/base/connection'].locationURL;
|
|
|
|
const roomName = getRoomName(state);
|
|
|
|
const dialInPage = getDialInfoPageURL(roomName, locationURL);
|
|
|
|
|
|
|
|
openURLInBrowser(dialInPage, true);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-04-16 10:47:10 +00:00
|
|
|
/**
|
|
|
|
* Creates a new audio track based on a device id and replaces the current one.
|
|
|
|
*
|
|
|
|
* @param {string} deviceId - The deviceId of the microphone.
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
export function replaceAudioTrackById(deviceId: string) {
|
2020-06-19 07:03:26 +00:00
|
|
|
return async (dispatch: Function, getState: Function) => {
|
2020-04-16 10:47:10 +00:00
|
|
|
try {
|
2020-06-19 07:03:26 +00:00
|
|
|
const tracks = getState()['features/base/tracks'];
|
|
|
|
const newTrack = await createLocalTrack('audio', deviceId);
|
|
|
|
const oldTrack = getLocalAudioTrack(tracks)?.jitsiTrack;
|
2020-04-16 10:47:10 +00:00
|
|
|
|
2020-06-19 07:03:26 +00:00
|
|
|
dispatch(replaceLocalTrack(oldTrack, newTrack));
|
2020-04-16 10:47:10 +00:00
|
|
|
} catch (err) {
|
|
|
|
dispatch(setDeviceStatusWarning('prejoin.audioTrackError'));
|
|
|
|
logger.log('Error replacing audio track', err);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new video track based on a device id and replaces the current one.
|
|
|
|
*
|
|
|
|
* @param {string} deviceId - The deviceId of the camera.
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
export function replaceVideoTrackById(deviceId: Object) {
|
2020-06-19 07:03:26 +00:00
|
|
|
return async (dispatch: Function, getState: Function) => {
|
2020-04-16 10:47:10 +00:00
|
|
|
try {
|
2020-06-19 07:03:26 +00:00
|
|
|
const tracks = getState()['features/base/tracks'];
|
|
|
|
const newTrack = await createLocalTrack('video', deviceId);
|
|
|
|
const oldTrack = getLocalVideoTrack(tracks)?.jitsiTrack;
|
2020-04-16 10:47:10 +00:00
|
|
|
|
2020-06-19 07:03:26 +00:00
|
|
|
dispatch(replaceLocalTrack(oldTrack, newTrack));
|
2020-04-16 10:47:10 +00:00
|
|
|
} catch (err) {
|
|
|
|
dispatch(setDeviceStatusWarning('prejoin.videoTrackError'));
|
|
|
|
logger.log('Error replacing video track', err);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the device status as OK with the corresponding text.
|
|
|
|
*
|
|
|
|
* @param {string} deviceStatusText - The text to be set.
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
|
|
|
export function setDeviceStatusOk(deviceStatusText: string) {
|
|
|
|
return {
|
|
|
|
type: SET_DEVICE_STATUS,
|
|
|
|
value: {
|
|
|
|
deviceStatusText,
|
|
|
|
deviceStatusType: 'ok'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the device status as 'warning' with the corresponding text.
|
|
|
|
*
|
|
|
|
* @param {string} deviceStatusText - The text to be set.
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
|
|
|
export function setDeviceStatusWarning(deviceStatusText: string) {
|
|
|
|
return {
|
|
|
|
type: SET_DEVICE_STATUS,
|
|
|
|
value: {
|
|
|
|
deviceStatusText,
|
|
|
|
deviceStatusType: 'warning'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-05-14 12:30:24 +00:00
|
|
|
/**
|
|
|
|
* Action used to set the dial out status.
|
|
|
|
*
|
|
|
|
* @param {string} value - The status.
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
|
|
|
function setDialOutStatus(value: string) {
|
|
|
|
return {
|
|
|
|
type: SET_DIALOUT_STATUS,
|
|
|
|
value
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Action used to set the dial out country.
|
|
|
|
*
|
|
|
|
* @param {{ name: string, dialCode: string, code: string }} value - The country.
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
|
|
|
export function setDialOutCountry(value: Object) {
|
|
|
|
return {
|
|
|
|
type: SET_DIALOUT_COUNTRY,
|
|
|
|
value
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-07-02 09:18:38 +00:00
|
|
|
/**
|
|
|
|
* Action used to set the stance of the display name.
|
|
|
|
*
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
|
|
|
export function setPrejoinDisplayNameRequired() {
|
|
|
|
return {
|
|
|
|
type: SET_PREJOIN_DISPLAY_NAME_REQUIRED
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-05-14 12:30:24 +00:00
|
|
|
/**
|
|
|
|
* Action used to set the dial out number.
|
|
|
|
*
|
|
|
|
* @param {string} value - The dial out number.
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
|
|
|
export function setDialOutNumber(value: string) {
|
|
|
|
return {
|
|
|
|
type: SET_DIALOUT_NUMBER,
|
|
|
|
value
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-04-16 10:47:10 +00:00
|
|
|
/**
|
2020-05-07 07:42:55 +00:00
|
|
|
* Sets the visibility of the prejoin page for future uses.
|
2020-04-16 10:47:10 +00:00
|
|
|
*
|
2020-05-07 07:42:55 +00:00
|
|
|
* @param {boolean} value - The visibility value.
|
2020-04-16 10:47:10 +00:00
|
|
|
* @returns {Object}
|
|
|
|
*/
|
2020-05-07 07:42:55 +00:00
|
|
|
export function setSkipPrejoin(value: boolean) {
|
2020-04-16 10:47:10 +00:00
|
|
|
return {
|
2020-05-07 07:42:55 +00:00
|
|
|
type: SET_SKIP_PREJOIN,
|
2020-04-16 10:47:10 +00:00
|
|
|
value
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-05-07 07:42:55 +00:00
|
|
|
* Action used to set the visiblitiy of the 'JoinByPhoneDialog'.
|
2020-04-16 10:47:10 +00:00
|
|
|
*
|
2020-05-07 07:42:55 +00:00
|
|
|
* @param {boolean} value - The value.
|
2020-04-16 10:47:10 +00:00
|
|
|
* @returns {Object}
|
|
|
|
*/
|
2020-05-07 07:42:55 +00:00
|
|
|
export function setJoinByPhoneDialogVisiblity(value: boolean) {
|
2020-04-16 10:47:10 +00:00
|
|
|
return {
|
2020-05-07 07:42:55 +00:00
|
|
|
type: SET_JOIN_BY_PHONE_DIALOG_VISIBLITY,
|
2020-04-16 10:47:10 +00:00
|
|
|
value
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-05-07 07:42:55 +00:00
|
|
|
* Action used to set the initial errors after creating the tracks.
|
2020-04-16 10:47:10 +00:00
|
|
|
*
|
2020-05-07 07:42:55 +00:00
|
|
|
* @param {Object} value - The track errors.
|
2020-04-16 10:47:10 +00:00
|
|
|
* @returns {Object}
|
|
|
|
*/
|
2020-05-07 07:42:55 +00:00
|
|
|
export function setPrejoinDeviceErrors(value: Object) {
|
2020-04-16 10:47:10 +00:00
|
|
|
return {
|
2020-05-07 07:42:55 +00:00
|
|
|
type: SET_PREJOIN_DEVICE_ERRORS,
|
2020-04-16 10:47:10 +00:00
|
|
|
value
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Action used to set the visiblity of the prejoin page.
|
|
|
|
*
|
|
|
|
* @param {boolean} value - The value.
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
|
|
|
export function setPrejoinPageVisibility(value: boolean) {
|
|
|
|
return {
|
|
|
|
type: SET_PREJOIN_PAGE_VISIBILITY,
|
|
|
|
value
|
|
|
|
};
|
|
|
|
}
|