Skip to main content

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

PropertyTypeDescription
kind'WSController'Always 'WSController'.
namestringController name as registered in the API.
descriptionstring | undefinedHuman-readable description.
operationsResponsiveMap<WSOperation>Operations registered on this controller.
typesDataTypeMapLocal data types scoped to this controller.
ctorType | undefinedThe TypeScript class constructor registered for this controller.
instanceobject | undefinedResolved 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