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:
@@ -7,14 +7,6 @@ from core.runtime.createruntime import outputs
|
|||||||
|
|
||||||
|
|
||||||
def buildListener(listener, self):
|
def buildListener(listener, self):
|
||||||
|
|
||||||
if self.path == "/_matrix/app/v1/ping":
|
|
||||||
self.send_response(200)
|
|
||||||
self.send_header("Content-Type", "application/json")
|
|
||||||
self.end_headers()
|
|
||||||
self.wfile.write(b"{}")
|
|
||||||
return
|
|
||||||
|
|
||||||
if self.path.startswith(listener.acceptpath):
|
if self.path.startswith(listener.acceptpath):
|
||||||
|
|
||||||
#Prints can used buildlog for listener runtime
|
#Prints can used buildlog for listener runtime
|
||||||
@@ -32,12 +24,13 @@ def buildListener(listener, self):
|
|||||||
allow, status_code = buildFirewall(listener, outputs)
|
allow, status_code = buildFirewall(listener, outputs)
|
||||||
|
|
||||||
if allow:
|
if allow:
|
||||||
from core.execution.createthread import buildThread
|
#from core.execution.createthread import buildThread
|
||||||
|
from core.execution.executioncontract import executeContract
|
||||||
|
|
||||||
logging.info(outputs["firewall_allowed"])
|
logging.info(outputs["firewall_allowed"])
|
||||||
|
|
||||||
thread = buildThread(listener.execute)
|
#thread = buildThread(listener.execute)
|
||||||
|
executeContract(listener.execute)
|
||||||
|
|
||||||
|
|
||||||
self.send_response(status_code)
|
self.send_response(status_code)
|
||||||
|
|||||||
+14
-1
@@ -8,13 +8,26 @@ from .dispatcher import dispatchRequest
|
|||||||
from .createresponse import buildResponse
|
from .createresponse import buildResponse
|
||||||
from plugins.rmass.listeners import synapselistener
|
from plugins.rmass.listeners import synapselistener
|
||||||
from core.server.createlistener import buildListener
|
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))
|
port = int(os.environ.get("SERVER_PORT", 19001))
|
||||||
|
|
||||||
|
|
||||||
class RequestHandler(BaseHTTPRequestHandler):
|
class RequestHandler(BaseHTTPRequestHandler):
|
||||||
def do_POST(self):
|
def do_POST(self):
|
||||||
|
if self.path == "/_matrix/app/v1/ping":
|
||||||
|
|
||||||
|
from core.execution.createthread import buildThread
|
||||||
|
thread = buildThread(synapsesetbridgeonline)
|
||||||
|
|
||||||
|
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:
|
||||||
#lifecycles = {}
|
#lifecycles = {}
|
||||||
print("POST request received")
|
print("POST request received")
|
||||||
|
|
||||||
|
|||||||
+9
-7
@@ -5,8 +5,8 @@ import os
|
|||||||
from core.server.server import startServer
|
from core.server.server import startServer
|
||||||
from core.execution.createthread import buildThread
|
from core.execution.createthread import buildThread
|
||||||
from plugins.rmass.monitors import rmassmonitor
|
from plugins.rmass.monitors import rmassmonitor
|
||||||
#from plugins.rmass.actions import refresh_tokens
|
|
||||||
from plugins.rmass.operations import token_update
|
from plugins.rmass.operations import token_update
|
||||||
|
from plugins.rmass.actions import pingsynapse
|
||||||
|
|
||||||
from core.console import console
|
from core.console import console
|
||||||
from rich.logging import RichHandler
|
from rich.logging import RichHandler
|
||||||
@@ -28,6 +28,13 @@ logging.basicConfig(
|
|||||||
import login
|
import login
|
||||||
import synapsemessagepush
|
import synapsemessagepush
|
||||||
|
|
||||||
|
thread = threading.Thread(
|
||||||
|
target=startServer,
|
||||||
|
name="RMASS Bridge Server"
|
||||||
|
)
|
||||||
|
thread.start()
|
||||||
|
|
||||||
|
pingsynapse.mode = "continuous"
|
||||||
rmassmonitor.mode = "continuous"
|
rmassmonitor.mode = "continuous"
|
||||||
token_update.mode = "continuous"
|
token_update.mode = "continuous"
|
||||||
#refresh_tokens.mode = "continuous"
|
#refresh_tokens.mode = "continuous"
|
||||||
@@ -38,9 +45,4 @@ thread = buildThread(rmassmonitor)
|
|||||||
|
|
||||||
thread = buildThread(token_update)
|
thread = buildThread(token_update)
|
||||||
|
|
||||||
thread = threading.Thread(
|
thread = buildThread(pingsynapse)
|
||||||
target=startServer,
|
|
||||||
#args=(module, lifecycles)
|
|
||||||
name="RMASS Bridge Server"
|
|
||||||
)
|
|
||||||
thread.start()
|
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
name = "Synapse Wake"
|
name = "Synapse Ping"
|
||||||
|
|
||||||
kind = "action"
|
kind = "action"
|
||||||
|
|
||||||
alias = "synapseping"
|
alias = "pingsynapse"
|
||||||
|
|
||||||
showstatus = True
|
showstatus = True
|
||||||
|
|
||||||
|
sleeptime = 15
|
||||||
|
|
||||||
isrequest = True
|
isrequest = True
|
||||||
|
|
||||||
method = "POST"
|
method = "POST"
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
name = "Set RMASS Bridge Online"
|
||||||
|
|
||||||
|
kind = "action"
|
||||||
|
|
||||||
|
alias = "setrmassbridgeonline"
|
||||||
|
|
||||||
|
showstatus = True
|
||||||
|
|
||||||
|
#sleeptime = 15
|
||||||
|
|
||||||
|
isrequest = True
|
||||||
|
|
||||||
|
method = "PUT"
|
||||||
|
|
||||||
|
path = [
|
||||||
|
"https://loxthelion.com/_matrix/client/v3/presence/@rmass_bridge:loxthelion.com/status",
|
||||||
|
]
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
"Authorization": {
|
||||||
|
"os": "AS_TOKEN",
|
||||||
|
"prefix": "Bearer ",
|
||||||
|
},
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
}
|
||||||
|
|
||||||
|
keys = [
|
||||||
|
{
|
||||||
|
"keytitle": "presence",
|
||||||
|
"keyvalue": "online",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"keytitle": "status_msg",
|
||||||
|
"keyvalue": "RMASS Bridge Connected",
|
||||||
|
},
|
||||||
|
]
|
||||||
Reference in New Issue
Block a user