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

Not connecting to the socket #61

Closed
harivamshi81189 opened this issue Feb 19, 2020 · 5 comments
Closed

Not connecting to the socket #61

harivamshi81189 opened this issue Feb 19, 2020 · 5 comments

Comments

@harivamshi81189
Copy link

harivamshi81189 commented Feb 19, 2020

I am unable to connect to socket..... I am implementing a chat application
I am using the following code in initState ():

receiveEvent='RESPONSE';
eventName='CONNECT';
socket = io(MAIN_API_URL, <String, dynamic>{
      'transports': ['websocket'],
      'autoConnect': false,
    });
    socket.connect();
    socket.emit(eventName,
        json.encode({"incidentId": widget.incidentId, "shouldJoinRoom": true}));
    socket.on(receiveEvent, (jsonData) {
      try {
        print("hello");
        receivedChat = ChatResponse.fromJson(json.decode(jsonData));
        print("hi");
        if (receivedChat.from != user.id) {
          setState(() {
            chats.add(receivedChat);
          });
        }
      } catch (e) {
        print(e);
      }
    });

I am using the following code when the send button is tap

socket.emit(
           eventName,
            json.encode({
           "incidentId": widget.incidentId,
             "userId": user.id,
             "message": chat.text,
               "type": "text"
}));
@jumperchen
Copy link
Member

Which server version are you using? (NodeJS ?)

@jumperchen
Copy link
Member

This example works for me - #36 (comment)

@harivamshi81189
Copy link
Author

Which server version are you using? (NodeJS ?)

Yea I am using node js server

@harivamshi81189
Copy link
Author

This example works for me - #36 (comment)

I'll try and get back

@harivamshi81189
Copy link
Author

Thank u so much it resolved

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

2 participants