connect method

dynamic connect([
  1. Map<String, dynamic>? auth
])

connect connects to the server using the given auth parameters. If the auth is null, it uses the options to connect. If the auth is not null, it uses the options and the auth to connect. If the socket is already connected, it does nothing.

Implementation

connect([Map<String, dynamic>? auth]) {
  if (_socket != null || _socket?.active == true) return;
  late io.OptionBuilder optionBuilder;
  if (auth == null) {
    optionBuilder = options.toOptionBuilder();
  } else {
    optionBuilder = options.toOptionBuilder().setAuth(auth);
  }
  _socket = io.io(
    options.path,
    optionBuilder.build(),
  );
  _socket?.connect();
  _socket?.onDisconnect((data) {
    Future.delayed(Duration.zero).then((value) {
      if (_socket?.connected == false) _socket?.connect();
    });
  });
}