Commits on Dec 14, 2022

  1. Configuration menu
    Copy the full SHA
    547c541 View commit details
    Browse the repository at this point in the history

Commits on Jan 11, 2023

  1. refactor(typings): add types for io.engine (#4591)

    This adds typings for the socket.io engine field, which offers better
    IntelliSense when retrieving the server, as well as more confidence on
    the developer-side of what types of fields are entering the server.
    
    Related: #4590
    LeoDog896 committed Jan 11, 2023
    Configuration menu
    Copy the full SHA
    d4a9b2c View commit details
    Browse the repository at this point in the history

Commits on Jan 12, 2023

  1. docs: add Rust client implementation (#4592)

    client-only implementation -- it *may* add server-side support in the future.
    LeoDog896 committed Jan 12, 2023
    Configuration menu
    Copy the full SHA
    b7d54db View commit details
    Browse the repository at this point in the history
  2. perf: precompute the WebSocket frames when broadcasting

    Note:
    
    - only packets without binary attachments are affected
    - the permessage-deflate extension must be disabled (which is the default)
    
    Related:
    
    - socketio/socket.io-adapter@5f7b47d
    - socketio/engine.io@5e34722
    darrachequesne committed Jan 12, 2023
    Configuration menu
    Copy the full SHA
    da2b542 View commit details
    Browse the repository at this point in the history
  3. feat: implement connection state recovery

    Connection state recovery allows a client to reconnect after a
    temporary disconnection and restore its state:
    
    - id
    - rooms
    - data
    - missed packets
    
    Usage:
    
    ```js
    import { Server } from "socket.io";
    
    const io = new Server({
      connectionStateRecovery: {
        // default values
        maxDisconnectionDuration: 2 * 60 * 1000,
        skipMiddlewares: true,
      },
    });
    
    io.on("connection", (socket) => {
      console.log(socket.recovered); // whether the state was recovered or not
    });
    ```
    
    Here's how it works:
    
    - the server sends a session ID during the handshake (which is
    different from the current `id` attribute, which is public and can be
    freely shared)
    
    - the server also includes an offset in each packet (added at the end
    of the data array, for backward compatibility)
    
    - upon temporary disconnection, the server stores the client state for
    a given delay (implemented at the adapter level)
    
    - upon reconnection, the client sends both the session ID and the last
    offset it has processed, and the server tries to restore the state
    
    A few notes:
    
    - the base adapter exposes two additional methods, persistSession() and
    restoreSession(), that must be implemented by the other adapters in
    order to allow the feature to work within a cluster
    
    See: socketio/socket.io-adapter@f529412
    
    - acknowledgements are not affected, because it won't work if the
    client reconnects on another server (as the ack id is local)
    
    - any disconnection that lasts longer than the
    `maxDisconnectionDuration` value will result in a new session, so users
    will still need to care for the state reconciliation between the server
    and the client
    
    Related: #4510
    darrachequesne committed Jan 12, 2023
    Configuration menu
    Copy the full SHA
    54d5ee0 View commit details
    Browse the repository at this point in the history

Commits on Jan 18, 2023

  1. Configuration menu
    Copy the full SHA
    a21ad88 View commit details
    Browse the repository at this point in the history

Commits on Jan 19, 2023

  1. fix(typings): properly type emits with timeout

    When emitting with a timeout (added in version 4.4.0), the "err"
    argument was not properly typed and would require to split the client
    and server typings. It will now be automatically inferred as an Error
    object.
    
    Workaround for previous versions:
    
    ```ts
    type WithTimeoutAck<isEmitter extends boolean, args extends any[]> = isEmitter extends true ? [Error, ...args] : args;
    
    interface ClientToServerEvents<isEmitter extends boolean = false> {
        withAck: (data: { argName: boolean }, callback: (...args: WithTimeoutAck<isEmitter, [string]>) => void) => void;
    }
    
    interface ServerToClientEvents<isEmitter extends boolean = false> {
    
    }
    
    const io = new Server<ClientToServerEvents, ServerToClientEvents<true>>(3000);
    
    io.on("connection", (socket) => {
        socket.on("withAck", (val, cb) => {
            cb("123");
        });
    });
    
    const socket: Socket<ServerToClientEvents, ClientToServerEvents<true>> = ioc("http://localhost:3000");
    
    socket.timeout(100).emit("withAck", { argName: true }, (err, val) => {
      // ...
    });
    ```
    
    Related: socketio/socket.io-client#1555
    darrachequesne committed Jan 19, 2023
    Configuration menu
    Copy the full SHA
    f3ada7d View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    6c27b8b View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    1298839 View commit details
    Browse the repository at this point in the history

Commits on Jan 23, 2023

  1. feat: add the ability to clean up empty child namespaces (#4602)

    This commit adds a new option, "cleanupEmptyChildNamespaces". With this
    option enabled (disabled by default), when a socket disconnects from a
    dynamic namespace and if there are no other sockets connected to it
    then the namespace will be cleaned up and its adapter will be closed.
    
    Note: the namespace can be connected to later (it will be recreated)
    
    Related: socketio/socket.io-redis-adapter#480
    stevebaum23 authored and darrachequesne committed Jan 23, 2023
    Configuration menu
    Copy the full SHA
    5d9220b View commit details
    Browse the repository at this point in the history
  2. feat: add promise-based acknowledgements

    This commit adds some syntactic sugar around acknowledgements:
    
    - `emitWithAck()`
    
    ```js
    try {
      const responses = await io.timeout(1000).emitWithAck("some-event");
      console.log(responses); // one response per client
    } catch (e) {
      // some clients did not acknowledge the event in the given delay
    }
    
    io.on("connection", async (socket) => {
        // without timeout
      const response = await socket.emitWithAck("hello", "world");
    
      // with a specific timeout
      try {
        const response = await socket.timeout(1000).emitWithAck("hello", "world");
      } catch (err) {
        // the client did not acknowledge the event in the given delay
      }
    });
    ```
    
    - `serverSideEmitWithAck()`
    
    ```js
    try {
      const responses = await io.timeout(1000).serverSideEmitWithAck("some-event");
      console.log(responses); // one response per server (except itself)
    } catch (e) {
      // some servers did not acknowledge the event in the given delay
    }
    ```
    
    Related:
    
    - #4175
    - #4577
    - #4583
    darrachequesne committed Jan 23, 2023
    Configuration menu
    Copy the full SHA
    184f3cf View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    93d446a View commit details
    Browse the repository at this point in the history
  4. refactor: export DisconnectReason type

    Related: #4556
    darrachequesne committed Jan 23, 2023
    Configuration menu
    Copy the full SHA
    f8640d9 View commit details
    Browse the repository at this point in the history

Commits on Jan 24, 2023

  1. fix: add timeout method to remote socket (#4558)

    The RemoteSocket interface, which is returned when the client is
    connected on another Socket.IO server of the cluster, was lacking the
    `timeout()` method.
    
    Syntax:
    
    ```js
    const sockets = await io.fetchSockets();
    
    for (const socket of sockets) {
      if (someCondition) {
        socket.timeout(1000).emit("some-event", (err) => {
          if (err) {
            // the client did not acknowledge the event in the given delay
          }
        });
      }
    }
    ```
    
    Related: #4595
    walde1024 authored and darrachequesne committed Jan 24, 2023
    Configuration menu
    Copy the full SHA
    0c0eb00 View commit details
    Browse the repository at this point in the history

Commits on Jan 25, 2023

  1. refactor: do not include the pid by default

    So that the client knows whether the connection state recovery feature
    is enabled.
    
    See also: 54d5ee0
    darrachequesne committed Jan 25, 2023
    Configuration menu
    Copy the full SHA
    115a981 View commit details
    Browse the repository at this point in the history

Commits on Feb 4, 2023

  1. Configuration menu
    Copy the full SHA
    4e64123 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    8aa9499 View commit details
    Browse the repository at this point in the history

Commits on Feb 6, 2023

  1. revert: feat: expose current offset to allow deduplication

    This reverts commit 4e64123.
    
    Using the id of the socket is not possible, since it is lost upon
    reconnection (unless connection recovery is successful), so we revert
    the previous change.
    darrachequesne committed Feb 6, 2023
    Configuration menu
    Copy the full SHA
    3734b74 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    b2dd7cf View commit details
    Browse the repository at this point in the history
  3. refactor: do not persist session if connection state recovery if disa…

    …bled
    
    This is a follow-up commit of [1]. Without it, adapter.persistSession()
    would be called even if the connection state recovery feature was
    disabled.
    
    [1]: 54d5ee0
    darrachequesne committed Feb 6, 2023
    Configuration menu
    Copy the full SHA
    d8143cc View commit details
    Browse the repository at this point in the history

Commits on Feb 7, 2023

  1. chore(release): 4.6.0

    darrachequesne committed Feb 7, 2023
    Configuration menu
    Copy the full SHA
    a2e5d1f View commit details
    Browse the repository at this point in the history

Commits on Feb 16, 2023

  1. Configuration menu
    Copy the full SHA
    e71f3d7 View commit details
    Browse the repository at this point in the history

Commits on Feb 20, 2023

  1. fix(types): fix nodenext module resolution compatibility (#4625)

    The import added in [1] was invalid, because it used an non-exported
    class.
    
    Related: #4621
    
    [1]: d4a9b2c
    igorls authored and darrachequesne committed Feb 20, 2023
    Configuration menu
    Copy the full SHA
    d0b22c6 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    2a8565f View commit details
    Browse the repository at this point in the history
  3. fix: properly handle manually created dynamic namespaces

    Namespaces that match the regex of a parent namespace will now be added
    as a child of this namespace:
    
    ```js
    const parentNamespace = io.of(/^\/dynamic-\d+$/);
    const childNamespace = io.of("/dynamic-101");
    ```
    
    Related:
    
    - #4615
    - #4164
    - #4015
    - #3960
    darrachequesne committed Feb 20, 2023
    Configuration menu
    Copy the full SHA
    0d0a7a2 View commit details
    Browse the repository at this point in the history
  4. chore(release): 4.6.1

    darrachequesne committed Feb 20, 2023
    Configuration menu
    Copy the full SHA
    7952312 View commit details
    Browse the repository at this point in the history