Skip to content

Commit 3c99038

Browse files
docs: add documentation for the socket.recovered attribute
1 parent 44fef65 commit 3c99038

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

docs/categories/01-Documentation/connection-state-recovery.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ io.on("connection", (socket) => {
5858
```js
5959
socket.on("connect", () => {
6060
if (socket.recovered) {
61-
// any missed packets will be received
61+
// any event missed during the disconnection period will be received now
6262
} else {
6363
// new or unrecoverable session
6464
}

docs/client-api.md

+20
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,26 @@ socket.on("connect", () => {
492492
});
493493
```
494494

495+
#### socket.recovered
496+
497+
*Added in v4.6.0*
498+
499+
- [`<boolean>`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type)
500+
501+
Whether the connection state was successfully recovered during the last reconnection.
502+
503+
```js
504+
socket.on("connect", () => {
505+
if (socket.recovered) {
506+
// any event missed during the disconnection period will be received now
507+
} else {
508+
// new or unrecoverable session
509+
}
510+
});
511+
```
512+
513+
More information about this feature [here](../docs/categories/01-Documentation/connection-state-recovery.md).
514+
495515
### Methods
496516

497517
#### socket.close()

docs/server-api.md

+20
Original file line numberDiff line numberDiff line change
@@ -1727,6 +1727,26 @@ See also:
17271727

17281728
:::
17291729

1730+
#### socket.recovered
1731+
1732+
*Added in v4.6.0*
1733+
1734+
- [`<boolean>`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type)
1735+
1736+
Whether the connection state was successfully recovered during the last reconnection.
1737+
1738+
```js
1739+
io.on("connection", (socket) => {
1740+
if (socket.recovered) {
1741+
// recovery was successful: socket.id, socket.rooms and socket.data were restored
1742+
} else {
1743+
// new or unrecoverable session
1744+
}
1745+
});
1746+
```
1747+
1748+
More information about this feature [here](../docs/categories/01-Documentation/connection-state-recovery.md).
1749+
17301750
#### socket.request
17311751

17321752
* [`<http.IncomingMessage>`](https://nodejs.org/api/http.html#class-httpincomingmessage)

src/pages/how-to/implement-a-subscription-model.md

+2
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,5 @@ socket.on("connect", () => {
121121
The `!socket.recovered` condition is related to the [Connection state recovery feature](/docs/v4/connection-state-recovery).
122122

123123
If the connection state was successfully recovered, then the subscriptions (the rooms on the server side) will be automatically restored.
124+
125+
Reference: [`socket.recovered` attribute](/docs/v4/client-api/#socketrecovered)

0 commit comments

Comments
 (0)