@beta-gamer/react 0.1.11 → 0.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -2
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/index.mjs +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -68,7 +68,7 @@ export default function GamePage({ sessionToken }: { sessionToken: string }) {
|
|
|
68
68
|
|
|
69
69
|
| Component | Props | Description |
|
|
70
70
|
|-----------|-------|-------------|
|
|
71
|
-
| `BetaGamerProvider` | `token`, `serverUrl?` | Wrap your game UI with this. Handles socket connection and theme. |
|
|
71
|
+
| `BetaGamerProvider` | `token`, `serverUrl?`, `connectSocket?` | Wrap your game UI with this. Handles socket connection and theme. |
|
|
72
72
|
| `PlayerCard` | `player` (`"self"` \| `"opponent"`), `className?` | Player name + active-turn indicator |
|
|
73
73
|
| `Timer` | `player`, `initialSeconds?`, `className?` | Live countdown clock, syncs with server |
|
|
74
74
|
|
|
@@ -91,7 +91,19 @@ export default function GamePage({ sessionToken }: { sessionToken: string }) {
|
|
|
91
91
|
|
|
92
92
|
> **`showAfkWarning`** (default `true`) — set to `false` to hide the built-in AFK countdown banner and implement your own using the `{game}:afk_warning` / `{game}:afk_warning_cleared` socket events.
|
|
93
93
|
|
|
94
|
-
|
|
94
|
+
> **`connectSocket`** (default `true`) — set to `false` when using only board components (`ChessBoard`, `CheckersBoard`, etc.). Board components load the game inside an iframe which manages its own socket connection. Creating a second socket with the same token causes duplicate connections and AFK/turn bugs.
|
|
95
|
+
|
|
96
|
+
```tsx
|
|
97
|
+
// Using only board components — disable the outer socket
|
|
98
|
+
<BetaGamerProvider token={token} connectSocket={false}>
|
|
99
|
+
<ChessBoard className="board" />
|
|
100
|
+
</BetaGamerProvider>
|
|
101
|
+
|
|
102
|
+
// Using hooks (useSocket, useGameState) — keep socket enabled (default)
|
|
103
|
+
<BetaGamerProvider token={token}>
|
|
104
|
+
<MyCustomChessUI />
|
|
105
|
+
</BetaGamerProvider>
|
|
106
|
+
```
|
|
95
107
|
|
|
96
108
|
```tsx
|
|
97
109
|
import { useGameState, useSession, useSocket, useTheme } from '@beta-gamer/react';
|
package/dist/index.d.mts
CHANGED
|
@@ -51,9 +51,10 @@ interface BetaGamerProviderProps {
|
|
|
51
51
|
token: string;
|
|
52
52
|
serverUrl?: string;
|
|
53
53
|
socketPath?: string;
|
|
54
|
+
connectSocket?: boolean;
|
|
54
55
|
children: React.ReactNode;
|
|
55
56
|
}
|
|
56
|
-
declare function BetaGamerProvider({ token, serverUrl, socketPath, children }: BetaGamerProviderProps): react_jsx_runtime.JSX.Element;
|
|
57
|
+
declare function BetaGamerProvider({ token, serverUrl, socketPath, connectSocket, children }: BetaGamerProviderProps): react_jsx_runtime.JSX.Element;
|
|
57
58
|
declare function useBetaGamer(): BetaGamerContextValue;
|
|
58
59
|
|
|
59
60
|
/** Returns the current game state (status, players, winner, etc.) */
|
package/dist/index.d.ts
CHANGED
|
@@ -51,9 +51,10 @@ interface BetaGamerProviderProps {
|
|
|
51
51
|
token: string;
|
|
52
52
|
serverUrl?: string;
|
|
53
53
|
socketPath?: string;
|
|
54
|
+
connectSocket?: boolean;
|
|
54
55
|
children: React.ReactNode;
|
|
55
56
|
}
|
|
56
|
-
declare function BetaGamerProvider({ token, serverUrl, socketPath, children }: BetaGamerProviderProps): react_jsx_runtime.JSX.Element;
|
|
57
|
+
declare function BetaGamerProvider({ token, serverUrl, socketPath, connectSocket, children }: BetaGamerProviderProps): react_jsx_runtime.JSX.Element;
|
|
57
58
|
declare function useBetaGamer(): BetaGamerContextValue;
|
|
58
59
|
|
|
59
60
|
/** Returns the current game state (status, players, winner, etc.) */
|
package/dist/index.js
CHANGED
|
@@ -56,7 +56,7 @@ function decodeToken(token) {
|
|
|
56
56
|
return JSON.parse(atob(parts[1].replace(/-/g, "+").replace(/_/g, "/")));
|
|
57
57
|
}
|
|
58
58
|
var BetaGamerContext = (0, import_react.createContext)(null);
|
|
59
|
-
function BetaGamerProvider({ token, serverUrl = "https://api.beta-gamer.com", socketPath = "/socket.io", children }) {
|
|
59
|
+
function BetaGamerProvider({ token, serverUrl = "https://api.beta-gamer.com", socketPath = "/socket.io", connectSocket = true, children }) {
|
|
60
60
|
const session = decodeToken(token);
|
|
61
61
|
const [socket, setSocket] = (0, import_react.useState)(null);
|
|
62
62
|
const [gameState, setGameState] = (0, import_react.useState)({
|
|
@@ -64,6 +64,7 @@ function BetaGamerProvider({ token, serverUrl = "https://api.beta-gamer.com", so
|
|
|
64
64
|
players: session.players
|
|
65
65
|
});
|
|
66
66
|
(0, import_react.useEffect)(() => {
|
|
67
|
+
if (!connectSocket) return;
|
|
67
68
|
const s = (0, import_socket.io)(`${serverUrl}/${session.game}`, {
|
|
68
69
|
auth: { token },
|
|
69
70
|
path: socketPath,
|
package/dist/index.mjs
CHANGED
|
@@ -13,7 +13,7 @@ function decodeToken(token) {
|
|
|
13
13
|
return JSON.parse(atob(parts[1].replace(/-/g, "+").replace(/_/g, "/")));
|
|
14
14
|
}
|
|
15
15
|
var BetaGamerContext = createContext(null);
|
|
16
|
-
function BetaGamerProvider({ token, serverUrl = "https://api.beta-gamer.com", socketPath = "/socket.io", children }) {
|
|
16
|
+
function BetaGamerProvider({ token, serverUrl = "https://api.beta-gamer.com", socketPath = "/socket.io", connectSocket = true, children }) {
|
|
17
17
|
const session = decodeToken(token);
|
|
18
18
|
const [socket, setSocket] = useState(null);
|
|
19
19
|
const [gameState, setGameState] = useState({
|
|
@@ -21,6 +21,7 @@ function BetaGamerProvider({ token, serverUrl = "https://api.beta-gamer.com", so
|
|
|
21
21
|
players: session.players
|
|
22
22
|
});
|
|
23
23
|
useEffect(() => {
|
|
24
|
+
if (!connectSocket) return;
|
|
24
25
|
const s = io(`${serverUrl}/${session.game}`, {
|
|
25
26
|
auth: { token },
|
|
26
27
|
path: socketPath,
|