disconnect method

  1. @override
  2. @visibleForTesting
FutureOr<void> disconnect([
  1. int? code = 1000,
  2. String? reason = 'NORMAL_CLOSURE'
])
override

Closes the WebSocket connection. Set the optional code and reason arguments to send close information to the remote peer. If they are omitted, the peer will see No Status Rcvd (1005) code with no reason, indicates that no status code was provided even though one was expected. https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/code

Implementation

@override
@visibleForTesting
FutureOr<void> disconnect(
    [int? code = 1000, String? reason = 'NORMAL_CLOSURE']) async {
  _stateController.add(_state = WebSocketClientState.disconnecting(
      closeCode: code, closeReason: reason));
  await Future<void>.delayed(const Duration(milliseconds: 25));
  _stateController.add(_state =
      WebSocketClientState.closed(closeCode: code, closeReason: reason));
}