Skip to content

Commit d53548d

Browse files
SimonDanischshashi
authored andcommitted
put it all together
1 parent 8b51a69 commit d53548d

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

REQUIRE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ AssetRegistry
66
Requires
77
Compat 0.59
88
Widgets 0.3.1
9+
HTTP
10+
WebSockets

src/WebIO.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ include("render.jl")
1717
include("connection.jl")
1818
include("iframe.jl")
1919
include("devsetup.jl")
20+
include("providers/generic_http.jl")
2021

2122
"""
2223
setup_provider(s::Union{Symbol, AbstractString})

src/providers/generic_http.jl

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using WebSockets, Sockets
22
import HTTP, AssetRegistry, JSON
33
using WebSockets: is_upgrade, upgrade
4-
using WebIO
4+
55
struct WSConnection{T} <: WebIO.AbstractConnection
66
sock::T
77
end
@@ -156,17 +156,40 @@ end
156156

157157
const 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+
"""
159164
function 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[]
168177
end
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+
"""
170193
function 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
184206
end

0 commit comments

Comments
 (0)