kakajansh / echo

Laravel Echo for your Flutter apps.
MIT License
108 stars 69 forks source link

Exception: adding the URI to the io() method call #7

Closed Wissa-Azmy closed 5 years ago

Wissa-Azmy commented 5 years ago

I having a problem adding the URI to the io() method call as follows:

echo = new Echo({
      'broadcaster': 'socket.io',
      'client': IO.io('http://1.2.1.2:6001'),
      'auth': {
        'headers': {
          'Authorization': 'Bearer '
        }
      }
    });

It fires the following exception:

flutter: ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
flutter: The following NoSuchMethodError was thrown building MediaQuery(MediaQueryData(size: Size(414.0,
flutter: 896.0), devicePixelRatio: 2.0, textScaleFactor: 1.0, platformBrightness: Brightness.light, padding:
flutter: EdgeInsets(0.0, 44.0, 0.0, 34.0), viewInsets: EdgeInsets.zero, alwaysUse24HourFormat: false,
flutter: accessibleNavigation: falsedisableAnimations: falseinvertColors: falseboldText: false)):
flutter: Class 'Socket' has no instance method 'call'.
flutter: Receiver: Instance of 'Socket'
flutter: Tried calling: call("http://localhost:6001", _LinkedHashMap len:10)

Yet everything worked fine when I hard coded the URI in the _lookup method as below:

_lookup(uri , opts) {
  uri = 'http://1.2.1.2:6001';

  opts = opts ?? <dynamic, dynamic>{};
  Uri parsed = Uri.parse(uri);
  var id = '${parsed.scheme}://${parsed.host}:${parsed.port}';
  var path = parsed.path;
  var sameNamespace = cache.containsKey(id) && cache[id].nsps.containsKey(path);
  var newConnection = opts['forceNew'] == true ||
      opts['force new connection'] == true ||
      false == opts['multiplex'] ||
      sameNamespace;

  var io;

  if (newConnection) {
    _logger.fine('ignoring socket cache for $uri');
    io = new Manager(uri: uri, options: opts);
  } else {
    io = cache[id] ??= new Manager(uri: uri, options: opts);
  }
  if (parsed.query.isNotEmpty && opts['query'] == null) {
    opts['query'] = parsed.query;
  } else if (opts != null && opts['query'] is Map) {
    opts['query'] = encode(opts['query']);
  }
  return io.socket(parsed.path.isEmpty ? '/' : parsed.path, opts);
}
kakajansh commented 5 years ago

URI option should be passed as host parameter. Can you test below code?

echo = new Echo({
  'broadcaster': 'socket.io',
  'client': IO.io,
  'host': 'http://1.2.1.2:6001',
  'auth': {
    'headers': {
      'Authorization': 'Bearer '
     }
   }
});
Wissa-Azmy commented 5 years ago

That solved it 👍