Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No action from the library. #19

Closed
Kaganalper opened this issue Apr 14, 2019 · 4 comments
Closed

No action from the library. #19

Kaganalper opened this issue Apr 14, 2019 · 4 comments

Comments

@Kaganalper
Copy link

Hello,

First off, I want to thank all the contributers for the great API. I am new on the flutter side, and I saw that this library offers support for flutter so I wanted to try it out. However, I am not able to get any action from the library. It doesn't throw any errors, it doesn't get connected. It is purely idle.

I'm trying to run this on an actual android device.

Flutter doctor output:

[✓] Flutter (Channel stable, v1.2.1, on Mac OS X 10.14.2 18C54,
    locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK
    version 28.0.3)
[✓] iOS toolchain - develop for iOS devices (Xcode 10.1)
[!] Android Studio (version 3.3)
    ✗ Flutter plugin not installed; this adds Flutter specific
      functionality.
    ✗ Dart plugin not installed; this adds Dart specific
      functionality.
[✓] VS Code (version 1.33.1)
[✓] Connected device (1 available)
class SocketClientAPI {
  final String _base;
  final String _path;

  IO.Socket _socket;

  SocketClientAPI(this._base, this._path);

  Future<bool> handshake(String token) async {
    Completer<bool> isConnected = Completer<bool>();
    Map opts = Map<dynamic, dynamic>();
    
    opts['forceNew'] = true;
    opts['autoConnect'] = true;
    opts['query'] = {
      'accessToken': token,
    };


    _socket = IO.io(_base + _path, opts);

    _socket.on('connect', (_) {
      print('connect');
      print('id: ' + _socket.id);
      _socket.emit('save', 'test');
      isConnected.complete(true);
    });
    _socket.on('message_saved', (data) => print(data));
    _socket.on('disconnect', (_) => print('disconnect'));
    _socket.on('fromServer', (_) => print(_));


    _socket.on('error', (error) {
      print('error');
      print(error);
      isConnected.complete(false);
    });

    _socket.open();

    print('Conn: ' + _socket.connected.toString());
    print('Disc: ' + _socket.disconnected.toString());

    return isConnected.future;
  }
}

This is the final version of options as I traced from the manager.

{
   forceNew:true,
   autoConnect:true,
   query:{
      accessToken: "token"
   },
   path: "/socket.io",
   hostname: "192.168.1.62",
   secure:false,
   port:3000
}

Thanks in advance,
Kagan

@GuillaumeJulien
Copy link

Same issue, i think it was due to the iOS or Xcode Update.
I tried on Android Device (Pie 9.0) and it properly worked.

@Oskang09
Copy link
Contributor

try with http://192.168.1.62 instead only IP , i have same problem before.

@randomjoho
Copy link

hello,I have the same problem,Have you solved this problem?

@NimishDavid
Copy link

From the docs:

In Flutter env. it only works with dart:io websocket, not with dart:html websocket, so in this case you have to add 'transports': ['websocket'] when creates the socket instance.

For example,

IO.Socket socket = IO.io('http://localhost:3000', <String, dynamic>{
    'transports': ['websocket'],
    'extraHeaders': {'foo': 'bar'} // optional
  });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants