1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
|
// @flow
import Button from '@atlaskit/button';
import { FieldTextStateless } from '@atlaskit/field-text';
import { SpotlightTarget } from '@atlaskit/onboarding';
import Page from '@atlaskit/page';
import { AtlasKitThemeProvider } from '@atlaskit/theme';
import { generateRoomWithoutSeparator } from '@jitsi/js-utils/random';
import React, { Component } from 'react';
import { withTranslation } from 'react-i18next';
import { compose } from 'redux';
import type { Dispatch } from 'redux';
import { connect } from 'react-redux';
import { push } from 'react-router-redux';
import { Navbar } from '../../navbar';
import { Onboarding, startOnboarding } from '../../onboarding';
import { RecentList } from '../../recent-list';
import { createConferenceObjectFromURL } from '../../utils';
import { Body, FieldWrapper, Form, Header, Label, Wrapper } from '../styled';
type Props = {
/**
* Redux dispatch.
*/
dispatch: Dispatch<*>;
/**
* React Router location object.
*/
location: Object;
/**
* I18next translate function.
*/
t: Function;
};
type State = {
/**
* Timer for animating the room name geneeration.
*/
animateTimeoutId: ?TimeoutID,
/**
* Generated room name.
*/
generatedRoomname: string,
/**
* Current room name placeholder.
*/
roomPlaceholder: string,
/**
* Timer for re-generating a new room name.
*/
updateTimeoutId: ?TimeoutID,
/**
* 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 = {
animateTimeoutId: undefined,
generatedRoomname: '',
roomPlaceholder: '',
updateTimeoutId: undefined,
url
};
// Bind event handlers.
this._animateRoomnameChanging = this._animateRoomnameChanging.bind(this);
this._onURLChange = this._onURLChange.bind(this);
this._onFormSubmit = this._onFormSubmit.bind(this);
this._onJoin = this._onJoin.bind(this);
this._updateRoomname = this._updateRoomname.bind(this);
}
/**
* Start Onboarding once component is mounted.
* Start generating randdom room names.
*
* NOTE: It autonatically checks if the onboarding is shown or not.
*
* @returns {void}
*/
componentDidMount() {
this.props.dispatch(startOnboarding('welcome-page'));
this._updateRoomname();
}
/**
* Stop all timers when unmounting.
*
* @returns {voidd}
*/
componentWillUnmount() {
this._clearTimeouts();
}
/**
* Render function of component.
*
* @returns {ReactElement}
*/
render() {
return (
<Page navigation = { <Navbar /> }>
<AtlasKitThemeProvider mode = 'light'>
<Wrapper>
{ this._renderHeader() }
{ this._renderBody() }
<Onboarding section = 'welcome-page' />
</Wrapper>
</AtlasKitThemeProvider>
</Page>
);
}
_animateRoomnameChanging: (string) => void;
/**
* Animates the changing of the room name.
*
* @param {string} word - The part of room name that should be added to
* placeholder.
* @private
* @returns {void}
*/
_animateRoomnameChanging(word: string) {
let animateTimeoutId;
const roomPlaceholder = this.state.roomPlaceholder + word.substr(0, 1);
if (word.length > 1) {
animateTimeoutId
= setTimeout(
() => {
this._animateRoomnameChanging(
word.substring(1, word.length));
},
70);
}
this.setState({
animateTimeoutId,
roomPlaceholder
});
}
/**
* Method that clears timeouts for animations and updates of room name.
*
* @private
* @returns {void}
*/
_clearTimeouts() {
clearTimeout(this.state.animateTimeoutId);
clearTimeout(this.state.updateTimeoutId);
}
_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 || this.state.generatedRoomname;
const conference = createConferenceObjectFromURL(inputURL);
// Don't navigate if conference couldn't be created
if (!conference) {
return;
}
this.props.dispatch(push('/conference', conference));
}
_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
});
}
/**
* Renders the body for the welcome page.
*
* @returns {ReactElement}
*/
_renderBody() {
return (
<Body>
<RecentList />
</Body>
);
}
/**
* Renders the header for the welcome page.
*
* @returns {ReactElement}
*/
_renderHeader() {
const locationState = this.props.location.state;
const locationError = locationState && locationState.error;
const { t } = this.props;
return (
<Header>
<SpotlightTarget name = 'conference-url'>
<Form onSubmit = { this._onFormSubmit }>
<Label>{ t('enterConferenceNameOrUrl') } </Label>
<FieldWrapper>
<FieldTextStateless
autoFocus = { true }
isInvalid = { locationError }
isLabelHidden = { true }
onChange = { this._onURLChange }
placeholder = { this.state.roomPlaceholder }
shouldFitContainer = { true }
type = 'text'
value = { this.state.url } />
<Button
appearance = 'primary'
onClick = { this._onJoin }
type = 'button'>
{ t('go') }
</Button>
</FieldWrapper>
</Form>
</SpotlightTarget>
</Header>
);
}
_updateRoomname: () => void;
/**
* Triggers the generation of a new room name and initiates an animation of
* its changing.
*
* @protected
* @returns {void}
*/
_updateRoomname() {
const generatedRoomname = generateRoomWithoutSeparator();
const roomPlaceholder = '';
const updateTimeoutId = setTimeout(this._updateRoomname, 10000);
this._clearTimeouts();
this.setState(
{
generatedRoomname,
roomPlaceholder,
updateTimeoutId
},
() => this._animateRoomnameChanging(generatedRoomname));
}
}
export default compose(connect(), withTranslation())(Welcome);
|