mirror of
https://github.com/evennia/evennia.git
synced 2026-03-21 15:26:30 +01:00
Silenced the unhandled events from websocket connections.
This commit is contained in:
parent
b6642cdfe9
commit
b11c746f8f
2 changed files with 23 additions and 21 deletions
|
|
@ -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';
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -106,12 +106,15 @@ function onPrompt(args, kwargs) {
|
|||
"<div id='prompt' class='msg out'>" + args[0] + "</div>");
|
||||
}
|
||||
|
||||
// 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(
|
||||
"<div class='msg err'>"
|
||||
+ "Unhandled event:<br>"
|
||||
+ "Error or Unhandled event:<br>"
|
||||
+ cmdname + ", "
|
||||
+ JSON.stringify(args) + ", "
|
||||
+ JSON.stringify(kwargs) + "<p></div>");
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue