Add "force" option to allowReconnect

This commit is contained in:
Winston Chang
2016-03-28 21:29:23 -05:00
parent 486d4d1c88
commit 7cb0882c73
3 changed files with 31 additions and 26 deletions

View File

@@ -242,13 +242,16 @@ workerId <- local({
#' (as opposed to the request that downloaded the web page for the app).
#' }
#' \item{allowReconnect(value)}{
#' If \code{value} is \code{TRUE}, this tells the browser that, if the
#' session ends due to the network connection closing, attempt to reconnect
#' to the server. If a reconnection is successful, the browser will send all
#' the current input values to the new session on the server, and the server
#' will recalculate any outputs and send them back to the client. If
#' \code{value} is \code{FALSE}, reconnections will be disabled (this is the
#' default state).
#' If \code{value} is \code{TRUE} and run in a hosting environment (Shiny
#' Server or Connect) with reconnections enabled, then when the session ends
#' due to the network connection closing, the client will attempt to
#' reconnect to the server. If a reconnection is successful, the browser will
#' send all the current input values to the new session on the server, and
#' the server will recalculate any outputs and send them back to the client.
#' If \code{value} is \code{FALSE}, reconnections will be disabled (this is
#' the default state). If \code{"force"}, then the client browser will always
#' attempt to reconnect. The only reason to use \code{"force"} is for testing
#' on a local connection (without Shiny Server or Connect).
#' }
#' \item{sendCustomMessage(type, message)}{
#' Sends a custom message to the web page. \code{type} must be a
@@ -541,8 +544,8 @@ ShinySession <- R6Class(
},
allowReconnect = function(value) {
if (!(identical(value, TRUE) || identical(value, FALSE))) {
stop("value must be TRUE or FALSE")
if (!(identical(value, TRUE) || identical(value, FALSE) || identical(value, "force"))) {
stop('value must be TRUE, FALSE, or "force"')
}
private$write(toJSON(list(allowReconnect = value)))
},

View File

@@ -86,13 +86,16 @@
(as opposed to the request that downloaded the web page for the app).
}
\item{allowReconnect(value)}{
If \code{value} is \code{TRUE}, this tells the browser that, if the
session ends due to the network connection closing, attempt to reconnect
to the server. If a reconnection is successful, the browser will send all
the current input values to the new session on the server, and the server
will recalculate any outputs and send them back to the client. If
\code{value} is \code{FALSE}, reconnections will be disabled (this is the
default state).
If \code{value} is \code{TRUE} and run in a hosting environment (Shiny
Server or Connect) with reconnections enabled, then when the session ends
due to the network connection closing, the client will attempt to
reconnect to the server. If a reconnection is successful, the browser will
send all the current input values to the new session on the server, and
the server will recalculate any outputs and send them back to the client.
If \code{value} is \code{FALSE}, reconnections will be disabled (this is
the default state). If \code{"force"}, then the client browser will always
attempt to reconnect. The only reason to use \code{"force"} is for testing
on a local connection (without Shiny Server or Connect).
}
\item{sendCustomMessage(type, message)}{
Sends a custom message to the web page. \code{type} must be a

View File

@@ -82,12 +82,6 @@ var ShinyApp = function() {
var ws = new WebSocket(protocol + '//' + window.location.host + defaultPath);
ws.binaryType = 'arraybuffer';
// This flag indicates that reconnections are permitted by the server.
// When Shiny is running with Shiny Server, this flag will be present
// only on versions of SS that support reconnects. When running Shiny
// locally, this is set to true, because the "server" always permits
// reconnection.
ws.allowReconnect = true;
return ws;
};
@@ -225,8 +219,12 @@ var ShinyApp = function() {
}
// To try a reconnect, both the app (this.$allowReconnect) and the
// server (this.$socket.allowReconnect) must allow reconnections.
if (this.$allowReconnect === true && this.$socket.allowReconnect === true) {
// server (this.$socket.allowReconnect) must allow reconnections, or
// session$allowReconnect("force") was called. The "force" option should
// only be used for testing.
if ((this.$allowReconnect === true && this.$socket.allowReconnect === true) ||
this.$allowReconnect === "force")
{
var delay = reconnectDelay.next();
exports.showReconnectDialog(delay);
this.$scheduleReconnect(delay);
@@ -591,10 +589,11 @@ var ShinyApp = function() {
});
addMessageHandler('allowReconnect', function(message) {
if (!(message === true || message === false)) {
if (message === true || message === false || message === "force") {
this.$allowReconnect = message;
} else {
throw "Invalid value for allowReconnect: " + message;
}
this.$allowReconnect = message;
});
addMessageHandler('custom', function(message) {