onMessage method

Future<void> onMessage(
  1. WebsocketHandler handler, {
  2. List<WebsocketHandler> middlewares = const [],
})

Set a handler for messages to the socket.

Implementation

Future<void> onMessage(WebsocketHandler handler,
    {List<WebsocketHandler> middlewares = const []}) async {
  var registrationRequest = $wp.RegistrationRequest(
      eventType: $wp.WebsocketEventType.Message, socketName: name);

  final composedHandler =
      composeMiddleware([...middlewares, handler], WebsocketContext.fromCtx);

  var worker = WebsocketWorker(registrationRequest, composedHandler);

  await worker.start();
}