@beta-gamer/react-native 0.1.22 → 0.1.23

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/dist/index.d.mts CHANGED
@@ -1,9 +1,9 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import React from 'react';
3
- import * as socket_io_client from 'socket.io-client';
4
3
  import { Socket } from 'socket.io-client';
5
4
  import * as _socket_io_component_emitter from '@socket.io/component-emitter';
6
5
  import { ViewStyle, TextStyle } from 'react-native';
6
+ import { Chess } from 'chess.js';
7
7
 
8
8
  type GameType = 'chess' | 'checkers' | 'connect4' | 'tictactoe' | 'subway-runner';
9
9
  type MatchType = 'matchmaking' | 'private' | 'bot';
@@ -63,9 +63,24 @@ declare function useGameState(): GameState;
63
63
  /** Returns the decoded session payload (game, mode, matchType, players, theme) */
64
64
  declare function useSession(): SessionTokenPayload;
65
65
  /** Returns the raw Socket.IO socket — for advanced custom event handling */
66
- declare function useSocket(): socket_io_client.Socket<_socket_io_component_emitter.DefaultEventsMap, _socket_io_component_emitter.DefaultEventsMap> | null;
66
+ declare function useSocket(): Socket<_socket_io_component_emitter.DefaultEventsMap, _socket_io_component_emitter.DefaultEventsMap> | null;
67
67
  /** Returns the active theme tokens */
68
68
  declare function useTheme(): SessionTheme;
69
+ /**
70
+ * Creates and returns a Socket.IO socket connected to the game namespace.
71
+ * Use this when connectSocket=false on the provider and you are building a custom UI.
72
+ *
73
+ * The socket is automatically disconnected when the component unmounts.
74
+ *
75
+ * @example
76
+ * const socket = useConnect();
77
+ * useEffect(() => {
78
+ * if (!socket) return;
79
+ * socket.emit('matchmaking:join', { username: 'Alex', playerId: 'user_123', wantsBot: false });
80
+ * socket.on('game:started', (d) => { ... });
81
+ * }, [socket]);
82
+ */
83
+ declare function useConnect(): Socket | null;
69
84
 
70
85
  interface PlayerCardProps {
71
86
  player: 'self' | 'opponent';
@@ -83,12 +98,58 @@ interface TimerProps {
83
98
  }
84
99
  declare function Timer({ player, initialSeconds, style, textStyle }: TimerProps): react_jsx_runtime.JSX.Element;
85
100
 
101
+ interface ChessGameState {
102
+ socket: Socket | null;
103
+ roomId: string | null;
104
+ myPlayerId: string;
105
+ myColor: 'white' | 'black';
106
+ fen: string;
107
+ currentTurn: number;
108
+ players: any[];
109
+ clocks: {
110
+ self: number;
111
+ opponent: number;
112
+ };
113
+ selected: string | null;
114
+ legalMoves: string[];
115
+ lastMove: {
116
+ from: string;
117
+ to: string;
118
+ } | null;
119
+ moveHistory: {
120
+ san: string;
121
+ }[];
122
+ promotionMove: {
123
+ from: string;
124
+ to: string;
125
+ } | null;
126
+ gameOver: boolean;
127
+ gameResult: {
128
+ winner: string | null;
129
+ reason: string;
130
+ } | null;
131
+ afkWarning: {
132
+ playerId: string;
133
+ secondsRemaining: number;
134
+ } | null;
135
+ isMyTurn: boolean;
136
+ chess: Chess;
137
+ handleSquarePress: (square: string) => void;
138
+ emitMove: (from: string, to: string, promotion?: string) => void;
139
+ setPromotionMove: (m: {
140
+ from: string;
141
+ to: string;
142
+ } | null) => void;
143
+ }
144
+ declare function useChessGame(): ChessGameState;
145
+
86
146
  interface Props$3 {
87
147
  style?: ViewStyle;
148
+ layout?: 'default' | 'board-only';
88
149
  showAfkWarning?: boolean;
89
150
  onLeave?: () => void;
90
151
  }
91
- declare function ChessBoard({ style, showAfkWarning, onLeave }: Props$3): react_jsx_runtime.JSX.Element | null;
152
+ declare function ChessBoard({ style, layout, showAfkWarning, onLeave }: Props$3): react_jsx_runtime.JSX.Element | null;
92
153
 
93
154
  interface ChessMoveHistoryProps {
94
155
  style?: ViewStyle;
@@ -97,26 +158,107 @@ interface ChessMoveHistoryProps {
97
158
  }
98
159
  declare function ChessMoveHistory({ style, rowStyle, textStyle }: ChessMoveHistoryProps): react_jsx_runtime.JSX.Element;
99
160
 
161
+ interface Piece {
162
+ player: 'red' | 'black';
163
+ type: 'man' | 'king';
164
+ }
165
+ interface Move {
166
+ from: number;
167
+ to: number;
168
+ captures?: number[];
169
+ }
170
+ interface CheckersGameState {
171
+ socket: Socket | null;
172
+ roomId: string | null;
173
+ myPlayerId: string;
174
+ myColor: 'red' | 'black';
175
+ board: Array<Piece | null>;
176
+ currentTurn: number;
177
+ players: any[];
178
+ selectedPiece: number | null;
179
+ validMoves: Move[];
180
+ gameOver: boolean;
181
+ gameResult: {
182
+ winner: string | null;
183
+ reason: string;
184
+ } | null;
185
+ afkWarning: {
186
+ playerId: string;
187
+ secondsRemaining: number;
188
+ } | null;
189
+ isMyTurn: boolean;
190
+ handleCellPress: (pos: number) => void;
191
+ }
192
+ declare function useCheckersGame(): CheckersGameState;
100
193
  interface Props$2 {
101
194
  style?: ViewStyle;
195
+ layout?: 'default' | 'board-only';
102
196
  showAfkWarning?: boolean;
103
197
  onLeave?: () => void;
104
198
  }
105
- declare function CheckersBoard({ style, showAfkWarning, onLeave }: Props$2): react_jsx_runtime.JSX.Element | null;
199
+ declare function CheckersBoard({ style, layout, showAfkWarning, onLeave }: Props$2): react_jsx_runtime.JSX.Element | null;
106
200
 
201
+ interface Connect4GameState {
202
+ socket: Socket | null;
203
+ roomId: string | null;
204
+ myPlayerId: string;
205
+ myColor: 'red' | 'yellow';
206
+ board: Array<string | null>;
207
+ currentTurn: number;
208
+ players: any[];
209
+ lastMove: number | null;
210
+ winningCells: number[] | null;
211
+ gameOver: boolean;
212
+ gameResult: {
213
+ winner: string | null;
214
+ reason: string;
215
+ } | null;
216
+ afkWarning: {
217
+ playerId: string;
218
+ secondsRemaining: number;
219
+ } | null;
220
+ isMyTurn: boolean;
221
+ handleColumnPress: (col: number) => void;
222
+ }
223
+ declare function useConnect4Game(): Connect4GameState;
107
224
  interface Props$1 {
108
225
  style?: ViewStyle;
226
+ layout?: 'default' | 'board-only';
109
227
  showAfkWarning?: boolean;
110
228
  onLeave?: () => void;
111
229
  }
112
- declare function Connect4Board({ style, showAfkWarning, onLeave }: Props$1): react_jsx_runtime.JSX.Element | null;
230
+ declare function Connect4Board({ style, layout, showAfkWarning, onLeave }: Props$1): react_jsx_runtime.JSX.Element | null;
113
231
 
232
+ type Mark = 'X' | 'O' | null;
233
+ interface TictactoeGameState {
234
+ socket: Socket | null;
235
+ roomId: string | null;
236
+ myPlayerId: string;
237
+ myMark: 'X' | 'O';
238
+ board: Mark[];
239
+ currentTurn: number;
240
+ players: any[];
241
+ winningLine: number[] | null;
242
+ gameOver: boolean;
243
+ gameResult: {
244
+ winner: string | null;
245
+ reason: string;
246
+ } | null;
247
+ afkWarning: {
248
+ playerId: string;
249
+ secondsRemaining: number;
250
+ } | null;
251
+ isMyTurn: boolean;
252
+ handleCellPress: (idx: number) => void;
253
+ }
254
+ declare function useTictactoeGame(): TictactoeGameState;
114
255
  interface Props {
115
256
  style?: ViewStyle;
257
+ layout?: 'default' | 'board-only';
116
258
  showAfkWarning?: boolean;
117
259
  onLeave?: () => void;
118
260
  }
119
- declare function TictactoeBoard({ style, showAfkWarning, onLeave }: Props): react_jsx_runtime.JSX.Element | null;
261
+ declare function TictactoeBoard({ style, layout, showAfkWarning, onLeave }: Props): react_jsx_runtime.JSX.Element | null;
120
262
 
121
263
  declare function SubwayRunnerGame({ style }: {
122
264
  style?: ViewStyle;
@@ -130,4 +272,4 @@ declare function SubwayRunnerLives({ style, lifeStyle }: {
130
272
  lifeStyle?: ViewStyle;
131
273
  }): react_jsx_runtime.JSX.Element;
132
274
 
133
- export { BetaGamerProvider, CheckersBoard, ChessBoard, ChessMoveHistory, Connect4Board, type GameState, type GameType, type MatchType, PlayerCard, type SessionMode, type SessionPlayer, type SessionStatus, type SessionTheme, type SessionTokenPayload, SubwayRunnerGame, SubwayRunnerLives, SubwayRunnerScore, TictactoeBoard, Timer, useBetaGamer, useGameState, useSession, useSocket, useTheme };
275
+ export { BetaGamerProvider, CheckersBoard, type CheckersGameState, ChessBoard, type ChessGameState, ChessMoveHistory, Connect4Board, type Connect4GameState, type GameState, type GameType, type MatchType, PlayerCard, type SessionMode, type SessionPlayer, type SessionStatus, type SessionTheme, type SessionTokenPayload, SubwayRunnerGame, SubwayRunnerLives, SubwayRunnerScore, TictactoeBoard, type TictactoeGameState, Timer, useBetaGamer, useCheckersGame, useChessGame, useConnect, useConnect4Game, useGameState, useSession, useSocket, useTheme, useTictactoeGame };
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import React from 'react';
3
- import * as socket_io_client from 'socket.io-client';
4
3
  import { Socket } from 'socket.io-client';
5
4
  import * as _socket_io_component_emitter from '@socket.io/component-emitter';
6
5
  import { ViewStyle, TextStyle } from 'react-native';
6
+ import { Chess } from 'chess.js';
7
7
 
8
8
  type GameType = 'chess' | 'checkers' | 'connect4' | 'tictactoe' | 'subway-runner';
9
9
  type MatchType = 'matchmaking' | 'private' | 'bot';
@@ -63,9 +63,24 @@ declare function useGameState(): GameState;
63
63
  /** Returns the decoded session payload (game, mode, matchType, players, theme) */
64
64
  declare function useSession(): SessionTokenPayload;
65
65
  /** Returns the raw Socket.IO socket — for advanced custom event handling */
66
- declare function useSocket(): socket_io_client.Socket<_socket_io_component_emitter.DefaultEventsMap, _socket_io_component_emitter.DefaultEventsMap> | null;
66
+ declare function useSocket(): Socket<_socket_io_component_emitter.DefaultEventsMap, _socket_io_component_emitter.DefaultEventsMap> | null;
67
67
  /** Returns the active theme tokens */
68
68
  declare function useTheme(): SessionTheme;
69
+ /**
70
+ * Creates and returns a Socket.IO socket connected to the game namespace.
71
+ * Use this when connectSocket=false on the provider and you are building a custom UI.
72
+ *
73
+ * The socket is automatically disconnected when the component unmounts.
74
+ *
75
+ * @example
76
+ * const socket = useConnect();
77
+ * useEffect(() => {
78
+ * if (!socket) return;
79
+ * socket.emit('matchmaking:join', { username: 'Alex', playerId: 'user_123', wantsBot: false });
80
+ * socket.on('game:started', (d) => { ... });
81
+ * }, [socket]);
82
+ */
83
+ declare function useConnect(): Socket | null;
69
84
 
70
85
  interface PlayerCardProps {
71
86
  player: 'self' | 'opponent';
@@ -83,12 +98,58 @@ interface TimerProps {
83
98
  }
84
99
  declare function Timer({ player, initialSeconds, style, textStyle }: TimerProps): react_jsx_runtime.JSX.Element;
85
100
 
101
+ interface ChessGameState {
102
+ socket: Socket | null;
103
+ roomId: string | null;
104
+ myPlayerId: string;
105
+ myColor: 'white' | 'black';
106
+ fen: string;
107
+ currentTurn: number;
108
+ players: any[];
109
+ clocks: {
110
+ self: number;
111
+ opponent: number;
112
+ };
113
+ selected: string | null;
114
+ legalMoves: string[];
115
+ lastMove: {
116
+ from: string;
117
+ to: string;
118
+ } | null;
119
+ moveHistory: {
120
+ san: string;
121
+ }[];
122
+ promotionMove: {
123
+ from: string;
124
+ to: string;
125
+ } | null;
126
+ gameOver: boolean;
127
+ gameResult: {
128
+ winner: string | null;
129
+ reason: string;
130
+ } | null;
131
+ afkWarning: {
132
+ playerId: string;
133
+ secondsRemaining: number;
134
+ } | null;
135
+ isMyTurn: boolean;
136
+ chess: Chess;
137
+ handleSquarePress: (square: string) => void;
138
+ emitMove: (from: string, to: string, promotion?: string) => void;
139
+ setPromotionMove: (m: {
140
+ from: string;
141
+ to: string;
142
+ } | null) => void;
143
+ }
144
+ declare function useChessGame(): ChessGameState;
145
+
86
146
  interface Props$3 {
87
147
  style?: ViewStyle;
148
+ layout?: 'default' | 'board-only';
88
149
  showAfkWarning?: boolean;
89
150
  onLeave?: () => void;
90
151
  }
91
- declare function ChessBoard({ style, showAfkWarning, onLeave }: Props$3): react_jsx_runtime.JSX.Element | null;
152
+ declare function ChessBoard({ style, layout, showAfkWarning, onLeave }: Props$3): react_jsx_runtime.JSX.Element | null;
92
153
 
93
154
  interface ChessMoveHistoryProps {
94
155
  style?: ViewStyle;
@@ -97,26 +158,107 @@ interface ChessMoveHistoryProps {
97
158
  }
98
159
  declare function ChessMoveHistory({ style, rowStyle, textStyle }: ChessMoveHistoryProps): react_jsx_runtime.JSX.Element;
99
160
 
161
+ interface Piece {
162
+ player: 'red' | 'black';
163
+ type: 'man' | 'king';
164
+ }
165
+ interface Move {
166
+ from: number;
167
+ to: number;
168
+ captures?: number[];
169
+ }
170
+ interface CheckersGameState {
171
+ socket: Socket | null;
172
+ roomId: string | null;
173
+ myPlayerId: string;
174
+ myColor: 'red' | 'black';
175
+ board: Array<Piece | null>;
176
+ currentTurn: number;
177
+ players: any[];
178
+ selectedPiece: number | null;
179
+ validMoves: Move[];
180
+ gameOver: boolean;
181
+ gameResult: {
182
+ winner: string | null;
183
+ reason: string;
184
+ } | null;
185
+ afkWarning: {
186
+ playerId: string;
187
+ secondsRemaining: number;
188
+ } | null;
189
+ isMyTurn: boolean;
190
+ handleCellPress: (pos: number) => void;
191
+ }
192
+ declare function useCheckersGame(): CheckersGameState;
100
193
  interface Props$2 {
101
194
  style?: ViewStyle;
195
+ layout?: 'default' | 'board-only';
102
196
  showAfkWarning?: boolean;
103
197
  onLeave?: () => void;
104
198
  }
105
- declare function CheckersBoard({ style, showAfkWarning, onLeave }: Props$2): react_jsx_runtime.JSX.Element | null;
199
+ declare function CheckersBoard({ style, layout, showAfkWarning, onLeave }: Props$2): react_jsx_runtime.JSX.Element | null;
106
200
 
201
+ interface Connect4GameState {
202
+ socket: Socket | null;
203
+ roomId: string | null;
204
+ myPlayerId: string;
205
+ myColor: 'red' | 'yellow';
206
+ board: Array<string | null>;
207
+ currentTurn: number;
208
+ players: any[];
209
+ lastMove: number | null;
210
+ winningCells: number[] | null;
211
+ gameOver: boolean;
212
+ gameResult: {
213
+ winner: string | null;
214
+ reason: string;
215
+ } | null;
216
+ afkWarning: {
217
+ playerId: string;
218
+ secondsRemaining: number;
219
+ } | null;
220
+ isMyTurn: boolean;
221
+ handleColumnPress: (col: number) => void;
222
+ }
223
+ declare function useConnect4Game(): Connect4GameState;
107
224
  interface Props$1 {
108
225
  style?: ViewStyle;
226
+ layout?: 'default' | 'board-only';
109
227
  showAfkWarning?: boolean;
110
228
  onLeave?: () => void;
111
229
  }
112
- declare function Connect4Board({ style, showAfkWarning, onLeave }: Props$1): react_jsx_runtime.JSX.Element | null;
230
+ declare function Connect4Board({ style, layout, showAfkWarning, onLeave }: Props$1): react_jsx_runtime.JSX.Element | null;
113
231
 
232
+ type Mark = 'X' | 'O' | null;
233
+ interface TictactoeGameState {
234
+ socket: Socket | null;
235
+ roomId: string | null;
236
+ myPlayerId: string;
237
+ myMark: 'X' | 'O';
238
+ board: Mark[];
239
+ currentTurn: number;
240
+ players: any[];
241
+ winningLine: number[] | null;
242
+ gameOver: boolean;
243
+ gameResult: {
244
+ winner: string | null;
245
+ reason: string;
246
+ } | null;
247
+ afkWarning: {
248
+ playerId: string;
249
+ secondsRemaining: number;
250
+ } | null;
251
+ isMyTurn: boolean;
252
+ handleCellPress: (idx: number) => void;
253
+ }
254
+ declare function useTictactoeGame(): TictactoeGameState;
114
255
  interface Props {
115
256
  style?: ViewStyle;
257
+ layout?: 'default' | 'board-only';
116
258
  showAfkWarning?: boolean;
117
259
  onLeave?: () => void;
118
260
  }
119
- declare function TictactoeBoard({ style, showAfkWarning, onLeave }: Props): react_jsx_runtime.JSX.Element | null;
261
+ declare function TictactoeBoard({ style, layout, showAfkWarning, onLeave }: Props): react_jsx_runtime.JSX.Element | null;
120
262
 
121
263
  declare function SubwayRunnerGame({ style }: {
122
264
  style?: ViewStyle;
@@ -130,4 +272,4 @@ declare function SubwayRunnerLives({ style, lifeStyle }: {
130
272
  lifeStyle?: ViewStyle;
131
273
  }): react_jsx_runtime.JSX.Element;
132
274
 
133
- export { BetaGamerProvider, CheckersBoard, ChessBoard, ChessMoveHistory, Connect4Board, type GameState, type GameType, type MatchType, PlayerCard, type SessionMode, type SessionPlayer, type SessionStatus, type SessionTheme, type SessionTokenPayload, SubwayRunnerGame, SubwayRunnerLives, SubwayRunnerScore, TictactoeBoard, Timer, useBetaGamer, useGameState, useSession, useSocket, useTheme };
275
+ export { BetaGamerProvider, CheckersBoard, type CheckersGameState, ChessBoard, type ChessGameState, ChessMoveHistory, Connect4Board, type Connect4GameState, type GameState, type GameType, type MatchType, PlayerCard, type SessionMode, type SessionPlayer, type SessionStatus, type SessionTheme, type SessionTokenPayload, SubwayRunnerGame, SubwayRunnerLives, SubwayRunnerScore, TictactoeBoard, type TictactoeGameState, Timer, useBetaGamer, useCheckersGame, useChessGame, useConnect, useConnect4Game, useGameState, useSession, useSocket, useTheme, useTictactoeGame };