Overview
Royalti.io provides real-time WebSocket events so your application can receive instant updates about file processing status. Instead of polling the job status endpoint, you can subscribe to events and get immediate notifications when processing starts, progresses, completes, or fails.Why Use WebSocket Events?
- Instant Updates: Receive status changes immediately without polling
- Progress Tracking: Get granular progress updates (every 10%) during processing
- User-Scoped: Events are sent only to the user who uploaded the file
- Efficient: Reduces API calls and improves user experience
- Reliable: Built on Socket.io with automatic reconnection
Prerequisites
Authentication
You need a valid JWT access token to connect to the WebSocket server. Use the same token you use for REST API calls.Socket.io Client
Install the Socket.io client for your platform:- Node.js
- Python
- Browser
Quick Start
1
Connect to WebSocket
Establish a WebSocket connection with your JWT token:
Node.js
2
Subscribe to File Processing Events
Listen for file processing status updates:
Node.js
3
Upload a File
Upload a royalty file - events will automatically be sent to your WebSocket connection:
Node.js
Event Types
Royalti.io emits four types of file processing events:| Event | When Emitted | Contains |
|---|---|---|
file:processing:started | Processing begins | File ID, name, initial status |
file:processing:progress | Every ~10% progress | Progress percentage, status message |
file:processing:completed | Processing succeeds | Final stats, processing time |
file:processing:failed | Processing fails | Error message, failure details |
Event Payload Structure
All events share a common payload structure:Progress Stages
Progress updates are emitted at key processing stages. The exact stages depend on the file type:CSV/Text Files
| Progress | Stage |
|---|---|
| 0% | Processing started |
| 20% | Configuration loaded |
| 30-40% | Table ready, validation complete |
| 50% | BigQuery upload starting |
| 80% | BigQuery upload complete |
| 100% | Processing complete |
ZIP Files
| Progress | Stage |
|---|---|
| 0% | Processing started |
| 10% | Downloading ZIP |
| 30% | ZIP downloaded |
| 50% | Extracting files |
| 80% | Files queued for processing |
| 100% | Complete |
Excel Files
| Progress | Stage |
|---|---|
| 0% | Processing started |
| 20% | Creating sheet processor |
| 50% | Sheets discovered |
| 100% | Complete |
Code Examples
Complete Node.js Example
Node.js
Python Example
Python
React Hook Example
React
Best Practices
Error Handling
Always handle connection errors and implement reconnection logic:Node.js
Token Refresh
Update your token when it expires without losing the connection:Node.js
Cleanup
Always disconnect when your component unmounts or user logs out:Node.js
Combining with Notifications
WebSocket events provide real-time progress, while the notification system provides persistent records. Use both for a complete solution:Node.js
Troubleshooting
Connection fails with 'Authentication failed'
Connection fails with 'Authentication failed'
Cause: Your JWT token is invalid or expired.Solution: Ensure you’re using a valid access token. If using refresh tokens, exchange for a new access token before connecting.
Not receiving events after file upload
Not receiving events after file upload
Cause: WebSocket connection may have dropped or file was uploaded by a different user.Solution:
- Verify your WebSocket is connected (
socket.connected) - Events are user-scoped - only the uploader receives them
- Check that you’re listening to the correct event names
Receiving duplicate events
Receiving duplicate events
Cause: Multiple WebSocket connections or event handlers registered.Solution: Ensure you only create one socket connection per session and clean up event handlers when disconnecting.
Progress jumps from 0% to 100%
Progress jumps from 0% to 100%
Cause: File processing completed very quickly (small file) or progress events are being batched.Solution: This is normal for small files. For larger files, you should see intermediate progress updates.
API Reference
For REST API endpoints used with file uploads, see:- Get Upload URL - Request a signed URL for file upload
- File Detection - Trigger source detection
- Confirm Detection - Confirm and start processing
- Processing Status - Poll job status (alternative to WebSocket)
Support
If you encounter issues with WebSocket events:- Check our API Status Page for service status
- Contact support at [email protected]
- Include your
fileIdand timestamp when reporting issues