Overview
TheOrderRealtime interface provides a contract for establishing and managing real-time connections to receive order updates. It works in conjunction with OrderEvents to handle create and update notifications.
Source: application/order/order-realtime.ts, application/order/order-events.ts
Interface Definitions
OrderRealtime
OrderEvents
Methods
connect()
Establishes a real-time connection and registers event handlers for order notifications.Parameters
An object containing callback functions for order events
Optional callback invoked when a new order is createdSignature:
(order: OrderListDto) => voidParameters:order: The newly created order data
Optional callback invoked when an existing order is updatedSignature:
(order: OrderListDto) => voidParameters:order: The updated order data
Returns
This method does not return a value
Example
You can register only one of the event handlers if you don’t need both. Both
onCreated and onUpdated are optional.disconnect()
Closes the real-time connection and stops receiving order events.Returns
This method does not return a value
Example
Always call
disconnect() when you no longer need real-time updates to prevent memory leaks and unnecessary network traffic.OrderListDto Structure
Both event callbacks receive anOrderListDto object with the following structure:
Unique identifier for the order
Name of the partner/restaurant
URL to the partner’s image
Human-readable order number for display
Current status of the order (RECEIVED, CONFIRMED, PREPARING, READY, PICKED_UP, DELIVERED, CANCELLED)
Order priority level (NORMAL or HIGH)
Active timer value for the order
Name of the assigned courier
Usage Patterns
Basic Connection
React Hook Integration
Handling Only Updates
Implementation Notes
The
OrderRealtime interface does not specify the underlying transport mechanism (WebSocket, SSE, polling, etc.). The implementation determines the actual real-time technology used.Event handlers should be lightweight and non-blocking. For heavy processing, consider using a message queue or worker pattern.
Error Handling
Implementations should handle connection errors gracefully:Related
- OrderRepository - Order data operations
- useOrderDetail Hook - React hook for order details