bizydraft 0.2.76.dev20251027100756__py3-none-any.whl → 0.2.77__py3-none-any.whl

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.

Potentially problematic release.


This version of bizydraft might be problematic. Click here for more details.

@@ -21,77 +21,47 @@ app.registerExtension({
21
21
  pingTimeoutTimer: null, // ping超时计时器
22
22
 
23
23
  /**
24
- * 为特定socket开始心跳检测(每个socket独立的心跳)
24
+ * 开始心跳检测
25
25
  */
26
- startPingForSocket(socket) {
27
- if (!socket || socket.readyState !== WebSocket.OPEN) {
26
+ startPing() {
27
+ this.stopPing();
28
+
29
+ if (!this.socket || this.socket.readyState !== WebSocket.OPEN) {
28
30
  return;
29
31
  }
30
32
 
31
- // 在socket对象上存储心跳状态
32
- socket.pongReceived = false;
33
33
  // 立即发送一次ping消息
34
- socket.send('ping');
34
+ this.pongReceived = false;
35
+ this.socket.send('ping');
35
36
 
36
37
  // 设置ping超时检测
37
- socket.pingTimeoutTimer = setTimeout(() => {
38
- if (!socket.pongReceived && socket.readyState === WebSocket.OPEN) {
39
- console.log('心跳检测超时,关闭此连接');
40
- this.stopPingForSocket(socket);
41
- socket.close();
38
+ this.pingTimeoutTimer = setTimeout(() => {
39
+ if (!this.pongReceived) {
40
+ this.stopPing();
41
+ this.reconnect();
42
42
  }
43
43
  }, this.pingTimeout);
44
44
 
45
45
  // 设置定时发送ping
46
- socket.pingTimer = setInterval(() => {
47
- if (socket.readyState === WebSocket.OPEN) {
48
- socket.pongReceived = false;
49
- socket.send('ping');
46
+ this.pingTimer = setInterval(() => {
47
+ if (this.socket && this.socket.readyState === WebSocket.OPEN) {
48
+ this.pongReceived = false;
49
+ this.socket.send('ping');
50
50
  // 设置ping超时检测
51
- socket.pingTimeoutTimer = setTimeout(() => {
51
+ this.pingTimeoutTimer = setTimeout(() => {
52
52
  // 如果没有收到pong响应
53
- if (!socket.pongReceived) {
54
- console.log('心跳检测超时,关闭此连接');
55
- this.stopPingForSocket(socket);
56
- socket.close();
53
+ if (!this.pongReceived) {
54
+ console.log('心跳检测超时,重新连接WebSocket');
55
+ this.stopPing();
56
+ this.reconnect();
57
57
  }
58
58
  }, this.pingTimeout);
59
59
  } else {
60
- this.stopPingForSocket(socket);
60
+ this.stopPing();
61
61
  }
62
62
  }, this.pingInterval);
63
63
  },
64
64
 
65
- /**
66
- * 停止特定socket的心跳检测
67
- */
68
- stopPingForSocket(socket) {
69
- if (!socket) return;
70
-
71
- if (socket.pingTimer) {
72
- clearInterval(socket.pingTimer);
73
- socket.pingTimer = null;
74
- }
75
-
76
- if (socket.pingTimeoutTimer) {
77
- clearTimeout(socket.pingTimeoutTimer);
78
- socket.pingTimeoutTimer = null;
79
- }
80
- },
81
-
82
- /**
83
- * 开始心跳检测(保留向后兼容)
84
- */
85
- startPing() {
86
- this.stopPing();
87
-
88
- if (!this.socket || this.socket.readyState !== WebSocket.OPEN) {
89
- return;
90
- }
91
- // 使用新的socket专用心跳方法
92
- this.startPingForSocket(this.socket);
93
- },
94
-
95
65
  /**
96
66
  * 停止心跳检测
97
67
  */
@@ -132,6 +102,8 @@ app.registerExtension({
132
102
  // 标记为连接中
133
103
  this.isConnecting = true;
134
104
 
105
+ // 先关闭现有连接
106
+ this.closeSocket();
135
107
 
136
108
  const url = customUrl || app.api.socket.url;
137
109
  console.log('创建WebSocket连接:', url);
@@ -145,32 +117,20 @@ app.registerExtension({
145
117
  console.log('WebSocket连接已打开');
146
118
  // 清除连接中标志
147
119
  self.isConnecting = false;
148
- // 存储为单例(最新的连接)
120
+ // 存储为单例
149
121
  self.socket = socket;
150
122
  // 替换app.api.socket
151
123
  app.api.socket = socket;
152
- // 为这个socket启动独立的心跳检测
153
- self.startPingForSocket(socket);
124
+ // 开始心跳检测
125
+ self.startPing();
154
126
  };
155
127
 
156
128
  socket.onmessage = function (event) {
157
129
  try {
158
- // 从 WebSocket URL 中提取 taskId
159
- let taskIdFromUrl = null;
160
- try {
161
- const urlParams = new URLSearchParams(socket.url.split('?')[1]);
162
- taskIdFromUrl = urlParams.get('taskId');
163
- if (taskIdFromUrl) {
164
- taskIdFromUrl = parseInt(taskIdFromUrl, 10);
165
- }
166
- console.log('taskIdFromUrl:', taskIdFromUrl);
167
- } catch (e) {
168
- console.warn('无法从 WebSocket URL 中提取 taskId:', e);
169
- }
170
130
  // 处理心跳响应
171
131
  if (event.data === 'pong') {
172
- // 标记此socket收到pong响应
173
- socket.pongReceived = true;
132
+ // 标记收到pong响应
133
+ self.pongReceived = true;
174
134
  return;
175
135
  }
176
136
  if (event.data instanceof ArrayBuffer) {
@@ -242,40 +202,26 @@ app.registerExtension({
242
202
  if (event.data === '[DONE]') {
243
203
  console.log('收到[DONE]消息,任务已完成,停止心跳并关闭连接');
244
204
  self.taskRunning = false;
245
- self.stopPingForSocket(socket);
246
- if (socket.readyState === WebSocket.OPEN) {
247
- socket.close(1000);
248
- }
205
+ self.stopPing();
206
+ self.closeSocket(1000);
249
207
  return;
250
208
  }
251
209
  const msg = JSON.parse(event.data)
252
- // 发送进度信息,添加从 URL 中提取的 taskId
253
- if (msg.progress_info) {
254
- const progressData = { ...msg.progress_info };
255
- if (taskIdFromUrl && !progressData.task_id) {
256
- progressData.task_id = taskIdFromUrl;
257
- }
258
- window.parent.postMessage({
259
- type: 'functionResult',
260
- method: 'progress_info_change',
261
- result: progressData
262
- }, '*');
263
- }
210
+ window.parent.postMessage({
211
+ type: 'functionResult',
212
+ method: 'progress_info_change',
213
+ result: msg.progress_info
214
+ }, '*');
264
215
 
265
216
  switch (msg.type) {
266
217
  case 'load_start':
267
218
  case 'load_end':
268
219
  case 'prompt_id':
269
- // 发送准备状态信息,添加从 URL 中提取的 taskId
270
- const preparingData = { ...msg };
271
- if (taskIdFromUrl) {
272
- preparingData.task_id = taskIdFromUrl;
273
- console.log(`🔗 [WebSocket] 添加 task_id=${taskIdFromUrl} 到 ${msg.type} 消息`);
274
- }
220
+ // 发送准备状态信息
275
221
  window.parent.postMessage({
276
222
  type: 'functionResult',
277
223
  method: 'preparingStatus',
278
- result: preparingData
224
+ result: msg
279
225
  }, '*')
280
226
  break
281
227
  case 'status':
@@ -344,20 +290,20 @@ app.registerExtension({
344
290
  console.log('WebSocket 错误:', error);
345
291
  // 清除连接中标志
346
292
  self.isConnecting = false;
347
- // 停止此socket的心跳检测
348
- self.stopPingForSocket(socket);
293
+ // 停止心跳
294
+ self.stopPing();
349
295
  };
350
296
 
351
297
  socket.onclose = function(event) {
352
298
  console.log('WebSocket 连接已关闭, 状态码:', event.code, event.reason);
353
299
  // 清除连接中标志
354
300
  self.isConnecting = false;
355
- // 停止此socket的心跳检测
356
- self.stopPingForSocket(socket);
357
- // 清理单例引用(如果这是当前活跃的socket)
301
+ // 清理单例引用
358
302
  if (self.socket === socket) {
359
303
  self.socket = null;
360
304
  }
305
+ // 停止心跳
306
+ self.stopPing();
361
307
  };
362
308
 
363
309
  socket.registeredTypes = new Set();
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bizydraft
3
- Version: 0.2.76.dev20251027100756
3
+ Version: 0.2.77
4
4
  Summary: bizydraft
5
5
  Requires-Dist: loguru
6
6
  Requires-Dist: aiohttp
@@ -20,14 +20,14 @@ bizydraft/static/js/hookLoadModel.js,sha256=TWVmfKp45ta-nE6U5rY3Bv9wiaEBp0QMNt2x
20
20
  bizydraft/static/js/main.js,sha256=PRe4LdsquEQWrZDnVd4ubpVQuD1eDIedAXFFazKdoKQ,188
21
21
  bizydraft/static/js/nodeFocusHandler.js,sha256=24xXbS4Q-GjJdRqf11i-1pBo8MkOJ24F7MHFV44EG6Q,4683
22
22
  bizydraft/static/js/nodeParamsFilter.js,sha256=H7lBB0G8HNqoGhOCH1hNXqPU-rPlrFyTxg_f_JgLEMk,4168
23
- bizydraft/static/js/postEvent.js,sha256=o9yA3d3fuIHG7KBXI8GbZA4iGGWaPsw6Ec6N1xB4QsA,42427
23
+ bizydraft/static/js/postEvent.js,sha256=dnstkIU_898KvVka1wP8d1TJDLlAphDYghgpQpkTmLM,39864
24
24
  bizydraft/static/js/socket.js,sha256=VE3fTAgEfM0FZhL526Skt7OCRokOa3mzTCAjAomI_tE,2432
25
25
  bizydraft/static/js/tool.js,sha256=VupamUuh7tYiDnBTrL5Z_yLmhJinskhzRXwE3zfsKZM,2901
26
26
  bizydraft/static/js/uploadFile.js,sha256=WvglKzHMeOzDhOH3P-fLcPHxCLbKOJpo4DntoRxeJtI,4908
27
27
  bizydraft/static/js/workflow_io.js,sha256=FWAjncvWhvy-3nN_legD2fpRwgnIncpRLHU5X016a-U,5236
28
28
  bizydraft/static/js/hookLoad/media.js,sha256=5I34YUKBzxOhNQqdIvQrzaNhJcSpEUadAeDC8HsJ2Z4,2614
29
29
  bizydraft/static/js/hookLoad/model.js,sha256=JNFwnkiEQi_g1JauhjvA6V1XfXr3D5CuRodI4p_B0Ts,10570
30
- bizydraft-0.2.76.dev20251027100756.dist-info/METADATA,sha256=ddd2ywM1bCzBQuPyRQ8tA_QU-QOieBQYILLSQO6ZGeo,180
31
- bizydraft-0.2.76.dev20251027100756.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
32
- bizydraft-0.2.76.dev20251027100756.dist-info/top_level.txt,sha256=XtoBq6hjZhXIM7aas4GtPDtAiKo8FdLzMABXW8qqQ8M,10
33
- bizydraft-0.2.76.dev20251027100756.dist-info/RECORD,,
30
+ bizydraft-0.2.77.dist-info/METADATA,sha256=cSYdudyvrhRy3YH90u_Sk2LM8VCUHvSvrjTO2jAcBUA,162
31
+ bizydraft-0.2.77.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
32
+ bizydraft-0.2.77.dist-info/top_level.txt,sha256=XtoBq6hjZhXIM7aas4GtPDtAiKo8FdLzMABXW8qqQ8M,10
33
+ bizydraft-0.2.77.dist-info/RECORD,,