collabdocchat 2.0.7 → 2.0.9

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.
@@ -1,55 +1,54 @@
1
- const API_URL = 'http://localhost:3000/api';
2
-
3
- export class AuthService {
4
- async login(username, password) {
5
- const response = await fetch(`${API_URL}/auth/login`, {
6
- method: 'POST',
7
- headers: { 'Content-Type': 'application/json' },
8
- body: JSON.stringify({ username, password })
9
- });
10
-
11
- if (!response.ok) {
12
- const error = await response.json();
13
- throw new Error(error.message);
14
- }
15
-
16
- return await response.json();
17
- }
18
-
19
- async register(username, password) {
20
- const response = await fetch(`${API_URL}/auth/register`, {
21
- method: 'POST',
22
- headers: { 'Content-Type': 'application/json' },
23
- body: JSON.stringify({ username, password })
24
- });
25
-
26
- if (!response.ok) {
27
- const error = await response.json();
28
- throw new Error(error.message);
29
- }
30
-
31
- return await response.json();
32
- }
33
-
34
- async getCurrentUser() {
35
- const token = localStorage.getItem('token');
36
- const response = await fetch(`${API_URL}/auth/me`, {
37
- headers: { 'Authorization': `Bearer ${token}` }
38
- });
39
-
40
- if (!response.ok) {
41
- throw new Error('获取用户信息失败');
42
- }
43
-
44
- const data = await response.json();
45
- return data.user;
46
- }
47
-
48
- logout() {
49
- localStorage.removeItem('token');
50
- window.location.reload();
51
- }
52
- }
53
-
54
-
1
+ const API_URL = 'http://localhost:3000/api';
2
+
3
+ export class AuthService {
4
+ async login(username, password) {
5
+ const response = await fetch(`${API_URL}/auth/login`, {
6
+ method: 'POST',
7
+ headers: { 'Content-Type': 'application/json' },
8
+ body: JSON.stringify({ username, password })
9
+ });
10
+
11
+ if (!response.ok) {
12
+ const error = await response.json();
13
+ throw new Error(error.message);
14
+ }
15
+
16
+ return await response.json();
17
+ }
18
+
19
+ async register(username, password) {
20
+ const response = await fetch(`${API_URL}/auth/register`, {
21
+ method: 'POST',
22
+ headers: { 'Content-Type': 'application/json' },
23
+ body: JSON.stringify({ username, password })
24
+ });
25
+
26
+ if (!response.ok) {
27
+ const error = await response.json();
28
+ throw new Error(error.message);
29
+ }
30
+
31
+ return await response.json();
32
+ }
33
+
34
+ async getCurrentUser() {
35
+ const token = localStorage.getItem('token');
36
+ const response = await fetch(`${API_URL}/auth/me`, {
37
+ headers: { 'Authorization': `Bearer ${token}` }
38
+ });
39
+
40
+ if (!response.ok) {
41
+ throw new Error('获取用户信息失败');
42
+ }
43
+
44
+ const data = await response.json();
45
+ return data.user;
46
+ }
47
+
48
+ logout() {
49
+ localStorage.removeItem('token');
50
+ window.location.reload();
51
+ }
52
+ }
53
+
55
54
 
@@ -1,190 +1,80 @@
1
- export class WebSocketService {
2
- constructor() {
3
- this.ws = null;
4
- this.listeners = new Map();
5
- this.token = null;
6
- this.reconnectAttempts = 0;
7
- this.maxReconnectAttempts = 10;
8
- this.reconnectDelay = 1000;
9
- this.heartbeatInterval = null;
10
- this.isConnecting = false;
11
- this.isAuthenticated = false;
12
- }
13
-
14
- connect(token) {
15
- if (this.isConnecting) {
16
- console.log('�?正在连接中,请稍�?..');
17
- return;
18
- }
19
-
20
- this.token = token;
21
- this.isConnecting = true;
22
-
23
- try {
24
- this.ws = new WebSocket('ws://localhost:3000');
25
-
26
- this.ws.onopen = () => {
27
- console.log('�?WebSocket 连接成功');
28
- this.isConnecting = false;
29
- this.reconnectAttempts = 0;
30
- this.reconnectDelay = 1000;
31
- this.send({ type: 'auth', token });
32
- this.startHeartbeat();
33
- };
34
-
35
- this.ws.onmessage = (event) => {
36
- try {
37
- const data = JSON.parse(event.data);
38
-
39
- if (data.type === 'auth_success') {
40
- this.isAuthenticated = true;
41
- console.log('�?WebSocket 认证成功');
42
- } else if (data.type === 'pong') {
43
- // 心跳响应
44
- console.log('💓 心跳正常');
45
- }
46
-
47
- this.notifyListeners(data.type, data);
48
- } catch (error) {
49
- console.error('�?解析消息失败:', error);
50
- }
51
- };
52
-
53
- this.ws.onerror = (error) => {
54
- console.error('�?WebSocket 错误:', error);
55
- this.isConnecting = false;
56
- };
57
-
58
- this.ws.onclose = (event) => {
59
- console.log(`🔌 WebSocket 连接关闭 (代码: ${event.code}, 原因: ${event.reason || '未知'})`);
60
- this.isConnecting = false;
61
- this.isAuthenticated = false;
62
- this.stopHeartbeat();
63
-
64
- // 只有在非正常关闭时才重连
65
- if (event.code !== 1000 && this.reconnectAttempts < this.maxReconnectAttempts) {
66
- this.handleReconnect();
67
- }
68
- };
69
- } catch (error) {
70
- console.error('�?WebSocket 连接失败:', error);
71
- this.isConnecting = false;
72
- this.handleReconnect();
73
- }
74
- }
75
-
76
- handleReconnect() {
77
- if (this.reconnectAttempts >= this.maxReconnectAttempts) {
78
- console.error('�?达到最大重连次数,停止重连');
79
- this.notifyListeners('max_reconnect_reached', {
80
- message: '无法连接到服务器,请刷新页面重试'
81
- });
82
- return;
83
- }
84
-
85
- this.reconnectAttempts++;
86
- const delay = Math.min(this.reconnectDelay * Math.pow(2, this.reconnectAttempts - 1), 30000);
87
-
88
- console.log(`🔄 ${delay / 1000}秒后尝试�?${this.reconnectAttempts} 次重�?..`);
89
-
90
- setTimeout(() => {
91
- if (this.token) {
92
- this.connect(this.token);
93
- }
94
- }, delay);
95
- }
96
-
97
- startHeartbeat() {
98
- this.stopHeartbeat();
99
-
100
- this.heartbeatInterval = setInterval(() => {
101
- if (this.ws && this.ws.readyState === WebSocket.OPEN) {
102
- this.send({ type: 'ping', timestamp: Date.now() });
103
- }
104
- }, 30000); // �?0秒发送一次心�? }
105
-
106
- stopHeartbeat() {
107
- if (this.heartbeatInterval) {
108
- clearInterval(this.heartbeatInterval);
109
- this.heartbeatInterval = null;
110
- }
111
- }
112
-
113
- disconnect() {
114
- this.stopHeartbeat();
115
- this.reconnectAttempts = this.maxReconnectAttempts; // 阻止自动重连
116
-
117
- if (this.ws) {
118
- this.ws.close(1000, '用户主动断开');
119
- this.ws = null;
120
- }
121
-
122
- this.isAuthenticated = false;
123
- console.log('👋 WebSocket 已断开');
124
- }
125
-
126
- send(data) {
127
- if (this.ws && this.ws.readyState === WebSocket.OPEN) {
128
- this.ws.send(JSON.stringify(data));
129
- }
130
- }
131
-
132
- on(event, callback) {
133
- if (!this.listeners.has(event)) {
134
- this.listeners.set(event, []);
135
- }
136
- this.listeners.get(event).push(callback);
137
- }
138
-
139
- off(event, callback) {
140
- if (this.listeners.has(event)) {
141
- const callbacks = this.listeners.get(event);
142
- const index = callbacks.indexOf(callback);
143
- if (index > -1) {
144
- callbacks.splice(index, 1);
145
- }
146
- }
147
- }
148
-
149
- notifyListeners(event, data) {
150
- if (this.listeners.has(event)) {
151
- this.listeners.get(event).forEach(callback => callback(data));
152
- }
153
- }
154
-
155
- joinGroup(groupId) {
156
- this.send({ type: 'join_group', groupId });
157
- }
158
-
159
- sendChatMessage(groupId, username, content) {
160
- this.send({ type: 'chat_message', groupId, username, content });
161
- }
162
-
163
- syncDocument(documentId, content, cursorPosition) {
164
- this.send({ type: 'document_sync', documentId, content, cursorPosition });
165
- }
166
-
167
- respondToCall(groupId, username) {
168
- this.send({ type: 'call_response', groupId, username });
169
- }
170
-
171
- sendTyping(documentId, username, isTyping) {
172
- this.send({ type: 'typing', documentId, username, isTyping });
173
- }
174
-
175
- // 撤回消息
176
- recallMessage(messageId) {
177
- this.send({ type: 'recall_message', messageId });
178
- }
179
-
180
- // 标记消息为已�? markMessageAsRead(messageId) {
181
- this.send({ type: 'message_read', messageId });
182
- }
183
-
184
- // 发送用户在线状�? sendUserOnline(username) {
185
- this.send({ type: 'user_online', username });
186
- }
187
- }
188
-
189
-
1
+ export class WebSocketService {
2
+ constructor() {
3
+ this.ws = null;
4
+ this.listeners = new Map();
5
+ }
6
+
7
+ connect(token) {
8
+ this.ws = new WebSocket('ws://localhost:3000');
9
+
10
+ this.ws.onopen = () => {
11
+ console.log('✅ WebSocket 连接成功');
12
+ this.send({ type: 'auth', token });
13
+ };
14
+
15
+ this.ws.onmessage = (event) => {
16
+ const data = JSON.parse(event.data);
17
+ this.notifyListeners(data.type, data);
18
+ };
19
+
20
+ this.ws.onerror = (error) => {
21
+ console.error('❌ WebSocket 错误:', error);
22
+ };
23
+
24
+ this.ws.onclose = () => {
25
+ console.log('🔌 WebSocket 连接关闭');
26
+ setTimeout(() => this.connect(token), 3000);
27
+ };
28
+ }
29
+
30
+ send(data) {
31
+ if (this.ws && this.ws.readyState === WebSocket.OPEN) {
32
+ this.ws.send(JSON.stringify(data));
33
+ }
34
+ }
35
+
36
+ on(event, callback) {
37
+ if (!this.listeners.has(event)) {
38
+ this.listeners.set(event, []);
39
+ }
40
+ this.listeners.get(event).push(callback);
41
+ }
42
+
43
+ off(event, callback) {
44
+ if (this.listeners.has(event)) {
45
+ const callbacks = this.listeners.get(event);
46
+ const index = callbacks.indexOf(callback);
47
+ if (index > -1) {
48
+ callbacks.splice(index, 1);
49
+ }
50
+ }
51
+ }
52
+
53
+ notifyListeners(event, data) {
54
+ if (this.listeners.has(event)) {
55
+ this.listeners.get(event).forEach(callback => callback(data));
56
+ }
57
+ }
58
+
59
+ joinGroup(groupId) {
60
+ this.send({ type: 'join_group', groupId });
61
+ }
62
+
63
+ sendChatMessage(groupId, username, content) {
64
+ this.send({ type: 'chat_message', groupId, username, content });
65
+ }
66
+
67
+ syncDocument(documentId, content, cursorPosition) {
68
+ this.send({ type: 'document_sync', documentId, content, cursorPosition });
69
+ }
70
+
71
+ respondToCall(groupId, username) {
72
+ this.send({ type: 'call_response', groupId, username });
73
+ }
74
+
75
+ sendTyping(documentId, username, isTyping) {
76
+ this.send({ type: 'typing', documentId, username, isTyping });
77
+ }
78
+ }
79
+
190
80
 
@@ -1,4 +1,4 @@
1
- /**
1
+ /**
2
2
  * 优化后的协作工具样式
3
3
  * 美化白板、投票、代码编辑器等协作工具界�? */
4
4
 
@@ -1,4 +1,4 @@
1
- /**
1
+ /**
2
2
  * AI 助手系统
3
3
  * 提供智能回复、内容摘要、翻译等功能
4
4
  */
@@ -1,4 +1,4 @@
1
- /**
1
+ /**
2
2
  * 聊天增强功能模块
3
3
  * 包含消息撤回、@提及、已读状态等功能
4
4
  */
@@ -1,4 +1,4 @@
1
- /**
1
+ /**
2
2
  * 协作增强功能
3
3
  * 提供更多协作工具和功�? */
4
4
 
@@ -1,4 +1,4 @@
1
- /**
1
+ /**
2
2
  * 功能集成�? * 将所有增强功能集成到仪表板中
3
3
  */
4
4
 
@@ -1,4 +1,4 @@
1
- /**
1
+ /**
2
2
  * 新手引导系统
3
3
  * 提供交互式的新手引导和帮�? */
4
4
 
@@ -1,4 +1,4 @@
1
- /**
1
+ /**
2
2
  * 虚拟滚动实现
3
3
  * 用于优化长列表渲染性能
4
4
  */
@@ -1,4 +1,4 @@
1
- /**
1
+ /**
2
2
  * 权限管理系统
3
3
  * 提供细粒度的权限控制
4
4
  */
@@ -1,4 +1,4 @@
1
- /**
1
+ /**
2
2
  * 响应式处理器
3
3
  * 处理不同设备的交互优�?
4
4
  */
@@ -1,4 +1,4 @@
1
- /**
1
+ /**
2
2
  * 主题管理系统
3
3
  * 支持多种主题切换和自定义主题
4
4
  */
@@ -1,4 +1,4 @@
1
- /**
1
+ /**
2
2
  * UI 美化增强加载�? * 自动加载所有界面美化功�? * 确保所有优化的界面在启动时自动集成
3
3
  */
4
4