lukeed / sockette

The cutest little WebSocket wrapper! 🧦
MIT License
2.45k stars 81 forks source link

Wrapper `$.open` in a promise #60

Closed Gabiras12 closed 4 years ago

Gabiras12 commented 4 years ago

new Sockette returns a promise that is resolved once the connection in open and rejected on error.

With this is possible to await the connection and send message already. I know we have the onopen callback. this is just syntax sugar.

const ws = await new Sockette(`${wssURL}?token=${currentToken}`, {
      timeout: 5e3,
      maxAttempts: 10,
      onopen: e => console.log('Connected', e),
      onmessage: handleOnMessage,
      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)
    })
ws.json({ action: 'foo' })

this would fix this issue: https://github.com/lukeed/sockette/issues/47

lukeed commented 4 years ago

Hey,

Thank you for the suggestion but a priority for sockette is size. The only conveniences it seeks to offer are 1) reconnecting 2) JSON messages since that's a 90% use case. Everything else, including this request, is easily achievable in application code with little effort (as you've described).

I'm sorry but I won't be including this. I hope you understand.

Thanks again 🙇‍♂️