janus: allow work without ext_ip

This commit is contained in:
Maxim Devaev 2022-11-19 23:28:09 +03:00
parent 040e0d6fdf
commit eb05fd4d3b
2 changed files with 14 additions and 6 deletions

View File

@ -723,7 +723,7 @@ def _get_config_scheme() -> dict:
"--plugins-folder=/usr/lib/ustreamer/janus",
"--configs-folder=/etc/kvmd/janus",
"--interface={src_ip}",
"--stun-server={stun_host}:{stun_port}",
"{o_stun_server}",
], type=valid_command),
"cmd_remove": Option([], type=valid_options),
"cmd_append": Option([], type=valid_options),

View File

@ -78,11 +78,11 @@ class JanusRunner: # pylint: disable=too-many-instance-attributes
if netcfg != prev_netcfg:
logger.info("Got new %s", netcfg)
if netcfg.src_ip and netcfg.ext_ip:
if netcfg.src_ip:
await self.__stop_janus()
await self.__start_janus(netcfg)
else:
logger.error("Empty src_ip or ext_ip; stopping Janus ...")
logger.error("Empty src_ip; stopping Janus ...")
await self.__stop_janus()
prev_netcfg = netcfg
@ -160,12 +160,20 @@ class JanusRunner: # pylint: disable=too-many-instance-attributes
async def __start_janus_proc(self, netcfg: _Netcfg) -> None:
assert self.__janus_proc is None
placeholders = {
key: str(value)
for (key, value) in dataclasses.asdict(netcfg).items()
"o_stun_server": f"--stun-server={netcfg.stun_host}:{netcfg.stun_port}",
**{
key: str(value)
for (key, value) in dataclasses.asdict(netcfg).items()
},
}
cmd = list(self.__cmd)
if not netcfg.ext_ip:
placeholders["o_stun_server"] = ""
while "{o_stun_server}" in cmd:
cmd.remove("{o_stun_server}")
cmd = [
part.format(**placeholders)
for part in self.__cmd
for part in cmd
]
self.__janus_proc = await aioproc.run_process(cmd)
get_logger(0).info("Started Janus pid=%d: %s", self.__janus_proc.pid, tools.cmdfmt(cmd))