Skip to content

Commit

Permalink
Fix bugged check for live game, add console debug for users with trou…
Browse files Browse the repository at this point in the history
…ble cases.
  • Loading branch information
GreenAsJade committed Oct 18, 2023
1 parent 9e79564 commit c0f8b30
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
19 changes: 10 additions & 9 deletions src/components/NetworkStatus/NetworkStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import * as React from "react";
import * as preferences from "preferences";
import { _ } from "translate";
import { socket } from "sockets";
import { lookingAtOurLiveGame } from "TimeControl";

//interface NetworkStatusProps {}

Expand All @@ -37,14 +38,7 @@ export function NetworkStatus(): JSX.Element {
// Otherwise it's a discreet little icon
// (note: we don't check if it's their turn because it might become their turn at any time, they
// could do with knowing their internet is bad anyhow.)
const in_live_game =
typeof window !== "undefined" &&
window["global_goban"] &&
window["global_goban"].engine &&
window["global_goban"].engine.phase === "play" &&
window["global_goban"].engine.time_control !== "correspondence" &&
window["user"] &&
window["user"].id in window["global_goban"].engine.player_pool;
const in_live_game = lookingAtOurLiveGame();

React.useEffect(() => {
stateRef.current = state; // needed so we can refer to the current value in the async timer below
Expand Down Expand Up @@ -84,7 +78,14 @@ export function NetworkStatus(): JSX.Element {
}, []);

// let's leave this here - it might be handy if someone is having problems
console.log("Network status: ", state);
console.log(
"Network status: ",
state,
show_slow_internet_warning ? ": warning toggle on," : ": warning toggle off,",
in_live_game ? "in live game," : "not in live game,",
"time control:",
window["global_goban"]?.engine?.time_control,
);

if (state === "connected" || state === "went-away") {
return null;
Expand Down
6 changes: 2 additions & 4 deletions src/lib/sockets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import Debug from "debug";
import { GobanSocket, protocol, Goban, JGOFTimeControl } from "goban";
import { lookingAtOurLiveGame } from "TimeControl";

const debug = new Debug("sockets");

Expand Down Expand Up @@ -106,10 +107,7 @@ socket.on("latency", (latency, drift) => {
const goban = window["global_goban"] as Goban;
const time_control = goban.engine.time_control as JGOFTimeControl;

if (
time_control.speed !== "correspondence" &&
window["user"].id in goban.engine.player_pool
) {
if (lookingAtOurLiveGame()) {
switch (time_control.system) {
case "fischer":
timing_needed = time_control.time_increment || time_control.initial_time;
Expand Down

0 comments on commit c0f8b30

Please sign in to comment.