Implemented Synapse Ping as heartbeat for connection between synapse and RMASS Bridge. Also implemented set online action to update RMASS presence

This commit is contained in:
Lyncoln
2026-10-30 17:19:03 -04:00
parent b3094f75a9
commit 2c2a41fafb
5 changed files with 122 additions and 76 deletions
+69 -56
View File
@@ -8,90 +8,103 @@ from .dispatcher import dispatchRequest
from .createresponse import buildResponse
from plugins.rmass.listeners import synapselistener
from core.server.createlistener import buildListener
#from plugins.rmass.actions import pingsynapse
from plugins.rmass.actions import synapsesetbridgeonline
port = int(os.environ.get("SERVER_PORT", 19001))
class RequestHandler(BaseHTTPRequestHandler):
def do_POST(self):
#lifecycles = {}
print("POST request received")
if self.path == "/_matrix/app/v1/ping":
max_request_size = 1024
from core.execution.createthread import buildThread
thread = buildThread(synapsesetbridgeonline)
content_length = self.headers.get("Content-Length")
# Check whether Content-Length exists
if content_length is None:
response = {
"status": "error",
"message": "Content length required"
}
status = 411
self.send_response(200)
self.send_header("Content-Type", "application/json")
self.send_header("Content-Length", "2")
self.end_headers()
self.wfile.write(b"{}")
return
else:
# Attempt to convert the header into an integer
try:
length = int(content_length)
except ValueError:
length = None
#lifecycles = {}
print("POST request received")
# Validate the converted length
if length is None:
max_request_size = 1024
content_length = self.headers.get("Content-Length")
# Check whether Content-Length exists
if content_length is None:
response = {
"status": "error",
"message": "Invalid Content-Length"
"message": "Content length required"
}
status = 400
elif length < 0:
response = {
"status": "error",
"message": "Bad Request"
}
status = 400
elif length > max_request_size:
response = {
"status": "error",
"message": "Content exceeds maximum request size"
}
status = 413
status = 411
else:
# Content-Length is valid, so read the body
data = self.rfile.read(length)
# Attempt to convert the header into an integer
try:
request = json.loads(data)
length = int(content_length)
except ValueError:
length = None
except json.JSONDecodeError:
# Validate the converted length
if length is None:
response = {
"status": "error",
"message": "Invalid JSON received"
"message": "Invalid Content-Length"
}
status = 400
elif length < 0:
response = {
"status": "error",
"message": "Bad Request"
}
status = 400
elif length > max_request_size:
response = {
"status": "error",
"message": "Content exceeds maximum request size"
}
status = 413
else:
# Only valid JSON reaches the dispatcher
thread, lifecycles, module, mode = dispatchRequest(
request, lifecycles
)
# Content-Length is valid, so read the body
data = self.rfile.read(length)
response = buildResponse(module, thread, mode)
status = 200
try:
request = json.loads(data)
# Serialize the response
responsebytes = json.dumps(response).encode("utf-8")
except json.JSONDecodeError:
response = {
"status": "error",
"message": "Invalid JSON received"
}
status = 400
# Send one HTTP response
self.send_response(status)
self.send_header("Content-Type", "application/json")
self.send_header("Content-Length", str(len(responsebytes)))
self.end_headers()
else:
# Only valid JSON reaches the dispatcher
thread, lifecycles, module, mode = dispatchRequest(
request, lifecycles
)
self.wfile.write(responsebytes)
response = buildResponse(module, thread, mode)
status = 200
# Serialize the response
responsebytes = json.dumps(response).encode("utf-8")
# Send one HTTP response
self.send_response(status)
self.send_header("Content-Type", "application/json")
self.send_header("Content-Length", str(len(responsebytes)))
self.end_headers()
self.wfile.write(responsebytes)
def do_PUT(self):