Skip to main content
Version: 4.x

离线行为

缓冲事件

¥Buffered events

默认情况下,在 Socket 未连接时触发的任何事件都将被缓冲,直到重新连接为止。

¥By default, any event emitted while the Socket is not connected will be buffered until reconnection.

虽然在大多数情况下(当重新连接延迟很短时)很有用,但它可能会导致连接恢复时出现大量事件。

¥While useful in most cases (when the reconnection delay is short), it could result in a huge spike of events when the connection is restored.

有多种解决方案可以防止这种行为,具体取决于你的用例:

¥There are several solutions to prevent this behavior, depending on your use case:

  • 使用 Socket 实例的 connected 属性

    ¥use the connected attribute of the Socket instance

if (socket.connected) {
socket.emit( /* ... */ );
} else {
// ...
}
socket.volatile.emit( /* ... */ );