This repository has been archived by the owner on Dec 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
/
index.jsx
363 lines (340 loc) · 10.9 KB
/
index.jsx
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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
import React from 'react'
import * as Cookies from 'js-cookie'
import '../../assets/fonts/css/icons.css'
import Validator from '../../utils/Validator'
import { RESOLUTION_ARR } from '../../utils/Settings'
import './index.css'
class Index extends React.Component {
constructor(props) {
super(props)
this.state = {
joinBtn: false,
channel: '',
baseMode: 'avc',
transcode: 'interop',
attendeeMode: 'video',
videoProfile: '480p_4',
}
}
componentDidMount() {
window.addEventListener('keypress', (e) => {
e.keyCode === 13 && this.handleJoin()
})
}
/**
*
* @param {String} val 0-9 a-z A-Z _ only
* @param {Boolean} state
*/
handleChannel = (val, state) => {
this.setState({
channel: val,
joinBtn: state
})
}
handleJoin = () => {
if (!this.state.joinBtn) {
return
}
console.log(this.state)
Cookies.set('channel', this.state.channel)
Cookies.set('baseMode', this.state.baseMode)
Cookies.set('transcode', this.state.transcode)
Cookies.set('attendeeMode', this.state.attendeeMode)
Cookies.set('videoProfile', this.state.videoProfile)
window.location.hash = "meeting"
}
render() {
return (
<div className="wrapper index">
<div className="ag-header"></div>
<div className="ag-main">
<section className="login-wrapper">
<div className="login-header">
<img src={require('../../assets/images/ag-logo.png')} alt="" />
<p className="login-title">AgoraWeb v2.1</p>
<p className="login-subtitle">Powering Real-Time Communications</p>
</div>
<div className="login-body">
<div className="columns">
<div className="column is-12">
<InputChannel onChange={this.handleChannel} placeholder="Input a room name here"></InputChannel>
</div>
</div>
<div className="columns">
<div className="column is-7">
<BaseOptions
onChange={val => this.setState({ baseMode: val })}>
</BaseOptions>
</div>
<div className="column is-5">
<AdvancedOptions
onRadioChange={val => this.setState({ transcode: val })}
onSelectChange={val => this.setState({ videoProfile: val })}>
</AdvancedOptions>
</div>
</div>
<div className="columns">
<div className="column">
<div id="attendeeMode" className="control">
<label className="radio">
<input onChange={e => this.setState({ attendeeMode: e.target.value })}
value="video" type="radio"
name="attendee" defaultChecked />
<span className="radio-btn">
</span>
<span className="radio-img video">
</span>
<span className="radio-msg">Video Call : join with video call</span>
</label>
<br />
<label className="radio">
<input onChange={e => this.setState({ attendeeMode: e.target.value })}
value="audio-only" type="radio"
name="attendee" />
<span className="radio-btn">
</span>
<span className="radio-img audio">
</span>
<span className="radio-msg">Audio-only : join with audio call</span>
</label>
<br />
<label className="radio">
<input onChange={e => this.setState({ attendeeMode: e.target.value })}
value="audience" type="radio"
name="attendee" />
<span className="radio-btn">
</span>
<span className="radio-img audience">
</span>
<span className="radio-msg">Audience : join as an audience</span>
</label>
</div>
</div>
</div>
</div>
<div className="login-footer">
<a id="joinBtn"
onClick={this.handleJoin}
disabled={!this.state.joinBtn}
className="ag-rounded button is-info">Join
</a>
</div>
</section>
</div>
<div className="ag-footer">
<a className="ag-href" href="https://www.agora.io">
<span>Powered By Agora</span>
</a>
<div>
<span>Interested in Agora video call SDK? Contact </span>
<span className="ag-contact">sales@agora.io</span>
</div>
</div>
</div>
)
}
}
class InputChannel extends React.Component {
constructor(props) {
super(props)
this.state = {
errorMsg: '',
state: ''
}
}
validate = (val) => {
this.setState({
state: '',
errorMsg: ''
})
if (Validator.isNonEmpty(val.trim())) {
this.setState({
errorMsg: 'Cannot be empty!',
state: 'is-danger'
})
return false
}
else if (Validator.minLength(val.trim(), 1)) {
this.setState({
errorMsg: 'No shorter than 1!',
state: 'is-danger'
})
return false
}
else if (Validator.maxLength(val.trim(), 16)) {
this.setState({
errorMsg: 'No longer than 16!',
state: 'is-danger'
})
return false
}
else if (Validator.validChar(val.trim())) {
this.setState({
state: 'is-danger',
errorMsg: 'Only capital or lower-case letter, number and "_" are permitted!'
})
return false
}
else {
this.setState({
state: 'is-success'
})
return true
}
}
handleChange = (e) => {
let state = this.validate(e.target.value)
this.props.onChange(e.target.value, state)
}
render() {
let validateIcon = ''
switch (this.state.state) {
default:
case '':
validateIcon = ''; break;
case 'is-success':
validateIcon = (<i className="ag-icon ag-icon-valid"></i>); break;
case 'is-danger':
validateIcon = (<i className="ag-icon ag-icon-invalid"></i>); break;
}
return (
<div className="channel-wrapper control has-icons-left">
<input onInput={this.handleChange}
id="channel"
className={'ag-rounded input ' + this.state.state}
type="text"
placeholder={this.props.placeholder} />
<span className="icon is-small is-left">
<img src={require('../../assets/images/ag-login.png')} alt="" />
</span>
<span className="validate-icon">
{validateIcon}
</span>
<div className="validate-msg">
{this.state.errorMsg}
</div>
</div>
)
}
}
class BaseOptions extends React.Component {
constructor(props) {
super(props)
this._options = [
{
label: 'Agora Video Call',
value: 'avc',
content: 'One to one and group calls'
},
{
label: 'Agora Live',
value: 'al',
content: 'Enabling real-time interactions between the host and the audience'
}
]
this.state = {
active: false,
message: 'Agora Video Call',
}
}
handleSelect = (item) => {
let msg = item.label
let val = item.value
this.setState({
'message': msg,
'active': false
})
this.props.onChange(val)
}
render() {
const options = this._options.map((item, index) => {
return (
<div className="dropdown-item"
key={index}
onClick={(e) => this.handleSelect(item, e)}>
<p>{item.label}</p>
<hr />
<p>{item.content}</p>
</div>
)
})
return (
<div className={this.state.active ? 'dropdown is-active' : 'dropdown'}>
<div className="dropdown-trigger"
onClick={() => this.setState({ 'active': !this.state.active })}>
<a id="baseMode" className="ag-rounded button" aria-haspopup="true" aria-controls="baseModeOptions">
<span id="baseOptionLabel">{this.state.message}</span>
<span className="icon is-small">
<i className="ag-icon ag-icon-arrow-down" aria-hidden="true"></i>
</span>
</a>
</div>
<div className="dropdown-menu" id="baseModeOptions" role="menu">
<div className="dropdown-content">
{options}
</div>
</div>
</div>
)
}
}
class AdvancedOptions extends React.Component {
constructor(props) {
super(props)
this.state = {
active: false,
}
}
handleRadio = (e) => {
this.props.onRadioChange(e.target.value)
}
handleSelect = (e) => {
this.props.onSelectChange(e.target.value)
}
render() {
const options = Object.entries(RESOLUTION_ARR).map((item, index) => {
return (
<option key={index} value={item[0].split(",")[0]}>{item[1][0]}x {item[1][1]}, {item[1][2]}fps, {item[1][3]}kbps</option>
)
})
return (
<div className={this.state.active ? 'dropdown is-active' : 'dropdown'}>
<div className="dropdown-trigger"
onClick={() => this.setState({ 'active': !this.state.active })}>
<a id="advancedProfile" className="ag-rounded button" aria-haspopup="true" aria-controls="advancedOptions">
<span>Advanced</span>
</a>
</div>
<div className="dropdown-menu" id="advancedOptions" role="menu">
<div className="dropdown-content">
<div className="dropdown-item">
<div className="control">
<label className="radio">
<input value="" type="radio" name="transcode" onChange={this.handleRadio} />
<span>VP8-only</span>
</label>
<label className="radio">
<input value="interop" type="radio" defaultChecked onChange={this.handleRadio} name="transcode" />
<span>VP8 & H264</span>
</label>
<label className="radio">
<input value="h264_interop" type="radio" onChange={this.handleRadio} name="transcode" />
<span>H264-only</span>
</label>
</div>
</div>
<div className="dropdown-item">
<div className="select is-rounded">
<select onChange={this.handleSelect} defaultValue="480p_4" id="videoProfile" className="ag-rounded is-clipped">
{options}
</select>
</div>
</div>
</div>
</div>
</div>
)
}
}
export default Index