-
Notifications
You must be signed in to change notification settings - Fork 12
/
index.ios.js
95 lines (79 loc) · 2.46 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
/**
* Sample React Native App
* https://github.com/facebook/react-native
*/
'use strict';
var React = require('react-native');
var {
AppRegistry,
StyleSheet,
Text,
View,
requireNativeComponent,
NativeModules,
DeviceEventEmitter,
TouchableHighlight
} = React;
var VideoCoreView = requireNativeComponent('RCTVideoCoreView', null);
var VideoCore = React.createClass({
statics: {
startStreaming: function(url, key) {
NativeModules.VideoCoreViewManager.startStreaming(url, key)
},
stopStreaming: function() {
NativeModules.VideoCoreViewManager.stopStreaming()
},
},
getInitialState: function() {
return {
status: 'VCSessionStateNone'
}
},
componentWillMount: function(){
NativeModules.VideoCoreViewManager.stopStreaming()
this.connectionStatusChangedListener = DeviceEventEmitter.addListener('videocore.connectionStatusChanged', this._onConnectionStatusChanged)
},
_onConnectionStatusChanged: function(e) {
this.setState({
status: e
})
this.props.onConnectionStatusChanged && this.props.onConnectionStatusChanged(e)
},
componentWillUnmount: function(){
this.connectionStatusChangedListener.remove();
NativeModules.VideoCoreViewManager.stopStreaming()
},
render: function() {
return <VideoCoreView {...this.props} />
}
})
var RNVideoCore = React.createClass({
getInitialState: function() {
return {
showPreview: false
}
},
render: function() {
var previewOrButton = (this.state.showPreview) ?
<VideoCore style={{ alignSelf: 'stretch', flex: 1 }} onConnectionStatusChanged={(e) => console.log(e)}>
<TouchableHighlight onPress={() => VideoCore.startStreaming('rtmp://104.155.71.82:1935/live', 'myStream')}><Text style={{color: "#fff", margin: 50}}>START Streaming</Text></TouchableHighlight>
<TouchableHighlight onPress={() => VideoCore.stopStreaming()}><Text style={{color: "#fff", margin: 50}}>STOP Streaming</Text></TouchableHighlight>
</VideoCore> :
<TouchableHighlight onPress={() => this.setState({showPreview: true})}><Text>Open Streaming</Text></TouchableHighlight>
return (
<View style={styles.container}>
{previewOrButton}
</View>
);
}
});
var styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
}
});
// AppRegistry.registerComponent('RNVideoCore', () => RNVideoCore);
module.exports = VideoCore;