11using WebSockets, Sockets
22import HTTP, AssetRegistry, JSON
33using WebSockets: is_upgrade, upgrade
4- using WebIO
4+
55struct WSConnection{T} <: WebIO.AbstractConnection
66 sock:: T
77end
@@ -156,17 +156,40 @@ end
156156
157157const webio_server_config = Ref {typeof((url = "", http_port = 0, ws_url = ""))} ()
158158
159+ """
160+ Fetches the global configuration for our http + websocket server from environment
161+ variables. It will memoise the result, so after a first call, any update to
162+ the environment will get ignored.
163+ """
159164function global_server_config ()
160165 if ! isassigned (webio_server_config)
166+
167+ setbaseurl! (get (ENV , " JULIA_WEBIO_BASEURL" , " " ))
168+
161169 url = get (ENV , " WEBIO_SERVER_HOST_URL" , " 127.0.0.1" )
162170 http_port = parse (Int, get (ENV , " WEBIO_HTTP_PORT" , " 8081" ))
163171 ws_default = string (url, " :" , http_port, " /webio_websocket/" )
164172 ws_url = get (ENV , " WEBIO_WEBSOCKT_URL" , ws_default)
165173 webio_server_config[] = (url = url, http_port = http_port, ws_url = ws_url)
174+
166175 end
167176 webio_server_config[]
168177end
169178
179+ """
180+ Generic show method that will make sure that an asset & websocket server is running
181+ it will print the required html scripts + WebIO div mounting code directly into `io`.
182+ can be used in the following way to create a generic display method for webio:
183+ ```example
184+ function Base.display(d::MyWebDisplay, m::MIME"application/webio", app)
185+ println(d.io, "outer html")
186+ show(io, m, app)
187+ println(d.io, "close outer html")
188+ end
189+ ```
190+ The above example enables display code & webio code that doesn't rely on any
191+ provider dependencies.
192+ """
170193function Base. show (io:: IO , :: MIME"application/webio" , app:: Union{Scope, Node} )
171194 # Make sure we run a server
172195 c = global_server_config ()
@@ -179,6 +202,5 @@ function Base.show(io::IO, ::MIME"application/webio", app::Union{Scope, Node})
179202 println (io, " <script src=$(repr (webio_script)) ></script>" )
180203 println (io, " <script src=$(repr (ws_script)) ></script>" )
181204 tohtml (io, app)
182-
183205 return
184206end
0 commit comments