SimonDanisch / Bonito.jl

Serving JS to the browser
MIT License
204 stars 30 forks source link

More docs about extending #197

Closed fonsp closed 9 months ago

fonsp commented 10 months ago

Hey! Did I understand the extension system correctly? I made updates to the docs with the things I learned, but please correct the mistakes

Questions:

  1. Where is the right place to do something like start an HTTP server?
  2. How do I use my new connection type? How do I get the Session object?
  3. Do you let multiple clients connect to the same JSServe.FrontendConnection? To the same WebSocket? Or do you create a new JSServe.FrontendConnection for each client?
    • If you let multiple clients connect to the same JSServe.FrontendConnection, should Base.write(::MyConnection write to all connected clients?
fonsp commented 10 months ago

Can you also take a look at https://github.com/JuliaWeb/Hyperscript.jl/issues/43 ? Would be sad to leave the cool package unmaintained 😢

SimonDanisch commented 10 months ago

Thank you! : ) 1) it's either in setup_connection or as I do it for Websocket connection in the connection constructor: https://github.com/SimonDanisch/JSServe.jl/blob/master/src/connection/websocket.jl#L13-L15 (it creates a singleton server). 2) You shouldn't really need those. After registering your connection as the default in a certain situation, that connection type will always be used for a new session. So for e.g. Pluto, it's when Pluto is loaded: https://github.com/SimonDanisch/JSServe.jl/blob/master/src/registry.jl#L207-L210. 3) A session encapsulates the connection to a single client. For notebooks we do have subsessions and subconnections, that communicate via one global session and allow to still create a session for each cell (for better cleanup of the used resources).

edit: you do get the Session in setup_connection(session::Session{MyConnection}), and it gets called whenever a connection is created with your Connection type