This commit is contained in:
Fredrik Burmester
2025-02-15 17:29:44 +01:00
parent a25c01b7a8
commit 8202017110
98 changed files with 35 additions and 170 deletions

View File

@@ -45,7 +45,7 @@ import {
useDownloadProgress,
useDownloadError,
useDownloadComplete,
} from "@/modules/expo-hls-downloader";
} from "@/modules/hls-downloader";
interface NativeDownloadButton extends ViewProps {
item: BaseItemDto;

View File

@@ -1,5 +0,0 @@
module.exports = {
root: true,
extends: ["universe/native", "universe/web"],
ignorePatterns: ["build"],
};

View File

@@ -1,57 +0,0 @@
# OSX
#
.DS_Store
# VSCode
.vscode/
jsconfig.json
# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate
project.xcworkspace
# Android/IJ
#
.classpath
.cxx
.gradle
.idea
.project
.settings
local.properties
android.iml
android/app/libs
android/keystores/debug.keystore
# Cocoapods
#
example/ios/Pods
# Ruby
example/vendor/
# node.js
#
node_modules/
npm-debug.log
yarn-debug.log
yarn-error.log
# Expo
.expo/*

View File

@@ -1,14 +0,0 @@
# Exclude all top-level hidden directories by convention
/.*/
# Exclude tarballs generated by `npm pack`
/*.tgz
__mocks__
__tests__
/babel.config.js
/android/src/androidTest/
/android/src/test/
/android/build/
/example/

View File

@@ -1,9 +0,0 @@
{
"platforms": ["apple"],
"apple": {
"modules": ["ExpoHlsDownloaderModule"]
},
"android": {
"modules": ["expo.modules.hlsdownloader.ExpoHlsDownloaderModule"]
}
}

View File

@@ -1,43 +0,0 @@
{
"name": "expo-hls-downloader",
"version": "0.1.0",
"description": "Native HLS downloader",
"main": "build/index.js",
"types": "build/index.d.ts",
"scripts": {
"build": "expo-module build",
"clean": "expo-module clean",
"lint": "expo-module lint",
"test": "expo-module test",
"prepare": "expo-module prepare",
"prepublishOnly": "expo-module prepublishOnly",
"expo-module": "expo-module",
"open:ios": "xed example/ios",
"open:android": "open -a \"Android Studio\" example/android"
},
"keywords": [
"react-native",
"expo",
"expo-hls-downloader",
"ExpoHlsDownloader"
],
"repository": "https://github.com/streamyfin/streamyfin",
"bugs": {
"url": "https://github.com/streamyfin/streamyfin/issues"
},
"author": "Fredrik Burmester <fredrik.burmester@gmail.com> (fredrikburmester)",
"license": "MIT",
"homepage": "https://github.com/streamyfin/streamyfin#readme",
"dependencies": {},
"devDependencies": {
"@types/react": "~18.3.12",
"expo-module-scripts": "^4.0.3",
"expo": "~52.0.0",
"react-native": "0.76.0"
},
"peerDependencies": {
"expo": "*",
"react": "*",
"react-native": "*"
}
}

View File

@@ -1,3 +0,0 @@
import { requireNativeModule } from "expo";
export default requireNativeModule("ExpoHlsDownloader");

View File

@@ -1,10 +0,0 @@
// Reexport the native module. On web, it will be resolved to ExpoHlsDownloaderModule.web.ts
// and on native platforms to ExpoHlsDownloaderModule.ts
import ExpoHlsDownloaderModule from "./ExpoHlsDownloaderModule";
export { default } from "./ExpoHlsDownloaderModule";
export { default as ExpoHlsDownloaderView } from "./ExpoHlsDownloaderView";
export * from "./ExpoHlsDownloader.types";
export function downloadHLSAsset(url: string, assetTitle: string): void {
return ExpoHlsDownloaderModule.downloadHLSAsset(url, assetTitle);
}

View File

@@ -1,9 +0,0 @@
// @generated by expo-module-scripts
{
"extends": "expo-module-scripts/tsconfig.base",
"compilerOptions": {
"outDir": "./build"
},
"include": ["./src", "index.ts"],
"exclude": ["**/__mocks__/*", "**/__tests__/*", "**/__rsc_tests__/*"]
}

View File

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View File

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

View File

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View File

@@ -0,0 +1,9 @@
{
"platforms": ["apple"],
"apple": {
"modules": ["HlsDownloaderModule"]
},
"android": {
"modules": ["expo.modules.hlsdownloader.HlsDownloaderModule"]
}
}

View File

@@ -6,8 +6,8 @@ import type {
OnCompleteEventPayload,
OnErrorEventPayload,
OnProgressEventPayload,
} from "./src/ExpoHlsDownloader.types";
import ExpoHlsDownloaderModule from "./src/ExpoHlsDownloaderModule";
} from "./src/HlsDownloader.types";
import HlsDownloaderModule from "./src/HlsDownloaderModule";
/**
* Initiates an HLS download.
@@ -15,7 +15,7 @@ import ExpoHlsDownloaderModule from "./src/ExpoHlsDownloaderModule";
* @param assetTitle - A title for the asset.
*/
function downloadHLSAsset(url: string, assetTitle: string): void {
ExpoHlsDownloaderModule.downloadHLSAsset(url, assetTitle);
HlsDownloaderModule.downloadHLSAsset(url, assetTitle);
}
/**
@@ -26,7 +26,7 @@ function downloadHLSAsset(url: string, assetTitle: string): void {
function addProgressListener(
listener: (event: OnProgressEventPayload) => void
): EventSubscription {
return ExpoHlsDownloaderModule.addListener("onProgress", listener);
return HlsDownloaderModule.addListener("onProgress", listener);
}
/**
@@ -37,7 +37,7 @@ function addProgressListener(
function addErrorListener(
listener: (event: OnErrorEventPayload) => void
): EventSubscription {
return ExpoHlsDownloaderModule.addListener("onError", listener);
return HlsDownloaderModule.addListener("onError", listener);
}
/**
@@ -48,7 +48,7 @@ function addErrorListener(
function addCompleteListener(
listener: (event: OnCompleteEventPayload) => void
): EventSubscription {
return ExpoHlsDownloaderModule.addListener("onComplete", listener);
return HlsDownloaderModule.addListener("onComplete", listener);
}
/**

View File

@@ -1,7 +1,7 @@
import ExpoModulesCore
import AVFoundation
public class ExpoHlsDownloaderModule: Module {
public class HlsDownloaderModule: Module {
// Optional: Keep a strong reference to the delegate (for the current download)
private var currentDelegate: HLSDownloadDelegate?
@@ -13,17 +13,17 @@ public class ExpoHlsDownloaderModule: Module {
// Expose the download function.
Function("downloadHLSAsset") { (url: String, assetTitle: String) -> Void in
print("[ExpoHlsDownloaderModule] downloadHLSAsset called with url: \(url) and assetTitle: \(assetTitle)")
print("[HlsDownloaderModule] downloadHLSAsset called with url: \(url) and assetTitle: \(assetTitle)")
guard let assetURL = URL(string: url) else {
print("[ExpoHlsDownloaderModule] Invalid URL: \(url)")
print("[HlsDownloaderModule] Invalid URL: \(url)")
self.sendEvent("onError", ["error": "Invalid URL"])
return
}
let asset = AVURLAsset(url: assetURL)
let configuration = URLSessionConfiguration.background(withIdentifier: "com.example.hlsdownload.\(UUID().uuidString)")
print("[ExpoHlsDownloaderModule] Created background session configuration")
print("[HlsDownloaderModule] Created background session configuration")
let delegate = HLSDownloadDelegate(module: self)
self.currentDelegate = delegate
@@ -33,7 +33,7 @@ public class ExpoHlsDownloaderModule: Module {
assetDownloadDelegate: delegate,
delegateQueue: OperationQueue.main
)
print("[ExpoHlsDownloaderModule] Created download session")
print("[HlsDownloaderModule] Created download session")
guard let task = downloadSession.makeAssetDownloadTask(
asset: asset,
@@ -41,24 +41,24 @@ public class ExpoHlsDownloaderModule: Module {
assetArtworkData: nil,
options: nil
) else {
print("[ExpoHlsDownloaderModule] Failed to create download task")
print("[HlsDownloaderModule] Failed to create download task")
self.sendEvent("onError", ["error": "Failed to create download task"])
return
}
print("[ExpoHlsDownloaderModule] Starting download task for asset: \(assetTitle)")
print("[HlsDownloaderModule] Starting download task for asset: \(assetTitle)")
task.resume()
}
// Called when JavaScript starts observing events.
OnStartObserving {
print("[ExpoHlsDownloaderModule] Started observing events")
print("[HlsDownloaderModule] Started observing events")
// Additional setup if needed.
}
// Called when JavaScript stops observing events.
OnStopObserving {
print("[ExpoHlsDownloaderModule] Stopped observing events")
print("[HlsDownloaderModule] Stopped observing events")
// Clean up if necessary.
}
}
@@ -66,9 +66,9 @@ public class ExpoHlsDownloaderModule: Module {
// Delegate that listens to AVAssetDownloadURLSession events and emits them to JS.
class HLSDownloadDelegate: NSObject, AVAssetDownloadDelegate {
weak var module: ExpoHlsDownloaderModule?
weak var module: HlsDownloaderModule?
init(module: ExpoHlsDownloaderModule) {
init(module: HlsDownloaderModule) {
self.module = module
}

View File

@@ -12,13 +12,13 @@ export type OnCompleteEventPayload = {
location: string;
};
export type ExpoHlsDownloaderModuleEvents = {
export type HlsDownloaderModuleEvents = {
onProgress: (params: OnProgressEventPayload) => void;
onError: (params: OnErrorEventPayload) => void;
onComplete: (params: OnCompleteEventPayload) => void;
};
export type ExpoHlsDownloaderViewProps = {
export type HlsDownloaderViewProps = {
url: string;
style?: StyleProp<ViewStyle>;
};

View File

@@ -0,0 +1,3 @@
import { requireNativeModule } from "expo-modules-core";
export default requireNativeModule("HlsDownloader");

View File

@@ -132,6 +132,9 @@
"exclude": [
"react-native"
]
},
"autolinking": {
"nativeModulesDir": "modules"
}
}
}