Got the initial connect screen to display in webclient again.

This commit is contained in:
Griatch 2016-02-12 12:25:30 +01:00
parent 66641b54ab
commit d48691e121
5 changed files with 52 additions and 43 deletions

View file

@ -369,13 +369,21 @@ class PortalSessionHandler(SessionHandler):
# distribute outgoing data to the correct session methods.
if session:
print ("portalsessionhandler.data_out:", session, kwargs)
for cmdname, (cmdargs, cmdkwargs) in kwargs.iteritems():
try:
getattr(session, "send_%s" % cmdname)(*cmdargs, **cmdkwargs)
except AttributeError:
session.send_default(cmdname, *cmdargs, **cmdkwargs)
except Exception:
log_trace()
funcname = "send_%s" % cmdname
if hasattr(session, funcname):
# better to use hassattr here over try..except
# - avoids hiding AttributeErrors in the call.
try:
getattr(session, funcname)(*cmdargs, **cmdkwargs)
except Exception:
log_trace()
else:
try:
# note that send_default always takes cmdname
# as arg too.
session.send_default(cmdname, *cmdargs, **cmdkwargs)
except Exception:
log_trace()
PORTAL_SESSIONS = PortalSessionHandler()

View file

@ -143,7 +143,8 @@ class WebSocketClient(Protocol, Session):
"""
if args:
text = args.pop(0)
args = list(args)
text = args[0]
if text is None:
return
options = kwargs.get("options", {})
@ -156,16 +157,14 @@ class WebSocketClient(Protocol, Session):
# screenreader mode cleans up output
text = parse_ansi(text, strip_ansi=True, xterm256=False, mxp=False)
text = _RE_SCREENREADER_REGEX.sub("", text)
cmd = "prompt" if prompt else "text"
if raw:
# no processing
data = json.dumps([cmd, (text,) + args, kwargs])
args[0] = text
else:
# send normally, with html processing
data = json.dumps([cmd, (parse_html(text, strip_ansi=nomarkup),) + args, kwargs])
self.sendLine(data)
args[0] = parse_html(text, strip_ansi=nomarkup)
# send to client on required form [cmdname, args, kwargs]
self.sendLine(json.dumps([cmd, args, kwargs]))
def send_prompt(self, *args, **kwargs):
@ -186,4 +185,5 @@ class WebSocketClient(Protocol, Session):
client instead.
"""
print "send_default", cmdname, args, kwargs
session.sendLine(json.dumps([cmdname, args, kwargs]))

View file

@ -73,7 +73,7 @@ An "emitter" object must have a function
// make it safe to call multiple times.
return;
}
this.initialized = true;
this.initialized = true;
opts = opts || {};
this.emitter = opts.emitter || new DefaultEmitter();
@ -112,7 +112,7 @@ An "emitter" object must have a function
}
this.connection.msg(data);
log('client msg sending: ' + cmdname + " " + args + " " + outargs + " " + outkwargs);
log('client msg sending: ', cmdname, args, outargs, outkwargs);
},
// Evennia -> Client.
@ -126,7 +126,6 @@ An "emitter" object must have a function
// kwargs (obj): keyword-args to listener
//
emit: function (cmdname, args, kwargs) {
log('emit called with args: ' + cmdname + ',' + args + ',' + kwargs);
if (kwargs.cmdid) {
cmdmap[kwargs.cmdid].apply(this, [args, kwargs]);
delete cmdmap[kwargs.cmdid];
@ -153,8 +152,7 @@ An "emitter" object must have a function
// kwargs (obj): Argument to the listener.
//
var emit = function (cmdname, args, kwargs) {
log('emit', cmdname, args, kwargs);
log("DefaultEmitter.emit:", cmdname, args, kwargs);
if (listeners[cmdname]) {
listeners[cmdname].apply(this, [args, kwargs]);
};
@ -168,6 +166,7 @@ An "emitter" object must have a function
// to listen to cmdname events.
//
var on = function (cmdname, listener) {
log("DefaultEmitter.on", cmdname, listener);
if (typeof(listener === 'function')) {
listeners[cmdname] = listener;
};
@ -203,7 +202,7 @@ An "emitter" object must have a function
websocket.onerror = function (event) {
log("Websocket error to ", wsurl, event);
Evennia.emit('socket:error', [], event);
if (websocket.readyState === websocket.CLOSED) {
if (websocket.readyState === websocket.CLOSED) {
log("Websocket failed. Falling back to Ajax...");
Evennia.connection = AjaxCometConnection();
}
@ -221,7 +220,7 @@ An "emitter" object must have a function
Evennia.emit(data[0], data[1], data[2]);
};
websocket.msg = function(cmdname, args, kwargs) {
// send
// send
websocket.send(JSON.stringify([cmdname, args, kwargs]));
};
@ -290,17 +289,17 @@ An "emitter" object must have a function
// Args:
// msg (str): Message to log to console.
//
function log(msg) {
function log() {
if (Evennia.debug) {
console.log(msg);
console.log(arguments);
}
}
// Called when page has finished loading (kicks the client into gear)
$(document).ready(function() {
setTimeout( function () {
Evennia.init()
},
Evennia.init()
},
500
);
});

View file

@ -7,12 +7,12 @@
*
* The job of this code is to create listeners to subscribe to evennia
* messages, via Evennia.emitter.on(cmdname, listener) and to handle
* input from the user and send it to
* input from the user and send it to
* Evennia.msg(cmdname, args, kwargs, [callback]).
*
*/
//
//
// GUI Elements
//
@ -28,9 +28,9 @@ var inputlog = function() {
history[0] = ''; // the very latest input is empty for new entry.
function history_back() {
// step backwards in history stack
// step backwards in history stack
history_pos = Math.min(++history_pos, history.length - 1);
return history[history.length - 1 - history_pos];
return history[history.length - 1 - history_pos];
}
function history_fwd() {
// step forwards in history stack
@ -47,7 +47,7 @@ var inputlog = function() {
history[history.length] = '';
}
}
return {back: history_back,
return {back: history_back,
fwd: history_fwd,
add: history_add}
};
@ -91,7 +91,7 @@ $.fn.appendCaret = function() {
};
// GUI Event Handlers
// GUI Event Handlers
$(document).keydown( function(event) {
// catch all keyboard input, handle special chars
@ -126,16 +126,17 @@ function set_window_size() {
$(window).resize(set_window_size);
//
// Listeners
//
// Listeners
//
function doText(args, kwargs) {
// append message to previous ones
log("doText:", args, kwargs);
$("#messagewindow").append(
"<div class='msg out>" + args[0] + "</div>");
"<div class='msg out'>" + args[0] + "</div>");
// scroll message window to bottom
$("#messagewindow").animate({scrollTop: $('#messageindow')[0].scrollHeight});
$("#messagewindow").animate({scrollTop: $('#messagewindow')[0].scrollHeight});
}
function doPrompt(args, kwargs) {
@ -147,17 +148,18 @@ function doPrompt(args, kwargs) {
$(document).ready(function() {
// a small timeout to stop 'loading' indicator in Chrome
Evennia.init()
Evennia.init()
// register listeners
log("register listeners ...");
Evennia.emitter.on("text", doText);
Evennia.emitter.on("prompt", doPrompt);
set_window_size();
set_window_size();
// set an idle timer to avoid proxy servers to time out on us (every 3 minutes)
setInterval(function() {
log('Idle tick.');
Evennia.msg("text", ["idle"], {});
},
},
60000*3
);
});

View file

@ -4,14 +4,14 @@
- connecting - custom connect messages
- jquery_import - for changing to a local jquery version
- guilib_import - for using your own gui lib
-->
-->
{% block client %}
<div id="client">
<div id="messagewindow"> mainarea </div>
<div id="inputform">
<div id="messagewindow"></div>
<div id="inputform">
<textarea name="inputfield" type="text"> </textarea>
</div>
</div>