websocket static method

void websocket(
  1. String route,
  2. dynamic callback(
    1. WebsocketEvent
    ), {
  3. List middleware = const <dynamic>[],
})

add websocket route For this usage, you must use dox-websocket package.

Route.websocket('ws', (socket) {
  socket.on('intro', controller);
});

Implementation

static void websocket(
  String route,
  Function(WebsocketEvent) callback, {
  List<dynamic> middleware = const <dynamic>[],
}) {
  IDoxWebsocket? ws = Dox().websocket;
  if (ws == null) {
    throw Exception('websocket is not registered');
  }
  WebsocketEvent event = ws.create();
  Route()._addRoute(HttpRequestMethod.GET, Route()._prefix + route, <dynamic>[
    ...middleware,
    event.handle,
  ]);
  callback(event);
}