onDisconnect method

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

Set a handler for disconnection requests to the socket.

Implementation

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

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

  var worker = WebsocketWorker(registrationRequest, composedHandler);

  await worker.start();
}