reduce method

The method that returns the new state.

Implementation

@override
Future<ServerState> reduce() async {
  var handler = webSocketHandler((WebSocketChannel webSocket) async {
    dispatch(_SetSinkAction(sink: webSocket.sink));
    webSocket.stream.listen((message) {
      global.dispatch(_HandleClientMessageAction(message: message));
    }, onDone: () {
      dispatch(_ClientDisconnectedAction());
    });
  });

  final server = await shelf_io.serve(handler, '0.0.0.0', 9253);
  _logger.info('Serving at ws://${server.address.host}:${server.port}');
  return state.copyWith(
    running: true,
  );
}