WSController
Package: @opra/common
WSController is the runtime class that represents a WebSocket controller in an OPRA document. A controller groups related operations under a named scope and can declare local data types shared by its operations. You obtain a WSController instance through WSApi or by looking it up from the document.
Inheritance
DocumentElement
└── WSController
Properties
| Property | Type | Description |
|---|---|---|
kind | 'WSController' | Always 'WSController'. |
name | string | Controller name as registered in the API. |
description | string | undefined | Human-readable description. |
operations | ResponsiveMap<WSOperation> | Operations registered on this controller. |
types | DataTypeMap | Local data types scoped to this controller. |
ctor | Type | undefined | The TypeScript class constructor registered for this controller. |
instance | object | undefined | Resolved controller instance (populated at runtime). |
Methods
toJSON()
Returns a plain OpraSchema.WSController object for schema export, including all operations and local types.
toJSON(): OpraSchema.WSController
Obtaining a WSController instance
import { WSApi, WSController } from '@opra/common';
const document = await ApiDocumentFactory.createDocument({ ... });
if (document.api instanceof WSApi) {
const ctrl = document.api.findController('ChatController');
if (ctrl) {
console.log(ctrl.name); // 'ChatController'
console.log(ctrl.operations.size); // number of operations
for (const [name, op] of ctrl.operations) {
console.log(name, op.event);
}
}
}
→ WSApi · WSOperation