diff --git a/DESCRIPTION b/DESCRIPTION index 7cbabc5..45a946d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: servr Type: Package Title: A Simple HTTP Server to Serve Static Files or Dynamic Documents -Version: 0.29.1 +Version: 0.29.2 Authors@R: c( person("Yihui", "Xie", role = c("aut", "cre"), email = "xie@yihui.name", comment = c(ORCID = "0000-0003-0645-5666")), person("Carson", "Sievert", role = "ctb"), diff --git a/NEWS.md b/NEWS.md index 7d6a122..04a07b2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # CHANGES IN servr VERSION 0.30 +- Fixed a bug that caused WebSockets to fail when the URL contains a hash. # CHANGES IN servr VERSION 0.29 diff --git a/R/dynamic.R b/R/dynamic.R index 1d2c354..a1f5b63 100644 --- a/R/dynamic.R +++ b/R/dynamic.R @@ -191,9 +191,10 @@ dynamic_site = function( invisible(res) } +ws = "new WebSocket(location.href.replace(/^http/, 'ws').replace(/[?#].*/g, '').replace(/\\/?$/, '/websocket/'))" ws_js = function(js, interval, path) { path = gsub('"', '\\"', path, fixed = TRUE) - paste0('') + paste0('') } add_js = function(res, js, ...) { diff --git a/inst/resources/ws-reload.js b/inst/resources/ws-reload.js index 65870fd..ed05c9c 100644 --- a/inst/resources/ws-reload.js +++ b/inst/resources/ws-reload.js @@ -1,6 +1,5 @@ // automatically refresh the page when necessary (R will send a message to ws) -((interval, path) => { -const ws = new WebSocket(location.href.replace(/^http/, 'ws').replace(/\/?$/, '/websocket/')); +((interval, path, ws) => { let flag; ws.onmessage = e => { flag = true; diff --git a/inst/resources/ws-update.js b/inst/resources/ws-update.js index c9a8824..708d5e4 100644 --- a/inst/resources/ws-update.js +++ b/inst/resources/ws-update.js @@ -1,5 +1,4 @@ -((interval, path) => { -const ws = new WebSocket(location.href.replace(/^http/, 'ws').replace(/\/?$/, '/websocket/')); +((interval, path, ws) => { let flag; ws.onmessage = e => { flag = true;