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

Unclear documentation on socket.compress(value) #219

Open
AntonNeld opened this issue Feb 11, 2021 · 6 comments
Open

Unclear documentation on socket.compress(value) #219

AntonNeld opened this issue Feb 11, 2021 · 6 comments

Comments

@AntonNeld
Copy link

The text here is a bit unclear about when compression is used.

As I understand it, websocket compression is turned off by default. This means that setting socket.compress(true) will not necessarily turn on compression (when using the websocket transport, anyway). Did I get that right? Could it be made clearer with an explicit sentence like "Whether compression is actually used also depends on whether it is enabled in the underlying transport"?

@dverzolla
Copy link

Defaults to true when you don’t call the method.

That makes sense to me.

@AntonNeld
Copy link
Author

Let's say I use the defaults everywhere. If I have a socket that is using the websocket transport, will it use compression or not?

  • "Defaults to true when you don’t call the method." points to yes.
  • "perMessageDeflate" defaulting to "false" here points to no.

That is what I am confused about.

@dverzolla
Copy link

perMessageDeflate it's a different piece, check this out: https://github.com/websockets/ws#websocket-compression

I understand "perMessageDeflate" as is in the documentation:

ws supports the permessage-deflate extension which enables the client and server to negotiate a compression algorithm and its parameters, and then selectively apply it to the data payloads of each WebSocket message.

However you are pointing to transports, that are polling or websocket. Both are compressed by default.

websocket: "Defaults to true when you don’t call the method." points to yes.
polling: "parameters of the http compression for the polling transports (see zlib api docs). Set to false to disable." points to yes as well.

That's what I understood reading the docs. Would be good to see others opinion.

@thernstig
Copy link

@dverzolla I think this is a valid question. Then how is it compressed when socket.compress(true) if using websocket as the transport? What kind of compression is it using if not using perMessageDeflate?

A good note is to check the version 2 to 3 migration guide:

the WebSocket permessage-deflate extension is now disabled by default

Could it be that the default compress does not work if changing transport to websocket, unless also changing perMessageDeflate: true?

(I could also have sworn I read somewhere that v3 would use websocket as the default transport, but the docs still says it uses polling and I also cannot find where I read this).

@darrachequesne
Copy link
Member

@AntonNeld you are right, the documentation could be clearer on that point.

If perMessageDeflate is set to false (which is the default), the compression is indeed disabled for the whole duration of the WebSocket session.

Which gives us:

perMessageDeflate socket.emit() (default) socket.compress(false).emit() 
true Y N
false (default) N N

I could also have sworn I read somewhere that v3 would use websocket as the default transport

@thernstig this was indeed discussed, but we did not include the change (we stood by the reasoning detailed here)

@dverzolla
Copy link

Agree with you guys, as I arrived in socket.io on 3+ version, reading the documentation brought me to another understanding. Regards.

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

4 participants