Skip to content

Commit

Permalink
Set "ready" to false when the server is down
Browse files Browse the repository at this point in the history
  • Loading branch information
fatfisz committed May 23, 2020
1 parent 99a533d commit 20b423f
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions client/components/SocketContext.tsx
Expand Up @@ -54,6 +54,7 @@ export function SocketProvider({ children }: { children: ReactNode }) {
useSocketListener(socket, 'lobby state changed', setLobbyState);
useSocketListener(socket, 'room state changed', setRoomState);
useSocketListener(socket, 'server ready', () => setReady(true));
useSocketListener(socket, 'disconnect', () => setReady(false));

const value: ContextType<typeof SocketContext> = {
currentSessionId: session.id,
Expand Down
1 change: 1 addition & 0 deletions client/validators.tsx
Expand Up @@ -43,6 +43,7 @@ export const validators: Record<
name: string(),
})
),
disconnect: getValidator(string()),
};

function getValidator(...schemas: any[]) {
Expand Down
2 changes: 2 additions & 0 deletions shared/types/ServerEvents.tsx
Expand Up @@ -9,6 +9,7 @@ export interface ServerEvents {
'room state changed': [[RoomState], void];
'server ready': [[], void];
'session estabilished': [[SessionState], string];
disconnect: [[string], void];
};
received: {
'add next card': [[], void];
Expand All @@ -17,5 +18,6 @@ export interface ServerEvents {
'leave room': [[], void];
'select set': [[number[]], void];
'set name': [[string], void];
disconnect: [[string], void];
};
}
1 change: 0 additions & 1 deletion shared/types/Socket.tsx
Expand Up @@ -35,7 +35,6 @@ export interface ServerSocket<Events extends ServerEvents> {
name: EventName,
listener: Listener<ReceivedEvents<Events>[EventName]>
): RemoveListener;
on(name: 'disconnect', listener: () => void): RemoveListener;
}

export interface ClientSocket<Events extends ServerEvents> {
Expand Down

0 comments on commit 20b423f

Please sign in to comment.