Overview
The/ws/simulation WebSocket channel enables real-time streaming of surgical telemetry data from Unity-based surgical simulations to the Justina backend. Surgeons connect to this channel to transmit movement coordinates, surgical events, and timestamps during active simulation sessions.
Connection
Endpoint
Authentication
Requires a valid JWT token with ROLE_SURGEON (or ROLE_CIRUJANO). AI accounts cannot connect to this channel.
Connection Example
Message Protocol
Client → Server: Telemetry Data
Clients send surgical telemetry messages in JSON format:3D coordinates of the surgical instrument
- Array length: 2 or 3 elements
- Format:
[x, y, z]or[x, y] - Example:
[10.5, 20.3, 15.7]
Type of surgical event occurringValid values:
START- Surgery session beginsNONE- Normal movement, no special eventTUMOR_TOUCH- Instrument touched tumorHEMORRHAGE- Hemorrhage occurredFINISH- Surgery session ends
Unix timestamp in milliseconds
- Must be a positive number
- Example:
1709636400000
Telemetry Message Examples
Server → Client: Completion Response
When a surgery is finished (FINISH event received), the server responds with:Operation status, always
"SAVED" on successUnique identifier of the saved surgery session
Surgery Saved Response
The server only sends a response after receiving a
FINISH event. All other telemetry messages are acknowledged silently.Complete Workflow Example
Stream Movements
Continuously send telemetry data during surgery
- Send coordinates at regular intervals (e.g., 60 FPS)
- Include appropriate event types when they occur
Full Implementation Example
Error Handling
Validation Errors
If the telemetry message fails validation, the connection is closed with1003 BAD_DATA:
coordinatesmust be an array of 2 or 3 doubleseventmust be a valid SurgeryEvent enum valuetimestampmust be a positive number
Authentication Errors
Invalid or missing token results in1008 POLICY_VIOLATION:
Backend Processing
The backend performs these actions on telemetry receipt:Session Management
Each WebSocket connection maintains an in-memorySurgerySession object:
- Session Creation: First message creates new session
- Movement Accumulation: All movements stored in session
- Session Persistence: FINISH event triggers database save
- Session Cleanup: Session removed from memory after save
Performance Considerations
Message Frequency
Recommended telemetry transmission rates:- High precision: 60 messages/second (60 FPS)
- Standard: 30 messages/second (30 FPS)
- Low bandwidth: 10 messages/second (10 FPS)
Connection Limits
- One active simulation session per surgeon
- Multiple connections with same token create separate sessions
Message Size
Typical telemetry message size: ~100 bytes Estimated bandwidth:- 60 FPS: ~6 KB/s upload
- 30 FPS: ~3 KB/s upload
- 10 FPS: ~1 KB/s upload
Next Steps
AI Channel
Learn how AI systems receive surgery notifications
Surgery Endpoints
Access saved trajectory data via REST API