Introducing Text2 Chat - Real-time Messaging and Uncompressed File Sharing App
Here is everything you need to know about Text2 Chat's original binary (Bit-Exact) file processing mechanism and real-time transmission architecture designed to preserve raw byte data structures without degrading file quality.
1. Automatic Transcoding Mechanisms and the Original File Preservation Problem
To optimize cloud storage costs and reduce server bandwidth loads, many commercial communication platforms impose highly aggressive data compression filters. When you send an original PNG image or video file:
- Image Resizing & Lossy Transcoding: Servers automatically downscale the resolution to a standard size and force transcode it into low-quality JPEG/WebP formats, ruining the sharp edges of text, graphics, and system logs.
- Metadata Stripping: All metadata (EXIF, ICC Profile, camera info, capture device details) is stripped away, losing the original information essential for graphic design or professional image processing.
- Generation Loss on Video: 4K videos recorded from phones have their bitrates squeezed and are re-encoded into deeply compressed H.264 formats, losing motion details and causing pixelation.
This poses a major obstacle for developers who need to share clear screenshots of system logs, UI/UX Designers who want to inspect pixel-perfect interfaces, or Media Creators who wish to share high-quality RAW production files.
2. Three Original File Transmission Modes and Visual Chat Bubble Progress
Text2 Chat provides an original file transmission solution by offering three distinct file sending modes directly from the frontend interface and using an asynchronous upload handling mechanism:
⚙️ Details of the 3 Upload Modes:
- Standard Image Mode: Calls the helper function
compressImage(file)to compress images on the client side before uploading, optimizing file size and bandwidth when users only need a quick preview. - Original Image Mode: Completely bypasses the compression pipeline, supporting original image/video files at their native resolution, retaining 100% of the metadata and color profile.
- Document/File Mode: Uses a file picker input configured with
accept="*/*", allowing the transmission of any raw binary file format (zip, source code, SQL dump, RAW video).
Technically, Text2 Chat's file upload system is built around special mechanisms to optimize user experience:
- Instant Chat Bubble Display: As soon as a file is selected for sending, the app
creates a new chat bubble using
URL.createObjectURL(file)to instantly display the file (blob: image) on screen without waiting for the server upload to complete. - 200MB Max Upload Limit: The backend API strictly controls the size of uploaded
files by directly validating the byte stream of the upload:
len(file_bytes) > 200 * 1024 * 1024, ensuring system stability. - Granular Progress Tracking (Bubble-Level Progress): Uses
XMLHttpRequestwith thexhr.upload.onprogressevent to update a live progress overlay directly on the chat bubble:- Displays the actual upload size in a smooth unit format (e.g.,
15.4 MB / 45.0 MB (34%)). - Displays the exact number of bytes uploaded (e.g.,
16,148,120 / 47,185,920 B). - Provides a circular SVG progress tracker wrapping around the Cancel button. Users can
click this button to trigger
xhr.abort(), canceling the upload instantly.
- Displays the actual upload size in a smooth unit format (e.g.,
- Final CDN URL Update: Upon successful upload, the client receives the CDN storage URL from the server and swaps the temporary blob source for the actual file path, saving it to the local IndexedDB database and broadcasting it to the recipient via WebSocket.
3. Under the Hood: Real-time Technical Architecture (Real-time Stack)
The seamless messaging experience and resilient file transfer capabilities of Text2 Chat are achieved through a tight integration between the PWA Frontend and FastAPI Backend:
- FastAPI Backend & Cloudflare R2: The backend API is optimized to store files
directly in Cloudflare R2 (S3-compatible Object Storage). If the R2 connection fails, the
backend automatically falls back to local disk storage in the
./data/uploadsdirectory, ensuring system continuity. Conversation data is stored in PostgreSQL with optimized Connection Pooling. - Sub-100ms WebSockets & Heartbeats: A raw WebSocket connection to the
/ws/{username}?token=...endpoint ensures near-zero latency for message delivery and typing indicators. The application sends Heartbeat packets (ping/pong) every 25 seconds to check connection health and auto-reconnects when the network drops. - IndexedDB (Text2ChatDB v6) & Offline Sync: Messages, contacts, and drafts are
stored locally. In offline mode, messages are queued under a pending status. Once the network is
restored, the
autoSendPendingMessagesroutine is triggered automatically. On app launch, the client syncs past messages via the/api/messages/sync?since=update_idAPI to catch up on any background activity. - WebRTC Calling & Web Push: High-quality peer-to-peer voice and video calls are established directly between browsers via STUN/TURN servers. Features full integration of Web Push Notifications via Service Workers, fully compatible with background push notification systems on iOS PWAs.
Experience Original Data Transmission
Discover the solution for sharing files at their original quality, free from automatic compression and data alteration.