Merge pull request #3348 from volundmush/customizable_ajax

Ajax client classes are now customizable.
This commit is contained in:
Griatch 2023-12-10 17:41:12 +01:00 committed by GitHub
commit cd5b0de5b1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 5 deletions

View file

@ -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)"

View file

@ -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)

View file

@ -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"