Cloud constructor

Cloud(
  1. String owner,
  2. String distribution
)

Implementation

Cloud(String owner, String distribution) {
  if (owner.isEmpty || distribution.isEmpty) {
    if (kDebugMode) {
      print(
        '/!\\ [CLOUD] Owner or distribution is empty, not connecting to cloud',
      );
    }
    return;
  }
  final String server = String.fromEnvironment('DROPIN_CLOUD');
  if (server.isEmpty) {
    if (kDebugMode) {
      print(
        '/!\\ [CLOUD] DROPIN_CLOUD environment variable not set, not connecting to cloud',
      );
    }
    return;
  }
  final String uri = "$server/$owner/$distribution";
  if (kDebugMode) {
    print('[CLOUD] Connecting to $uri...');
  }
  _channel = WebSocketChannel.connect(Uri.parse(uri));
  _channel.ready
      .then((_) {
        if (kDebugMode) print('[CLOUD] Connected to server');
        _channel.stream.listen(_onMessage);
      })
      .onError((error, stackTrace) {
        if (kDebugMode) print('[CLOUD] Error connecting to server: $error');
      });
}