pusher / pusher-js

Pusher Javascript library
http://pusher.com
MIT License
2.11k stars 374 forks source link

Setting `enabledTransports` to only `wss` does not connect #676

Closed kohenkatz closed 1 year ago

kohenkatz commented 1 year ago

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

If the only enabled transport is wss and forceTLS is true, no connection to the server is attempted.

const pusher = new Pusher('test', {
  cluster: 'mt1',
  enabledTransports: ['wss'],
  forceTLS: true, // it doesn't make a difference if this is included or not
});

console.log(pusher.connection.state);

Fiddle: https://jsfiddle.net/kohenkatz/mpaerk67/

Observe that the console logs say the connection state is failed but the DevTools show that no WebSocket connection was attempted.

What is the expected behavior?

The client should connect via secure WebSocket.

Note that this configuration works:

const pusher = new Pusher('test', {
  cluster: 'mt1',
  enabledTransports: ['wss', 'ws'],
  forceTLS: true,
});

console.log(pusher.connection.state);

Which versions of Pusher, and which browsers / OS are affected by this issue? Did this work in previous versions of Pusher? If so, which?

I tested this with Pusher 7.6.0 and 8.0.0.

craigrileyuk commented 1 year ago

This is expected behaviour:

https://github.com/pusher/pusher-js#enabledtransports-array

Note: if you intend to use secure websockets, or wss, you can not simply specify wss in enabledTransports, you must specify ws in enabledTransports as well as set the forceTLS option to true.

kohenkatz commented 1 year ago

It's missing from the official documentation.