Class

PhysicsGatewayService

services/physics-gateway.PhysicsGatewayService(connectionId, physicsEngineHostOverrideopt)

Physics Gateway Service (RabbitMQ)

Constructor

# 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

View Source services/physics-gateway.service.js, line 97

Members

# stateQueueNameBase

Base name for state queue; per-connection queue is {stateQueueNameBase}_{connectionId} (exclusive)

View Source services/physics-gateway.service.js, line 118

Methods

# attachConnectionHandlers(logger)

Attach connection lifecycle handlers (close/error -> reconnect)

Parameters:
Name Type Description
logger object

Logger instance for connection lifecycle events

View Source services/physics-gateway.service.js, line 176

# 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

View Source services/physics-gateway.service.js, line 216

# async attemptSubscriptionReconnect()

Attempt to reconnect the subscription channel after a failure (e.g. channel closed)

View Source services/physics-gateway.service.js, line 541

# buildCompositeKey(investigationId) → {string}

Build composite key from connection ID and investigation ID

Parameters:
Name Type Description
investigationId string

Investigation ID

View Source services/physics-gateway.service.js, line 147

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.

View Source services/physics-gateway.service.js, line 781

# async connect()

Connect to RabbitMQ and set up command channel + reply queue

View Source services/physics-gateway.service.js, line 262

# async healthCheck() → {Promise.<IPhysicsResponse>}

Health check

View Source services/physics-gateway.service.js, line 770

The health check response

Promise.<IPhysicsResponse>

# markConnectionLost()

Mark command path as disconnected; clear channel/queue refs, keep connection ref for now

View Source services/physics-gateway.service.js, line 193

# 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)

View Source services/physics-gateway.service.js, line 163

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

View Source services/physics-gateway.service.js, line 206

# 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

View Source services/physics-gateway.service.js, line 605

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)

View Source services/physics-gateway.service.js, line 686

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())

View Source services/physics-gateway.service.js, line 395

Promise.<void>

# stateRoutingKey(compositeKey) → {string}

Build RabbitMQ routing key for state (state.{connection_id}.{investigation_id})

Parameters:
Name Type Description
compositeKey string

connectionId:investigationId

View Source services/physics-gateway.service.js, line 155

Routing key "state.connectionId.investigationId"

string

# stopSubscription()

Stop the subscription channel

View Source services/physics-gateway.service.js, line 581

# 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

View Source services/physics-gateway.service.js, line 349

# 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

View Source services/physics-gateway.service.js, line 497