离线行为
缓冲事件
¥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:
if (socket.connected) {
socket.emit( /* ... */ );
} else {
// ...
}
使用 不稳定事件
¥use volatile events
socket.volatile.emit( /* ... */ );