Skip to content

Commit

Permalink
Fix Mux integration. Use HTTP.WebSockets instead of Websockets.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
mkitti committed Aug 19, 2024
1 parent 6662f46 commit b4fc8e9
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/providers/mux.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,21 @@ function webio_serve(app::Mux.App, args...)
end


struct WebSockConnection <: WebIO.AbstractConnection
sock
struct WebSockConnection{T} <: WebIO.AbstractConnection
sock::T
end

function create_socket(req)
function create_socket(req::Dict)
sock = req[:socket]
conn = WebSockConnection(sock)
# Dispatch on the type of socket if needed
_create_socket(sock)
end

t = @async while isopen(sock)
data = read(sock)
function _create_socket(sock::Mux.HTTP.WebSockets.WebSocket)
conn = WebSockConnection(sock)

# Iteration ends when the socket is closed
t = @async for data in sock
msg = JSON.parse(String(data))
WebIO.dispatch(conn, msg)
end
Expand All @@ -48,10 +52,11 @@ function create_socket(req)
end

function Sockets.send(p::WebSockConnection, data)
write(p.sock, sprint(io->JSON.print(io,data)))
Mux.HTTP.WebSockets.send(p.sock, sprint(io->JSON.print(io,data)))
end

Base.isopen(p::WebSockConnection) = isopen(p.sock)
# May not be strictly true
Base.isopen(p::WebSockConnection) = !Mux.HTTP.WebSockets.isclosed(p.sock)

Mux.Response(o::AbstractWidget) = Mux.Response(Widgets.render(o))
function Mux.Response(content::Union{Node, Scope})
Expand Down

0 comments on commit b4fc8e9

Please sign in to comment.