mirror of
https://github.com/netzbegruenung/jitsi-meet-electron.git
synced 2024-05-04 09:43:42 +02:00
177 lines
4.7 KiB
JavaScript
177 lines
4.7 KiB
JavaScript
// @flow
|
|
|
|
import Button from '@atlaskit/button';
|
|
import { FieldTextStateless } from '@atlaskit/field-text';
|
|
import Page from '@atlaskit/page';
|
|
import { AtlasKitThemeProvider } from '@atlaskit/theme';
|
|
|
|
import React, { Component } from 'react';
|
|
import type { Dispatch } from 'redux';
|
|
import { connect } from 'react-redux';
|
|
import { push } from 'react-router-redux';
|
|
|
|
import { Navbar } from '../../navbar';
|
|
import { normalizeServerURL } from '../../utils';
|
|
|
|
import { WelcomeWrapper as Wrapper, Content, Form } from '../styled';
|
|
|
|
|
|
type Props = {
|
|
|
|
/**
|
|
* Redux dispatch.
|
|
*/
|
|
dispatch: Dispatch<*>;
|
|
|
|
/**
|
|
* React Router location object.
|
|
*/
|
|
location: Object;
|
|
};
|
|
|
|
type State = {
|
|
|
|
/**
|
|
* URL of the room to join.
|
|
* If this is not a url it will be treated as room name for default domain.
|
|
*/
|
|
url: string;
|
|
};
|
|
|
|
/**
|
|
* Welcome Component.
|
|
*/
|
|
class Welcome extends Component<Props, State> {
|
|
/**
|
|
* Initializes a new {@code Welcome} instance.
|
|
*
|
|
* @inheritdoc
|
|
*/
|
|
constructor(props: Props) {
|
|
super(props);
|
|
|
|
// Initialize url value in state if passed using location state object.
|
|
let url = '';
|
|
|
|
// Check and parse url if exists in location state.
|
|
if (props.location.state) {
|
|
const { room, serverURL } = props.location.state;
|
|
|
|
if (room && serverURL) {
|
|
url = `${serverURL}/${room}`;
|
|
}
|
|
}
|
|
|
|
this.state = { url };
|
|
|
|
// Bind event handlers.
|
|
this._onURLChange = this._onURLChange.bind(this);
|
|
this._onFormSubmit = this._onFormSubmit.bind(this);
|
|
this._onJoin = this._onJoin.bind(this);
|
|
}
|
|
|
|
/**
|
|
* Render function of component.
|
|
*
|
|
* @returns {ReactElement}
|
|
*/
|
|
render() {
|
|
const { state } = this.props.location;
|
|
|
|
return (
|
|
<Page navigation = { <Navbar /> }>
|
|
<AtlasKitThemeProvider mode = 'light'>
|
|
<Wrapper>
|
|
<Content>
|
|
<Form onSubmit = { this._onFormSubmit }>
|
|
<FieldTextStateless
|
|
autoFocus = { true }
|
|
isInvalid = { state && state.error }
|
|
isLabelHidden = { true }
|
|
onChange = { this._onURLChange }
|
|
shouldFitContainer = { true }
|
|
type = 'text'
|
|
value = { this.state.url } />
|
|
</Form>
|
|
<Button
|
|
appearance = 'primary'
|
|
onClick = { this._onJoin }
|
|
type = 'button'>
|
|
GO
|
|
</Button>
|
|
</Content>
|
|
</Wrapper>
|
|
</AtlasKitThemeProvider>
|
|
</Page>
|
|
);
|
|
}
|
|
|
|
_onFormSubmit: (*) => void;
|
|
|
|
/**
|
|
* Prevents submission of the form and delegates the join logic.
|
|
*
|
|
* @param {Event} event - Event by which this function is called.
|
|
* @returns {void}
|
|
*/
|
|
_onFormSubmit(event: Event) {
|
|
event.preventDefault();
|
|
this._onJoin();
|
|
}
|
|
|
|
_onJoin: (*) => void;
|
|
|
|
/**
|
|
* Redirect and join conference.
|
|
*
|
|
* @returns {void}
|
|
*/
|
|
_onJoin() {
|
|
const inputURL = this.state.url;
|
|
const lastIndexOfSlash = inputURL.lastIndexOf('/');
|
|
let room;
|
|
let serverURL;
|
|
|
|
if (lastIndexOfSlash === -1) {
|
|
// This must be only the room name.
|
|
room = inputURL;
|
|
} else {
|
|
// Take the substring after last slash to be the room name.
|
|
room = inputURL.substring(lastIndexOfSlash + 1);
|
|
|
|
// Take the substring before last slash to be the Server URL.
|
|
serverURL = inputURL.substring(0, lastIndexOfSlash);
|
|
|
|
// Normalize the server URL.
|
|
serverURL = normalizeServerURL(serverURL);
|
|
}
|
|
|
|
// Don't navigate if no room was specified.
|
|
if (!room) {
|
|
return;
|
|
}
|
|
|
|
this.props.dispatch(push('/conference', {
|
|
room,
|
|
serverURL
|
|
}));
|
|
}
|
|
|
|
_onURLChange: (*) => void;
|
|
|
|
/**
|
|
* Keeps URL input value and URL in state in sync.
|
|
*
|
|
* @param {SyntheticInputEvent<HTMLInputElement>} event - Event by which
|
|
* this function is called.
|
|
* @returns {void}
|
|
*/
|
|
_onURLChange(event: SyntheticInputEvent<HTMLInputElement>) {
|
|
this.setState({
|
|
url: event.currentTarget.value
|
|
});
|
|
}
|
|
}
|
|
|
|
export default connect()(Welcome);
|