-
Notifications
You must be signed in to change notification settings - Fork 183
/
NodeCameraModule.js
99 lines (86 loc) · 2.37 KB
/
NodeCameraModule.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
import React, { Component } from 'react';
import { PropTypes } from 'prop-types';
import { requireNativeComponent, View, UIManager, findNodeHandle } from 'react-native';
var RCT_VIDEO_REF = 'NodeCameraView';
class NodeCameraView extends Component {
constructor(props) {
super(props);
}
_onChange(event) {
if (!this.props.onStatus) {
return;
}
this.props.onStatus(event.nativeEvent.code, event.nativeEvent.message);
}
switchCamera() {
UIManager.dispatchViewManagerCommand(
findNodeHandle(this.refs[RCT_VIDEO_REF]),
UIManager.RCTNodeCamera.Commands.switch,
null
);
}
startPreview() {
UIManager.dispatchViewManagerCommand(
findNodeHandle(this.refs[RCT_VIDEO_REF]),
UIManager.RCTNodeCamera.Commands.startprev,
null
);
}
stopPreview() {
UIManager.dispatchViewManagerCommand(
findNodeHandle(this.refs[RCT_VIDEO_REF]),
UIManager.RCTNodeCamera.Commands.stopprev,
null
);
}
start() {
UIManager.dispatchViewManagerCommand(
findNodeHandle(this.refs[RCT_VIDEO_REF]),
UIManager.RCTNodeCamera.Commands.start,
null
);
}
stop() {
UIManager.dispatchViewManagerCommand(
findNodeHandle(this.refs[RCT_VIDEO_REF]),
UIManager.RCTNodeCamera.Commands.stop,
null
);
}
render() {
return <RCTNodeCamera
{...this.props}
ref={RCT_VIDEO_REF}
onChange={this._onChange.bind(this)}
/>;
};
}
NodeCameraView.name = RCT_VIDEO_REF;
NodeCameraView.propTypes = {
outputUrl: PropTypes.string,
camera: PropTypes.shape({
cameraId: PropTypes.oneOf([0, 1]),
cameraFrontMirror: PropTypes.bool
}),
audio: PropTypes.shape({
bitrate: PropTypes.number,
profile: PropTypes.oneOf([0, 1, 2]),
samplerate: PropTypes.oneOf([8000, 16000, 32000, 44100, 48000]),
}),
video: PropTypes.shape({
preset: PropTypes.number,
bitrate: PropTypes.number,
profile: PropTypes.oneOf([0, 1, 2]),
fps: PropTypes.oneOf([15, 20, 24, 30]),
videoFrontMirror: PropTypes.bool
}),
autopreview:PropTypes.bool,
denoise: PropTypes.bool,
smoothSkinLevel: PropTypes.oneOf([0, 1, 2, 3, 4, 5]),
onStatus: PropTypes.func,
...View.propTypes // 包含默认的View的属性
};
const RCTNodeCamera = requireNativeComponent('RCTNodeCamera', NodeCameraView, {
nativeOnly: { onChange: true }
});
module.exports = NodeCameraView;