diff --git a/app/components/ConferenceModal.js b/app/components/ConferenceModal.js index f353b34..c94cadd 100644 --- a/app/components/ConferenceModal.js +++ b/app/components/ConferenceModal.js @@ -1,152 +1,178 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { View } from 'react-native'; import { Portal, Dialog, Button, Text, TextInput, Surface, Chip } from 'react-native-paper'; import KeyboardAwareDialog from './KeyBoardAwareDialog'; const DialogType = Platform.OS === 'ios' ? KeyboardAwareDialog : Dialog; import config from '../config'; import styles from '../assets/styles/blink/_ConferenceModal.scss'; class ConferenceModal extends Component { constructor(props) { super(props); this.state = { targetUri: props.targetUri ? props.targetUri.split('@')[0] : '', myInvitedParties: props.myInvitedParties, participants: null }; this.handleConferenceTargetChange = this.handleConferenceTargetChange.bind(this); this.onHide = this.onHide.bind(this); this.joinAudio = this.joinAudio.bind(this); this.joinVideo = this.joinVideo.bind(this); + } + componentDidMount() { this.handleConferenceTargetChange(this.state.targetUri); } //getDerivedStateFromProps(nextProps, state) { UNSAFE_componentWillReceiveProps(nextProps) { let uri = ''; if (nextProps.targetUri) { uri = nextProps.targetUri.split('@')[0]; } this.setState({targetUri: uri, myInvitedParties: nextProps.myInvitedParties}); this.handleConferenceTargetChange(uri); } handleConferenceTargetChange(value) { let targetUri = value; let participants = null; let sanitizedParticipants = []; let username; let domain; if (targetUri) { let uri = `${targetUri.replace(/[\s()-]/g, '')}@${config.defaultConferenceDomain}`; uri = uri.split('@')[0].toLowerCase(); if (this.props.myInvitedParties && this.props.myInvitedParties.hasOwnProperty(uri)) { participants = this.props.myInvitedParties[uri].toString(); participants.split(',').forEach((item) => { - item = item.trim(); + item = item.trim().toLowerCase(); if (item.indexOf('@') === -1) { item = `${item}@${config.defaultDomain}`; } username = item.split('@')[0]; domain = item.split('@')[1]; if (username && username !== ',') { if (domain === config.defaultDomain) { sanitizedParticipants.push(username); } else { sanitizedParticipants.push(item); } } }); } } this.setState({targetUri: targetUri, participants: sanitizedParticipants.toString()}); } joinAudio(event) { event.preventDefault(); const uri = `${this.state.targetUri.replace(/[\s()-]/g, '')}@${config.defaultConferenceDomain}`; - this.props.handleConferenceCall(uri.toLowerCase(), {audio: true, video: false, participants: this.state.participants.split(',')}); + const participants = []; + + if (this.state.participants) { + this.state.participants.split(',').forEach((item) => { + item = item.trim().toLowerCase(); + if (item.indexOf('@') === -1) { + item = `${item}@${config.defaultDomain}`; + } + participants.push(item); + }); + } + + this.props.handleConferenceCall(uri.toLowerCase(), {audio: true, video: false, participants: participants}); } joinVideo(event) { event.preventDefault(); const uri = `${this.state.targetUri.replace(/[\s()-]/g, '')}@${config.defaultConferenceDomain}`; - this.props.handleConferenceCall(uri.toLowerCase(), {audio: true, video: true, participants: this.state.participants.split(',')}); + const participants = []; + + if (this.state.participants) { + this.state.participants.split(',').forEach((item) => { + item = item.trim().toLowerCase(); + if (item.indexOf('@') === -1) { + item = `${item}@${config.defaultDomain}`; + } + participants.push(item); + }); + } + + this.props.handleConferenceCall(uri.toLowerCase(), {audio: true, video: true, participants: participants}); } onHide() { this.props.handleConferenceCall(null); } render() { const validUri = this.state.targetUri.length > 0 && this.state.targetUri.indexOf('@') === -1; return ( Join Conference {this.setState({participants: value});}} value={this.state.participants} placeholder="bob,carol,alice@sip2sip.info" /> ); } } ConferenceModal.propTypes = { show: PropTypes.bool.isRequired, handleConferenceCall: PropTypes.func.isRequired, myInvitedParties: PropTypes.object, targetUri: PropTypes.string.isRequired }; export default ConferenceModal; diff --git a/app/components/InviteParticipantsModal.js b/app/components/InviteParticipantsModal.js index 9015e26..f441832 100644 --- a/app/components/InviteParticipantsModal.js +++ b/app/components/InviteParticipantsModal.js @@ -1,111 +1,105 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; import autoBind from 'auto-bind'; import { View } from 'react-native'; import { Dialog, Portal, Text, Button, Surface, TextInput } from 'react-native-paper'; import KeyboardAwareDialog from './KeyBoardAwareDialog'; const DialogType = Platform.OS === 'ios' ? KeyboardAwareDialog : Dialog; import config from '../config'; import styles from '../assets/styles/blink/_InviteParticipantsModal.scss'; class InviteParticipantsModal extends Component { constructor(props) { super(props); autoBind(this); let difference = this.props.previousParticipants.filter(x => !this.props.currentParticipants.includes(x)); - console.log('this.props.previousParticipants', this.props.previousParticipants); - console.log('this.props.currentParticipants', this.props.currentParticipants); - this.state = { participants: difference.toString(), previousParticipants: this.props.previousParticipants, currentParticipants: this.props.currentParticipants } } UNSAFE_componentWillReceiveProps(nextProps) { if (nextProps.hasOwnProperty('muted')) { this.setState({audioMuted: nextProps.muted}); } let difference = nextProps.previousParticipants.filter(x => !nextProps.currentParticipants.includes(x)); this.setState({ participants: difference.toString(), previousParticipants: nextProps.previousParticipants, currentParticipants: nextProps.currentParticipants }); - - console.log('this.props.previousParticipants', this.props.previousParticipants); - console.log('this.props.currentParticipants', this.props.currentParticipants); } invite(event) { event.preventDefault(); const uris = []; if (this.state.participants) { this.state.participants.split(',').forEach((item) => { item = item.trim(); if (item.indexOf('@') === -1) { item = `${item}@${config.defaultDomain}`; } uris.push(item); }); } if (uris) { this.props.inviteParticipants(uris); this.setState({participants: null}); } this.props.close(); } onInputChange(value) { this.setState({participants: value}); } render() { return ( Invite participants Enter participants to invite ); } } InviteParticipantsModal.propTypes = { show: PropTypes.bool.isRequired, close: PropTypes.func.isRequired, inviteParticipants: PropTypes.func, currentParticipants: PropTypes.array, previousParticipants: PropTypes.array, room: PropTypes.string }; export default InviteParticipantsModal;