-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Overview
Create a JavaScript-based prototype demonstrating Mesh v2 client integration. This prototype serves as a reference implementation for Phase 3 frontend work in smalruby3-gui.
Related Issues:
- Phase 3: Mesh v2拡張機能ブロックの実装 smalruby3-gui#453 (Phase 3: Mesh v2 Frontend Extension)
- EPIC: Mesh v2 拡張機能の実装 smalruby3-gui#444 (EPIC: Mesh v2 Extension Implementation)
Purpose
Provide a working example of Mesh v2 client implementation using vanilla JavaScript (not TypeScript) to match Smalruby's technology stack and validate the backend API design before full GUI integration.
Technical Requirements
Technology Stack
- Client: Vanilla JavaScript (ES6+)
- GraphQL Client: Apollo Client or AWS Amplify
- UI: Simple HTML/CSS web page
- Server: Node.js/Express for static file serving
- No build tools: Direct browser execution
Directory Structure
mesh-v2/
├── examples/
│ └── javascript-client/
│ ├── index.html # Main web page
│ ├── mesh-client.js # Mesh v2 client library
│ ├── app.js # Application logic
│ ├── server.js # Simple Express server
│ ├── package.json # Dependencies
│ └── README.md # Usage instructions
Features to Implement
1. Domain Management
- Parse `?mesh=domain` URL parameter (max 256 characters)
- Support no-domain mode (backend uses sourceIp auto-detection)
- Display current domain in UI
- Domain input field for manual override
2. Group Operations
-
Create Group
- Input: group name
- Option: specify domain or use auto-detected sourceIp
- Display created groupId and fullId (id@domain)
- Show host status indicator
-
List Groups
- Query groups by current domain
- Display: groupId, name, hostId
- Refresh button for manual updates
-
Join Group
- Select from listed groups
- Input: nodeId and node name
- Show success/error messages
- Display joined group info
-
Dissolve Group
- Exit current group
- Handle host exit (group dissolution)
- Clear UI state
-
Role Display
- Show if current node is host or member
- Visual indicator for host privileges
3. Sensor Data Transmission
-
Set Sensor Values
- UI controls for multiple sensors (e.g., sliders, inputs)
- Sensor types: temperature, brightness, distance, etc.
- Display current values
-
Change Detection
- Only transmit when sensor values change
- Local state tracking
- Visual indicator when data is sent
-
Rate Limiting
- Maximum 4 sends per second (250ms intervals)
- Queue system for rapid changes
- Display rate limit status
-
Display Other Nodes' Data
- Subscribe to sensor updates in group
- Real-time display of other nodes' sensors
- Show nodeId for each data source
- Update timestamps
4. Event System
-
Send Events
- Event name input
- Payload input (JSON or text)
- Send button
- Rate limiting: max 2 events/sec (500ms intervals)
- Send confirmation feedback
-
Receive Events
- Subscribe to group events via WebSocket
- Display event history (last 20 events)
- Show: event name, payload, sender nodeId, timestamp
- Auto-scroll to latest
-
Event Queue Management
- Handle rapid event sends with queuing
- Visual queue status
5. Connection & Session Management
-
API Configuration
- AppSync endpoint URL input (or from config)
- API Key input (or from config)
- Save to localStorage for convenience
-
Connection Status
- WebSocket connection indicator (connected/disconnected)
- Auto-reconnect on connection loss
- Display connection errors
-
90-Minute Session Limit
- Track session duration
- Display remaining time
- Auto-logout warning at 85 minutes
- Automatic group exit on timeout
6. User Interface
-
Layout Sections
+------------------+------------------+ | Configuration | Connection Status| +------------------+------------------+ | Group Management | Current Group | +------------------+------------------+ | Sensor Data | Other Nodes Data | +------------------+------------------+ | Event Send | Event History | +------------------+------------------+ -
Responsive Design
- Works on desktop browsers
- Clear visual hierarchy
- Error message display areas
-
Real-Time Updates
- WebSocket subscription for sensor data
- WebSocket subscription for events
- WebSocket subscription for group dissolution
Implementation Plan
Phase 1: Basic Setup (Day 1)
- Create directory structure
- Set up Express server
- Create basic HTML page
- Configure GraphQL client (Apollo/Amplify)
- Test connection to staging AppSync API
Phase 2: Group Management (Day 2)
- Implement createGroup mutation
- Implement listGroupsByDomain query
- Implement joinGroup mutation (when available in backend)
- Implement dissolveGroup mutation (when available in backend)
- Add UI for group operations
Phase 3: Sensor Data (Day 3)
- Implement reportDataByNode mutation
- Add sensor value inputs (3-5 sample sensors)
- Implement change detection logic
- Add rate limiting (250ms throttle)
- Subscribe to onDataUpdateInGroup
- Display other nodes' sensor data
Phase 4: Events (Day 4)
- Implement fireEventByNode mutation
- Add event send UI
- Implement rate limiting (500ms throttle)
- Subscribe to onEventInGroup
- Display event history
Phase 5: Polish (Day 5)
- Add 90-minute session timer
- Improve error handling
- Add connection status indicators
- Write README documentation
- Test all features end-to-end
Testing Checklist
Domain Handling
- URL parameter `?mesh=testdomain` works
- No parameter uses sourceIp auto-detection
- 256-character domain limit enforced
- Domain persists across page refreshes
Group Operations
- Create group with custom domain
- Create group with auto-detected domain (sourceIp)
- List shows all groups in current domain
- Join group from list
- Dissolve Group as host
Sensor Data
- Sensor changes trigger transmission
- Unchanged sensors don't send data
- Rate limit (4/sec) prevents flooding
- Other nodes' data appears in real-time
- WebSocket subscription updates immediately
Events
- Events send successfully
- Rate limit (2/sec) enforced
- Events received via subscription
- Event history displays correctly
- Payload JSON parsing works
Session Management
- 90-minute timer counts down
- Warning at 85 minutes
- Auto-logout at 90 minutes
- Reconnection after disconnect
Success Criteria
- ✅ Two browser windows can communicate via Mesh v2
- ✅ All CRUD operations for groups work
- ✅ Sensor data updates appear in real-time
- ✅ Events transmit between nodes
- ✅ Rate limits prevent API abuse
- ✅ Code is simple and readable (reference quality)
- ✅ README provides clear usage instructions
Documentation Requirements
README.md
- Installation instructions
- Configuration (AppSync endpoint, API key)
- How to run the server
- How to use the web interface
- Architecture overview
- Code structure explanation
Code Comments
- Explain GraphQL queries/mutations/subscriptions
- Document rate limiting logic
- Clarify change detection algorithm
- Note any Smalruby-specific considerations
Deliverables
- Working JavaScript client in `examples/javascript-client/`
- Simple Express server for file serving
- Comprehensive README.md
- All features tested and working
- Screenshots or demo video (optional)
Notes
- Keep code simple - this is a reference implementation
- Prioritize clarity over optimization
- Use modern JavaScript (ES6+) but avoid complex frameworks
- GraphQL subscriptions should use WebSocket protocol
- Consider localStorage for saving API configuration
🤖 Generated with Claude Code
Co-Authored-By: Claude Sonnet 4.5 noreply@anthropic.com