Added close-handlers to websocket and did some other cleanup.

This commit is contained in:
Griatch 2016-02-14 13:52:08 +01:00
parent 166189a7a5
commit b6642cdfe9
4 changed files with 20 additions and 5 deletions

View file

@ -231,7 +231,10 @@ An "emitter" object must have a function
websocket.send(JSON.stringify(data));
};
websocket.close = function() {
// close connection.
// tell the server this connection is closing (usually
// tied to when the client window is closed). This
// Makes use of a websocket-protocol specific instruction.
websocket.send(JSON.stringify(["websocket_close", [], {}]));
}
return websocket;
};

View file

@ -138,6 +138,9 @@ $(document).ready(function() {
Evennia.emitter.on("text", onText);
Evennia.emitter.on("prompt", onPrompt);
Evennia.emitter.on("default", onDefault);
// 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,