ServerWebsocket constructor

ServerWebsocket({
  1. required PteroClient client,
  2. required String serverId,
  3. FutureOr<void> onConnectionError(
    1. Object error,
    2. StackTrace stacktrace
    )?,
  4. bool autoConnect = true,
})

Start a connection to the server's websocket.

The connection may not be authenticated yet, so you should await ready before sending any messages.

Make sure to listen to errors to catch any errors that occur. or use onError to listen for initial connection errors.

Implementation

// ignore: sort_unnamed_constructors_first
ServerWebsocket({
  required this.client,
  required this.serverId,
  // onError
  FutureOr<void> Function(
    Object error,
    StackTrace stacktrace,
  )? onConnectionError,
  bool autoConnect = true,
}) {
  if (!autoConnect) return;

  final connectFuture = _connect();
  if (onConnectionError != null) connectFuture.catchError(onConnectionError);
}