How ErikrafT Drop Works
ErikrafT Drop uses a hybrid approach combining WebRTC for direct peer-to-peer communication and WebSocket servers for signaling and discovery. The system is designed to work primarily on local networks while supporting remote connections through pairing.Connection Flow
1. Initial Connection
When a user opens ErikrafT Drop in their browser:- WebSocket Connection: The client connects to the signaling server via WebSocket
- Device Identification: A unique peer ID is generated and stored in sessionStorage
- Network Detection: The server identifies the client’s IP address for local network grouping
- WebRTC Capability Check: The browser’s WebRTC support is detected and reported
2. Device Discovery
Devices discover each other through multiple mechanisms:Local Network Discovery
- Devices on the same IP address are automatically grouped together by the server
- The server maintains rooms based on IP addresses (
_rooms[roomId]) - When a device connects, it receives a list of peers already in its IP-based room
- New connections trigger
peer-joinedevents for existing devices
Device Pairing
- Paired devices use encrypted 256-character room secrets stored in IndexedDB
- Room secrets are persisted across browser sessions using the PersistentStorage class
- The server matches devices with identical room secrets regardless of IP address
- Paired devices remain discoverable even when on different networks
3. WebRTC Connection Process
Signaling Phase
- Offer Creation: The initiating peer creates a WebRTC offer using
RTCPeerConnection.createOffer() - Signal Relay: The offer is sent through the WebSocket server to the target peer
- Answer Creation: The receiving peer creates an answer using
RTCPeerConnection.createAnswer() - ICE Exchange: Both peers exchange ICE candidates for network path discovery
- Connection Establishment: WebRTC establishes a direct connection when possible
DataChannel Setup
File Transfer Process
1. Transfer Request
When files are selected for transfer:- File Metadata: The sender creates headers with file information (name, size, MIME type)
- Transfer Request: A
requestmessage is sent to the recipient - User Confirmation: The recipient displays a transfer request dialog
- Accept/Decline: The recipient responds with
files-transfer-response
2. File Chunking
Large files are divided into manageable chunks:- FileChunker Class: Breaks files into 64KB chunks
- Partition Management: Groups chunks into 1MB partitions for progress tracking
- Memory Management: Prevents browser memory overload with large files
3. Data Transfer
Once the transfer is accepted:- Header Transmission: File metadata is sent first
- Chunk Streaming: File chunks are sent sequentially via DataChannel
- Progress Tracking: Both sender and receiver track transfer progress
- Completion Notification:
file-transfer-completemessage confirms successful transfer
Security Architecture
WebRTC Encryption
- DTLS/SRTP: All WebRTC communications are encrypted by the browser
- Certificate Exchange: Peers exchange certificates during connection setup
- Perfect Forward Secrecy: Each session uses unique encryption keys
Server Security
- No File Storage: The server never handles file content, only signaling
- Rate Limiting: Pairing attempts are limited to prevent abuse
- IP Validation: LAN-only mode restricts connections to local networks
- Hashed IDs: Peer IDs are salted and hashed for privacy
Fallback Mechanisms
WebSocket Fallback
When WebRTC is unavailable:- Detection: The server detects WebRTC capability via
webrtc_supportedparameter - WSPeer Class: Creates WebSocket-based peer connections
- Base64 Encoding: File chunks are encoded as base64 for WebSocket transmission
- Server Relay: The WebSocket server relays all data between peers
iOS Memory Management
Special handling for iOS devices:Room Management
The server maintains different types of rooms:- IP Rooms:
roomType: 'ip'- Devices on the same local network - Secret Rooms:
roomType: 'secret'- Paired devices using room secrets - Public Rooms:
roomType: 'public-id'- Temporary rooms with 5-character codes