Skip to content

Commit

Permalink
factor out the JS code to create new WS and make sure hashes and quer…
Browse files Browse the repository at this point in the history
…ies are removed for the WS URL
  • Loading branch information
yihui committed Feb 16, 2024
1 parent 45bc0df commit b784562
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]", comment = c(ORCID = "0000-0003-0645-5666")),
person("Carson", "Sievert", role = "ctb"),
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
3 changes: 2 additions & 1 deletion R/dynamic.R
Original file line number Diff line number Diff line change
Expand Up @@ -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('<script>', js, '(', interval * 1000, ', "', path, '");</script>')
paste0('<script>', js, '(', interval * 1000, ', "', path, '", ', ws, ');</script>')
}

add_js = function(res, js, ...) {
Expand Down
3 changes: 1 addition & 2 deletions inst/resources/ws-reload.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
3 changes: 1 addition & 2 deletions inst/resources/ws-update.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit b784562

Please sign in to comment.