Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
essenciary committed Oct 8, 2020
2 parents f4e24fc + f8d7297 commit d50a728
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
4 changes: 2 additions & 2 deletions files/embedded/channels.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Genie.WebChannels = {};
Genie.WebChannels.load_channels = function() {
let port = Genie.Settings.websockets_port == Genie.Settings.server_port ? window.location.port : Genie.Settings.websockets_port
var socket = new WebSocket('ws://' + window.location.hostname + ':' + port);
let port = Genie.Settings.websockets_port == Genie.Settings.server_port ? window.location.port : Genie.Settings.websockets_port;
var socket = new WebSocket(window.location.protocol.replace("http", "ws") + '//' + window.location.hostname + ':' + port);
var channels = Genie.WebChannels;

channels.channel = socket;
Expand Down
32 changes: 17 additions & 15 deletions src/Assets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,10 @@ end
Outputs the channels.js file included with the Genie package
"""
function channels() :: String
string(js_settings(), embedded(joinpath("files", "embedded", "channels.js")))
function channels(channel::String = Genie.config.webchannels_default_route) :: String
s = string(js_settings(), embedded(joinpath("files", "embedded", "channels.js")))
channel == Genie.config.webchannels_default_route || (s = replace(s, r"""(?<=webchannels_default_route":")[^"]+""" => channel))
return s
end


Expand All @@ -113,38 +115,38 @@ end
Outputs the channels JavaScript content within `<script>...</script>` tags, for embedding into the page.
"""
function channels_script() :: String
function channels_script(channel::String = Genie.config.webchannels_default_route) :: String
"""
<script>
$(channels())
$(channels(channel))
</script>
"""
end


"""
channels_support() :: String
channels_support(channel = Genie.config.webchannels_default_route) :: String
Provides full web channels support, setting up routes for loading support JS files, web sockets subscription and
returning the `<script>` tag for including the linked JS file into the web page.
"""
function channels_support() :: String
Router.route("/$(Genie.config.webchannels_default_route)/$(Genie.config.webchannels_js_file)") do
Genie.Renderer.Js.js(channels())
function channels_support(channel::String = Genie.config.webchannels_default_route) :: String
Router.route("/$(channel)/$(Genie.config.webchannels_js_file)") do
Genie.Renderer.Js.js(channels(channel))
end

Router.channel("/$(Genie.config.webchannels_default_route)/$(Genie.config.webchannels_subscribe_channel)") do
WebChannels.subscribe(Genie.Requests.wsclient(), Genie.config.webchannels_default_route)
Router.channel("/$(channel)/$(Genie.config.webchannels_subscribe_channel)") do
WebChannels.subscribe(Genie.Requests.wsclient(), channel)
"Subscription: OK"
end

Router.channel("/$(Genie.config.webchannels_default_route)/$(Genie.config.webchannels_unsubscribe_channel)") do
WebChannels.unsubscribe(Genie.Requests.wsclient(), Genie.config.webchannels_default_route)
Router.channel("/$(channel)/$(Genie.config.webchannels_unsubscribe_channel)") do
WebChannels.unsubscribe(Genie.Requests.wsclient(), channel)
WebChannels.unsubscribe_disconnected_clients()
"Unsubscription: OK"
end

"<script src=\"/$(Genie.config.webchannels_default_route)/$(Genie.config.webchannels_js_file)?v=$(Genie.Configuration.GENIE_VERSION)\"></script>"
@info channel
"<script src=\"/$(channel)/$(Genie.config.webchannels_js_file)?v=$(Genie.Configuration.GENIE_VERSION)\"></script>"
end


Expand All @@ -166,4 +168,4 @@ function favicon_support() :: String
"<link rel=\"icon\" type=\"image/x-icon\" href=\"/favicon.ico\" />"
end

end
end

0 comments on commit d50a728

Please sign in to comment.