connect method
override
Connects to the server using the given uri and protocol.
Implementation
@override
Future<void> connect(
{required String uri,
String protocol = "duo-instance",
Map<String, dynamic>? headers}) {
if (_state != WebSocketClientState.disconnected) {
return Future.error(
StateError("WebSocketClient: cannot connect in $_state state"));
}
_state = WebSocketClientState.connecting;
final channel = IOWebSocketChannel.connect(uri,
protocols: [protocol], headers: headers);
_socketChannel = channel;
return channel.ready.then(_handleConnect).catchError(_handleConnectError);
}