forked from stringeecom/stringee-react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringeeRoom.js
More file actions
executable file
·132 lines (109 loc) · 3 KB
/
StringeeRoom.js
File metadata and controls
executable file
·132 lines (109 loc) · 3 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import { Component } from "react";
import PropTypes from "prop-types";
import { NativeModules, NativeEventEmitter, Platform } from "react-native";
import { roomEvents } from "./helpers/StringeeHelper";
import { each } from "underscore";
const RNStringeeRoom = NativeModules.RNStringeeRoom;
export default class extends Component {
static propTypes = {
eventHandlers: PropTypes.object
};
constructor(props) {
super(props);
this._events = [];
this._subscriptions = [];
this._eventEmitter = new NativeEventEmitter(RNStringeeRoom);
}
componentWillMount() {
this.sanitizeRoomEvents(this.props.eventHandlers);
}
componentWillUnmount() {
this._unregisterEvents();
}
render() {
return null;
}
_unregisterEvents() {
this._subscriptions.forEach(e => e.remove());
this._subscriptions = [];
this._events.forEach(e => RNStringeeRoom.removeNativeEvent(e));
this._events = [];
}
sanitizeRoomEvents(events) {
if (typeof events !== "object") {
return;
}
const platform = Platform.OS;
each(events, (handler, type) => {
const eventName = roomEvents[platform][type];
if (eventName !== undefined) {
this._subscriptions.push(
this._eventEmitter.addListener(eventName, data => {
handler(data);
})
);
this._events.push(eventName);
RNStringeeRoom.setNativeEvent(eventName);
} else {
console.log(`${type} is not a supported event`);
}
});
}
makeRoom(callback: RNStringeeEventCallback) {
RNStringeeRoom.makeRoom(callback);
}
joinRoom(roomId: number, callback: RNStringeeEventCallback) {
RNStringeeRoom.joinRoom(roomId, callback);
}
publishLocalStream(
roomId: number,
config: string,
callback: RNStringeeEventCallback
) {
RNStringeeRoom.publishLocalStream(roomId, config, callback);
}
unPublishLocalStream(
roomId: number,
streamId: string,
callback: RNStringeeEventCallback
) {
RNStringeeRoom.unPublishLocalStream(roomId, streamId, callback);
}
subscribe(
roomId: number,
streamId: string,
callback: RNStringeeEventCallback
) {
RNStringeeRoom.subscribe(roomId, streamId, callback);
}
unSubscribe(
roomId: number,
streamId: string,
callback: RNStringeeEventCallback
) {
RNStringeeRoom.unSubscribe(roomId, streamId, callback);
}
destroy(roomId: number, callback: RNStringeeEventCallback) {
RNStringeeRoom.destroy(roomId, callback);
}
switchCamera() {
RNStringeeRoom.switchCamera();
}
mute(isMute: boolean) {
RNStringeeRoom.mute(isMute);
}
turnOnCamera(isOn: boolean, callback: RNStringeeEventCallback) {
RNStringeeRoom.turnOnCamera(isOn, callback);
}
setSpeakerphoneOn(isOn: boolean) {
RNStringeeRoom.setSpeakerphoneOn(isOn);
}
getStats(
roomId: number,
streamId: string,
useVideoTrack: boolean,
callback: RNStringeeEventCallback
) {
RNStringeeRoom.getStats(roomId, streamId, useVideoTrack, callback);
}
}