Skip to content

Commit 98d0c13

Browse files
docs: add missing manager options
1 parent 18b2fca commit 98d0c13

File tree

1 file changed

+83
-35
lines changed

1 file changed

+83
-35
lines changed

src/site/markdown/initialization.md

Lines changed: 83 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,17 @@ It is the name of the path that is captured on the server side.
153153

154154
The server and the client values must match:
155155

156-
*Server*
156+
*Client*
157+
158+
```java
159+
IO.Options options = IO.Options.builder()
160+
.setPath("/my-custom-path/")
161+
.build();
162+
163+
Socket socket = IO.socket(URI.create("https://example.com"), options);
164+
```
165+
166+
*JavaScript Server*
157167

158168
```js
159169
import { Server } from "socket.io";
@@ -167,16 +177,6 @@ io.on("connection", (socket) => {
167177
});
168178
```
169179

170-
*Client*
171-
172-
```java
173-
IO.Options options = IO.Options.builder()
174-
.setPath("/my-custom-path/")
175-
.build();
176-
177-
Socket socket = IO.socket(URI.create("https://example.com"), options);
178-
```
179-
180180
Please note that this is different from the path in the URI, which represents the [Namespace](https://socket.io/docs/v4/namespaces/).
181181

182182
Example:
@@ -200,14 +200,6 @@ Additional query parameters (then found in `socket.handshake.query` object on th
200200

201201
Example:
202202

203-
*Server*
204-
205-
```js
206-
io.on("connection", (socket) => {
207-
console.log(socket.handshake.query); // prints { x: '42', EIO: '4', transport: 'polling' }
208-
});
209-
```
210-
211203
*Client*
212204

213205
```java
@@ -218,6 +210,14 @@ IO.Options options = IO.Options.builder()
218210
Socket socket = IO.socket(URI.create("https://example.com"), options);
219211
```
220212

213+
*JavaScript Server*
214+
215+
```js
216+
io.on("connection", (socket) => {
217+
console.log(socket.handshake.query); // prints { x: '42', EIO: '4', transport: 'polling' }
218+
});
219+
```
220+
221221
Note: The `socket.handshake.query` object contains the query parameters that were sent during the Socket.IO handshake, it won't be updated for the duration of the current session, which means changing the `query` on the client-side will only be effective when the current session is closed and a new one is created:
222222

223223
```java
@@ -237,14 +237,6 @@ Additional headers (then found in `socket.handshake.headers` object on the serve
237237

238238
Example:
239239

240-
*Server*
241-
242-
```js
243-
io.on("connection", (socket) => {
244-
console.log(socket.handshake.headers); // prints { accept: '*/*', authorization: 'bearer 1234', connection: 'Keep-Alive', 'accept-encoding': 'gzip', 'user-agent': 'okhttp/3.12.12' }
245-
});
246-
```
247-
248240
*Client*
249241

250242
```java
@@ -255,6 +247,14 @@ IO.Options options = IO.Options.builder()
255247
Socket socket = IO.socket(URI.create("https://example.com"), options);
256248
```
257249

250+
*JavaScript Server*
251+
252+
```js
253+
io.on("connection", (socket) => {
254+
console.log(socket.handshake.headers); // prints { accept: '*/*', authorization: 'bearer 1234', connection: 'Keep-Alive', 'accept-encoding': 'gzip', 'user-agent': 'okhttp/3.12.12' }
255+
});
256+
```
257+
258258
Note: Similar to the `query` option above, the `socket.handshake.headers` object contains the headers that were sent during the Socket.IO handshake, it won't be updated for the duration of the current session, which means changing the `extraHeaders` on the client-side will only be effective when the current session is closed and a new one is created:
259259

260260
```java
@@ -297,6 +297,54 @@ options.webSocketFactory = okHttpClient;
297297
Socket socket = IO.socket(URI.create("https://example.com"), options);
298298
```
299299

300+
### Manager options
301+
302+
These settings will be shared by all Socket instances attached to the same Manager.
303+
304+
#### `reconnection`
305+
306+
Default value: `true`
307+
308+
Whether reconnection is enabled or not. If set to `false`, you need to manually reconnect.
309+
310+
#### `reconnectionAttempts`
311+
312+
Default value: `Integer.MAX_VALUE`
313+
314+
The number of reconnection attempts before giving up.
315+
316+
#### `reconnectionDelay`
317+
318+
Default value: `1_000`
319+
320+
The initial delay before reconnection in milliseconds (affected by the [randomizationFactor](#randomizationfactor) value).
321+
322+
#### `reconnectionDelayMax`
323+
324+
Default value: `5_000`
325+
326+
The maximum delay between two reconnection attempts. Each attempt increases the reconnection delay by 2x.
327+
328+
#### `randomizationFactor`
329+
330+
Default value: `0.5`
331+
332+
The randomization factor used when reconnecting (so that the clients do not reconnect at the exact same time after a server crash, for example).
333+
334+
Example with the default values:
335+
336+
- 1st reconnection attempt happens between 500 and 1500 ms (`1000 * 2^0 * (<something between -0.5 and 1.5>)`)
337+
- 2nd reconnection attempt happens between 1000 and 3000 ms (`1000 * 2^1 * (<something between -0.5 and 1.5>)`)
338+
- 3rd reconnection attempt happens between 2000 and 5000 ms (`1000 * 2^2 * (<something between -0.5 and 1.5>)`)
339+
- next reconnection attempts happen after 5000 ms
340+
341+
#### `timeout`
342+
343+
Default value: `20_000`
344+
345+
The timeout in milliseconds for each connection attempt.
346+
347+
300348
### Socket options
301349

302350
These settings are specific to the given Socket instance.
@@ -309,14 +357,6 @@ Credentials that are sent when accessing a namespace (see also [here](https://so
309357

310358
Example:
311359

312-
*Server*
313-
314-
```js
315-
io.on("connection", (socket) => {
316-
console.log(socket.handshake.auth); // prints { token: 'abcd' }
317-
});
318-
```
319-
320360
*Client*
321361

322362
```java
@@ -327,6 +367,14 @@ IO.Options options = IO.Options.builder()
327367
Socket socket = IO.socket(URI.create("https://example.com"), options);
328368
```
329369

370+
*JavaScript Server*
371+
372+
```js
373+
io.on("connection", (socket) => {
374+
console.log(socket.handshake.auth); // prints { token: 'abcd' }
375+
});
376+
```
377+
330378
You can update the `auth` map when the access to the Namespace is denied:
331379

332380
```java

0 commit comments

Comments
 (0)