VMServiceClient.connect constructor

  1. dynamic url

Connects to the VM service protocol at url.

url may be a ws:// or a http:// URL. If it's ws://, it's interpreted as the URL to connect to directly. If it's http://, it's interpreted as the URL for the Dart observatory, and the corresponding WebSocket URL is determined based on that. It may be either a String or a Uri.

If this encounters a connection error, done will complete with a WebSocketChannelException.


factory VMServiceClient.connect(url) {
  if (url is! Uri && url is! String) {
    throw new ArgumentError.value(url, "url", "must be a String or a Uri");

  var uri = url is String ? Uri.parse(url) : url;
  if (uri.scheme == 'http') {
    var path = uri.path.endsWith('/') ? uri.path : uri.path + '/';
    uri = uri.replace(scheme: 'ws', path: '${path}ws');

  // TODO(nweiz): Just use [WebSocketChannel.connect] when cross-platform
  // libraries work.
  return new VMServiceClient(new IOWebSocketChannel.connect(uri).cast());