-
Notifications
You must be signed in to change notification settings - Fork 40
/
BroadcastView.js
121 lines (106 loc) · 3.44 KB
/
BroadcastView.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import React, {Component} from 'react';
import { PropTypes } from "prop-types";
import {StyleSheet, requireNativeComponent, NativeModules, View, DeviceEventEmitter, Platform} from 'react-native';
const BroadcastManager = NativeModules.BroadcastModule;
const styles = StyleSheet.create({
base: {
overflow: 'hidden',
},
});
export default class BroadcastView extends Component {
setNativeProps(nativeProps) {
this._root.setNativeProps(nativeProps);
}
componentWillMount(){
if(Platform.OS == 'android'){
DeviceEventEmitter.addListener('broadcastTimer', (seconds) => {
this.props.onBroadcastVideoEncoded({seconds:seconds})
});
}
}
_assignRoot = (component) => {
this._root = component;
};
_onBroadcastStart = (event) => {
if(Platform.OS == 'android'){
BroadcastManager.startTimer(1.1, 3600);
}
if (this.props.onBroadcastStart) {
this.props.onBroadcastStart(event.nativeEvent);
}
};
_onBroadcastFail = (event) => {
if (this.props.onBroadcastFail) {
this.props.onBroadcastFail(event.nativeEvent);
}
};
_onBroadcastStatusChange = (event) => {
if (this.props.onBroadcastStatusChange) {
this.props.onBroadcastStatusChange(event.nativeEvent);
}
};
_onBroadcastEventReceive = (event) => {
if (this.props.onBroadcastEventReceive) {
this.props.onBroadcastEventReceive(event.nativeEvent);
}
};
_onBroadcastErrorReceive = (event) => {
if (this.props.onBroadcastErrorReceive) {
this.props.onBroadcastErrorReceive(event.nativeEvent);
}
};
_onBroadcastVideoEncoded = (event) => {
if (this.props.onBroadcastVideoEncoded) {
this.props.onBroadcastVideoEncoded(event.nativeEvent);
}
};
_onBroadcastStop = (event) => {
if (this.props.onBroadcastStop) {
this.props.onBroadcastStop(event.nativeEvent);
}
};
render() {
const nativeProps = Object.assign({}, this.props);
Object.assign(nativeProps, {
style: [styles.base, nativeProps.style],
onBroadcastStart: this._onBroadcastStart,
onBroadcastFail: this._onBroadcastFail,
onBroadcastStatusChange: this._onBroadcastStatusChange,
onBroadcastEventReceive: this._onBroadcastEventReceive,
onBroadcastErrorReceive: this._onBroadcastErrorReceive,
onBroadcastVideoEncoded: this._onBroadcastVideoEncoded,
onBroadcastStop: this._onBroadcastStop,
});
return (
<RNBroadcastView
ref={this._assignRoot}
{...nativeProps}
/>
);
}
}
BroadcastView.propTypes = {
hostAddress: PropTypes.string.isRequired,
applicationName: PropTypes.string.isRequired,
sdkLicenseKey: PropTypes.string.isRequired,
broadcastName: PropTypes.string.isRequired,
backgroundMode: PropTypes.bool,
sizePreset: PropTypes.number,
videoOrientation: PropTypes.oneOf(['landscape', 'portrait']),
port: PropTypes.number,
username: PropTypes.string.isRequired,
password: PropTypes.string.isRequired,
broadcasting: PropTypes.bool.isRequired,
muted: PropTypes.bool,
flashOn: PropTypes.bool,
frontCamera: PropTypes.bool,
onBroadcastStart: PropTypes.func,
onBroadcastFail: PropTypes.func,
onBroadcastStatusChange: PropTypes.func,
onBroadcastEventReceive: PropTypes.func,
onBroadcastErrorReceive: PropTypes.func,
onBroadcastVideoEncoded: PropTypes.func,
onBroadcastStop: PropTypes.func,
...View.propTypes,
};
const RNBroadcastView = requireNativeComponent('RNBroadcastView', BroadcastView);