-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
App.js
82 lines (77 loc) · 1.55 KB
/
App.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
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow strict-local
*/
import React, {useState} from 'react';
import {
Button,
SafeAreaView,
StyleSheet,
View,
StatusBar,
} from 'react-native';
import { Colors } from 'react-native/Libraries/NewAppScreen';
import { mediaDevices, RTCView } from 'react-native-webrtc';
const App = () => {
const [stream, setStream] = useState(null);
const start = async () => {
console.log('start');
if (!stream) {
try {
const s = await mediaDevices.getUserMedia({ video: true });
setStream(s);
} catch(e) {
console.error(e);
}
}
};
const stop = () => {
console.log('stop');
if (stream) {
stream.release();
setStream(null);
}
};
return (
<>
<StatusBar barStyle="dark-content" />
<SafeAreaView style={styles.body}>
{
stream &&
<RTCView
streamURL={stream.toURL()}
style={styles.stream} />
}
<View
style={styles.footer}>
<Button
title = "Start"
onPress = {start} />
<Button
title = "Stop"
onPress = {stop} />
</View>
</SafeAreaView>
</>
);
};
const styles = StyleSheet.create({
body: {
backgroundColor: Colors.white,
...StyleSheet.absoluteFill
},
stream: {
flex: 1
},
footer: {
backgroundColor: Colors.lighter,
position: 'absolute',
bottom: 0,
left: 0,
right: 0
},
});
export default App;