mirror of
https://github.com/Moepchi/webspeak3.git
synced 2026-12-01 00:42:49 +08:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5e7add6dc8 | ||
|
|
983ce1e105 | ||
|
|
7d14c3409e |
No files matched your search
@@ -47,16 +47,23 @@ def xrpc(method: str, payload: dict | bytes, token: str | None = None, content_t
|
||||
return json.load(res)
|
||||
|
||||
|
||||
def fetch(url: str, retries: int = 2) -> tuple[bytes, str]:
|
||||
def fetch(url: str, attempt: int = 1) -> tuple[bytes, str]:
|
||||
req = urllib.request.Request(url, headers={"User-Agent": "webspeak3-release-announcer"})
|
||||
try:
|
||||
with urllib.request.urlopen(req, timeout=30) as res:
|
||||
return res.read(), res.headers.get_content_type()
|
||||
except urllib.error.HTTPError as err:
|
||||
if err.code != 429 or not retries: # GitHub's image service throttles bursts now and then
|
||||
# GitHub's image service throttles right after a release, often for over a minute.
|
||||
# 15+30+45+60 s stays well inside the job's 5-minute timeout.
|
||||
if err.code != 429 or attempt > 4:
|
||||
raise
|
||||
time.sleep(10)
|
||||
return fetch(url, retries - 1)
|
||||
wait = 15 * attempt
|
||||
retry_after = err.headers.get("Retry-After", "")
|
||||
if retry_after.isdigit():
|
||||
wait = min(int(retry_after), 60)
|
||||
print(f"Preview image throttled (429), retrying in {wait} s.")
|
||||
time.sleep(wait)
|
||||
return fetch(url, attempt + 1)
|
||||
|
||||
|
||||
def link_card(release: dict, text: str) -> dict:
|
||||
|
||||
@@ -1148,6 +1148,10 @@ async fn run(args: Args) -> Result<()> {
|
||||
loop {
|
||||
let mut events = con.events();
|
||||
let outcome = tokio::select! {
|
||||
// After a stall (e.g. CPU steal) the missed audio ticks fire in a burst.
|
||||
// Polling in order drains the queued packets first, otherwise a tick can
|
||||
// find an empty queue and play Opus loss concealment instead.
|
||||
biased;
|
||||
line = stdin_lines.next_line() => LoopOutcome::StdinLine(line),
|
||||
ev = events.next() => LoopOutcome::ConEvent(ev),
|
||||
_ = audio_ticker.tick() => LoopOutcome::AudioTick,
|
||||
|
||||
+16
-2
@@ -8000,14 +8000,17 @@ function AppInner() {
|
||||
// detach and run the drop handling right away.
|
||||
socket.onmessage = socket.onerror = socket.onclose = null;
|
||||
socket.close();
|
||||
logClient("warning", "Connection", `No keepalive from the gateway for ${KEEPALIVE_TIMEOUT_MS / 1000} s`);
|
||||
current().onclose();
|
||||
}, KEEPALIVE_TIMEOUT_MS);
|
||||
}
|
||||
if (event.data !== KEEPALIVE_MESSAGE) current().onmessage(event);
|
||||
};
|
||||
socket.onerror = () => current().onerror();
|
||||
socket.onclose = () => {
|
||||
socket.onclose = (event) => {
|
||||
clearTimeout(watchdog);
|
||||
// 1000/1001 are clean closes; 1006 means the link died without a close frame.
|
||||
logClient("info", "Connection", `Gateway connection closed (code ${event.code ?? "?"})`);
|
||||
current().onclose();
|
||||
};
|
||||
};
|
||||
@@ -8113,7 +8116,7 @@ function AppInner() {
|
||||
// network blip, or the page coming back from being backgrounded/suspended
|
||||
// — without disturbing which tab is active or losing chat/scroll history.
|
||||
const reconnectSession = (sessionId: string) => {
|
||||
const params = sessionParamsRef.current.get(sessionId);
|
||||
let params = sessionParamsRef.current.get(sessionId);
|
||||
const rec = sessionsRef.current.get(sessionId);
|
||||
if (!params || !rec) return;
|
||||
// Already open or mid-(re)connect — nothing to do.
|
||||
@@ -8121,6 +8124,17 @@ function AppInner() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Come back in the channel we were in, like the native client does. Kept
|
||||
// in the params so a failed attempt (empty client list) still aims there.
|
||||
const isActive = sessionId === activeSessionIdRef.current;
|
||||
const state = isActive ? { clients, ownClientId } : rec.parked;
|
||||
const lastChannel = state?.clients.find((c) => c.id === state.ownClientId)?.channel;
|
||||
if (lastChannel) {
|
||||
const cachedPassword = isActive ? channelPasswordCacheRef.current.get(lastChannel) : undefined;
|
||||
params = { ...params, defaultChannel: `/${lastChannel}`, channelPassword: cachedPassword ?? params.channelPassword };
|
||||
sessionParamsRef.current.set(sessionId, params);
|
||||
}
|
||||
|
||||
logClient("info", "Connection", `Reconnecting to ${params.host}…`);
|
||||
const socket = DEMO_MODE ? new DemoSocket() : new WebSocket(GATEWAY_URL);
|
||||
rec.socket = socket;
|
||||
|
||||
Reference in new issue
Block a user