connect method

void connect({
  1. dynamic url,
})

Connect to the ROS node, the url can override what was provided in the constructor.

Implementation

void connect({dynamic url}) {
  this.url = url ?? this.url;
  url ??= this.url;
  try {
    // Initialize the connection to the ROS node with a Websocket channel.
    _channel = initializeWebSocketChannel(url);
    stream =
        _channel.stream.asBroadcastStream().map((raw) => json.decode(raw));
    // Update the connection status.
    status = Status.connected;
    _statusController.add(status);
    // Listen for messages on the connection to update the status.
    _channelListener = stream.listen((data) {
      //print('INCOMING: $data');
      if (status != Status.connected) {
        status = Status.connected;
        _statusController.add(status);
      }
    }, onError: (error) {
      status = Status.errored;
      _statusController.add(status);
    }, onDone: () {
      status = Status.closed;
      _statusController.add(status);
    });
  } on WebSocketChannelException  {
    status = Status.errored;
    _statusController.add(status);
  }
}