
Overview
Peerbeam is a browser-based file-sharing app designed to make file transfers faster, more private, and less of a hassle compared to existing options like FTP servers or going through third-party file hosting services. Unlike conventional methods that rely on intermediary hosting services or relay servers to store and forward data, Peerbeam uses WebRTC to create a direct connection between devices.
Technologies
- Frontend: SvelteKit, TypeScript
- Backend: Node.js
- Deployment: Vercel
- Connection Protocol: WebRTC
The Problem
Most existing solutions for file transfers fall into two categories. On one hand, there’s FTP/SFTP, which are fast and reliable but not always practical. It requires network configuration and a server on the receiving side, which doesn't really work for mobile users. On the other hand, you might turn to file-hosting services or email attachments, both of which introduce upload/download delays.
Worse still, you might end up using some sketchy link-sharing site; your files could end up anywhere!
WebRTC addresses these issues by bypassing intermediaries entirely, transferring data directly between devices.
How it works
Peerbeam uses WebRTC to establish direct connections between devices. Here’s a simplified breakdown:
- Session Initialization: When you open the site, it generates a unique Peer ID for your session. This ID identifies your device for the transfer process.
- Connection Setup: Share your Peer ID via QR code or a link. The app’s signaling server (using PeerJS) helps devices exchange connection details (like IP addresses) to establish a connection.
- File Transfer: Once the connection is established, files are transferred directly between devices.
This works across most networks and devices, but some edge cases complicate things.
Challenges
WebRTC handles NAT traversal well in most cases, but when two users are both trying to connect from behind symmetric NATs, a direct connection isn’t possible. These networks tightly control how external addresses are mapped, making it necessary to use a TURN server to relay data between devices. While this means relying on a third-party server, the data remains encrypted. The relay acts as a communication layer between the two computers, enabling simultaneous uploading and downloading. This makes transfers faster than traditional file hosting, where files are first uploaded and then downloaded sequentially.
Another challenge is performance. Peerbeam-web is faster than most other web-based options the connection is direct, but browser restrictions mean it’s not as fast as dedicated tools like FTP or the CLI version of Peerbeam. The CLI app typically achieves speeds on par with FTP.
Future Plans
I plan to host a TURN server to make connections more reliable. Even though the symmetric NAT issue is an edge case, the site needs to be as easy to use as possible—otherwise, people will just keep emailing all their files. TURN servers do eat up a lot of bandwidth, but only a small percentage of users would actually need them. Also, I might have gotten a bit carried away with the site’s UI. I’m thinking it’s time to reign things in a bit.