bizydraft 0.2.76__py3-none-any.whl → 0.2.76.dev20251024093830__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,47 +21,77 @@ app.registerExtension({
21
21
  pingTimeoutTimer: null, // ping超时计时器
22
22
 
23
23
  /**
24
- * 开始心跳检测
24
+ * 为特定socket开始心跳检测(每个socket独立的心跳)
25
25
  */
26
- startPing() {
27
- this.stopPing();
28
-
29
- if (!this.socket || this.socket.readyState !== WebSocket.OPEN) {
26
+ startPingForSocket(socket) {
27
+ if (!socket || socket.readyState !== WebSocket.OPEN) {
30
28
  return;
31
29
  }
32
30
 
31
+ // 在socket对象上存储心跳状态
32
+ socket.pongReceived = false;
33
33
  // 立即发送一次ping消息
34
- this.pongReceived = false;
35
- this.socket.send('ping');
34
+ socket.send('ping');
36
35
 
37
36
  // 设置ping超时检测
38
- this.pingTimeoutTimer = setTimeout(() => {
39
- if (!this.pongReceived) {
40
- this.stopPing();
41
- this.reconnect();
37
+ socket.pingTimeoutTimer = setTimeout(() => {
38
+ if (!socket.pongReceived && socket.readyState === WebSocket.OPEN) {
39
+ console.log('心跳检测超时,关闭此连接');
40
+ this.stopPingForSocket(socket);
41
+ socket.close();
42
42
  }
43
43
  }, this.pingTimeout);
44
44
 
45
45
  // 设置定时发送ping
46
- this.pingTimer = setInterval(() => {
47
- if (this.socket && this.socket.readyState === WebSocket.OPEN) {
48
- this.pongReceived = false;
49
- this.socket.send('ping');
46
+ socket.pingTimer = setInterval(() => {
47
+ if (socket.readyState === WebSocket.OPEN) {
48
+ socket.pongReceived = false;
49
+ socket.send('ping');
50
50
  // 设置ping超时检测
51
- this.pingTimeoutTimer = setTimeout(() => {
51
+ socket.pingTimeoutTimer = setTimeout(() => {
52
52
  // 如果没有收到pong响应
53
- if (!this.pongReceived) {
54
- console.log('心跳检测超时,重新连接WebSocket');
55
- this.stopPing();
56
- this.reconnect();
53
+ if (!socket.pongReceived) {
54
+ console.log('心跳检测超时,关闭此连接');
55
+ this.stopPingForSocket(socket);
56
+ socket.close();
57
57
  }
58
58
  }, this.pingTimeout);
59
59
  } else {
60
- this.stopPing();
60
+ this.stopPingForSocket(socket);
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
+
65
95
  /**
66
96
  * 停止心跳检测
67
97
  */
@@ -102,8 +132,6 @@ app.registerExtension({
102
132
  // 标记为连接中
103
133
  this.isConnecting = true;
104
134
 
105
- // 先关闭现有连接
106
- this.closeSocket();
107
135
 
108
136
  const url = customUrl || app.api.socket.url;
109
137
  console.log('创建WebSocket连接:', url);
@@ -117,20 +145,32 @@ app.registerExtension({
117
145
  console.log('WebSocket连接已打开');
118
146
  // 清除连接中标志
119
147
  self.isConnecting = false;
120
- // 存储为单例
148
+ // 存储为单例(最新的连接)
121
149
  self.socket = socket;
122
150
  // 替换app.api.socket
123
151
  app.api.socket = socket;
124
- // 开始心跳检测
125
- self.startPing();
152
+ // 为这个socket启动独立的心跳检测
153
+ self.startPingForSocket(socket);
126
154
  };
127
155
 
128
156
  socket.onmessage = function (event) {
129
157
  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
+ }
130
170
  // 处理心跳响应
131
171
  if (event.data === 'pong') {
132
- // 标记收到pong响应
133
- self.pongReceived = true;
172
+ // 标记此socket收到pong响应
173
+ socket.pongReceived = true;
134
174
  return;
135
175
  }
136
176
  if (event.data instanceof ArrayBuffer) {
@@ -202,26 +242,40 @@ app.registerExtension({
202
242
  if (event.data === '[DONE]') {
203
243
  console.log('收到[DONE]消息,任务已完成,停止心跳并关闭连接');
204
244
  self.taskRunning = false;
205
- self.stopPing();
206
- self.closeSocket(1000);
245
+ self.stopPingForSocket(socket);
246
+ if (socket.readyState === WebSocket.OPEN) {
247
+ socket.close(1000);
248
+ }
207
249
  return;
208
250
  }
209
251
  const msg = JSON.parse(event.data)
210
- window.parent.postMessage({
211
- type: 'functionResult',
212
- method: 'progress_info_change',
213
- result: msg.progress_info
214
- }, '*');
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
+ }
215
264
 
216
265
  switch (msg.type) {
217
266
  case 'load_start':
218
267
  case 'load_end':
219
268
  case 'prompt_id':
220
- // 发送准备状态信息
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
+ }
221
275
  window.parent.postMessage({
222
276
  type: 'functionResult',
223
277
  method: 'preparingStatus',
224
- result: msg
278
+ result: preparingData
225
279
  }, '*')
226
280
  break
227
281
  case 'status':
@@ -290,20 +344,20 @@ app.registerExtension({
290
344
  console.log('WebSocket 错误:', error);
291
345
  // 清除连接中标志
292
346
  self.isConnecting = false;
293
- // 停止心跳
294
- self.stopPing();
347
+ // 停止此socket的心跳检测
348
+ self.stopPingForSocket(socket);
295
349
  };
296
350
 
297
351
  socket.onclose = function(event) {
298
352
  console.log('WebSocket 连接已关闭, 状态码:', event.code, event.reason);
299
353
  // 清除连接中标志
300
354
  self.isConnecting = false;
301
- // 清理单例引用
355
+ // 停止此socket的心跳检测
356
+ self.stopPingForSocket(socket);
357
+ // 清理单例引用(如果这是当前活跃的socket)
302
358
  if (self.socket === socket) {
303
359
  self.socket = null;
304
360
  }
305
- // 停止心跳
306
- self.stopPing();
307
361
  };
308
362
 
309
363
  socket.registeredTypes = new Set();
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bizydraft
3
- Version: 0.2.76
3
+ Version: 0.2.76.dev20251024093830
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=dnstkIU_898KvVka1wP8d1TJDLlAphDYghgpQpkTmLM,39864
23
+ bizydraft/static/js/postEvent.js,sha256=o9yA3d3fuIHG7KBXI8GbZA4iGGWaPsw6Ec6N1xB4QsA,42427
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=BD9RJxTMGO8wagOI9IZNYzKfsOnpyl0JtEUghpURpaI,2620
29
29
  bizydraft/static/js/hookLoad/model.js,sha256=C7Hi6BkdtEAgNCwpT71ZRgv9BaYKBsyNu8wt9h5hYvk,10576
30
- bizydraft-0.2.76.dist-info/METADATA,sha256=N7GBtzZA1p8JWeLncuBsNfjBblcEL7So9Zx9Gh0EH08,162
31
- bizydraft-0.2.76.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
32
- bizydraft-0.2.76.dist-info/top_level.txt,sha256=XtoBq6hjZhXIM7aas4GtPDtAiKo8FdLzMABXW8qqQ8M,10
33
- bizydraft-0.2.76.dist-info/RECORD,,
30
+ bizydraft-0.2.76.dev20251024093830.dist-info/METADATA,sha256=dOZIzq3t2lIWw12pZh7FfhnXf0wBT9QLyrQkDjrpNJA,180
31
+ bizydraft-0.2.76.dev20251024093830.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
32
+ bizydraft-0.2.76.dev20251024093830.dist-info/top_level.txt,sha256=XtoBq6hjZhXIM7aas4GtPDtAiKo8FdLzMABXW8qqQ8M,10
33
+ bizydraft-0.2.76.dev20251024093830.dist-info/RECORD,,