connect method

  1. @override
Future<void> connect()
override

Implementation

@override
Future<void> connect() async {
  // print('connecting');
  try {
    _socket = WebSocketChannel.connect(
      Uri.parse(
        '$url&useOnCloseEvent=true',
      ),
    );
  } catch (e) {
    throw ReownCoreError(
      code: -1,
      message: 'No internet connection: ${e.toString()}',
    );
  }

  _channel = _socket!.cast<String>();

  if (_channel == null) {
    // print('Socket channel is null, waiting...');
    await Future.delayed(const Duration(milliseconds: 500));
    if (_channel == null) {
      // print('Socket channel is still null, throwing ');
      throw Exception('Socket channel is null');
    }
  }

  await _socket!.ready;

  // Check if the request was successful (status code 200)
  // try {} catch (e) {
  //   throw ReownCoreError(
  //     code: 400,
  //     message: 'WebSocket connection failed, missing or invalid project id.',
  //   );
  // }
}