Skip to content

Commit

Permalink
Add connection_quality setting (hidden for now)
Browse files Browse the repository at this point in the history
  • Loading branch information
DevilXD committed Aug 16, 2023
1 parent 643a9f9 commit d5410b2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class SettingsFile(TypedDict):
priority: list[str]
priority_only: bool
autostart_tray: bool
connection_quality: int
tray_notifications: bool


Expand All @@ -29,6 +30,7 @@ class SettingsFile(TypedDict):
"autostart": False,
"priority_only": True,
"autostart_tray": False,
"connection_quality": 1,
"language": DEFAULT_LANG,
"tray_notifications": True,
}
Expand All @@ -51,6 +53,7 @@ class Settings:
priority: list[str]
priority_only: bool
autostart_tray: bool
connection_quality: int
tray_notifications: bool

PASSTHROUGH = ("_settings", "_args", "_altered")
Expand Down
13 changes: 12 additions & 1 deletion twitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,13 +648,24 @@ async def get_session(self) -> aiohttp.ClientSession:
# if loading in the cookies file ends up in an error, just ignore it
# clear the jar, just in case
cookie_jar.clear()
# create timeouts
# connection quality mulitiplier determines the magnitude of timeouts
connection_quality = self.settings.connection_quality
if connection_quality < 1:
connection_quality = self.settings.connection_quality = 1
elif connection_quality > 6:
connection_quality = self.settings.connection_quality = 6
timeout = aiohttp.ClientTimeout(
sock_connect=5*connection_quality,
total=10*connection_quality,
)
# create session, limited to 50 connections at maximum
connector = aiohttp.TCPConnector(limit=50)
self._session = aiohttp.ClientSession(
timeout=timeout,
connector=connector,
cookie_jar=cookie_jar,
headers={"User-Agent": USER_AGENT},
timeout=aiohttp.ClientTimeout(connect=5, total=10),
)
return self._session

Expand Down

0 comments on commit d5410b2

Please sign in to comment.