feat(invite): Add conference id to dial-in numbers display

DialInNumbersForm has been modified to display a conference id to be used for
dialing into the conference. The changes include:
- Requesting the conference id and adding the conference id to the redux store
- Displaying the conference id in DialInNumbersForm
- Modifying the copy behavior to support copying the new message to clipboard
- DialInNumbersForm does not display until all ajax requests have completed
  successfully. This eliminates the need for the REQUESTING state.
This commit is contained in:
Leonard Kim 2017-05-16 12:19:30 -07:00
parent 896dcde2b2
commit 47c07c2e76
7 changed files with 137 additions and 148 deletions

View File

@ -8,6 +8,19 @@
.invite-dialog { .invite-dialog {
.dial-in-numbers { .dial-in-numbers {
.dial-in-numbers-copy {
opacity: 0;
pointer-events: none;
position: fixed;
user-select: text;
-webkit-user-select: text;
}
.dial-in-numbers-conference-id {
color: orange;
margin-left: 3px;
}
.dial-in-numbers-trigger { .dial-in-numbers-trigger {
position: relative; position: relative;
width: 100%; width: 100%;

View File

@ -437,14 +437,13 @@
}, },
"invite": { "invite": {
"addPassword": "Add password", "addPassword": "Add password",
"dialInNumbers": "Dial-in telephone numbers", "callNumber": "Call __number__",
"errorFetchingNumbers": "Failed to obtain dial-in numbers", "enterId": "Enter Meeting ID: __meetingId__ following by # to dial in from a phone",
"howToDialIn": "To dial in, use one of the following numbers and meeting ID",
"hidePassword": "Hide password", "hidePassword": "Hide password",
"inviteTo": "Invite people to __conferenceName__", "inviteTo": "Invite people to __conferenceName__",
"loadingNumbers": "Loading...", "invitedYouTo": "__userName__ has invited you to the __meetingUrl__ conference",
"locked": "This call is locked. New callers must have the link and enter the password to join.", "locked": "This call is locked. New callers must have the link and enter the password to join.",
"noNumbers": "No numbers available",
"numbersDisabled": "Dialing in has been disabled",
"showPassword": "Show password", "showPassword": "Show password",
"unlocked": "This call is unlocked. Any new caller with the link may join the call." "unlocked": "This call is unlocked. Any new caller with the link may join the call."
} }

View File

@ -12,17 +12,6 @@ import { Symbol } from '../base/react';
export const UPDATE_DIAL_IN_NUMBERS_FAILED export const UPDATE_DIAL_IN_NUMBERS_FAILED
= Symbol('UPDATE_DIAL_IN_NUMBERS_FAILED'); = Symbol('UPDATE_DIAL_IN_NUMBERS_FAILED');
/**
* The type of the action which signals a request for dial-in numbers has been
* started.
*
* {
* type: UPDATE_DIAL_IN_NUMBERS_REQUEST
* }
*/
export const UPDATE_DIAL_IN_NUMBERS_REQUEST
= Symbol('UPDATE_DIAL_IN_NUMBERS_REQUEST');
/** /**
* The type of the action which signals a request for dial-in numbers has * The type of the action which signals a request for dial-in numbers has
* succeeded. * succeeded.

View File

@ -2,7 +2,6 @@ import { openDialog } from '../../features/base/dialog';
import { import {
UPDATE_DIAL_IN_NUMBERS_FAILED, UPDATE_DIAL_IN_NUMBERS_FAILED,
UPDATE_DIAL_IN_NUMBERS_REQUEST,
UPDATE_DIAL_IN_NUMBERS_SUCCESS UPDATE_DIAL_IN_NUMBERS_SUCCESS
} from './actionTypes'; } from './actionTypes';
import { InviteDialog } from './components'; import { InviteDialog } from './components';
@ -11,6 +10,10 @@ declare var $: Function;
declare var APP: Object; declare var APP: Object;
declare var config: Object; declare var config: Object;
const CONFERENCE_ID_ENDPOINT = config.conferenceMapperUrl;
const DIAL_IN_NUMBERS_ENDPOINT = config.dialInNumbersUrl;
const MUC_URL = config && config.hosts && config.hosts.muc;
/** /**
* Opens the Invite Dialog. * Opens the Invite Dialog.
* *
@ -18,34 +21,46 @@ declare var config: Object;
*/ */
export function openInviteDialog() { export function openInviteDialog() {
return openDialog(InviteDialog, { return openDialog(InviteDialog, {
conferenceUrl: encodeURI(APP.ConferenceUrl.getInviteUrl()), conferenceUrl: encodeURI(APP.ConferenceUrl.getInviteUrl())
dialInNumbersUrl: config.dialInNumbersUrl
}); });
} }
/** /**
* Sends an ajax request for dial-in numbers. * Sends an ajax requests for dial-in numbers and conference id.
* *
* @param {string} dialInNumbersUrl - The endpoint for retrieving json that
* includes numbers for dialing in to a conference.
* @returns {Function} * @returns {Function}
*/ */
export function updateDialInNumbers(dialInNumbersUrl) { export function updateDialInNumbers() {
return dispatch => { return (dispatch, getState) => {
dispatch({
type: UPDATE_DIAL_IN_NUMBERS_REQUEST if (!CONFERENCE_ID_ENDPOINT || !DIAL_IN_NUMBERS_ENDPOINT || !MUC_URL) {
return;
}
const { room } = getState()['features/base/conference'];
const conferenceIdUrl
= `${CONFERENCE_ID_ENDPOINT}?conference=${room}@${MUC_URL}`;
Promise.all([
$.getJSON(DIAL_IN_NUMBERS_ENDPOINT),
$.getJSON(conferenceIdUrl)
]).then(([ numbersResponse, idResponse ]) => {
if (!idResponse.conference || !idResponse.id) {
return Promise.reject(idResponse.message);
}
dispatch({
type: UPDATE_DIAL_IN_NUMBERS_SUCCESS,
conferenceId: idResponse,
dialInNumbers: numbersResponse
});
})
.catch(error => {
dispatch({
type: UPDATE_DIAL_IN_NUMBERS_FAILED,
error
});
}); });
$.getJSON(dialInNumbersUrl)
.success(response =>
dispatch({
type: UPDATE_DIAL_IN_NUMBERS_SUCCESS,
response
}))
.error(error =>
dispatch({
type: UPDATE_DIAL_IN_NUMBERS_FAILED,
error
}));
}; };
} }

View File

@ -4,6 +4,7 @@ import React, { Component } from 'react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { translate } from '../../base/i18n'; import { translate } from '../../base/i18n';
import { getLocalParticipant } from '../../base/participants';
import { updateDialInNumbers } from '../actions'; import { updateDialInNumbers } from '../actions';
@ -25,15 +26,20 @@ class DialInNumbersForm extends Component {
* @static * @static
*/ */
static propTypes = { static propTypes = {
/**
* The name of the current user.
*/
_currentUserName: React.PropTypes.string,
/** /**
* The redux state representing the dial-in numbers feature. * The redux state representing the dial-in numbers feature.
*/ */
_dialIn: React.PropTypes.object, _dialIn: React.PropTypes.object,
/** /**
* The url for retrieving dial-in numbers. * The url for the JitsiConference.
*/ */
dialInNumbersUrl: React.PropTypes.string, conferenceUrl: React.PropTypes.string,
/** /**
* Invoked to send an ajax request for dial-in numbers. * Invoked to send an ajax request for dial-in numbers.
@ -77,35 +83,32 @@ class DialInNumbersForm extends Component {
/** /**
* The internal reference to the DOM/HTML element backing the React * The internal reference to the DOM/HTML element backing the React
* {@code Component} input. It is necessary for the implementation of * {@code Component} text area. It is necessary for the implementation
* copying to the clipboard. * of copying to the clipboard.
* *
* @private * @private
* @type {HTMLInputElement} * @type {HTMLTextAreaElement}
*/ */
this._inputElement = null; this._copyElement = null;
// Bind event handlers so they are only bound once for every instance. // Bind event handlers so they are only bound once for every instance.
this._onClick = this._onClick.bind(this); this._onCopyClick = this._onCopyClick.bind(this);
this._onOpenChange = this._onOpenChange.bind(this); this._onOpenChange = this._onOpenChange.bind(this);
this._onSelect = this._onSelect.bind(this); this._onSelect = this._onSelect.bind(this);
this._setInput = this._setInput.bind(this); this._setCopyElement = this._setCopyElement.bind(this);
} }
/** /**
* Dispatches a request for numbers if not already present in the redux * Sets a default number to display in the dropdown trigger.
* store. If numbers are present, sets a default number to display in the
* dropdown trigger.
* *
* @inheritdoc * @inheritdoc
* returns {void} * returns {void}
*/ */
componentDidMount() { componentWillMount() {
if (this.props._dialIn.numbers) { if (this.props._dialIn.numbers) {
this._setDefaultNumber(this.props._dialIn.numbers); this._setDefaultNumber(this.props._dialIn.numbers);
} else { } else {
this.props.dispatch( this.props.dispatch(updateDialInNumbers());
updateDialInNumbers(this.props.dialInNumbersUrl));
} }
} }
@ -123,52 +126,46 @@ class DialInNumbersForm extends Component {
} }
/** /**
* Implements React's {@link Component#render()}. * Implements React's {@link Component#render()}. Returns null if the
* component is not ready for display.
* *
* @inheritdoc * @inheritdoc
* @returns {ReactElement} * @returns {ReactElement|null}
*/ */
render() { render() {
const { t, _dialIn } = this.props; const { _dialIn, t } = this.props;
const { conferenceId, numbers, numbersEnabled } = _dialIn;
const { selectedNumber } = this.state;
const numbers = _dialIn.numbers; if (!conferenceId || !numbers || !numbersEnabled || !selectedNumber) {
const items = numbers ? this._formatNumbers(numbers) : []; return null;
const isEnabled = this._isDropdownEnabled();
const inputWrapperClassNames
= `form-control__container ${isEnabled ? '' : 'is-disabled'}
${_dialIn.loading ? 'is-loading' : ''}`;
let triggerText = '';
if (!_dialIn.numbersEnabled) {
triggerText = t('invite.numbersDisabled');
} else if (this.state.selectedNumber
&& this.state.selectedNumber.content) {
triggerText = this.state.selectedNumber.content;
} else if (!numbers && _dialIn.loading) {
triggerText = t('invite.loadingNumbers');
} else if (_dialIn.error) {
triggerText = t('invite.errorFetchingNumbers');
} else {
triggerText = t('invite.noNumbers');
} }
const items = numbers ? this._formatNumbers(numbers) : [];
return ( return (
<div className = 'form-control dial-in-numbers'> <div className = 'form-control dial-in-numbers'>
<label className = 'form-control__label'> <label className = 'form-control__label'>
{ t('invite.dialInNumbers') } { t('invite.howToDialIn') }
<span className = 'dial-in-numbers-conference-id'>
{ conferenceId }
</span>
</label> </label>
<div className = { inputWrapperClassNames }> <div className = 'form-control__container'>
{ this._createDropdownMenu(items, triggerText) } { this._createDropdownMenu(items, selectedNumber.content) }
<button <button
className = 'button-control button-control_light' className = 'button-control button-control_light'
disabled = { !isEnabled } onClick = { this._onCopyClick }
onClick = { this._onClick }
type = 'button'> type = 'button'>
Copy Copy
</button> </button>
</div> </div>
<textarea
className = 'dial-in-numbers-copy'
readOnly = { true }
ref = { this._setCopyElement }
tabIndex = '-1'
value = { this._generateCopyText() } />
</div> </div>
); );
} }
@ -209,7 +206,6 @@ class DialInNumbersForm extends Component {
<input <input
className = 'input-control' className = 'input-control'
readOnly = { true } readOnly = { true }
ref = { this._setInput }
type = 'text' type = 'text'
value = { triggerText || '' } /> value = { triggerText || '' } />
<span className = 'dial-in-numbers-trigger-icon'> <span className = 'dial-in-numbers-trigger-icon'>
@ -288,19 +284,26 @@ class DialInNumbersForm extends Component {
} }
/** /**
* Determines if the dropdown can be opened. * Creates a message describing how to dial in to the conference.
* *
* @private * @private
* @returns {boolean} True if the dropdown can be opened. * @returns {string}
*/ */
_isDropdownEnabled() { _generateCopyText() {
const { selectedNumber } = this.state; const welcome = this.props.t('invite.invitedYouTo', {
meetingUrl: this.props.conferenceUrl,
userName: this.props._currentUserName
});
return Boolean( const callNumber = this.props.t('invite.callNumber',
this.props._dialIn.numbersEnabled { number: this.state.selectedNumber.number });
&& selectedNumber const stepOne = `1) ${callNumber}`;
&& selectedNumber.content
); const enterId = this.props.t('invite.enterId',
{ meetingId: this.props._dialIn.conferenceId });
const stepTwo = `2) ${enterId}`;
return `${welcome}\n${stepOne}\n${stepTwo}`;
} }
/** /**
@ -311,16 +314,11 @@ class DialInNumbersForm extends Component {
* @private * @private
* @returns {void} * @returns {void}
*/ */
_onClick() { _onCopyClick() {
const displayedValue = this.state.selectedNumber.content;
const desiredNumber = this.state.selectedNumber.number;
const startIndex = displayedValue.indexOf(desiredNumber);
try { try {
this._input.focus(); this._copyElement.select();
this._input.setSelectionRange(startIndex, displayedValue.length);
document.execCommand('copy'); document.execCommand('copy');
this._input.blur(); this._copyElement.blur();
} catch (err) { } catch (err) {
logger.error('error when copying the text', err); logger.error('error when copying the text', err);
} }
@ -337,7 +335,7 @@ class DialInNumbersForm extends Component {
*/ */
_onOpenChange(dropdownEvent) { _onOpenChange(dropdownEvent) {
this.setState({ this.setState({
isDropdownOpen: this._isDropdownEnabled() && dropdownEvent.isOpen isDropdownOpen: dropdownEvent.isOpen
}); });
} }
@ -355,6 +353,19 @@ class DialInNumbersForm extends Component {
}); });
} }
/**
* Sets the internal reference to the DOM/HTML element backing the React
* {@code Component} text area.
*
* @param {HTMLTextAreaElement} element - The DOM/HTML element for this
* {@code Component}'s text area.
* @private
* @returns {void}
*/
_setCopyElement(element) {
this._copyElement = element;
}
/** /**
* Updates the internal state of the currently selected number by defaulting * Updates the internal state of the currently selected number by defaulting
* to the first available number. * to the first available number.
@ -370,19 +381,6 @@ class DialInNumbersForm extends Component {
selectedNumber: numbers[0] selectedNumber: numbers[0]
}); });
} }
/**
* Sets the internal reference to the DOM/HTML element backing the React
* {@code Component} input.
*
* @param {HTMLInputElement} element - The DOM/HTML element for this
* {@code Component}'s input.
* @private
* @returns {void}
*/
_setInput(element) {
this._input = element;
}
} }
/** /**
@ -392,11 +390,16 @@ class DialInNumbersForm extends Component {
* @param {Object} state - The Redux state. * @param {Object} state - The Redux state.
* @private * @private
* @returns {{ * @returns {{
* _currentUserName: React.PropTypes.string,
* _dialIn: React.PropTypes.object * _dialIn: React.PropTypes.object
* }} * }}
*/ */
function _mapStateToProps(state) { function _mapStateToProps(state) {
const { name }
= getLocalParticipant(state['features/base/participants']);
return { return {
_currentUserName: name,
_dialIn: state['features/invite/dial-in'] _dialIn: state['features/invite/dial-in']
}; };
} }

View File

@ -41,11 +41,6 @@ class InviteDialog extends Component {
*/ */
conferenceUrl: React.PropTypes.string, conferenceUrl: React.PropTypes.string,
/**
* The url for retrieving dial-in numbers.
*/
dialInNumbersUrl: React.PropTypes.string,
/** /**
* Invoked to obtain translated strings. * Invoked to obtain translated strings.
*/ */
@ -68,7 +63,7 @@ class InviteDialog extends Component {
* @returns {ReactElement} * @returns {ReactElement}
*/ */
render() { render() {
const { _conference } = this.props; const { _conference, conferenceUrl } = this.props;
const titleString const titleString
= this.props.t( = this.props.t(
'invite.inviteTo', 'invite.inviteTo',
@ -80,8 +75,8 @@ class InviteDialog extends Component {
okTitleKey = 'dialog.done' okTitleKey = 'dialog.done'
titleString = { titleString }> titleString = { titleString }>
<div className = 'invite-dialog'> <div className = 'invite-dialog'>
<ShareLinkForm toCopy = { this.props.conferenceUrl } /> <ShareLinkForm toCopy = { conferenceUrl } />
{ this._renderDialInNumbersForm() } <DialInNumbersForm conferenceUrl = { conferenceUrl } />
<PasswordContainer <PasswordContainer
conference = { _conference.conference } conference = { _conference.conference }
locked = { _conference.locked } locked = { _conference.locked }
@ -91,22 +86,6 @@ class InviteDialog extends Component {
</Dialog> </Dialog>
); );
} }
/**
* Creates a React {@code Component} for displaying and copying to clipboard
* telephone numbers for dialing in to the conference.
*
* @private
* @returns {ReactElement|null}
*/
_renderDialInNumbersForm() {
return (
this.props.dialInNumbersUrl
? <DialInNumbersForm
dialInNumbersUrl = { this.props.dialInNumbersUrl } />
: null
);
}
} }
/** /**

View File

@ -4,7 +4,6 @@ import {
import { import {
UPDATE_DIAL_IN_NUMBERS_FAILED, UPDATE_DIAL_IN_NUMBERS_FAILED,
UPDATE_DIAL_IN_NUMBERS_REQUEST,
UPDATE_DIAL_IN_NUMBERS_SUCCESS UPDATE_DIAL_IN_NUMBERS_SUCCESS
} from './actionTypes'; } from './actionTypes';
@ -19,24 +18,16 @@ ReducerRegistry.register(
case UPDATE_DIAL_IN_NUMBERS_FAILED: { case UPDATE_DIAL_IN_NUMBERS_FAILED: {
return { return {
...state, ...state,
error: action.error, error: action.error
loading: false
}; };
} }
case UPDATE_DIAL_IN_NUMBERS_REQUEST: {
return {
...state,
error: null,
loading: true
};
}
case UPDATE_DIAL_IN_NUMBERS_SUCCESS: { case UPDATE_DIAL_IN_NUMBERS_SUCCESS: {
const { numbers, numbersEnabled } = action.response; const { numbers, numbersEnabled } = action.dialInNumbers;
return { return {
conferenceId: action.conferenceId.id,
error: null, error: null,
loading: false,
numbers, numbers,
numbersEnabled numbersEnabled
}; };