configureServer method

Future configureServer(
  1. Angel app
)

Configures an Angel instance to listen for WebSocket connections.

Implementation

Future configureServer(Angel app) async {
  // As its own type, and, of a subclass, as AngelWebSocket too.
  app.container.registerSingleton(this, as: runtimeType);

  if (runtimeType != AngelWebSocket) {
    app.container.registerSingleton<AngelWebSocket>(this);
  }

  // Set up services
  wireAllServices(app);

  app.onService.listen((_) {
    wireAllServices(app);
  });

  if (synchronizationChannel != null) {
    synchronizationChannel?.stream.listen(
      (e) => batchEvent(e, notify: false),
      // E.g. a refused publish: logged, rather than uncaught.
      onError: (Object e, StackTrace st) =>
          app.logger.warning('WebSocket synchronization failed', e, st),
    );
  }

  app.shutdownHooks.add((_) => synchronizationChannel?.sink.close());
}