socket.io-client
socket.io-client copied to clipboard
feat: add options for controlling buffer usage
Note: the socket.io.js file is the generated output of make socket.io.js, and should not be manually modified.
The kind of change this PR does introduce
- [ ] a bug fix
- [x] a new feature
- [ ] an update to the documentation
- [ ] a code change that improves performance
- [ ] other
Current behaviour
Currently, users cannot opt-out of buffer usage, which may not be wanted if they need the events to not be delayed until a reconnection is made (for receive events). For send events it would act like volatile but for all events.
New behaviour
Users can control buffer usage
Other information (e.g. related issues)
With these options, wouldn't it be necessary for the user to always check the value of socket.connected (as the packet might be silently discarded)?
In other words, what is the difference between:
// enableSendBuffer: true
if (socket.connected) { // prevents the event from being added to the buffer
socket.emit(/* ... */);
}
and
// enableSendBuffer: false
if (socket.connected) { // prevents the event from being silently discarded
socket.emit(/* ... */);
}
Well, from what I saw the buffer is only used (as adding packets) when the socket is not connected, so were it would be an issue?
If the user explicitly set enableSendBuffer: false then he's aware that if no connection is established the packet will be discarded, the idea of enableSendBuffer: false is that all packets works like they're volatile (instead of setting volatile in each event)
Anything you need for merging this PR @darrachequesne? I'd like to drop the .patch and have this integrated natively.