Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[contrib] merge: pull request #108 from 'ogunden/connectmon'

  • Loading branch information...
commit 51e00c0539b7606a40c37381d35c79ad7f2c6ee1 2 parents 87f840e + 14754de
@BourgerieQuentin BourgerieQuentin authored
View
31 lib/plugins/server/session.js
@@ -114,10 +114,18 @@ var LowLevelPingLoop = {};
var linked_with_server = true;
+ // for setting a custom handler when the connection
+ // between client and server is lost.
+ var connection_lost_handler = null;
+
function break_ping_loop() {
linked_with_server = false;
- jlog("Error: the connexion with the server seems to be lost. Please reload");
- throw("Error: the connexion with the server seems to be lost. Please reload");
+ if (connection_lost_handler == null) {
+ jlog("Error: the connection with the server seems to be lost. Please reload");
+ throw("Error: the connection with the server seems to be lost. Please reload");
+ } else {
+ connection_lost_handler();
+ }
}
// Domain used for AJAX request
@@ -469,8 +477,13 @@ var LowLevelPingLoop = {};
/** Make somethings when an error occurs with the ping loop */
function error_ping_response(xhr, str, exn){
if (failure_delay == max_failure_delay){
- jlog("Error: the connexion with the server seems to be lost");
+ if (connection_lost_handler == null) {
+ jlog("Error: the connection with the server seems to be lost.");
return;
+ } else {
+ connection_lost_handler();
+ return;
+ }
} else {
//jlog("Warning: could not reach the server. Retrying in " + failure_delay);
}
@@ -571,6 +584,10 @@ var LowLevelPingLoop = {};
domain_url = d;
}
+ LowLevelSession.set_connection_lost_handler = function(h) {
+ connection_lost_handler = h;
+ }
+
LowLevelSession.llmake = function(st, unserialize, fun_session,
ctx, dfun, more, concurrent) {
the_ping_loop();
@@ -755,6 +772,14 @@ function set_uu(x0, x1) {
}
/**
+ * @register {(-> void) -> void}
+ */
+function set_connection_lost_handler(f) {
+ LowLevelSession.set_connection_lost_handler(f);
+ return js_void;
+}
+
+/**
* @register {string -> void}
*/
function set_domain_url(d) {
View
14 lib/stdlib/core/rpc/core/session.opa
@@ -190,6 +190,20 @@ Session = {{
@client set_domain_url = %%Session.set_domain_url%%
/**
+ * Set a custom handler function for the case when the
+ * connection between client and server appears to be
+ * lost. If this in not set, the default is to print
+ * "the connection with the server seems to be lost" to
+ * the client screen.
+ *
+ * Be sure to pass a `client` function here (e.g.
+ * `client function my_handler() { ... }`), as it will
+ * probably be called when the server is not available!
+ */
+ @client set_connection_lost_handler =
+ %%Session.set_connection_lost_handler%%
+
+ /**
* {2 Creating sessions}
*/
Please sign in to comment.
Something went wrong with that request. Please try again.