Skip to content

Commit

Permalink
Add media proxy only mode
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Jul 12, 2024
1 parent ad2e2e3 commit 5f97f8c
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions heisenbridge/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ async def ensure_hidden_room(self):

return use_hidden_room

async def run(self, listen_address, listen_port, homeserver_url, owner, safe_mode):
async def run(self, listen_address, listen_port, homeserver_url, owner, safe_mode, media_proxy):
if "sender_localpart" not in self.registration:
print("Missing sender_localpart from registration file.")
sys.exit(1)
Expand Down Expand Up @@ -542,6 +542,8 @@ async def run(self, listen_address, listen_port, homeserver_url, owner, safe_mod
print(f"Heisenbridge v{__version__}", flush=True)
if safe_mode:
print("Safe mode is enabled.", flush=True)
if media_proxy:
print("Media proxy only mode.", flush=True)

url = urllib.parse.urlparse(homeserver_url)
ws = None
Expand Down Expand Up @@ -654,7 +656,9 @@ async def run(self, listen_address, listen_port, homeserver_url, owner, safe_mod
# load config from HS
await self.load()

if self.config["media_key"]:
if "heisenbridge" in self.registration and "media_key" in self.registration["heisenbridge"]:
self.media_key = self.registration["heisenbridge"]["media_key"].encode("utf-8")
elif self.config["media_key"]:
self.media_key = self.config["media_key"].encode("utf-8")
else:
self.media_key = self.registration["hs_token"].encode("utf-8")
Expand All @@ -679,6 +683,11 @@ async def run(self, listen_address, listen_port, homeserver_url, owner, safe_mod
else:
self.media_path = self.DEFAULT_MEDIA_PATH

if media_proxy:
logging.info("Media proxy mode startup complete")
await asyncio.Event().wait()
return

logging.info("Starting presence loop")
self._keepalive()

Expand Down Expand Up @@ -906,6 +915,12 @@ async def async_main():
help="reset ALL bridge configuration from homeserver and exit",
default=argparse.SUPPRESS,
)
parser.add_argument(
"--media-proxy",
action="store_true",
help="run in media proxy mode",
default=False,
)
parser.add_argument(
"--safe-mode",
action="store_true",
Expand Down Expand Up @@ -976,7 +991,7 @@ async def async_main():

service.load_reg(args.config)

if args.identd:
if args.identd and not args.media_proxy:
identd = Identd()
await identd.start_listening(service, args.identd_port)

Expand Down Expand Up @@ -1015,7 +1030,7 @@ async def async_main():
except Exception:
pass

await service.run(listen_address, listen_port, args.homeserver, args.owner, args.safe_mode)
await service.run(listen_address, listen_port, args.homeserver, args.owner, args.safe_mode, args.media_proxy)


def main():
Expand Down

0 comments on commit 5f97f8c

Please sign in to comment.