forked from voximplant/react-native-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ios.js
99 lines (83 loc) · 2.47 KB
/
index.ios.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
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
/*
* Copyright (c) 2011-2018, Zingaya, Inc. All rights reserved.
*/
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
DeviceEventEmitter,
Button
} from 'react-native';
import VoxImplant from "react-native-voximplant";
import Loader from './Loader';
import LoginForm from './LoginForm';
import UserAgent from './UserAgent';
import pushManager from './PushManager';
import loginManager from './LoginManager';
var _this,
formInstance;
export default class VoxImplantDemo extends Component {
constructor() {
super();
pushManager.init();
this.state = {
page: 'connection',
userName: ''
};
}
componentDidMount() {
_this = this;
loginManager.getInstance().on('onLoggedIn', (param) => this.onLogin(param));
loginManager.getInstance().on('onConnected', () => this.onConnected());
loginManager.getInstance().on('onConnectionFailed', (reason) => this.onConnectionFailed(reason));
loginManager.getInstance().on('onConnectionClosed', () => this.onConnectionClosed());
loginManager.getInstance().connect(false);
if (loginManager.getInstance().loggedIn) {
_this.setState({page: 'useragent'});
} else if (loginManager.getInstance().connected) {
_this.setState({page: 'login'});
}
}
onConnected() {
_this.setState({page: 'login'});
}
onLogin(displayName) {
_this.setState({userName: displayName, page: 'useragent'});
}
onConnectionFailed(reason) {
console.log("connection failed");
this.setState({ page: 'retry' });
}
onConnectionClosed() {
console.log("connection closed");
this.setState({ page: 'connection'});
loginManager.getInstance().connect(false);
}
reconnect() {
this.setState({ page: 'connection' });
loginManager.getInstance().connect(false)
}
render() {
let ui = <Loader />;
if (this.state.page === 'retry') {
ui = (
<View style={{ flex: 1, alignItems:'center', justifyContent:'center' }}>
<Text>Internet connection is lost. Reconnect?</Text>
<Button title="OK" onPress={ () => this.reconnect() }/>
</View>
);
}
if (this.state.page === 'login') {
ui = <LoginForm
ref={(component) => formInstance = component}
/>;
}
if (this.state.page === 'useragent') {
ui = <UserAgent uaDisplayName={this.state.userName} />;
}
return ui;
}
}
AppRegistry.registerComponent('VoxImplantDemo', () => VoxImplantDemo);