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

Still in CONNECTING state #47

Open
iDVB opened this issue Apr 28, 2019 · 1 comment
Open

Still in CONNECTING state #47

iDVB opened this issue Apr 28, 2019 · 1 comment

Comments

@iDVB
Copy link

iDVB commented Apr 28, 2019

First time I've used sockets in a while...

I'm building a simple react voting example that allows a room of people to click as many times and as fast as they want on one of 6 choices and that will cast their vote.

This definitely seems like an issue with how fast everything can process each vote.

However, I'm not sure where to start?

This is the bulk of the code:

  const onVote = vote => {
    console.log({ vote, ws });
    ws.json({
      action: 'sendMessage',
      data: JSON.stringify(vote)
    });
  };

  const onMessageReceied = ({ data }) => {
    console.log({ data });
    const voteData = JSON.parse(data);
    console.log({ onMessageReceied: voteData });
    setBallotsList({ ...ballotsList, ...voteData });
  };

  useEffect(() => {
    console.log({ ballotsList });
    ws = new Sockette(config.site.api, {
      timeout: 5e3,
      maxAttempts: 1,
      onopen: e => console.log('connected:', e),
      onmessage: e => onMessageReceied(e),
      onreconnect: e => console.log('Reconnecting...', e),
      onmaximum: e => console.log('Stop Attempting!', e),
      onclose: e => console.log('Closed!', e),
      onerror: e => console.log('Error:', e)
    });
    return function cleanup() {
      ws && ws.close();
      ws = null;
    };
  }, [ballotsList]);
@hakimio
Copy link

hakimio commented Sep 23, 2019

You just have to wait for connection to be established before you can start sending messages.

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

No branches or pull requests

2 participants