pikvm/pikvm#1339: Pass ICE servers to the Web UI

This commit is contained in:
Maxim Devaev 2025-02-24 19:51:43 +02:00
parent 72ef037959
commit 1cb5c11239
4 changed files with 26 additions and 6 deletions

View File

@ -96,7 +96,7 @@ depends=(
certbot
platform-io-access
raspberrypi-utils
"ustreamer>=6.31"
"ustreamer>=6.33"
# Systemd UDEV bug
"systemd>=248.3-2"

View File

@ -21,6 +21,7 @@ class _Netcfg:
nat_type: StunNatType = dataclasses.field(default=StunNatType.ERROR)
src_ip: str = dataclasses.field(default="")
ext_ip: str = dataclasses.field(default="")
stun_host: str = dataclasses.field(default="")
stun_ip: str = dataclasses.field(default="")
stun_port: int = dataclasses.field(default=0)
@ -172,7 +173,10 @@ class JanusRunner: # pylint: disable=too-many-instance-attributes
part.format(**placeholders)
for part in cmd
]
self.__janus_proc = await aioproc.run_process(cmd)
self.__janus_proc = await aioproc.run_process(
cmd=cmd,
env={"JANUS_USTREAMER_WEB_ICE_URL": f"stun:{netcfg.stun_host}:{netcfg.stun_port}"},
)
get_logger(0).info("Started Janus pid=%d: %s", self.__janus_proc.pid, tools.cmdfmt(cmd))
async def __kill_janus_proc(self) -> None:

View File

@ -30,6 +30,7 @@ class StunInfo:
nat_type: StunNatType
src_ip: str
ext_ip: str
stun_host: str
stun_ip: str
stun_port: int
@ -102,6 +103,7 @@ class Stun:
nat_type=nat_type,
src_ip=src_ip,
ext_ip=ext_ip,
stun_host=self.__host,
stun_ip=self.__stun_ip,
stun_port=self.__port,
)

View File

@ -49,6 +49,8 @@ export function JanusStreamer(__setActive, __setInactive, __setInfo, __orient, _
var __state = null;
var __frames = 0;
var __ice = null;
/************************************************************************/
self.getOrientation = () => __orient;
@ -99,6 +101,7 @@ export function JanusStreamer(__setActive, __setInactive, __setInfo, __orient, _
"server": tools.makeWsUrl("janus/ws"),
"ipv6": true,
"destroyOnUnload": false,
"iceServers": () => __getIceServers(),
"success": __attachJanus,
"error": function(error) {
__logError(error);
@ -109,6 +112,15 @@ export function JanusStreamer(__setActive, __setInactive, __setInfo, __orient, _
}
};
var __getIceServers = function() {
if (__ice !== null && __ice.url) {
__logInfo("Using the custom ICE Server got from uStreamer:", __ice);
return [{"urls": __ice.url}];
} else {
return [];
}
};
var __finishJanus = function() {
if (__stop) {
if (__retry_ensure_timeout !== null) {
@ -201,7 +213,8 @@ export function JanusStreamer(__setActive, __setInactive, __setInfo, __orient, _
"success": function(handle) {
__handle = handle;
__logInfo("uStreamer attached:", handle.getPlugin(), handle.getId());
__sendWatch();
__logInfo("Sending FEATURES ...");
__handle.send({"message": {"request": "features"}});
},
"error": function(error) {
@ -232,7 +245,7 @@ export function JanusStreamer(__setActive, __setInactive, __setInfo, __orient, _
__stopRetryEmsgInterval();
if (msg.result) {
__logInfo("Got uStreamer result message:", msg.result.status); // starting, started, stopped
__logInfo("Got uStreamer result message:", msg.result); // starting, started, stopped
if (msg.result.status === "started") {
__setActive();
__setInfo(false, false, "");
@ -242,6 +255,8 @@ export function JanusStreamer(__setActive, __setInactive, __setInfo, __orient, _
} else if (msg.result.status === "features") {
tools.feature.setEnabled($("stream-audio"), msg.result.features.audio);
tools.feature.setEnabled($("stream-mic"), msg.result.features.mic);
__ice = msg.result.features.ice;
__sendWatch();
}
} else if (msg.error_code || msg.error) {
__logError("Got uStreamer error message:", msg.error_code, "-", msg.error);
@ -367,8 +382,7 @@ export function JanusStreamer(__setActive, __setInactive, __setInfo, __orient, _
var __sendWatch = function() {
if (__handle) {
__logInfo(`Sending WATCH(orient=${__orient}, audio=${__allow_audio}, mic=${__allow_mic}) + FEATURES ...`);
__handle.send({"message": {"request": "features"}});
__logInfo(`Sending WATCH(orient=${__orient}, audio=${__allow_audio}, mic=${__allow_mic}) ...`);
__handle.send({"message": {"request": "watch", "params": {
"orientation": __orient,
"audio": __allow_audio,