# new PhysicsGatewayService(connectionId, physicsEngineHostOverrideopt)
Creates a new physics gateway service instance
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
connectionId |
string
|
Unique connection ID (from websocket) |
|
physicsEngineHostOverride |
string
|
<optional> |
Optional host override (e.g. for dev-stage); when not set, uses PHYSICS_ENGINE_HOST from env |
Members
# stateQueueNameBase
Base name for state queue; per-connection queue is {stateQueueNameBase}_{connectionId} (exclusive)
Methods
# attachConnectionHandlers(logger)
Attach connection lifecycle handlers (close/error -> reconnect)
Parameters:
| Name | Type | Description |
|---|---|---|
logger |
object
|
Logger instance for connection lifecycle events |
# async attemptConnectionReconnect(logger)
Reconnect after connection/channel loss (e.g. user internet drop). Retries with backoff.
Parameters:
| Name | Type | Description |
|---|---|---|
logger |
object
|
Logger instance for reconnection attempts |
# async attemptSubscriptionReconnect()
Attempt to reconnect the subscription channel after a failure (e.g. channel closed)
# buildCompositeKey(investigationId) → {string}
Build composite key from connection ID and investigation ID
Parameters:
| Name | Type | Description |
|---|---|---|
investigationId |
string
|
Investigation ID |
Composite key in format "connectionId:investigationId"
string
# close()
Close all connections and cleanup resources. Exclusive queues (replies, state) are deleted by RabbitMQ when the connection closes.
# async connect()
Connect to RabbitMQ and set up command channel + reply queue
# async healthCheck() → {Promise.<IPhysicsResponse>}
Health check
The health check response
Promise.<IPhysicsResponse>
# markConnectionLost()
Mark command path as disconnected; clear channel/queue refs, keep connection ref for now
# routingKeyToCompositeKey(routingKey) → {string}
Parse routing key state.{connection_id}.{investigation_id} to compositeKey (connectionId:investigationId)
Parameters:
| Name | Type | Description |
|---|---|---|
routingKey |
string
|
RabbitMQ routing key (e.g. state.connId.invId) |
Composite key connectionId:investigationId
string
# scheduleConnectionReconnect(logger)
Schedule a single reconnection attempt (debounced by reconnecting flag)
Parameters:
| Name | Type | Description |
|---|---|---|
logger |
object
|
Logger instance for reconnection events |
# async sendCommand(command) → {Promise.<IPhysicsResponse>}
Send a command and wait for response (RPC over RabbitMQ)
Parameters:
| Name | Type | Description |
|---|---|---|
command |
IPhysicsCommand
|
The command to send |
The response
Promise.<IPhysicsResponse>
# async sendCommandToEngine(command) → {Promise.<IPhysicsResponse>}
Send one command to the engine and wait for reply.
Parameters:
| Name | Type | Description |
|---|---|---|
command |
IPhysicsCommand
|
Command (payload.connection_id already set by sendCommand) |
Response from Chrono
Promise.<IPhysicsResponse>
# async startSubscription(logger) → {Promise.<void>}
Start subscription channel and consumer
Parameters:
| Name | Type | Description |
|---|---|---|
logger |
object
|
Logger instance (from getLogger()) |
Promise.<void>
# stateRoutingKey(compositeKey) → {string}
Build RabbitMQ routing key for state (state.{connection_id}.{investigation_id})
Parameters:
| Name | Type | Description |
|---|---|---|
compositeKey |
string
|
connectionId:investigationId |
Routing key "state.connectionId.investigationId"
string
# stopSubscription()
Stop the subscription channel
# subscribe(investigationId, callback)
Subscribe to state broadcasts for a specific investigation
Parameters:
| Name | Type | Description |
|---|---|---|
investigationId |
string
|
The investigation ID to subscribe to |
callback |
StateCallback
|
Callback function for state updates |
# unsubscribe(investigationId, callbackopt)
Unsubscribe from state broadcasts for a specific investigation
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
investigationId |
string
|
The investigation ID to unsubscribe from |
|
callback |
StateCallback
|
<optional> |
Optional specific callback to remove |