connect method

Future<bool> connect()

-- PUBLIC FUNCTIONS THAT APPLY TO THIS INSTANCE

Implementation

Future<bool> connect() async {
  _accumulator = '';
  await close();
  status = OnyxConnectionStatus.connecting;
  try {
    var socket = await Socket.connect(
      settings.ip,
      settings.port,
      timeout: const Duration(seconds: 1),
    );
    _listener = socket.listen(_tcpDataHandler, onDone: () {
      status = OnyxConnectionStatus.disconnected;
    });
    _socket = socket;
    await _expectResponse(timeoutMsg: 'connection message not received');
    status = OnyxConnectionStatus.connected;
    await loadCueLists();
    resetHeartbeat();
    return true;
  } on SocketException catch (e) {
    _dbg(e);
    status = OnyxConnectionStatus.failed;
    return false;
  } on TimeoutException catch (e) {
    _dbg(e);
    status = OnyxConnectionStatus.failed;
    return false;
  }
}