@yehuo2003/ha-frp-rn
v1.0.0
Published
React Native FRP module for network penetration
Maintainers
Readme
ha-frp-rn
React Native FRP (Fast Reverse Proxy) 模块,用于网络穿透,支持 Android 平台。
项目概述
ha-frp-rn 是一个 React Native 原生模块,实现了 FRP 客户端功能,用于建立从设备到 FRP 服务器的连接,实现网络穿透。该模块基于 ha-shared-core 中定义的 IFrpService 接口,提供了跨平台的 FRP 功能支持。
功能特性
- ✅ 支持 Android 平台
- ✅ 实现 IFrpService 接口,与 ha-shared-core 无缝集成
- ✅ 支持远程配置获取与本地默认配置 fallback
- ✅ TypeScript 完全支持
- ✅ 模块化设计,易于扩展和维护
- ✅ 支持 FRP 状态监控和日志记录
- ✅ 支持多种 FRP 配置类型
安装
npm
npm install ha-frp-rnyarn
yarn add ha-frp-rn对等依赖
该模块依赖于以下包:
- react-native (^0.72.0)
- ha-shared-core (本地依赖)
使用示例
基本使用
import { createFrpService, FrpConfigType } from 'ha-frp-rn';
// 创建 FRP 服务实例
const frpService = createFrpService();
// 初始化服务
await frpService.initialize();
// 启动 FRP 服务(使用默认配置)
const instanceId = await frpService.start();
// 获取 FRP 状态
const status = await frpService.getStatus(instanceId);
// 停止 FRP 服务
await frpService.stop(instanceId);自定义配置
import { createFrpService, FrpConfig, FrpConfigType } from 'ha-frp-rn';
const frpService = createFrpService();
// 创建自定义配置
const customConfig: FrpConfig = {
name: 'custom-config',
type: FrpConfigType.VISITOR,
enabled: true,
visitorConfig: {
name: 'custom-visitor',
type: FrpConfigType.VISITOR,
enabled: true,
serverAddr: 'your-frps-server.com',
serverPort: 7000,
token: 'your-token',
proxies: [
// 代理配置
]
}
};
// 使用自定义配置启动
await frpService.start(customConfig);强制使用远程配置
// 强制从远程API获取配置
const instanceId = await frpService.start(undefined, true);打包命令
构建模块
npm run build开发模式(监听文件变化)
npm run build:dev类型检查
npm run typecheck代码检查
npm run lint生成打包文件
npm packAPI 文档
核心类
ReactNativeFrpService
实现了 IFrpService 接口,提供了完整的 FRP 功能:
initialize(): 初始化 FRP 服务start(config?: FrpConfig | string, forceRemoteConfig?: boolean): 启动 FRP 服务stop(instanceId?: string): 停止 FRP 服务restart(instanceId: string, forceRemoteConfig?: boolean): 重启 FRP 服务getStatus(instanceId?: string): 获取 FRP 状态getStats(instanceId: string): 获取 FRP 统计信息loadConfig(config: string | FrpConfig): 加载 FRP 配置saveConfig(config: FrpConfig, filePath: string): 保存 FRP 配置validateConfig(config: FrpConfig): 验证 FRP 配置getLogs(instanceId: string, limit?: number, offset?: number): 获取 FRP 日志onLog(instanceId: string, callback: (log: FrpLogEntry) => void): 监听 FRP 日志onStatusChange(callback: (instanceId: string, status: FrpStatus) => void): 监听 FRP 状态变化onError(callback: (instanceId: string, error: Error) => void): 监听 FRP 错误getVersion(): 获取 FRP 版本cleanup(): 清理 FRP 服务资源
FrpConfigManager
用于管理 FRP 配置,支持从远程 API 获取和本地默认配置:
getConfig(forceRemote: boolean = false): 获取 FRP 配置clearCache(): 清除配置缓存getLastUpdated(): 获取配置最后更新时间
配置管理
配置优先级
- 远程配置:通过 API 请求获取的配置(优先级最高)
- 本地默认配置:打包在 assets 目录中的
frpc-visitor-default.toml文件
默认配置
默认配置文件位于 assets/frpc-visitor-default.toml,包含了基本的 FRP 访问者配置。
平台支持
| 平台 | 状态 | |------|------| | Android | ✅ 支持 | | iOS | ⏳ 开发中 |
开发指南
目录结构
ha-frp-rn/
├── assets/ # 资源文件目录
│ └── frpc-visitor-default.toml # 默认 FRP 配置
├── src/ # 源代码目录
│ ├── index.ts # 入口文件
│ └── android/ # Android 原生代码
├── .gitignore # Git 忽略文件
├── package.json # 项目配置
├── tsconfig.json # TypeScript 配置
├── tsconfig.build.json # 构建用 TypeScript 配置
└── README.md # 项目说明文档开发流程
- 克隆仓库
- 安装依赖:
npm install - 运行类型检查:
npm run typecheck - 构建模块:
npm run build - 在 React Native 项目中测试使用
许可证
MIT License
贡献
欢迎提交 Issue 和 Pull Request!
联系我们
如有问题或建议,请通过 GitHub Issues 反馈。
