-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCustomTwilioVideoView.js
More file actions
117 lines (96 loc) · 2.56 KB
/
Copy pathCustomTwilioVideoView.js
File metadata and controls
117 lines (96 loc) · 2.56 KB
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
// @flow
import {
requireNativeComponent,
View,
Platform,
UIManager,
NativeModules,
findNodeHandle,
// $FlowFixMe
} from 'react-native';
import React, { PropTypes, Component } from 'react';
const propTypes = {
...View.propTypes,
/**
* Callback that is called when camera source changes
*/
onCameraSwitched: PropTypes.func,
/**
* Callback that is called when video is toggled.
*/
onVideoChanged: PropTypes.func,
/**
* Callback that is called when a audio is toggled.
*/
onAudioChanged: PropTypes.func,
/**
* Callback that is called when user is connected to a room.
*/
onRoomDidConnect: PropTypes.func,
/**
* Callback that is called when connecting to room fails.
*/
onConnectFailure: PropTypes.func,
/**
* Callback that is called when user is disconnected from room.
*/
onRoomDidDisconnect: PropTypes.func,
/**
* Callback called a participant enters a room.
*/
onRoomParticipantDidConnect: PropTypes.func,
/**
* Callback that is called when a participant exits a room.
*/
onRoomParticipantDidDisconnect: PropTypes.func,
};
const nativeEvents = {
connectToRoom: 1,
disconnect: 2,
switchCamera: 3,
toggleVideo: 4,
toggleSound: 5,
};
class CustomTwilioVideoView extends Component {
startCall({ accessToken }) {
this.runCommand(nativeEvents.connectToRoom, [accessToken]);
}
endCall() {
this.runCommand(nativeEvents.disconnect, []);
}
switchCamera() {
this.runCommand(nativeEvents.switchCamera, []);
}
toggleVideo() {
this.runCommand(nativeEvents.toggleVideo, []);
}
toggleSound() {
this.runCommand(nativeEvents.toggleSound, []);
}
runCommand(event, args) {
switch (Platform.OS) {
case 'android':
UIManager.dispatchViewManagerCommand(
findNodeHandle(this),
event,
args
);
break;
default:
break;
}
}
render() {
return (
<NativeCustomTwilioVideoView
onConnected={(event) => {
this.props.onRoomDidConnect && this.props.onRoomDidConnect(event.nativeEvent);
}}
{...this.props}
/>
);
}
}
CustomTwilioVideoView.propTypes = propTypes;
const NativeCustomTwilioVideoView = requireNativeComponent('RNCustomTwilioVideoView', CustomTwilioVideoView);
module.exports = CustomTwilioVideoView;