Skip to content

Commit

Permalink
Use register connection rather than force_connection
Browse files Browse the repository at this point in the history
Otherwise we can only have one connection(!) >_<
  • Loading branch information
frankier committed Oct 13, 2024
1 parent c51812d commit aecd5bb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ You may like to add some custom behaviour to the route such as authentication. I
```julia
function __init__()
const route_base = "/foobar/"
oxygen_bonito = Oxygen.setup_bonito_connection(CONTEXT[]; setup_force_connection=true, route_base=foobar)
oxygen_bonito = Oxygen.setup_bonito_connection(CONTEXT[]; setup_register_connection=true, route_base=route_base)
route_pattern = route_base * "{session_id}"
@websocket route_pattern function mybonitohandler(websocket::HTTP.WebSocket, session_id::String)
# Add custom behaviour here
Expand Down
18 changes: 10 additions & 8 deletions src/extensions/plotting/bonito_connection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using HTTP.WebSockets

import .Bonito: setup_connection
using .Bonito: FrontendConnection, WebSocketHandler, Session, setup_websocket_connection_js
using .Bonito: run_connection_loop, force_connection!
using .Bonito: run_connection_loop, register_connection!
using .Bonito: CleanupPolicy, DefaultCleanupPolicy, allow_soft_close, soft_close, should_cleanup

export OxygenWebSocketConnection, mk_bonito_websocket_handler, setup_bonito_connection
Expand Down Expand Up @@ -38,7 +38,7 @@ BonitoConnectionContext(policy=DefaultCleanupPolicy()) = BonitoConnectionContext
context::Context;
setup_all=false,
setup_route=setup_all,
setup_force_connection=setup_all,
setup_register_connection=setup_all,
route_base="/bonito_websocket/"
)
Expand All @@ -50,20 +50,22 @@ function setup_bonito_connection(
context::Context;
setup_all=false,
setup_route=setup_all,
setup_force_connection=setup_all,
route_base="/bonito_websocket/"
setup_register_connection=setup_all,
route_base="/bonito-websocket/"
)
context.ext[:bonito_connection] = BonitoConnectionContext()
handler = mk_bonito_websocket_handler(context)
connection = OxygenWebSocketConnection(context, route_base)
if setup_route
Oxygen.Core.register(context, WEBSOCKET, route_base * "{session_id}", handler)
end
if setup_force_connection
force_connection!(connection)
function mk_connection()
return OxygenWebSocketConnection(context, route_base)
end
if setup_register_connection
register_connection!(mk_connection, OxygenWebSocketConnection)
end
return (;
connection,
mk_connection,
handler
)
end
Expand Down

0 comments on commit aecd5bb

Please sign in to comment.