From b11c746f8f2e155daf19790136b63350be9ec79d Mon Sep 17 00:00:00 2001 From: Griatch Date: Sun, 14 Feb 2016 15:29:31 +0100 Subject: [PATCH] Silenced the unhandled events from websocket connections. --- .../webclient/static/webclient/js/evennia.js | 32 ++++++++----------- .../static/webclient/js/webclient_gui.js | 12 +++++-- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/evennia/web/webclient/static/webclient/js/evennia.js b/evennia/web/webclient/static/webclient/js/evennia.js index 24c237bf21..44c95e1c2b 100644 --- a/evennia/web/webclient/static/webclient/js/evennia.js +++ b/evennia/web/webclient/static/webclient/js/evennia.js @@ -58,8 +58,7 @@ An "emitter" object must have a function debug: true, initialized: false, - // Initialize. - // startup Evennia emitter and connection. + // Initialize the Evennia object with emitter and connection. // // Args: // opts (obj): @@ -82,24 +81,21 @@ An "emitter" object must have a function opts = opts || {}; this.emitter = opts.emitter || new DefaultEmitter(); - if (opts.connection) { + if (opts.ckonnection) { this.connection = opts.connection; } else if (window.WebSocket && wsactive) { this.connection = new WebsocketConnection(); - if (!this.connection) { - this.connection = new AjaxCometConnection(); - } } else { this.connection = new AjaxCometConnection(); } log('Evennia initialized.') }, - // Client -> Evennia. - // Called by the frontend to send a command to Evennia. + // client -> Evennia. + // called by the frontend to send a command to Evennia. // - // Args: + // args: // cmdname (str): String identifier to call // kwargs (obj): Data argument for calling as cmdname(kwargs) // callback (func): If given, will be given an eventual return @@ -191,7 +187,7 @@ An "emitter" object must have a function var off = function (cmdname) { delete listeners[cmdname] }; - return {emit:emit, on:on, off:off} + return {emit:emit, on:on, off:off}; }; // Websocket Connector @@ -201,15 +197,15 @@ An "emitter" object must have a function var websocket = new WebSocket(wsurl); // Handle Websocket open event websocket.onopen = function (event) { - Evennia.emit('connection.open', ["websocket"], event); + Evennia.emit('connection_open', ["websocket"], event); }; // Handle Websocket close event websocket.onclose = function (event) { - Evennia.emit('connection.close', ["websocket"], event); + Evennia.emit('connection_close', ["websocket"], event); }; // Handle websocket errors websocket.onerror = function (event) { - Evennia.emit('connection.error', ["websocket"], event); + Evennia.emit('connection_error', ["websocket"], event); if (websocket.readyState === websocket.CLOSED) { log("Websocket failed. Falling back to Ajax..."); Evennia.connection = AjaxCometConnection(); @@ -254,12 +250,12 @@ An "emitter" object must have a function success: function(data) { data = JSON.parse(data); - log ("connection.open", ["AJAX/COMET"], data); + log ("connection_open", ["AJAX/COMET"], data); client_hash = data.suid; poll(); }, error: function(req, stat, err) { - Evennia.emit("connection.error", ["AJAX/COMET init error"], err); + Evennia.emit("connection_error", ["AJAX/COMET init error"], err); log("AJAX/COMET: Connection error: " + err); } }); @@ -274,7 +270,7 @@ An "emitter" object must have a function data: {mode:'input', data: JSON.stringify(data), 'suid': client_hash}, success: function(req, stat, err) {}, error: function(req, stat, err) { - Evennia.emit("connection.error", ["AJAX/COMET send error"], err); + Evennia.emit("connection_error", ["AJAX/COMET send error"], err); log("AJAX/COMET: Server returned error.",req,stat,err); } }); @@ -315,11 +311,11 @@ An "emitter" object must have a function success: function(data){ client_hash = '0'; - Evennia.emit("connection.close", ["AJAX/COMET"], {}); + Evennia.emit("connection_close", ["AJAX/COMET"], {}); log("AJAX/COMET connection closed cleanly.") }, error: function(req, stat, err){ - Evennia.emit("connection.err", ["AJAX/COMET close error"], err); + Evennia.emit("connection_err", ["AJAX/COMET close error"], err); client_hash = '0'; } }); diff --git a/evennia/web/webclient/static/webclient/js/webclient_gui.js b/evennia/web/webclient/static/webclient/js/webclient_gui.js index b78fa11aa8..12db6b2f49 100644 --- a/evennia/web/webclient/static/webclient/js/webclient_gui.js +++ b/evennia/web/webclient/static/webclient/js/webclient_gui.js @@ -106,12 +106,15 @@ function onPrompt(args, kwargs) { "
" + args[0] + "
"); } +// Handler silencing events we don't do anything with. +function onSilence(cmdname, args, kwargs) {} + // Handler unrecognized commands from server function onDefault(cmdname, args, kwargs) { mwin = $("#messagewindow"); mwin.append( "
" - + "Unhandled event:
" + + "Error or Unhandled event:
" + cmdname + ", " + JSON.stringify(args) + ", " + JSON.stringify(kwargs) + "

"); @@ -138,14 +141,17 @@ $(document).ready(function() { Evennia.emitter.on("text", onText); Evennia.emitter.on("prompt", onPrompt); Evennia.emitter.on("default", onDefault); + // silence currently unused events + Evennia.emitter.on("connection_open", onSilence); + Evennia.emitter.on("connection_close", onSilence); + // Event when closing window (have to have Evennia initialized) $(window).bind("beforeunload", Evennia.connection.close); - doWindowResize(); - // set an idle timer to send idle every 3 minutes, // to avoid proxy servers timing out on us setInterval(function() { + // Connect to server Evennia.msg("text", ["idle"], {}); }, 60000*3