forked from zhigang1992/react-native-video-cache
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: using RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD for sync metho…
…d call
- Loading branch information
1 parent
59f8ad5
commit d4ce3ad
Showing
6 changed files
with
44 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,36 @@ | ||
/** | ||
* Sample React Native App | ||
* | ||
* adapted from App.js generated by the following command: | ||
* | ||
* react-native init example | ||
* | ||
* https://github.com/facebook/react-native | ||
*/ | ||
import React, { Component } from "react"; | ||
import { StyleSheet, Text, View } from "react-native"; | ||
import convertToCache from "react-native-video-cache"; | ||
|
||
import React, { Component } from 'react'; | ||
import { Platform, StyleSheet, Text, View } from 'react-native'; | ||
import convertToCache from 'react-native-video-cache'; | ||
|
||
export default class App extends Component<{}> { | ||
state = { | ||
status: 'starting', | ||
message: '--' | ||
}; | ||
componentDidMount() { | ||
convertToCache('https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-720p.mp4').then((message) => { | ||
this.setState({ | ||
status: 'native callback received', | ||
message | ||
}); | ||
}); | ||
} | ||
render() { | ||
return ( | ||
<View style={styles.container}> | ||
<Text style={styles.welcome}>☆VideoCache example☆</Text> | ||
<Text style={styles.instructions}>STATUS: {this.state.status}</Text> | ||
<Text style={styles.welcome}>☆NATIVE CALLBACK MESSAGE☆</Text> | ||
<Text style={styles.instructions}>{this.state.message}</Text> | ||
</View> | ||
); | ||
} | ||
export default function App() { | ||
const url = | ||
"https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-720p.mp4"; | ||
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> | ||
</View> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
backgroundColor: '#F5FCFF', | ||
justifyContent: "center", | ||
alignItems: "center", | ||
backgroundColor: "#F5FCFF", | ||
padding: 20 | ||
}, | ||
welcome: { | ||
fontSize: 20, | ||
textAlign: 'center', | ||
textAlign: "center", | ||
margin: 10, | ||
}, | ||
instructions: { | ||
textAlign: 'center', | ||
color: '#333333', | ||
textAlign: "center", | ||
color: "#333333", | ||
marginBottom: 5, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,20 @@ | ||
#import "VideoCache.h" | ||
#import <KTVHTTPCache/KTVHTTPCache.h> | ||
|
||
|
||
@implementation VideoCache | ||
|
||
RCT_EXPORT_MODULE() | ||
|
||
RCT_EXPORT_METHOD(convert:(NSString *)url | ||
resolver:(RCTPromiseResolveBlock)resolve | ||
rejecter:(RCTPromiseRejectBlock)reject) | ||
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(convert:(NSString *)url) | ||
{ | ||
if (!KTVHTTPCache.proxyIsRunning) { | ||
NSError *error; | ||
[KTVHTTPCache proxyStart:&error]; | ||
if (error) { | ||
reject(@"init.error", @"failed to start proxy server", error); | ||
return; | ||
if (!KTVHTTPCache.proxyIsRunning) { | ||
NSError *error; | ||
[KTVHTTPCache proxyStart:&error]; | ||
if (error) { | ||
return url; | ||
} | ||
} | ||
} | ||
resolve([KTVHTTPCache proxyURLWithOriginalURL:[NSURL URLWithString:url]].absoluteString); | ||
return [KTVHTTPCache proxyURLWithOriginalURL:[NSURL URLWithString:url]].absoluteString; | ||
} | ||
|
||
|
||
@end |
8 changes: 8 additions & 0 deletions
8
ios/VideoCache.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |