/
rtc.js
74 lines (60 loc) · 1.54 KB
/
rtc.js
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
const React = require('react');
const cl = require('classnames');
const propTypes = require('prop-types');
class MainRtc extends React.Component {
constructor(props) {
const {container} = props;
super(props)
this.state = {
is : false,
end : false
}
this.container = container;
}
componentDidMount() {
let timer = Number(this.props.timerSwitch)
if (isNaN(timer) || timer < 5) timer = 5;
setTimeout(()=>this.setState({is:true}),timer);
}
componentWillReceiveProps(np) {
if (this.state.is && this.state.end != np.isEnd) {
this.setState({end:np.isEnd})
}
}
getProps() {
let {className, classStart, classMain, classEnd, container, timerSwitch, isEnd, ...props} = this.props;
let { end } = this.state;
classStart = classStart || 'start';
classMain = classMain || 'main';
classEnd = classEnd || 'end';
className = className || '';
props.className = cl(className,{
[classStart] : !end && !this.state.is,
[classMain] : !end && this.state.is,
[classEnd] : !!end
})
console.log(props.className)
return props
}
render() {
return React.createElement(this.container,this.getProps(),this.props.children)
}
}
MainRtc.defaultProps = {
timerSwitch : 123,
className : '_',
classStart : 'start',
classMain : 'main',
classEnd : 'end',
isEnd : false,
container : 'div'
}
MainRtc.propTypes = {
className : propTypes.string,
classStart : propTypes.string,
classMein : propTypes.string,
classEnd : propTypes.string,
isEnd : propTypes.bool,
timerSwitch : propTypes.number
}
module.exports = MainRtc