ha-frp-rn 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,217 @@
1
+ # ha-frp-rn
2
+
3
+ React Native FRP (Fast Reverse Proxy) 模块,用于网络穿透,支持 Android 平台。
4
+
5
+ ## 项目概述
6
+
7
+ ha-frp-rn 是一个 React Native 原生模块,实现了 FRP 客户端功能,用于建立从设备到 FRP 服务器的连接,实现网络穿透。该模块基于 ha-shared-core 中定义的 IFrpService 接口,提供了跨平台的 FRP 功能支持。
8
+
9
+ ## 功能特性
10
+
11
+ - ✅ 支持 Android 平台
12
+ - ✅ 实现 IFrpService 接口,与 ha-shared-core 无缝集成
13
+ - ✅ 支持远程配置获取与本地默认配置 fallback
14
+ - ✅ TypeScript 完全支持
15
+ - ✅ 模块化设计,易于扩展和维护
16
+ - ✅ 支持 FRP 状态监控和日志记录
17
+ - ✅ 支持多种 FRP 配置类型
18
+
19
+ ## 安装
20
+
21
+ ### npm
22
+
23
+ ```bash
24
+ npm install ha-frp-rn
25
+ ```
26
+
27
+ ### yarn
28
+
29
+ ```bash
30
+ yarn add ha-frp-rn
31
+ ```
32
+
33
+ ### 对等依赖
34
+
35
+ 该模块依赖于以下包:
36
+
37
+ - react-native (^0.72.0)
38
+ - ha-shared-core (本地依赖)
39
+
40
+ ## 使用示例
41
+
42
+ ### 基本使用
43
+
44
+ ```typescript
45
+ import { createFrpService, FrpConfigType } from 'ha-frp-rn';
46
+
47
+ // 创建 FRP 服务实例
48
+ const frpService = createFrpService();
49
+
50
+ // 初始化服务
51
+ await frpService.initialize();
52
+
53
+ // 启动 FRP 服务(使用默认配置)
54
+ const instanceId = await frpService.start();
55
+
56
+ // 获取 FRP 状态
57
+ const status = await frpService.getStatus(instanceId);
58
+
59
+ // 停止 FRP 服务
60
+ await frpService.stop(instanceId);
61
+ ```
62
+
63
+ ### 自定义配置
64
+
65
+ ```typescript
66
+ import { createFrpService, FrpConfig, FrpConfigType } from 'ha-frp-rn';
67
+
68
+ const frpService = createFrpService();
69
+
70
+ // 创建自定义配置
71
+ const customConfig: FrpConfig = {
72
+ name: 'custom-config',
73
+ type: FrpConfigType.VISITOR,
74
+ enabled: true,
75
+ visitorConfig: {
76
+ name: 'custom-visitor',
77
+ type: FrpConfigType.VISITOR,
78
+ enabled: true,
79
+ serverAddr: 'your-frps-server.com',
80
+ serverPort: 7000,
81
+ token: 'your-token',
82
+ proxies: [
83
+ // 代理配置
84
+ ]
85
+ }
86
+ };
87
+
88
+ // 使用自定义配置启动
89
+ await frpService.start(customConfig);
90
+ ```
91
+
92
+ ### 强制使用远程配置
93
+
94
+ ```typescript
95
+ // 强制从远程API获取配置
96
+ const instanceId = await frpService.start(undefined, true);
97
+ ```
98
+
99
+ ## 打包命令
100
+
101
+ ### 构建模块
102
+
103
+ ```bash
104
+ npm run build
105
+ ```
106
+
107
+ ### 开发模式(监听文件变化)
108
+
109
+ ```bash
110
+ npm run build:dev
111
+ ```
112
+
113
+ ### 类型检查
114
+
115
+ ```bash
116
+ npm run typecheck
117
+ ```
118
+
119
+ ### 代码检查
120
+
121
+ ```bash
122
+ npm run lint
123
+ ```
124
+
125
+ ### 生成打包文件
126
+
127
+ ```bash
128
+ npm pack
129
+ ```
130
+
131
+ ## API 文档
132
+
133
+ ### 核心类
134
+
135
+ #### ReactNativeFrpService
136
+
137
+ 实现了 IFrpService 接口,提供了完整的 FRP 功能:
138
+
139
+ - `initialize()`: 初始化 FRP 服务
140
+ - `start(config?: FrpConfig | string, forceRemoteConfig?: boolean)`: 启动 FRP 服务
141
+ - `stop(instanceId?: string)`: 停止 FRP 服务
142
+ - `restart(instanceId: string, forceRemoteConfig?: boolean)`: 重启 FRP 服务
143
+ - `getStatus(instanceId?: string)`: 获取 FRP 状态
144
+ - `getStats(instanceId: string)`: 获取 FRP 统计信息
145
+ - `loadConfig(config: string | FrpConfig)`: 加载 FRP 配置
146
+ - `saveConfig(config: FrpConfig, filePath: string)`: 保存 FRP 配置
147
+ - `validateConfig(config: FrpConfig)`: 验证 FRP 配置
148
+ - `getLogs(instanceId: string, limit?: number, offset?: number)`: 获取 FRP 日志
149
+ - `onLog(instanceId: string, callback: (log: FrpLogEntry) => void)`: 监听 FRP 日志
150
+ - `onStatusChange(callback: (instanceId: string, status: FrpStatus) => void)`: 监听 FRP 状态变化
151
+ - `onError(callback: (instanceId: string, error: Error) => void)`: 监听 FRP 错误
152
+ - `getVersion()`: 获取 FRP 版本
153
+ - `cleanup()`: 清理 FRP 服务资源
154
+
155
+ #### FrpConfigManager
156
+
157
+ 用于管理 FRP 配置,支持从远程 API 获取和本地默认配置:
158
+
159
+ - `getConfig(forceRemote: boolean = false)`: 获取 FRP 配置
160
+ - `clearCache()`: 清除配置缓存
161
+ - `getLastUpdated()`: 获取配置最后更新时间
162
+
163
+ ## 配置管理
164
+
165
+ ### 配置优先级
166
+
167
+ 1. **远程配置**:通过 API 请求获取的配置(优先级最高)
168
+ 2. **本地默认配置**:打包在 assets 目录中的 `frpc-visitor-default.toml` 文件
169
+
170
+ ### 默认配置
171
+
172
+ 默认配置文件位于 `assets/frpc-visitor-default.toml`,包含了基本的 FRP 访问者配置。
173
+
174
+ ## 平台支持
175
+
176
+ | 平台 | 状态 |
177
+ |------|------|
178
+ | Android | ✅ 支持 |
179
+ | iOS | ⏳ 开发中 |
180
+
181
+ ## 开发指南
182
+
183
+ ### 目录结构
184
+
185
+ ```
186
+ ha-frp-rn/
187
+ ├── assets/ # 资源文件目录
188
+ │ └── frpc-visitor-default.toml # 默认 FRP 配置
189
+ ├── src/ # 源代码目录
190
+ │ ├── index.ts # 入口文件
191
+ │ └── android/ # Android 原生代码
192
+ ├── .gitignore # Git 忽略文件
193
+ ├── package.json # 项目配置
194
+ ├── tsconfig.json # TypeScript 配置
195
+ ├── tsconfig.build.json # 构建用 TypeScript 配置
196
+ └── README.md # 项目说明文档
197
+ ```
198
+
199
+ ### 开发流程
200
+
201
+ 1. 克隆仓库
202
+ 2. 安装依赖:`npm install`
203
+ 3. 运行类型检查:`npm run typecheck`
204
+ 4. 构建模块:`npm run build`
205
+ 5. 在 React Native 项目中测试使用
206
+
207
+ ## 许可证
208
+
209
+ MIT License
210
+
211
+ ## 贡献
212
+
213
+ 欢迎提交 Issue 和 Pull Request!
214
+
215
+ ## 联系我们
216
+
217
+ 如有问题或建议,请通过 GitHub Issues 反馈。
@@ -0,0 +1,141 @@
1
+ # ===============================================
2
+ # frpc visitor config for native clients (Android / Windows)
3
+ #
4
+ # ✏️ BEFORE USE:
5
+ # 1. Replace all 'change_me_*' with real secretKey values
6
+ # 2. Update FRP_SERVER_ADDR and auth.token if needed
7
+ # 3. Save as 'frpc-visitor.toml' and load into your client
8
+ #
9
+ # This file is auto-generated from:
10
+ # - .env (优先)
11
+ # - .env.example
12
+ # - visitors/builtin/*.toml
13
+ # To update, run: ./scripts/render-full-config.py
14
+ # ===============================================
15
+
16
+ serverAddr = "103.236.89.242"
17
+ serverPort = 7000
18
+ auth.token = "2ab9901b45476e8dabaa12c8b556dd5b"
19
+
20
+ [[visitors]]
21
+ name = "aiws-stcp"
22
+ type = "stcp"
23
+ serverName = "gx10-a880-aiws-stcp"
24
+ secretKey = "your_strong_secret_here_32_chars"
25
+ bindPort = -1
26
+
27
+
28
+ [[visitors]]
29
+ name = "aiws-xtcp"
30
+ type = "xtcp"
31
+ serverName = "gx10-a880-aiws-xtcp"
32
+ secretKey = "your_strong_secret_here_32_chars"
33
+ bindAddr = "127.0.0.1"
34
+ bindPort = 10006
35
+ fallbackTo = "aiws-stcp"
36
+ fallbackTimeoutMs = 200
37
+
38
+
39
+ [[visitors]]
40
+ name = "dialog-agent2-10197"
41
+ type = "xtcp"
42
+ serverName = "gx10-a880-dialog-agent2-10197-xtcp"
43
+ secretKey = "your_strong_secret_here_32_chars"
44
+ bindAddr = "127.0.0.1"
45
+ bindPort = 10197
46
+ fallbackTo = "dialog-agent2-10197-stcp"
47
+ fallbackTimeoutMs = 300
48
+
49
+ [[visitors]]
50
+ name = "dialog-agent2-10197-stcp"
51
+ type = "stcp"
52
+ serverName = "gx10-a880-dialog-agent2-10197-stcp"
53
+ secretKey = "your_strong_secret_here_32_chars"
54
+ bindPort = -1
55
+
56
+
57
+ [[visitors]]
58
+ name = "frigate-stcp"
59
+ type = "stcp"
60
+ serverName = "gx10-a880-frigate-stcp"
61
+ secretKey = "your_strong_secret_here_32_chars"
62
+ bindPort = -1
63
+
64
+
65
+ [[visitors]]
66
+ name = "frigate-xtcp"
67
+ type = "xtcp"
68
+ serverName = "gx10-a880-frigate-xtcp"
69
+ secretKey = "your_strong_secret_here_32_chars"
70
+ bindAddr = "127.0.0.1"
71
+ bindPort = 5000
72
+ fallbackTo = "frigate-stcp"
73
+ fallbackTimeoutMs = 500
74
+
75
+
76
+ [[visitors]]
77
+ name = "ha-stcp"
78
+ type = "stcp"
79
+ serverName = "gx10-a880-ha-stcp"
80
+ secretKey = "your_strong_secret_here_32_chars"
81
+ bindPort = -1
82
+
83
+
84
+ [[visitors]]
85
+ name = "ha-xtcp"
86
+ type = "xtcp"
87
+ serverName = "gx10-a880-ha-xtcp"
88
+ secretKey = "your_strong_secret_here_32_chars"
89
+ bindAddr = "127.0.0.1"
90
+ bindPort = 8123
91
+ fallbackTo = "ha-stcp"
92
+ fallbackTimeoutMs = 500
93
+
94
+
95
+ # xtcp visitor for TCP port 7880
96
+ [[visitors]]
97
+ name = "livekit-7880-xtcp"
98
+ type = "xtcp"
99
+ serverName = "gx10-a880-livekit-7880-xtcp"
100
+ secretKey = "your_strong_secret_here_32_chars"
101
+ bindAddr = "127.0.0.1"
102
+ bindPort = 7880
103
+ fallbackTo = "livekit-7880-stcp"
104
+ fallbackTimeoutMs = 300
105
+
106
+ # stcp visitor for TCP port 7880
107
+ [[visitors]]
108
+ name = "livekit-7880-stcp"
109
+ type = "stcp"
110
+ serverName = "gx10-a880-livekit-7880-stcp"
111
+ secretKey = "your_strong_secret_here_32_chars"
112
+ bindPort = -1
113
+
114
+ # sudp visitor for UDP port 7883
115
+ [[visitors]]
116
+ name = "livekit-7883-sudp"
117
+ type = "sudp"
118
+ serverName = "gx10-a880-livekit-7883-sudp"
119
+ secretKey = "your_strong_secret_here_32_chars"
120
+ bindAddr = "127.0.0.1"
121
+ bindPort = 7883
122
+
123
+
124
+ [[visitors]]
125
+ name = "ssh-stcp"
126
+ type = "stcp"
127
+ serverName = "gx10-a880-ssh-stcp"
128
+ secretKey = "your_strong_secret_here_32_chars"
129
+ bindPort = -1
130
+
131
+
132
+ [[visitors]]
133
+ name = "ssh-xtcp"
134
+ type = "xtcp"
135
+ serverName = "gx10-a880-ssh-xtcp"
136
+ secretKey = "your_strong_secret_here_32_chars"
137
+ bindAddr = "127.0.0.1"
138
+ bindPort = 2222
139
+ fallbackTo = "ssh-stcp"
140
+ fallbackTimeoutMs = 500
141
+
@@ -0,0 +1,91 @@
1
+ /**
2
+ * @Author: LinZhuMing
3
+ * @Date: 2025-12-19
4
+ * @LastEditors: LinZhuMing
5
+ * @LastEditTime: 2025-12-19
6
+ * @FilePath: \ha-frp-rn\src\index.ts
7
+ * @Description: React Native FRP模块入口文件
8
+ */
9
+ import { IFrpService, FrpConfig, FrpStatus, FrpStats, FrpLogEntry } from 'ha-shared-core';
10
+ /**
11
+ * FRP配置管理器
12
+ *
13
+ * 用途:管理FRP配置,支持从远程API获取和本地默认配置
14
+ */
15
+ export declare class FrpConfigManager {
16
+ private defaultConfigPath;
17
+ private remoteConfigCache;
18
+ private configLastUpdated;
19
+ /**
20
+ * 获取FRP配置
21
+ *
22
+ * @param forceRemote - 是否强制从远程获取配置
23
+ * @returns Promise<FrpConfig> - FRP配置对象
24
+ */
25
+ getConfig(forceRemote?: boolean): Promise<FrpConfig>;
26
+ /**
27
+ * 从远程API获取配置
28
+ *
29
+ * @returns Promise<FrpConfig> - 远程FRP配置
30
+ */
31
+ private fetchConfigFromApi;
32
+ /**
33
+ * 加载本地默认配置
34
+ *
35
+ * @returns FrpConfig - 本地默认配置
36
+ */
37
+ private loadDefaultConfig;
38
+ /**
39
+ * 清除配置缓存
40
+ */
41
+ clearCache(): void;
42
+ /**
43
+ * 获取配置最后更新时间
44
+ *
45
+ * @returns Date | null - 配置最后更新时间
46
+ */
47
+ getLastUpdated(): Date | null;
48
+ }
49
+ /**
50
+ * React Native FRP服务实现类
51
+ *
52
+ * 用途:提供React Native环境下的FRP功能实现
53
+ * 支持:Android平台,未来将支持iOS平台
54
+ */
55
+ export declare class ReactNativeFrpService implements IFrpService {
56
+ private frpService;
57
+ private eventEmitter;
58
+ private configManager;
59
+ constructor();
60
+ private initAndroidModule;
61
+ initialize(): Promise<void>;
62
+ start(config?: FrpConfig | string, forceRemoteConfig?: boolean): Promise<string>;
63
+ stop(instanceId?: string): Promise<void>;
64
+ restart(instanceId: string, forceRemoteConfig?: boolean): Promise<void>;
65
+ getStatus(instanceId?: string): Promise<FrpStatus | Record<string, FrpStatus>>;
66
+ getStats(instanceId: string): Promise<FrpStats>;
67
+ loadConfig(config: string | FrpConfig): Promise<FrpConfig>;
68
+ saveConfig(config: FrpConfig, filePath: string): Promise<void>;
69
+ validateConfig(config: FrpConfig): Promise<boolean>;
70
+ getLogs(instanceId: string, limit?: number, offset?: number): Promise<FrpLogEntry[]>;
71
+ onLog(instanceId: string, callback: (log: FrpLogEntry) => void): void;
72
+ onStatusChange(callback: (instanceId: string, status: FrpStatus) => void): void;
73
+ onError(callback: (instanceId: string, error: Error) => void): void;
74
+ getVersion(): Promise<string>;
75
+ cleanup(): Promise<void>;
76
+ /**
77
+ * 获取配置管理器实例
78
+ *
79
+ * @returns FrpConfigManager - 配置管理器实例
80
+ */
81
+ getConfigManager(): FrpConfigManager;
82
+ }
83
+ /**
84
+ * FRP服务工厂函数
85
+ *
86
+ * 用途:创建并返回FRP服务实例
87
+ * @returns {ReactNativeFrpService} FRP服务实例
88
+ */
89
+ export declare function createFrpService(): ReactNativeFrpService;
90
+ export { FrpConfigType, FrpStatus, FrpLogLevel, type IFrpService, type FrpConfig, type FrpStats, type FrpLogEntry } from 'ha-shared-core';
91
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,EAA8B,QAAQ,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAEtH;;;;GAIG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,iBAAiB,CAAsC;IAC/D,OAAO,CAAC,iBAAiB,CAA0B;IACnD,OAAO,CAAC,iBAAiB,CAAqB;IAE9C;;;;;OAKG;IACG,SAAS,CAAC,WAAW,GAAE,OAAe,GAAG,OAAO,CAAC,SAAS,CAAC;IAmBjE;;;;OAIG;YACW,kBAAkB;IAMhC;;;;OAIG;IACH,OAAO,CAAC,iBAAiB;IAmBzB;;OAEG;IACH,UAAU,IAAI,IAAI;IAKlB;;;;OAIG;IACH,cAAc,IAAI,IAAI,GAAG,IAAI;CAG9B;AAED;;;;;GAKG;AACH,qBAAa,qBAAsB,YAAW,WAAW;IACvD,OAAO,CAAC,UAAU,CAAM;IACxB,OAAO,CAAC,YAAY,CAAM;IAC1B,OAAO,CAAC,aAAa,CAAmB;;IAaxC,OAAO,CAAC,iBAAiB;IAKnB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAK3B,KAAK,CAAC,MAAM,CAAC,EAAE,SAAS,GAAG,MAAM,EAAE,iBAAiB,GAAE,OAAe,GAAG,OAAO,CAAC,MAAM,CAAC;IAkBvF,IAAI,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKxC,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,iBAAiB,GAAE,OAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAO9E,SAAS,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,C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025-12-19
4
+ * @LastEditors: LinZhuMing
5
+ * @LastEditTime: 2025-12-19
6
+ * @FilePath: \ha-frp-rn\src\index.ts
7
+ * @Description: React Native FRP模块入口文件
8
+ */
9
+ import { Platform } from 'react-native';
10
+ import { FrpStatus, FrpConfigType } from 'ha-shared-core';
11
+ /**
12
+ * FRP配置管理器
13
+ *
14
+ * 用途:管理FRP配置,支持从远程API获取和本地默认配置
15
+ */
16
+ export class FrpConfigManager {
17
+ constructor() {
18
+ this.defaultConfigPath = 'assets/frpc-visitor-default.toml';
19
+ this.remoteConfigCache = null;
20
+ this.configLastUpdated = null;
21
+ }
22
+ /**
23
+ * 获取FRP配置
24
+ *
25
+ * @param forceRemote - 是否强制从远程获取配置
26
+ * @returns Promise<FrpConfig> - FRP配置对象
27
+ */
28
+ async getConfig(forceRemote = false) {
29
+ // 如果有缓存且不强制远程获取,则返回缓存
30
+ if (this.remoteConfigCache && !forceRemote) {
31
+ return this.remoteConfigCache;
32
+ }
33
+ try {
34
+ // 尝试从远程API获取配置
35
+ const remoteConfig = await this.fetchConfigFromApi();
36
+ this.remoteConfigCache = remoteConfig;
37
+ this.configLastUpdated = new Date();
38
+ return remoteConfig;
39
+ }
40
+ catch (error) {
41
+ console.warn('Failed to fetch config from API, using default config:', error);
42
+ // 如果远程获取失败,则使用本地默认配置
43
+ return this.loadDefaultConfig();
44
+ }
45
+ }
46
+ /**
47
+ * 从远程API获取配置
48
+ *
49
+ * @returns Promise<FrpConfig> - 远程FRP配置
50
+ */
51
+ async fetchConfigFromApi() {
52
+ // 这里将在后续实现中添加从远程API获取配置的逻辑
53
+ // 目前模拟API调用失败,使用默认配置
54
+ throw new Error('Remote config API not implemented yet');
55
+ }
56
+ /**
57
+ * 加载本地默认配置
58
+ *
59
+ * @returns FrpConfig - 本地默认配置
60
+ */
61
+ loadDefaultConfig() {
62
+ // 这里将在后续实现中添加从本地文件加载配置的逻辑
63
+ // 目前返回一个基础的默认配置
64
+ return {
65
+ name: 'default-config',
66
+ type: FrpConfigType.VISITOR,
67
+ enabled: true,
68
+ visitorConfig: {
69
+ name: 'default-visitor-config',
70
+ type: FrpConfigType.VISITOR,
71
+ enabled: true,
72
+ serverAddr: '103.236.89.242',
73
+ serverPort: 7000,
74
+ token: '2ab9901b45476e8dabaa12c8b556dd5b',
75
+ proxies: []
76
+ }
77
+ };
78
+ }
79
+ /**
80
+ * 清除配置缓存
81
+ */
82
+ clearCache() {
83
+ this.remoteConfigCache = null;
84
+ this.configLastUpdated = null;
85
+ }
86
+ /**
87
+ * 获取配置最后更新时间
88
+ *
89
+ * @returns Date | null - 配置最后更新时间
90
+ */
91
+ getLastUpdated() {
92
+ return this.configLastUpdated;
93
+ }
94
+ }
95
+ /**
96
+ * React Native FRP服务实现类
97
+ *
98
+ * 用途:提供React Native环境下的FRP功能实现
99
+ * 支持:Android平台,未来将支持iOS平台
100
+ */
101
+ export class ReactNativeFrpService {
102
+ constructor() {
103
+ this.configManager = new FrpConfigManager();
104
+ if (Platform.OS === 'android') {
105
+ // 初始化Android原生模块
106
+ this.initAndroidModule();
107
+ }
108
+ else {
109
+ throw new Error(`FRP service is not supported on ${Platform.OS} platform yet`);
110
+ }
111
+ }
112
+ initAndroidModule() {
113
+ // 这里将在后续实现中初始化Android原生模块
114
+ console.log('Initializing Android FRP module...');
115
+ }
116
+ async initialize() {
117
+ // 初始化FRP服务
118
+ console.log('Initializing FRP service...');
119
+ }
120
+ async start(config, forceRemoteConfig = false) {
121
+ // 如果没有提供配置,则从配置管理器获取
122
+ let finalConfig;
123
+ if (!config) {
124
+ finalConfig = await this.configManager.getConfig(forceRemoteConfig);
125
+ }
126
+ else if (typeof config === 'string') {
127
+ // 从文件路径加载配置
128
+ finalConfig = await this.loadConfig(config);
129
+ }
130
+ else {
131
+ finalConfig = config;
132
+ }
133
+ // 启动FRP服务
134
+ console.log('Starting FRP service with config:', finalConfig);
135
+ return 'mock-instance-id';
136
+ }
137
+ async stop(instanceId) {
138
+ // 停止FRP服务
139
+ console.log('Stopping FRP service...', instanceId);
140
+ }
141
+ async restart(instanceId, forceRemoteConfig = false) {
142
+ // 重启FRP服务
143
+ console.log('Restarting FRP service...', instanceId);
144
+ await this.stop(instanceId);
145
+ await this.start(undefined, forceRemoteConfig);
146
+ }
147
+ async getStatus(instanceId) {
148
+ // 获取FRP服务状态
149
+ console.log('Getting FRP status...', instanceId);
150
+ return FrpStatus.IDLE;
151
+ }
152
+ async getStats(instanceId) {
153
+ // 获取FRP统计信息
154
+ console.log('Getting FRP stats...', instanceId);
155
+ return {
156
+ startTime: new Date().toISOString(),
157
+ uptime: 0,
158
+ bytesSent: 0,
159
+ bytesReceived: 0,
160
+ connections: 0,
161
+ totalConnections: 0
162
+ };
163
+ }
164
+ async loadConfig(config) {
165
+ // 加载FRP配置
166
+ console.log('Loading FRP config...', config);
167
+ if (typeof config === 'string') {
168
+ // 从文件加载配置(需要实现)
169
+ throw new Error('Loading config from file is not implemented yet');
170
+ }
171
+ return config;
172
+ }
173
+ async saveConfig(config, filePath) {
174
+ // 保存FRP配置
175
+ console.log('Saving FRP config...', config, filePath);
176
+ }
177
+ async validateConfig(config) {
178
+ // 验证FRP配置
179
+ console.log('Validating FRP config...', config);
180
+ return true;
181
+ }
182
+ async getLogs(instanceId, limit, offset) {
183
+ // 获取FRP日志
184
+ console.log('Getting FRP logs...', instanceId, limit, offset);
185
+ return [];
186
+ }
187
+ onLog(instanceId, callback) {
188
+ // 监听FRP日志
189
+ console.log('Setting up log listener...', instanceId);
190
+ }
191
+ onStatusChange(callback) {
192
+ // 监听FRP状态变化
193
+ console.log('Setting up status change listener...');
194
+ }
195
+ onError(callback) {
196
+ // 监听FRP错误
197
+ console.log('Setting up error listener...');
198
+ }
199
+ async getVersion() {
200
+ // 获取FRP版本信息
201
+ console.log('Getting FRP version...');
202
+ return '1.0.0';
203
+ }
204
+ async cleanup() {
205
+ // 清理FRP服务资源
206
+ console.log('Cleaning up FRP service...');
207
+ }
208
+ /**
209
+ * 获取配置管理器实例
210
+ *
211
+ * @returns FrpConfigManager - 配置管理器实例
212
+ */
213
+ getConfigManager() {
214
+ return this.configManager;
215
+ }
216
+ }
217
+ /**
218
+ * FRP服务工厂函数
219
+ *
220
+ * 用途:创建并返回FRP服务实例
221
+ * @returns {ReactNativeFrpService} FRP服务实例
222
+ */
223
+ export function createFrpService() {
224
+ return new ReactNativeFrpService();
225
+ }
226
+ // 导出FRP相关类型和枚举
227
+ export { FrpConfigType, FrpStatus, FrpLogLevel } from 'ha-shared-core';
228
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAA0B,SAAS,EAAE,aAAa,EAAsC,MAAM,gBAAgB,CAAC;AAEtH;;;;GAIG;AACH,MAAM,OAAO,gBAAgB;IAA7B;QACU,sBAAiB,GAAG,kCAAkC,CAAC;QACvD,sBAAiB,GAAqB,IAAI,CAAC;QAC3C,sBAAiB,GAAgB,IAAI,CAAC;IA8EhD,CAAC;IA5EC;;;;;OAKG;IACH,KAAK,CAAC,SAAS,CAAC,cAAuB,KAAK;QAC1C,sBAAsB;QACtB,IAAI,IAAI,CAAC,iBAAiB,IAAI,CAAC,WAAW,EAAE,CAAC;YAC3C,OAAO,IAAI,CAAC,iBAAiB,CAAC;QAChC,CAAC;QAED,IAAI,CAAC;YACH,eAAe;YACf,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,kBAAkB,EAAE,CAAC;YACrD,IAAI,CAAC,iBAAiB,GAAG,YAAY,CAAC;YACtC,IAAI,CAAC,iBAAiB,GAAG,IAAI,IAAI,EAAE,CAAC;YACpC,OAAO,YAAY,CAAC;QACtB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,IAAI,CAAC,wDAAwD,EAAE,KAAK,CAAC,CAAC;YAC9E,q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AsC,CAAC,CAAC;IACtD,CAAC;IAED,OAAO,CAAC,QAAoD;QAC1D,UAAU;QACV,OAAO,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAC;IAC9C,CAAC;IAED,KAAK,CAAC,UAAU;QACd,YAAY;QACZ,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;QACtC,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,KAAK,CAAC,OAAO;QACX,YAAY;QACZ,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;IAC5C,CAAC;IAED;;;;OAIG;IACH,gBAAgB;QACd,OAAO,IAAI,CAAC,aAAa,CAAC;IAC5B,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB;IAC9B,OAAO,IAAI,qBAAqB,EAAE,CAAC;AACrC,CAAC;AAED,eAAe;AACf,OAAO,EACL,aAAa,EACb,SAAS,EACT,WAAW,EAKZ,MAAM,gBAAgB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "ha-frp-rn",
3
+ "version": "1.0.0",
4
+ "description": "React Native FRP module for network penetration",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "source": "src/index.ts",
9
+ "files": [
10
+ "dist/**/*",
11
+ "jniLibs/**/*",
12
+ "assets/**/*",
13
+ "README.md",
14
+ "package.json"
15
+ ],
16
+ "keywords": [
17
+ "frp",
18
+ "react-native",
19
+ "network-penetration",
20
+ "reverse-proxy",
21
+ "smart-home"
22
+ ],
23
+ "author": "LinZhuMing",
24
+ "license": "MIT",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/yehuo2003/ha-frp-rn.git"
28
+ },
29
+ "homepage": "https://github.com/yehuo2003/ha-frp-rn#readme",
30
+ "bugs": {
31
+ "url": "https://github.com/yehuo2003/ha-frp-rn/issues"
32
+ },
33
+ "engines": {
34
+ "node": ">=16.0.0"
35
+ },
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
39
+ "scripts": {
40
+ "build": "rimraf dist && node build.js",
41
+ "build:dev": "tsc --project tsconfig.build.json --watch --skipLibCheck --noErrorTruncation --noEmitOnError false",
42
+ "test": "jest",
43
+ "lint": "eslint src/**/*.ts src/**/*.tsx",
44
+ "typecheck": "tsc --noEmit --skipLibCheck",
45
+ "prepublishOnly": "npm run build"
46
+ },
47
+ "dependencies": {
48
+ "events": "^3.3.0",
49
+ "ha-shared-core": "file:../ha-shared-core"
50
+ },
51
+ "devDependencies": {
52
+ "@types/jest": "^29.5.0",
53
+ "@types/react-native": "^0.72.0",
54
+ "@typescript-eslint/eslint-plugin": "^6.0.0",
55
+ "@typescript-eslint/parser": "^6.0.0",
56
+ "@yehuo2003/ha-frp-rn": "^1.0.0",
57
+ "eslint": "^8.45.0",
58
+ "jest": "^29.5.0",
59
+ "react-native": "^0.72.0",
60
+ "rimraf": "^5.0.0",
61
+ "ts-jest": "^29.1.0",
62
+ "typescript": "^5.0.4"
63
+ },
64
+ "peerDependencies": {
65
+ "react": "^18.0.0",
66
+ "react-native": "^0.72.0"
67
+ }
68
+ }