@saiboniuma/realtime-core 0.1.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,68 @@
1
+ # @saiboniuma/realtime-core
2
+
3
+ > 实时通讯核心库 — 基于 SignalR 的聊天消息、认证、会话管理 SDK。
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ npm install @saiboniuma/realtime-core
9
+ ```
10
+
11
+ ## 快速使用
12
+
13
+ ```typescript
14
+ import { RealtimeClient } from '@saiboniuma/realtime-core';
15
+
16
+ const client = new RealtimeClient({
17
+ baseURL: 'https://api.example.com',
18
+ wsAddr: 'https://api.example.com/hubs/chat',
19
+ logLevel: 2, // 0=trace 1=debug 2=info 3=warn 4=error
20
+ });
21
+
22
+ // 登录(建立 SignalR 连接)
23
+ await client.login(userId, token);
24
+
25
+ // 发送消息
26
+ const msg = await client.message.sendText(recvId, 'hello');
27
+
28
+ // 监听新消息
29
+ client.events.on('message:received', (msg) => {
30
+ console.log('收到消息:', msg);
31
+ });
32
+ ```
33
+
34
+ ## 模块结构
35
+
36
+ | 模块 | 说明 |
37
+ |------|------|
38
+ | `RealtimeClient` | 核心客户端,管理 SignalR HubConnection |
39
+ | `AuthService` | 认证服务(登录、token 续期) |
40
+ | `MessageService` | 消息收发(文本、图片等) |
41
+ | `ConversationService` | 会话管理 |
42
+ | `SessionManager` | 会话状态管理 |
43
+ | `TokenRefresher` | Token 自动续期 |
44
+ | `UploadService` | 文件上传 |
45
+ | `EventManager` | 事件管理器 |
46
+
47
+ ## 构建
48
+
49
+ ```bash
50
+ npm install
51
+ npm run build # 输出到 dist/
52
+ npm run type-check # 类型检查
53
+ ```
54
+
55
+ ## 依赖
56
+
57
+ - `@microsoft/signalr` ^8.0.7
58
+ - TypeScript ~5.6.3
59
+ - Vite ^6.2.0
60
+
61
+ ## 发布
62
+
63
+ ```bash
64
+ pnpm build
65
+ pnpm publish --access public # 发布到 npmjs.com
66
+ ```
67
+
68
+ Registry: `https://registry.npmjs.org/`