-
Notifications
You must be signed in to change notification settings - Fork 17
/
index.js
47 lines (41 loc) · 1.15 KB
/
index.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
import { DeviceEventEmitter, NativeModules } from 'react-native';
const { TorrentStreamer } = NativeModules;
const TORRENT_STREAMER_DOWNLOAD_EVENTS = {
error: 'error',
progress: 'progress',
status: 'status',
ready: 'ready',
stop: 'stop'
};
const _TorrentStreamerDownloadHandlers = {};
const TorrentStreamerPackage = {
addEventListener: (type, handler) => {
_TorrentStreamerDownloadHandlers[handler] = DeviceEventEmitter.addListener(
TORRENT_STREAMER_DOWNLOAD_EVENTS[type],
(torrentStreamerData) => {
handler(torrentStreamerData);
}
);
},
removeEventListener: (type, handler) =>{
if (!_TorrentStreamerDownloadHandlers[handler]) {
return;
}
_TorrentStreamerDownloadHandlers[handler].remove();
_TorrentStreamerDownloadHandlers[handler] = null;
},
setup: (location, removeAfterStop)=>{
removeAfterStop = removeAfterStop || true
TorrentStreamer.setup(location, removeAfterStop);
},
start: url => {
TorrentStreamer.start(url);
},
stop: () => {
TorrentStreamer.stop()
},
open: (path, type) =>{
TorrentStreamer.open(path, type);
}
}
export default TorrentStreamerPackage