mirror of
https://github.com/zhigang1992/react-native-video-cache.git
synced 2026-01-12 16:42:21 +08:00
feat: add back async version
This commit is contained in:
@@ -28,4 +28,13 @@ public class VideoCacheModule extends ReactContextBaseJavaModule {
|
||||
}
|
||||
return this.proxy.getProxyUrl(url);
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void convertAsync(String url, Promise promise) {
|
||||
if (this.proxy == null) {
|
||||
this.proxy = new HttpProxyCacheServer(this.reactContext);
|
||||
}
|
||||
promise.resolve(this.proxy.getProxyUrl(url));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,16 +1,22 @@
|
||||
import React, { Component } from "react";
|
||||
import React, {Component, useEffect, useState} from "react";
|
||||
import { StyleSheet, Text, View } from "react-native";
|
||||
import convertToCache from "react-native-video-cache";
|
||||
import convertToCache, {convertAsync} from "react-native-video-cache";
|
||||
|
||||
export default function App() {
|
||||
const url =
|
||||
"https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-720p.mp4";
|
||||
const [asyncVersion, setAsyncVersion] = useState();
|
||||
useEffect(() => {
|
||||
convertAsync(url).then(setAsyncVersion)
|
||||
}, [])
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
<Text style={styles.welcome}>☆Original URL☆</Text>
|
||||
<Text style={styles.instructions}>{url}</Text>
|
||||
<Text style={styles.welcome}>☆Proxy URL for Video Component☆</Text>
|
||||
<Text style={styles.instructions}>{convertToCache(url)}</Text>
|
||||
<Text style={styles.welcome}>☆Async Proxy URL☆</Text>
|
||||
<Text style={styles.instructions}>{asyncVersion}</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4720,7 +4720,7 @@ react-is@^16.8.1, react-is@^16.8.3, react-is@^16.8.4:
|
||||
integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==
|
||||
|
||||
"react-native-video-cache@file:..":
|
||||
version "1.0.0"
|
||||
version "2.0.2"
|
||||
|
||||
react-native@0.59:
|
||||
version "0.59.10"
|
||||
|
||||
3
index.js
3
index.js
@@ -6,3 +6,6 @@ export default (url) => {
|
||||
}
|
||||
return NativeModules.VideoCache.convert(url)
|
||||
};
|
||||
|
||||
export const convertAsync = VideoCache.convertAsync;
|
||||
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
export default (url) => url;
|
||||
export const convertAsync = Promise.resolve;
|
||||
|
||||
@@ -17,4 +17,19 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(convert:(NSString *)url)
|
||||
return [KTVHTTPCache proxyURLWithOriginalURL:[NSURL URLWithString:url]].absoluteString;
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(convertAsync:(NSString *)url
|
||||
resolver:(RCTPromiseResolveBlock)resolve
|
||||
rejecter:(RCTPromiseRejectBlock)reject)
|
||||
{
|
||||
if (!KTVHTTPCache.proxyIsRunning) {
|
||||
NSError *error;
|
||||
[KTVHTTPCache proxyStart:&error];
|
||||
if (error) {
|
||||
reject(@"init.error", @"failed to start proxy server", error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
resolve([KTVHTTPCache proxyURLWithOriginalURL:[NSURL URLWithString:url]].absoluteString);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user