This reverts commit 7427109658.
The new version of the `cookie` package contains code with optional chaining (`?.`), which is not supported by older Node.js versions (< 14).
The types for cookie are now bundled, so that there is no conflict with the types coming from `cookie@1`:
> error TS2724: '"cookie"' has no exported member named 'CookieSerializeOptions'. Did you mean 'SerializeOptions'?
>
> import type { CookieSerializeOptions } from "cookie";
> ~~~~~~~~~~~~~~~~~~~~~~
Related: https://github.com/socketio/socket.io/issues/5283
This should fix the following issue:
```
SyntaxError: Named export 'WebSocket' not found. The requested module 'ws' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from 'ws';
const { WebSocket } = pkg;
```
The "_placeholder" attribute is used when sending binary data, and was
incorrectly mangled (converted to a random short property, like "it",
to reduce the bundle size).
This bug was introduced in [1], included in `socket.io-client@4.8.0`.
[1]: 7085f0e3e4
Related: https://github.com/socketio/socket.io/issues/5215
Before this change, the following error would be thrown when compiling
with TypeScript:
```
node_modules/engine.io-client/build/esm/transports/websocket.node.d.ts:12:101 - error TS1340: Module 'ws' does not refer to a type, but is used as a type here. Did you mean 'typeof import('ws')'?
12 createSocket(uri: string, protocols: string | string[] | undefined, opts: Record<string, any>): import("ws");
~~~~~~~~~~~~
```
This behavior was introduced in [1], included in version `6.6.0`.
The return type is forced as `any`, so that the `@types/ws` dependency
is optional.
[1]: f4d898ee96
Related: https://github.com/socketio/socket.io/issues/5202
By default, Babel uses `Object.defineProperty()` when transpiling
classes. We'll now use the loose mode which creates a more terse
output.
| | before | after |
|----------|---------|---------|
| min+gzip | 14.9 KB | 14.6 KB |
| min+br | 13.4 KB | 13.1 KB |
Reference: https://babeljs.io/docs/babel-plugin-transform-classes
In some specific cases, the transport was not closed right away,
leaving the Node.js process alive even after closing the server.
The HTTP long-polling transport would be closed after the heartbeat
failure and the `closeTimeout` delay (20 + 25 + 30 seconds).
Example:
```js
io.on("connection", (socket) => {
// the writeBuffer is not empty, so the transport is not closed right away
io.close();
});
```
Related: https://github.com/socketio/socket.io/issues/5088
When a laptop is suspended or a phone is locked, the timer that is used
to check the liveness of the connection is paused and is not able to
detect that the heartbeat has failed.
Previously, emitting a message after resuming the page would lose the
message. The status of the timer will now be checked before sending the
message, so that it gets buffered and sent upon reconnection.
Note: we could also have used the Page Visibility API or a custom
setTimeout() method based on setInterval(), but this would not be as
reliable as the current solution.
Reference: https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API
Related: https://github.com/socketio/socket.io/issues/5135