Skip to content

Commit e85b007

Browse files
Merge pull request #248287 from vicancy/vicancy-patch-3
Update socketio-migrate-from-self-hosted.md
2 parents 59d9e04 + 69d4668 commit e85b007

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

articles/azure-web-pubsub/socketio-migrate-from-self-hosted.md

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,19 @@ Locate `index.js` in the server-side code.
3636
```javascript
3737
const { useAzureSocketIO } = require("@azure/web-pubsub-socket.io");
3838
```
39-
40-
3. Add configuration so that the server can connect with your Web PubSub for Socket.IO resource.
39+
40+
3. Locate in your server-side code where Socket.IO server is created and wrap it with `useAzureSocketIO()`:
4141
```javascript
42-
const wpsOptions = {
42+
const io = require("socket.io")();
43+
useAzureSocketIO(io, {
4344
hub: "eio_hub", // The hub name can be any valid string.
4445
connectionString: process.argv[2]
45-
};
46-
```
47-
48-
4. Locate in your server-side code where Socket.IO server is created and append `.useAzureSocketIO(wpsOptions)`:
49-
```javascript
50-
const io = require("socket.io")();
51-
useAzureSocketIO(io, wpsOptions);
46+
});
5247
```
53-
>[!IMPORTANT]
54-
> `useAzureSocketIO` is an asynchronous method. Here we `await`. So you need to wrap it and related code in an asynchronous function.
48+
>[!IMPORTANT]
49+
> `useAzureSocketIO` is an asynchronous method and it does initialization steps to connect to Web PubSub. You can `await useAzureSocketIO(...)` or use `useAzureSocketIO(...).then(...)` to make sure your app server starts to serve requests after the initialization succeeds.
5550
56-
5. If you use the following server APIs, add `async` before using them as they're asynchronous with Web PubSub for Socket.IO.
51+
4. If you use the following server APIs, add `async` before using them as they're asynchronous with Web PubSub for Socket.IO.
5752
- [server.socketsJoin](https://socket.io/docs/v4/server-api/#serversocketsjoinrooms)
5853
- [server.socketsLeave](https://socket.io/docs/v4/server-api/#serversocketsleaverooms)
5954
- [socket.join](https://socket.io/docs/v4/server-api/#socketjoinroom)

0 commit comments

Comments
 (0)