Skip to content

Commit 7ebc13b

Browse files
feat: mvp demo
1 parent f6339c5 commit 7ebc13b

File tree

8 files changed

+2670
-2
lines changed

8 files changed

+2670
-2
lines changed

.env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Server Configuration
2+
PORT=3000
3+
4+
# Admin password for display/control page
5+
ADMIN_PASSWORD=admin123

README.md

Lines changed: 160 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,160 @@
1-
# 2026-lightning-talk
1+
# 🎈 Ball Drop - Real-Time Interactive Application
2+
3+
A real-time interactive ball drop application featuring physics simulation with Matter.js, WebSocket communication, and Gravatar integration.
4+
5+
## Features
6+
7+
### 🖥️ Admin Display Page
8+
- **Secure Login**: Fixed password authentication for admin access
9+
- **Physics Engine**: Real-time 2D physics simulation using Matter.js
10+
- **Customizable Physics**: Adjust gravity and elasticity in real-time
11+
- **Ball Visualization**: Profile images from Gravatar as falling balls with various colors
12+
- **Countdown Timer**: Set and display countdown with automatic start/stop
13+
- **Manual Controls**: Start/stop ball dropping manually
14+
- **Reset Function**: Remove floor to make all balls fall off screen
15+
16+
### 👥 User Page
17+
- **Email Entry**: Users enter their email address
18+
- **Gravatar Preview**: Automatic avatar display for confirmation
19+
- **Waiting Room**: Hold screen until game starts
20+
- **Timer Display**: Real-time countdown when active
21+
- **Drop Button**: Interactive button to drop balls (appears during active period)
22+
- **Rate Limiting**: Maximum one ball per second per user
23+
- **Color Selection**: Choose from 8 vibrant colors for your ball
24+
25+
### 🔧 Server Features
26+
- **WebSocket Rooms**: Separate rooms for display, controllers, and users
27+
- **Rate Limiting**: Server-side enforcement of 1 ball per second per user
28+
- **Payload Validation**: Size limits and data validation
29+
- **Room Filtering**: Messages sent only to relevant rooms
30+
- **Security**: Password protection and input sanitization
31+
32+
## Installation
33+
34+
```bash
35+
# Install dependencies
36+
pnpm install
37+
38+
# Start the server
39+
pnpm start
40+
```
41+
42+
The server will run on `http://localhost:3000` by default.
43+
44+
## Usage
45+
46+
### Environment Variables
47+
48+
```bash
49+
PORT=3000 # Server port (default: 3000)
50+
ADMIN_PASSWORD=admin123 # Admin password (default: admin123)
51+
```
52+
53+
### Accessing the Application
54+
55+
1. **Admin/Display Screen**: Open `http://localhost:3000/admin.html`
56+
- Login with the admin password
57+
- Control physics settings, countdown timer, and game state
58+
- View all balls dropping in real-time
59+
60+
2. **User Screen**: Open `http://localhost:3000/` or `http://localhost:3000/index.html`
61+
- Enter your email address
62+
- Confirm your Gravatar avatar
63+
- Wait for the game to start
64+
- Drop balls when the button appears
65+
66+
### Typical Flow
67+
68+
1. Admin opens the display page and logs in
69+
2. Admin sets physics parameters (gravity, elasticity)
70+
3. Admin sets countdown timer (e.g., 60 seconds)
71+
4. Admin clicks "Start Countdown"
72+
5. Admin enables "Allow Ball Dropping"
73+
6. Users join and wait for countdown
74+
7. When countdown reaches zero, users can start dropping balls
75+
8. Each user can drop one ball per second
76+
9. Admin can stop dropping at any time
77+
10. Admin can reset to clear all balls
78+
79+
## Architecture
80+
81+
### WebSocket Rooms
82+
83+
- **`display`**: Admin/display screens receive ball drop events
84+
- **`controllers`**: Admin controls room for sending commands
85+
- **`users`**: Regular users receive game state updates
86+
87+
### Rate Limiting
88+
89+
- Server enforces 1 request per second per socket
90+
- Client-side cooldown display
91+
- Prevents spam and ensures fair play
92+
93+
### Security Features
94+
95+
- Password-protected admin access
96+
- Input validation on all user data
97+
- Payload size limits (1MB max)
98+
- Email length validation
99+
- Color format validation
100+
- Room-based message filtering
101+
102+
## Technology Stack
103+
104+
- **Backend**: Node.js with Express
105+
- **WebSocket**: Socket.IO for real-time communication
106+
- **Physics**: Matter.js for 2D physics simulation
107+
- **Avatars**: Gravatar API for user profile images
108+
- **Frontend**: Vanilla JavaScript, HTML5, CSS3
109+
110+
## File Structure
111+
112+
```
113+
.
114+
├── server.js # Express + Socket.IO server
115+
├── public/
116+
│ ├── index.html # User page
117+
│ └── admin.html # Admin/display page
118+
├── package.json
119+
└── README.md
120+
```
121+
122+
## API Events
123+
124+
### Client → Server
125+
126+
- `admin:login` - Admin authentication
127+
- `user:join` - User joins with email
128+
- `user:drop` - User drops a ball
129+
- `admin:updatePhysics` - Update physics settings
130+
- `admin:toggleDropping` - Enable/disable dropping
131+
- `admin:startCountdown` - Start countdown timer
132+
- `admin:reset` - Reset world (remove floor)
133+
134+
### Server → Client
135+
136+
- `admin:authenticated` - Authentication result
137+
- `user:joined` - User successfully joined
138+
- `user:error` - Error message for user
139+
- `user:dropped` - Confirmation of ball drop
140+
- `ball:add` - New ball to display
141+
- `physics:update` - Physics settings changed
142+
- `dropping:changed` - Dropping state changed
143+
- `countdown:start` - Countdown started
144+
- `countdown:end` - Countdown ended
145+
- `world:reset` - World reset triggered
146+
147+
## Development
148+
149+
```bash
150+
# Run in development mode
151+
pnpm dev
152+
```
153+
154+
## License
155+
156+
Apache-2.0
157+
158+
## Author
159+
160+
Elvis Mao

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<meta charset="UTF-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6-
<title>Falling Balls</title>
6+
<title>Falling Balls Example</title>
77
<script src="https://cdn.jsdelivr.net/npm/matter-js@0.19.0/build/matter.min.js"></script>
88
<style>
99
html,

package.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "2026-lightning-talk",
3+
"version": "1.0.0",
4+
"description": "Real-time interactive ball drop application with Matter.js physics",
5+
"main": "server.js",
6+
"scripts": {
7+
"start": "node server.js",
8+
"dev": "node server.js",
9+
"test": "echo \"Error: no test specified\" && exit 1"
10+
},
11+
"keywords": ["websocket", "socket.io", "matter.js", "physics", "real-time"],
12+
"author": "Elvis Mao",
13+
"license": "Apache-2.0",
14+
"packageManager": "pnpm@10.21.0",
15+
"dependencies": {
16+
"express": "^5.1.0",
17+
"fastify": "^5.6.2",
18+
"matter-js": "^0.20.0",
19+
"socket.io": "^4.8.1"
20+
},
21+
"devDependencies": {
22+
"prettier": "^3.6.2"
23+
}
24+
}

0 commit comments

Comments
 (0)