Skip to content

Commit 1d2cafb

Browse files
committed
[ UDPDATE ] react native support
0 parents  commit 1d2cafb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+11001
-0
lines changed

.gitattributes

Whitespace-only changes.

.gitignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# OSX
2+
#
3+
.DS_Store
4+
5+
# node.js
6+
#
7+
node_modules/
8+
npm-debug.log
9+
yarn-error.log
10+
11+
# Android/IntelliJ
12+
#
13+
build/
14+
.idea
15+
.gradle
16+
local.properties
17+
*.iml
18+
19+
# BUCK
20+
buck-out/
21+
\.buckd/
22+
*.keystore

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
example

README.md

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
## React-Native-Torrent-Streamer
2+
3+
> Torrent Streamer for react-native
4+
5+
*Only Android support now.*
6+
7+
### - 0.2.0 Release
8+
9+
* Support react-native 0.60.x
10+
* TorrentStream-Android updated to
11+
12+
#### Integrate
13+
14+
##### Android
15+
16+
* Install via npm
17+
`yarn add react-native-torrent-streamer`
18+
19+
* Add `android/build.gradle`
20+
```Diff
21+
...
22+
allprojects {
23+
...
24+
dependencies {
25+
...
26+
+ maven {
27+
+ url("https://jitpack.io")
28+
+ }
29+
}
30+
}
31+
```
32+
33+
#### Usage
34+
35+
```Javascript
36+
import React, { Component } from 'react';
37+
import { AppRegistry, StyleSheet, View, Text, TouchableHighlight } from 'react-native'
38+
39+
import TorrentStreamer from 'react-native-torrent-streamer'
40+
41+
export default class App extends Component<{}> {
42+
state = {
43+
progress: 0,
44+
buffer: 0,
45+
downloadSpeed: 0,
46+
seeds: 0
47+
}
48+
49+
componentDidMount() {
50+
TorrentStreamer.addEventListener('error', this.onError)
51+
TorrentStreamer.addEventListener('status', this.onStatus.bind(this))
52+
TorrentStreamer.addEventListener('ready', this.onReady.bind(this))
53+
TorrentStreamer.addEventListener('stop', this.onStop.bind(this))
54+
}
55+
56+
onError(e) {
57+
console.log(e)
58+
}
59+
60+
onStatus({progress, buffer, downloadSpeed, seeds}) {
61+
this.setState({
62+
progress,
63+
buffer,
64+
downloadSpeed,
65+
seeds
66+
})
67+
}
68+
69+
onReady(data) {
70+
TorrentStreamer.open(data.url, 'video/mp4')
71+
}
72+
73+
onStop(data) {
74+
console.log('stop')
75+
}
76+
77+
render() {
78+
const { progress, buffer, downloadSpeed, seeds } = this.state
79+
80+
return (
81+
<View style={styles.container}>
82+
<TouchableHighlight
83+
style={styles.button}
84+
onPress={this._handleStart.bind(this)}>
85+
<Text >Start Torrent!</Text>
86+
</TouchableHighlight>
87+
88+
<TouchableHighlight
89+
style={styles.button}
90+
onPress={this._handleStop.bind(this)}>
91+
<Text >Stop Torrent!</Text>
92+
</TouchableHighlight>
93+
94+
{buffer ? <Text>Buffer: {buffer}</Text> : null}
95+
{downloadSpeed ? <Text>Download Speed: {(downloadSpeed / 1024).toFixed(2)} Kbs/seg</Text> : null}
96+
{progress ? <Text>Progress: {parseFloat(progress).toFixed(2)}</Text> : null}
97+
{seeds ? <Text>Seeds: {seeds}</Text> : null}
98+
</View>
99+
)
100+
}
101+
102+
_handleStart() {
103+
TorrentStreamer.start('magnet:?xt=urn:btih:88594aaacbde40ef3e2510c47374ec0aa396c08e&dn=bbb%5Fsunflower%5F1080p%5F30fps%5Fnormal.mp4&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80%2Fannounce&tr=udp%3A%2F%2Ftracker.publicbt.com%3A80%2Fannounce&ws=http%3A%2F%2Fdistribution.bbb3d.renderfarming.net%2Fvideo%2Fmp4%2Fbbb%5Fsunflower%5F1080p%5F30fps%5Fnormal.mp4')
104+
}
105+
106+
_handleStop() {
107+
this.setState({
108+
progress: 0,
109+
buffer: 0,
110+
downloadSpeed: 0,
111+
seeds: 0
112+
}, () => {
113+
TorrentStreamer.stop()
114+
})
115+
}
116+
}
117+
118+
const styles = StyleSheet.create({
119+
container: {
120+
flex: 1,
121+
justifyContent: 'center',
122+
alignItems: 'center',
123+
backgroundColor: '#F5FCFF',
124+
}
125+
})
126+
```
127+
128+
#### LICENSE
129+
MIT

android/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
README
2+
======
3+
4+
If you want to publish the lib as a maven dependency, follow these steps before publishing a new version to npm:
5+
6+
1. Be sure to have the Android [SDK](https://developer.android.com/studio/index.html) and [NDK](https://developer.android.com/ndk/guides/index.html) installed
7+
2. Be sure to have a `local.properties` file in this folder that points to the Android SDK and NDK
8+
```
9+
ndk.dir=/Users/{username}/Library/Android/sdk/ndk-bundle
10+
sdk.dir=/Users/{username}/Library/Android/sdk
11+
```
12+
3. Delete the `maven` folder
13+
4. Run `./gradlew installArchives`
14+
5. Verify that latest set of generated files is in the maven folder with the correct version number

android/build.gradle

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
// android/build.gradle
2+
3+
// based on:
4+
//
5+
// * https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle
6+
// original location:
7+
// - https://github.com/facebook/react-native/blob/0.58-stable/local-cli/templates/HelloWorld/android/build.gradle
8+
//
9+
// * https://github.com/facebook/react-native/blob/0.60-stable/template/android/app/build.gradle
10+
// original location:
11+
// - https://github.com/facebook/react-native/blob/0.58-stable/local-cli/templates/HelloWorld/android/app/build.gradle
12+
13+
def DEFAULT_COMPILE_SDK_VERSION = 28
14+
def DEFAULT_BUILD_TOOLS_VERSION = '28.0.3'
15+
def DEFAULT_MIN_SDK_VERSION = 16
16+
def DEFAULT_TARGET_SDK_VERSION = 28
17+
18+
def safeExtGet(prop, fallback) {
19+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
20+
}
21+
22+
apply plugin: 'com.android.library'
23+
apply plugin: 'maven'
24+
25+
buildscript {
26+
// The Android Gradle plugin is only required when opening the android folder stand-alone.
27+
// This avoids unnecessary downloads and potential conflicts when the library is included as a
28+
// module dependency in an application project.
29+
// ref: https://docs.gradle.org/current/userguide/tutorial_using_tasks.html#sec:build_script_external_dependencies
30+
if (project == rootProject) {
31+
repositories {
32+
google()
33+
jcenter()
34+
}
35+
dependencies {
36+
classpath 'com.android.tools.build:gradle:3.4.1'
37+
}
38+
}
39+
}
40+
41+
apply plugin: 'com.android.library'
42+
apply plugin: 'maven'
43+
44+
android {
45+
compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
46+
buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION)
47+
defaultConfig {
48+
minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
49+
targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
50+
versionCode 1
51+
versionName "1.0"
52+
}
53+
lintOptions {
54+
abortOnError false
55+
}
56+
}
57+
58+
repositories {
59+
// ref: https://www.baeldung.com/maven-local-repository
60+
mavenLocal()
61+
maven {
62+
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
63+
url "$rootDir/../node_modules/react-native/android"
64+
}
65+
maven {
66+
// Android JSC is installed from npm
67+
url "$rootDir/../node_modules/jsc-android/dist"
68+
}
69+
google()
70+
jcenter()
71+
}
72+
73+
dependencies {
74+
//noinspection GradleDynamicVersion
75+
implementation 'com.facebook.react:react-native:+' // From node_modules
76+
implementation "com.github.TorrentStream:TorrentStream-Android:2.6.1"
77+
}
78+
79+
def configureReactNativePom(def pom) {
80+
def packageJson = new groovy.json.JsonSlurper().parseText(file('../package.json').text)
81+
82+
pom.project {
83+
name packageJson.title
84+
artifactId packageJson.name
85+
version = packageJson.version
86+
group = "com.ghondar.torrentstreamer"
87+
description packageJson.description
88+
url packageJson.repository.baseUrl
89+
90+
licenses {
91+
license {
92+
name packageJson.license
93+
url packageJson.repository.baseUrl + '/blob/master/' + packageJson.licenseFilename
94+
distribution 'repo'
95+
}
96+
}
97+
98+
developers {
99+
developer {
100+
id packageJson.author.username
101+
name packageJson.author.name
102+
}
103+
}
104+
}
105+
}
106+
107+
afterEvaluate { project ->
108+
// some Gradle build hooks ref:
109+
// https://www.oreilly.com/library/view/gradle-beyond-the/9781449373801/ch03.html
110+
task androidJavadoc(type: Javadoc) {
111+
source = android.sourceSets.main.java.srcDirs
112+
classpath += files(android.bootClasspath)
113+
classpath += files(project.getConfigurations().getByName('compile').asList())
114+
include '**/*.java'
115+
}
116+
117+
task androidJavadocJar(type: Jar, dependsOn: androidJavadoc) {
118+
classifier = 'javadoc'
119+
from androidJavadoc.destinationDir
120+
}
121+
122+
task androidSourcesJar(type: Jar) {
123+
classifier = 'sources'
124+
from android.sourceSets.main.java.srcDirs
125+
include '**/*.java'
126+
}
127+
128+
android.libraryVariants.all { variant ->
129+
def name = variant.name.capitalize()
130+
def javaCompileTask = variant.javaCompileProvider.get()
131+
132+
task "jar${name}"(type: Jar, dependsOn: javaCompileTask) {
133+
from javaCompileTask.destinationDir
134+
}
135+
}
136+
137+
artifacts {
138+
archives androidSourcesJar
139+
archives androidJavadocJar
140+
}
141+
142+
task installArchives(type: Upload) {
143+
configuration = configurations.archives
144+
repositories.mavenDeployer {
145+
// Deploy to react-native-event-bridge/maven, ready to publish to npm
146+
repository url: "file://${projectDir}/../android/maven"
147+
configureReactNativePom pom
148+
}
149+
}
150+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="com.ghondar.torrentstreamer">
3+
<uses-permission android:name="android.permission.INTERNET" />
4+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
5+
</manifest>

0 commit comments

Comments
 (0)