A native macOS peer-to-peer chat application built with Swift, SwiftUI, and WebRTC.
The signaling server is a minimal Python WebSocket relay. It only forwards connection setup messages (SDP offers/answers and ICE candidates) — no chat messages ever pass through it.
cd signaling_server
pip install -r requirements.txt
python server.py --port 8080The server will listen on ws://localhost:8080 by default.
cd MathsChat
swift build
swift runOr build a standalone .app bundle:
cd .
bash build_app.sh
open MathsChat.app- Run the app on two Macs (or two instances on the same Mac for testing).
- On the first Mac: Enter the signaling server URL (e.g.,
ws://localhost:8080orws://YOUR_SERVER_IP:8080), choose a room code (e.g.,euler-42), enter your display name, and check "I will initiate the connection". Click Connect. - On the second Mac: Enter the same signaling server URL and room code, enter your display name, and uncheck "I will initiate the connection". Click Connect.
- Wait a few seconds for the WebRTC connection to establish (you'll see "Connected" in green).
- Start chatting! Messages are sent directly peer-to-peer with DTLS encryption.
- Signaling Server (
signaling_server/server.py): Minimal Python WebSocket relay for connection setup only. - WebRTC Client (
Sources/Networking/WebRTCClient.swift): Handles RTCPeerConnection, RTCDataChannel, ICE, and DTLS. - Signaling Client (
Sources/Networking/SignalingClient.swift): WebSocket client for exchanging SDP and ICE candidates. - Chat Engine (
Sources/Services/ChatEngine.swift): Orchestrates signaling + WebRTC + message handling. - SwiftUI Views (
Sources/Views/): Native macOS chat interface.
maths_chat/
├── spec.md # Full specification
├── README.md # This file
├── build_app.sh # Build script for .app bundle
├── signaling_server/
│ ├── server.py # Python WebSocket signaling server
│ └── requirements.txt # Python dependencies
└── MathsChat/ # Swift package
├── Package.swift
└── Sources/
├── App/ # App entry point
├── Views/ # SwiftUI views
├── Networking/ # WebRTC + Signaling clients
├── Models/ # Data models
└── Services/ # Chat engine
- Swift 5.9+
- macOS 14+
- WebRTC (via
stasel/WebRTCSPM package, v126.0.0) - Python 3.8+ (for signaling server)
- websockets Python package
- The first build may take several minutes as it downloads and compiles the WebRTC framework (~100MB).
- For testing on the same machine, run two instances of the app.
- For internet P2P, ensure the signaling server is reachable from both machines (or use a cloud VM).
- Messages are encrypted in transit via WebRTC's built-in DTLS.
- Chat history is stored locally on each machine (not yet implemented in this prototype).
- "Room is full": Only 2 peers per room. Make sure you're not trying to connect a third client.
- Connection fails: Check that the signaling server is running and reachable. Check firewall settings.
- Build errors: Ensure you have Xcode Command Line Tools installed (
xcode-select --install).