evennia.server.portal.webclient_ajax¶
AJAX/COMET fallback webclient
The AJAX/COMET web client consists of two components running on twisted and django. They are both a part of the Evennia website url tree (so the testing website might be located on http://localhost:4001/, whereas the webclient can be found on http://localhost:4001/webclient.)
- /webclient - this url is handled through django’s template
system and serves the html page for the client itself along with its javascript chat program.
- /webclientdata - this url is called by the ajax chat using
POST requests (long-polling when necessary) The WebClient resource in this module will handle these requests and act as a gateway to sessions connected over the webclient.
-
class
evennia.server.portal.webclient_ajax.
LazyEncoder
(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]¶ Bases:
json.encoder.JSONEncoder
-
default
(obj)[source]¶ Implement this method in a subclass such that it returns a serializable object for **o**, or calls the base implementation (to raise a **TypeError**).
For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return JSONEncoder.default(self, o)
-
-
class
evennia.server.portal.webclient_ajax.
AjaxWebClient
[source]¶ Bases:
twisted.web.resource.Resource
An ajax/comet long-polling transport
-
isLeaf
= True¶
-
allowedMethods
= ('POST',)¶
-
get_client_sessid
(request)[source]¶ Helper to get the client session id out of the request.
- Parameters
request (Request) – Incoming request object.
- Returns
csessid (int) – The client-session id.
-
lineSend
(csessid, data)[source]¶ This adds the data to the buffer and/or sends it to the client as soon as possible.
- Parameters
csessid (int) – Session id.
data (list) – A send structure [cmdname, [args], {kwargs}].
-
client_disconnect
(csessid)[source]¶ Disconnect session with given csessid.
- Parameters
csessid (int) – Session id.
-
mode_init
(request)[source]¶ This is called by render_POST when the client requests an init mode operation (at startup)
- Parameters
request (Request) – Incoming request.
-
mode_keepalive
(request)[source]¶ This is called by render_POST when the client is replying to the keepalive.
-
mode_input
(request)[source]¶ This is called by render_POST when the client is sending data to the server.
- Parameters
request (Request) – Incoming request.
-
mode_receive
(request)[source]¶ This is called by render_POST when the client is telling us that it is ready to receive data as soon as it is available. This is the basis of a long-polling (comet) mechanism: the server will wait to reply until data is available.
- Parameters
request (Request) – Incoming request.
-
mode_close
(request)[source]¶ This is called by render_POST when the client is signalling that it is about to be closed.
- Parameters
request (Request) – Incoming request.
-
render_POST
(request)[source]¶ This function is what Twisted calls with POST requests coming in from the ajax client. The requests should be tagged with different modes depending on what needs to be done, such as initializing or sending/receving data through the request. It uses a long-polling mechanism to avoid sending data unless there is actual data available.
- Parameters
request (Request) – Incoming request.
-
-
class
evennia.server.portal.webclient_ajax.
AjaxWebClientSession
(*args, **kwargs)[source]¶ Bases:
evennia.server.session.Session
This represents a session running in an AjaxWebclient.
-
get_client_session
()[source]¶ Get the Client browser session (used for auto-login based on browser session)
- Returns
csession (ClientSession) –
- This is a django-specific internal representation
of the browser session.
-
disconnect
(reason='Server disconnected.')[source]¶ Disconnect from server.
- Parameters
reason (str) – Motivation for the disconnect.
-
data_out
(**kwargs)[source]¶ Data Evennia -> User
- Keyword Arguments
kwargs (any) – Options to the protocol
-
send_text
(*args, **kwargs)[source]¶ Send text data. This will pre-process the text for color-replacement, conversion to html etc.
- Parameters
text (str) – Text to send.
- Keyword Arguments
options (dict) – Options-dict with the following keys understood: - raw (bool): No parsing at all (leave ansi-to-html markers unparsed). - nocolor (bool): Remove all color. - screenreader (bool): Use Screenreader mode. - send_prompt (bool): Send a prompt with parsed html
-
send_default
(cmdname, *args, **kwargs)[source]¶ Data Evennia -> User.
- Parameters
cmdname (str) – The first argument will always be the oob cmd name.
*args (any) – Remaining args will be arguments for cmd.
- Keyword Arguments
options (dict) – These are ignored for oob commands. Use command arguments (which can hold dicts) to send instructions to the client instead.
-