This directory contains PartyKit server implementations for real-time multiplayer features.
Real-time polling system where users can create polls, vote, and see results update live.
Features:
- Create polls with multiple options
- Real-time vote updates
- One vote per user
- Poll creator can end the poll
- Connection count tracking
Client Usage:
import { PollClient } from '~/components/PollClient'
<PollClient
roomId="my-poll-room"
host="localhost:1999"
/>Demo: /demo/party/polls
Kahoot-style quiz game with real-time gameplay, scoring, and leaderboards.
Features:
- Host creates games with multiple questions
- Players join with their names
- Real-time question delivery
- Time-based scoring (faster = more points)
- Live leaderboards
- Final rankings
Host Usage:
import { KahootHost } from '~/components/KahootHost'
<KahootHost
roomId="game-xyz"
host="localhost:1999"
/>Player Usage:
import { KahootPlayer } from '~/components/KahootPlayer'
<KahootPlayer
roomId="game-xyz"
playerName="John"
host="localhost:1999"
/>Demo:
- Host:
/demo/party/kahoot-host - Player:
/demo/party/kahoot-player?room=<room-id>
- Install dependencies (already done):
bun install- Configure environment variables:
cp .env.example .env.localStart the PartyKit development server:
bunx partykit devThis will start the PartyKit server on localhost:1999.
In another terminal, start the Vite development server:
bun run devThis will start the application on localhost:3000.
- Open the polls demo at
http://localhost:3000/demo/party/polls - Open the same URL in multiple browser windows to see real-time updates
- Create a poll in one window and vote in others
For Kahoot:
- Open the host dashboard at
http://localhost:3000/demo/party/kahoot-host - Copy the player link and open it in other windows/devices
- Create questions, wait for players, and start the game
- Login to PartyKit:
bunx partykit login- Deploy your servers:
bunx partykit deploy- Update your
.envfile with the production PartyKit URL:
VITE_PARTYKIT_HOST=your-project.partykit.dev
Client Message Types:
- create_poll: Create a new poll
- vote: Submit a vote
- end_poll: End the current poll
- get_results: Request current results
Server Message Types:
- poll_created: Poll was created
- poll_updated: Poll state changed
- poll_ended: Poll was ended
- error: Error occurred
- connection_count: Number of connected users
Client Message Types (Host):
- host_create: Create a game
- host_start: Start the game
- host_next_question: Move to next question
- host_end_game: End the game
Client Message Types (Player):
- player_join: Join the game
- player_answer: Submit an answer
Server Message Types:
- game_created: Game was created
- player_joined: New player joined
- game_started: Game started
- question_started: New question
- question_ended: Question ended with results
- game_ended: Game ended with final rankings
- player_answered: A player submitted an answer
- game_state: Current game state
- error: Error occurred
Both servers use PartyKit's built-in storage:
- Polls: Stores poll data and voter list
- Kahoot: Stores game state, questions, and player data
Storage persists across server restarts within the same room.
The partykit.json file configures the available parties:
{
"parties": {
"polls": "party/polls.ts",
"kahoot": "party/kahoot.ts"
}
}Each party is accessible via its name in the PartySocket connection.