Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
ComfyUI
Commits
5ea59771
Commit
5ea59771
authored
Mar 07, 2023
by
comfyanonymous
Browse files
Merge branch 'socketsession' of
https://github.com/pythongosssss/ComfyUI
parents
19415c3a
5c55c933
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
3 deletions
+25
-3
execution.py
execution.py
+2
-0
server.py
server.py
+15
-2
web/scripts/api.js
web/scripts/api.js
+8
-1
No files found.
execution.py
View file @
5ea59771
...
@@ -55,6 +55,7 @@ def recursive_execute(server, prompt, outputs, current_item, extra_data={}):
...
@@ -55,6 +55,7 @@ def recursive_execute(server, prompt, outputs, current_item, extra_data={}):
input_data_all
=
get_input_data
(
inputs
,
class_def
,
outputs
,
prompt
,
extra_data
)
input_data_all
=
get_input_data
(
inputs
,
class_def
,
outputs
,
prompt
,
extra_data
)
if
server
.
client_id
is
not
None
:
if
server
.
client_id
is
not
None
:
server
.
last_node_id
=
unique_id
server
.
send_sync
(
"executing"
,
{
"node"
:
unique_id
},
server
.
client_id
)
server
.
send_sync
(
"executing"
,
{
"node"
:
unique_id
},
server
.
client_id
)
obj
=
class_def
()
obj
=
class_def
()
...
@@ -188,6 +189,7 @@ class PromptExecutor:
...
@@ -188,6 +189,7 @@ class PromptExecutor:
for
x
in
executed
:
for
x
in
executed
:
self
.
old_prompt
[
x
]
=
copy
.
deepcopy
(
prompt
[
x
])
self
.
old_prompt
[
x
]
=
copy
.
deepcopy
(
prompt
[
x
])
finally
:
finally
:
self
.
server
.
last_node_id
=
None
if
self
.
server
.
client_id
is
not
None
:
if
self
.
server
.
client_id
is
not
None
:
self
.
server
.
send_sync
(
"executing"
,
{
"node"
:
None
},
self
.
server
.
client_id
)
self
.
server
.
send_sync
(
"executing"
,
{
"node"
:
None
},
self
.
server
.
client_id
)
...
...
server.py
View file @
5ea59771
...
@@ -32,21 +32,34 @@ class PromptServer():
...
@@ -32,21 +32,34 @@ class PromptServer():
self
.
web_root
=
os
.
path
.
join
(
os
.
path
.
dirname
(
self
.
web_root
=
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)),
"web"
)
os
.
path
.
realpath
(
__file__
)),
"web"
)
routes
=
web
.
RouteTableDef
()
routes
=
web
.
RouteTableDef
()
self
.
last_node_id
=
None
self
.
client_id
=
None
@
routes
.
get
(
'/ws'
)
@
routes
.
get
(
'/ws'
)
async
def
websocket_handler
(
request
):
async
def
websocket_handler
(
request
):
ws
=
web
.
WebSocketResponse
()
ws
=
web
.
WebSocketResponse
()
await
ws
.
prepare
(
request
)
await
ws
.
prepare
(
request
)
sid
=
uuid
.
uuid4
().
hex
sid
=
request
.
rel_url
.
query
.
get
(
'clientId'
,
''
)
if
sid
:
# Reusing existing session, remove old
self
.
sockets
.
pop
(
sid
,
None
)
else
:
sid
=
uuid
.
uuid4
().
hex
self
.
sockets
[
sid
]
=
ws
self
.
sockets
[
sid
]
=
ws
try
:
try
:
# Send initial state to the new client
# Send initial state to the new client
await
self
.
send
(
"status"
,
{
"status"
:
self
.
get_queue_info
(),
'sid'
:
sid
},
sid
)
await
self
.
send
(
"status"
,
{
"status"
:
self
.
get_queue_info
(),
'sid'
:
sid
},
sid
)
# On reconnect if we are the currently executing client send the current node
if
self
.
client_id
==
sid
and
self
.
last_node_id
is
not
None
:
await
self
.
send
(
"executing"
,
{
"node"
:
self
.
last_node_id
},
sid
)
async
for
msg
in
ws
:
async
for
msg
in
ws
:
if
msg
.
type
==
aiohttp
.
WSMsgType
.
ERROR
:
if
msg
.
type
==
aiohttp
.
WSMsgType
.
ERROR
:
print
(
'ws connection closed with exception %s'
%
ws
.
exception
())
print
(
'ws connection closed with exception %s'
%
ws
.
exception
())
finally
:
finally
:
self
.
sockets
.
pop
(
sid
)
self
.
sockets
.
pop
(
sid
,
None
)
return
ws
return
ws
@
routes
.
get
(
"/"
)
@
routes
.
get
(
"/"
)
...
...
web/scripts/api.js
View file @
5ea59771
...
@@ -28,7 +28,13 @@ class ComfyApi extends EventTarget {
...
@@ -28,7 +28,13 @@ class ComfyApi extends EventTarget {
}
}
let
opened
=
false
;
let
opened
=
false
;
this
.
socket
=
new
WebSocket
(
`ws
${
window
.
location
.
protocol
===
"
https:
"
?
"
s
"
:
""
}
://
${
location
.
host
}
/ws`
);
let
existingSession
=
sessionStorage
[
"
Comfy.SessionId
"
]
||
""
;
if
(
existingSession
)
{
existingSession
=
"
?clientId=
"
+
existingSession
;
}
this
.
socket
=
new
WebSocket
(
`ws
${
window
.
location
.
protocol
===
"
https:
"
?
"
s
"
:
""
}
://
${
location
.
host
}
/ws
${
existingSession
}
`
);
this
.
socket
.
addEventListener
(
"
open
"
,
()
=>
{
this
.
socket
.
addEventListener
(
"
open
"
,
()
=>
{
opened
=
true
;
opened
=
true
;
...
@@ -62,6 +68,7 @@ class ComfyApi extends EventTarget {
...
@@ -62,6 +68,7 @@ class ComfyApi extends EventTarget {
case
"
status
"
:
case
"
status
"
:
if
(
msg
.
data
.
sid
)
{
if
(
msg
.
data
.
sid
)
{
this
.
clientId
=
msg
.
data
.
sid
;
this
.
clientId
=
msg
.
data
.
sid
;
sessionStorage
[
"
Comfy.SessionId
"
]
=
this
.
clientId
;
}
}
this
.
dispatchEvent
(
new
CustomEvent
(
"
status
"
,
{
detail
:
msg
.
data
.
status
}));
this
.
dispatchEvent
(
new
CustomEvent
(
"
status
"
,
{
detail
:
msg
.
data
.
status
}));
break
;
break
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment