Skip to content

WebSocket Controller Decorator

This file defines the Controller class decorator for the @sodacore/core WebSocket (WS) module. It marks a class as a WebSocket controller, attaches necessary metadata for routing, and registers the controller under a specific namespace for WebSocket event handling.


Features

  • Controller Registration: Adds metadata to register the class as a WebSocket controller within the Sodacore framework.
  • Namespace Support: Associates the controller with a specific namespace, used to route WebSocket events to the correct controller.
  • Service Tagging: Tags the controller as providing WebSocket services for internal discovery and routing.

Usage

typescript
import Controller from './decorators/controller';

@Controller('chat')
export class ChatController {
	// Define WebSocket event handler methods here
}

API

Controller(namespace: string): ClassDecorator

  • namespace: The namespace to associate with the controller (used for routing WebSocket events).
  • Returns: A class decorator function.

How It Works

  • Sets the type metadata to 'controller' for autowiring.
  • Sets the namespace metadata under the 'ws' namespace to the provided value.
  • Adds 'ws' to the controller's services metadata array for service discovery.

Notes

  • This decorator is intended for use with WebSocket controller classes in the Sodacore framework.
  • The namespace is required and is used to route incoming WebSocket events to the appropriate controller.
  • The metadata set by this decorator is used by the framework's WebSocket router to discover and register controllers.

Released under the Apache-2.0 License.