This repository contains a minimal WebSocket server and a SwiftUI iOS app that lets users add coins to a jar. When a user taps the jar, the global coin count is updated on the server and broadcast to all connected clients in real-time.
Contents
server/— Node.js WebSocket server and a static test client (index.html).ios/JarApp/— SwiftUI app source files (drop into Xcode project).
Quick start (server)
- Open a terminal and navigate to
server/.
cd server
npm install
npm start- Open http://localhost:8080 in multiple browser tabs to test live sync.
Topic support
- When adding a coin you can optionally include a short topic description. The server records topics and counts how many times each was added.
- As you type a topic in the browser test client it will request suggestions from the server based on past recorded topics (fuzzy matching). You can pick a suggested topic to reuse it.
- The server persists topics to
server/state.jsonso counts survive restarts.
Testing on iOS device or simulator
- The SwiftUI app connects to
ws://localhost:8080by default. If running on a device, replacelocalhostwith your machine's LAN IP. You can do this by setting the environment variableJAR_SERVER_URLin the scheme's Run > Environment Variables, e.g.ws://192.168.1.5:8080. - Open the
ios/JarAppfolder in Xcode and create a new SwiftUI app project, then addJarApp.swift,ContentView.swift, andNetworkManager.swiftinto the project.
Notes & next steps
- Add an image asset named
jarand replace the placeholder withImage("jar")inContentViewfor a nicer UI. - Consider adding persistent storage on the server (file or database) if you want state to survive restarts.
- For production, secure WebSocket (wss://) and authentication will be required.
How to test the topic flow
- Start the server (
npm start) and open http://localhost:8080 in two browser tabs. - In one tab, type a topic (for example "budget", "vacation plan") and click Add 1 — that topic will be recorded.
- In other tabs, try typing a similar topic and you'll see server-suggested matches; selecting one will reuse the recorded topic and increment its count.