-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
203 lines (180 loc) · 4.92 KB
/
index.js
File metadata and controls
203 lines (180 loc) · 4.92 KB
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
import React from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
NativeModules,
VrButton,
Image,
asset,
AsyncStorage,
VrHeadModel
} from 'react-360';
import Background from './components/Background.js';
import ProyectorComponente from './components/ProyectorComponente.js';
import MarksComponente from './components/Marks.js';
const Proyector = () => (
<ProyectorComponente/>
);
const Marks = () => (
<MarksComponente/>
);
// Extract our custom native module
const ConexionModule = NativeModules.ConexionModule;
const {AudioModule} = NativeModules;
export default class Ediphy360 extends React.Component {
constructor() {
super();
this.state = {
imgBack: undefined,
urlBack: undefined,
format:'2D',
playAudio: false,
showAudio: false,
currRot: [],
};
//console.log(VrHeadModel)
this.escucharConexion=this.escucharConexion.bind(this);
}
escucharConexion() {
ConexionModule.conexionIframe(datos => {
if(datos.audioBack){
/*try{
AsyncStorage.setItem('showAudio', datos.audioBack.play);
}catch(error){
console.log("Error al guardar datos");
}*/
this.setState({
showAudio: datos.audioBack.play
});
}
if(datos.urlBack){
/*try{
AsyncStorage.setItem('urlBack', datos.urlBack);
}catch(error){
console.log("Error al guardar datos");
}*/
this.setState({
urlBack: datos.urlBack
});
}
if(datos.imagenBack){
/*try{
AsyncStorage.setItem('imgBack', datos.imagenBack);
}catch(error){
console.log("Error al guardar datos");
}*/
this.setState({
imgBack: datos.imagenBack
});
}
this.escucharConexion();
});
}
componentDidMount() {
this.escucharConexion();
/*try {
const valueI = AsyncStorage.getItem('imgBack');
valueI.then(valor =>{
if(valor !== null){
this.setState({ imgBack: valor });
}
});
const valueA = AsyncStorage.getItem('showAudio');
valueA.then(valor =>{
if(valor !== null){
this.setState({ showAudio: valor });
}
});
const valueU = AsyncStorage.getItem('urlBack');
valueU.then(valor =>{
if(valor !== null){
this.setState({ urlBack: valor });
}
});
const valueM = AsyncStorage.getItem('marks');
valueM.then(valor =>{
if(valor !== null){
this.setState({ marks: valor });
}
});
}catch(error){
console.log("Error al leer datos");
}*/
setInterval(()=>{
let currRot = VrHeadModel.rotation();
if(JSON.stringify(this.state.currRot) === '[]') this.setState({ currRot: currRot });
if(JSON.stringify(currRot) !== JSON.stringify(this.state.currRot)){
console.log(currRot)
this.setState({ currRot: currRot });
ConexionModule.handlePosition(currRot);
}
},2000)
}
_playAudio = () => {
let visor = ConexionModule.enVisor(visor => {
if(visor === 'true'){
//console.log("Empieza el audio de ambiente");
AudioModule.playEnvironmental({
source: asset('audio/Blue_Jacket.mp3'),
volume: 0.7,
});
}
});
};
_stopAudio = () => {
//console.log("Se para el audio de ambiente");
AudioModule.stopEnvironmental();
};
render() {
return (
<View style={styles.panelForControls}>
<Background imgBack={this.state.imgBack} urlBack={this.state.urlBack} format={this.state.format} />
{this.state.showAudio ? (
<View style={styles.controls}>
<VrButton onClick={this._playAudio} style={styles.button}>
<Text style={styles.buttonText}>{'Play'}</Text>
</VrButton>
<VrButton onClick={this._stopAudio} style={styles.button}>
<Text style={styles.buttonText}>{'Stop'}</Text>
</VrButton>
</View>) : null}
</View>
);
}
};
const styles = StyleSheet.create({
panelForControls: {
// Fill the entire surface
width: 200,
height: 90,
backgroundColor: 'rgba(255, 255, 255, 0)',
flexDirection: 'column',
justifyContent: 'flex-start',
alignItems: 'center',
},
controls: {
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
marginTop: 20,
width: 170,
},
button: {
backgroundColor: 'rgba(255, 255, 255, 0.6)',
borderRadius: 5,
justifyContent: 'center',
width: 60,
height: 60,
},
buttonText: {
textAlign: 'center',
color: 'white',
fontSize: 20,
fontWeight: 'bold',
}
});
AppRegistry.registerComponent('Ediphy360', () => Ediphy360);
AppRegistry.registerComponent('Proyector', () => Proyector);
AppRegistry.registerComponent('Marks', () => Marks);