/
index.android.js
76 lines (65 loc) · 2.31 KB
/
index.android.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
'use strict';
var React = require('react');
var ReactNative = require('react-native');
var DeviceEventEmitter = ReactNative.DeviceEventEmitter;
var ReactHoundifyModule = ReactNative.NativeModules.ReactHoundifyModule;
var MainView = require('./react-components/main-view');
var MirrorApp = React.createClass({
getInitialState: function () {
return {
responseType: null,
recording: false,
response: null,
transcript: "",
error: null
}
},
componentWillMount: function() {
var self = this;
DeviceEventEmitter.addListener('houndifyResponseSuccess', function(ev) {
var response = typeof(ev.results) === 'string' ? JSON.parse(ev.results) : ev.results;
self.setState({
responseType: 'houndifyResponseSuccess',
response: response
});
});
DeviceEventEmitter.addListener('houndifyResponseTranscript', function(ev) {
self.setState({
responseType: 'houndifyResponseTranscript',
transcript: ev.results || "Listening..."
});
});
DeviceEventEmitter.addListener('houndifyRecordingStarted', function(ev) {
self.setState({
responseType: 'houndifyRecordingStarted',
recording: true,
response: null,
transcript: "Listening..."
});
});
DeviceEventEmitter.addListener('houndifyRecordingStopped', function(ev) {
self.setState({
responseType: 'houndifyRecordingStopped',
recording: false
});
});
DeviceEventEmitter.addListener('houndifyResponseError', function(ev) {
self.setState({
responseType: 'houndifyResponseError',
error: ev.error
});
});
},
componentDidMount: function() {
console.disableYellowBox = true;
},
houndify: {
speak: ReactHoundifyModule.speak,
indexDevices: ReactHoundifyModule.indexDevices,
setVolume: ReactHoundifyModule.setVolume
},
render: function() {
return (<MainView {...this.state} {...this.houndify} />);
}
})
ReactNative.AppRegistry.registerComponent('MirrorApp', () => MirrorApp);