ServerWebsocket constructor
ServerWebsocket({
- required PteroClient client,
- required String serverId,
- FutureOr<
void> onConnectionError(- Object error,
- StackTrace stacktrace
- 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);
}