mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-13 01:30:31 +08:00
simplified streamer client
This commit is contained in:
parent
8164594b92
commit
55307fe8da
@ -26,8 +26,6 @@ from typing import Dict
|
|||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
|
||||||
from ...logging import get_logger
|
|
||||||
|
|
||||||
from ... import __version__
|
from ... import __version__
|
||||||
|
|
||||||
|
|
||||||
@ -63,10 +61,7 @@ class KvmdClient:
|
|||||||
except aiohttp.ClientResponseError as err:
|
except aiohttp.ClientResponseError as err:
|
||||||
if err.status in [401, 403]:
|
if err.status in [401, 403]:
|
||||||
return False
|
return False
|
||||||
get_logger(0).exception("Can't check user access")
|
raise
|
||||||
except Exception:
|
|
||||||
get_logger(0).exception("Can't check user access")
|
|
||||||
return False
|
|
||||||
|
|
||||||
@contextlib.asynccontextmanager
|
@contextlib.asynccontextmanager
|
||||||
async def ws(self, user: str, passwd: str) -> aiohttp.ClientWebSocketResponse: # pylint: disable=invalid-name
|
async def ws(self, user: str, passwd: str) -> aiohttp.ClientWebSocketResponse: # pylint: disable=invalid-name
|
||||||
@ -77,23 +72,17 @@ class KvmdClient:
|
|||||||
) as ws:
|
) as ws:
|
||||||
yield ws
|
yield ws
|
||||||
|
|
||||||
async def set_streamer_params(self, user: str, passwd: str, quality: int=-1, desired_fps: int=-1) -> None:
|
async def set_streamer_params(self, user: str, passwd: str, quality: int, desired_fps: int) -> None:
|
||||||
params = {
|
async with self.__make_session(user, passwd) as session:
|
||||||
key: value
|
async with session.post(
|
||||||
for (key, value) in [
|
url=f"http://{self.__host}:{self.__port}/streamer/set_params",
|
||||||
("quality", quality),
|
timeout=self.__timeout,
|
||||||
("desired_fps", desired_fps),
|
params={
|
||||||
]
|
"quality": quality,
|
||||||
if value >= 0
|
"desired_fps": desired_fps,
|
||||||
}
|
},
|
||||||
if params:
|
) as response:
|
||||||
async with self.__make_session(user, passwd) as session:
|
response.raise_for_status()
|
||||||
async with session.post(
|
|
||||||
url=f"http://{self.__host}:{self.__port}/streamer/set_params",
|
|
||||||
timeout=self.__timeout,
|
|
||||||
params=params,
|
|
||||||
) as response:
|
|
||||||
response.raise_for_status()
|
|
||||||
|
|
||||||
# =====
|
# =====
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user