disconnect method

  1. @override
Future<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
Future<void> disconnect(
    [int? code = 1000, String? reason = 'NORMAL_CLOSURE']) {
  if (_isClosed) return Future<void>.error(const WSClientClosed());
  return _eventQueue.push('disconnect', () {
    WebSocketConnectionManager.instance.stopMonitoringConnection(this);
    return _client.disconnect(code, reason);
  });
}