diff --git a/evennia/server/portal/service.py b/evennia/server/portal/service.py index 6f28b81329..048ad8ea17 100644 --- a/evennia/server/portal/service.py +++ b/evennia/server/portal/service.py @@ -191,9 +191,8 @@ class EvenniaPortalService(MultiService): webclientstr = "" if settings.WEBCLIENT_ENABLED: # create ajax client processes at /webclientdata - from evennia.server.portal import webclient_ajax - - ajax_webclient = webclient_ajax.AjaxWebClient() + ajax_class = class_from_module(settings.AJAX_CLIENT_CLASS) + ajax_webclient = ajax_class() ajax_webclient.sessionhandler = evennia.PORTAL_SESSION_HANDLER web_root.putChild(b"webclientdata", ajax_webclient) webclientstr = "webclient (ajax only)" diff --git a/evennia/server/portal/webclient_ajax.py b/evennia/server/portal/webclient_ajax.py index df900d123e..24279b3215 100644 --- a/evennia/server/portal/webclient_ajax.py +++ b/evennia/server/portal/webclient_ajax.py @@ -31,7 +31,7 @@ from evennia.server import session from evennia.utils import utils from evennia.utils.ansi import parse_ansi from evennia.utils.text2html import parse_html -from evennia.utils.utils import to_bytes, ip_from_request +from evennia.utils.utils import to_bytes, class_from_module, ip_from_request _CLIENT_SESSIONS = utils.mod_import(settings.SESSION_ENGINE).SessionStore _RE_SCREENREADER_REGEX = re.compile( @@ -70,6 +70,8 @@ class AjaxWebClient(resource.Resource): """ + client_protocol = class_from_module(settings.AJAX_PROTOCOL_CLASS) + isLeaf = True allowedMethods = ("POST",) @@ -205,7 +207,7 @@ class AjaxWebClient(resource.Resource): request.getHost().port, ) - sess = AjaxWebClientSession() + sess = self.client_protocol() sess.client = self sess.init_session("ajax/comet", remote_addr, self.sessionhandler) diff --git a/evennia/settings_default.py b/evennia/settings_default.py index 297da47a2b..76e020c418 100644 --- a/evennia/settings_default.py +++ b/evennia/settings_default.py @@ -1177,6 +1177,16 @@ SSL_PROTOCOL_CLASS = "evennia.server.portal.ssl.SSLProtocol" # for all webclient connections. WEBSOCKET_PROTOCOL_CLASS = "evennia.server.portal.webclient.WebSocketClient" +# Ajax Web Client classes. Evennia uses AJAX as a fallback for the webclient by +# default. AJAX may in general be more useful for mobile clients as it's +# resilient to IP address changes. + +# The Ajax Client Class is used to manage all AJAX sessions. +AJAX_CLIENT_CLASS = "evennia.server.webclient.ajax.AjaxWebClient" + +# Ajax Protocol Class is used for all AJAX client connections. +AJAX_PROTOCOL_CLASS = "evennia.server.webclient_ajax.AjaxWebClientSession" + # Protocol for the SSH interface. This inherits from BASE_SESSION_CLASS. SSH_PROTOCOL_CLASS = "evennia.server.portal.ssh.SshProtocol"