@@ -50,7 +50,6 @@ function serve_assets(req)
5050end
5151
5252function websocket_handler (ws)
53- println (" handling websocket" )
5453 conn = WSConnection (ws)
5554 while isopen (ws)
5655 data, success = WebSockets. readguarded (ws)
@@ -79,57 +78,24 @@ const routing_callback = Ref{Any}((req)-> missing)
7978 logging_io = devnull
8079 )
8180
82- usage:
83-
84- ```example
85- asset_port = 8081
86- base_url = "127.0.0.1"
87- const app = Ref{Any}()
88- #WebIO.setbaseurl!(baseurl) # plus port!?
89- server = WebIOServer(
90- baseurl = base_url, http_port = asset_port, verbose = true
91- ) do req
92- req.target != "/" && return missing # don't do anything
93- isassigned(app) || return "no app"
94- ws_url = string("ws://", base_url, ':', asset_port, "/webio_websocket/")
95- webio_script = wio_asseturl("/webio/dist/bundle.js")
96- ws_script = wio_asseturl("/providers/websocket_connection.js")
81+ usage to serve some webio html:
82+
83+ ```example
84+ using WebSockets, WebIO
85+ app = Ref{Any}(node(:div, "hi"))
86+ function serve_app(req)
87+ req.target != "/" && return missing
9788 return sprint() do io
98- print(io, "
99- <!doctype html>
100- <html>
101- <head>
102- <meta charset="UTF-8">
103- <script> var websocket_url = \$ (repr(ws_url)) </script>
104- <script src="\$ webio_script"></script>
105- <script src="\$ ws_script"></script>
106- </head>
107- <body>
108- ")
109- tohtml(io, app[])
110- print(io, "
111- </body>
112- </html>
113- ")
89+ print(io, \"\"\"
90+ <!doctype html><html><head>
91+ <meta charset="UTF-8"></head><body>
92+ \"\"\" )
93+ show(io, MIME"application/webio"(), app[])
94+ print(io, "</body></html>")
11495 end
11596 end
116-
117- w = Scope()
118-
119- obs = Observable(w, "rand-value", 0.0)
120-
121- on(obs) do x
122- println("JS sent \$ x")
123- end
124-
125- using JSExpr
126- app[] = w(
127- dom"button"(
128- "generate random",
129- events=Dict("click"=>@js () -> \$ obs[] = Math.random()),
130- ),
131- );
132- ```
97+ server = WebIO.WebIOServer(serve_app, logger = stdout, verbose = true)
98+ ```
13399"""
134100function WebIOServer (
135101 default_response:: Function = (req)-> missing ;
@@ -150,9 +116,9 @@ function WebIOServer(
150116 req. target == websocket_route && websocket_handler (sock)
151117 end
152118 server = WebSockets. ServerWS (handler, wshandler, logger; server_kw_args... )
153- # server_task = with_logger(NullLogger()) do
154- server_task = @async WebSockets. serve (server, baseurl, http_port, verbose)
155- # end
119+ server_task = with_logger (NullLogger ()) do
120+ @async WebSockets. serve (server, baseurl, http_port, verbose)
121+ end
156122 singleton_instance[] = WebIOServer (server, server_task)
157123 end
158124 return singleton_instance[]
0 commit comments