Skip to content

Commit 4019dbe

Browse files
Merge pull request #249753 from zackliu/socketio-quickstart
Update quickstart for Web PubSub for Socket.IO
2 parents b3cbeff + ab4e833 commit 4019dbe

10 files changed

+82
-64
lines changed
81.6 KB
Loading
81.4 KB
Loading
81.8 KB
Loading
36.5 KB
Loading

articles/azure-web-pubsub/socketio-overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Overview Socket.IO on Azure
33
description: Get an overview of Azure's support for the open-source Socket.IO library.
4-
keywords: Socket.IO, Socket.IO on Azure, multi-node Socket.IO, scaling Socket.IO
4+
keywords: Socket.IO, Socket.IO on Azure, multi-node Socket.IO, scaling Socket.IO, socketio, azure socketio
55
author: kevinguo-ed
66
ms.author: kevinguo
77
ms.date: 07/27/2023
Lines changed: 77 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: 'Quickstart: Incorporate Web PubSub for Socket.IO in your app'
33
description: In this quickstart, you learn how to use Web PubSub for Socket.IO on an existing Socket.IO app.
4-
keywords: Socket.IO, Socket.IO on Azure, multi-node Socket.IO, scaling Socket.IO
4+
keywords: Socket.IO, Socket.IO on Azure, multi-node Socket.IO, scaling Socket.IO, socketio, azure socketio
55
author: xingsy97
66
ms.author: siyuanxing
77
ms.date: 08/01/2023
@@ -11,7 +11,7 @@ ms.topic: quickstart
1111

1212
# Quickstart: Incorporate Web PubSub for Socket.IO in your app
1313

14-
This quickstart is for existing Socket.IO users. It demonstrates how quickly you can incorporate Web PubSub for Socket.IO in your app to simplify development, speed up deployment, and achieve scalability without complexity.
14+
This quickstart demonstrates how to create a Web PubSub for Socket.IO resource and quickly incorporate it in your Socket.IO app to simplify development, speed up deployment, and achieve scalability without complexity.
1515

1616
Code shown in this quickstart is in CommonJS. If you want to use an ECMAScript module, see the [chat demo for Socket.IO with Azure Web PubSub](https://github.com/Azure/azure-webpubsub/tree/main/experimental/sdk/webpubsub-socketio-extension/examples/chat).
1717

@@ -23,13 +23,37 @@ Code shown in this quickstart is in CommonJS. If you want to use an ECMAScript m
2323
2424
## Create a Web PubSub for Socket.IO resource
2525

26-
1. Go to the [Azure portal](https://portal.azure.com/).
27-
1. Search for **socket.io**, and then select **Web PubSub for Socket.IO**.
28-
1. Select a plan, and then select **Create**.
26+
To create a Web PubSub for Socket.IO, you can use the following one-click button to create or follow the actions below to search in Azure portal.
2927

30-
:::image type="content" source="./media/socketio-migrate-from-self-hosted/create-resource.png" alt-text="Screenshot of the Web PubSub for Socket.IO service in the Azure portal.":::
28+
- Use the following button to create a Web PubSub for Socket.IO resource in Azure
3129

32-
## Initialize a Node project and install required packages
30+
[![Deploy to Azure](https://aka.ms/deploytoazurebutton)](https://ms.portal.azure.com/#create/Microsoft.WebPubSubForSocketIO)
31+
32+
- Search from Azure portal search bar
33+
34+
1. Go to the [Azure portal](https://portal.azure.com/).
35+
36+
1. Search for **socket.io**, in the search bar and then select **Web PubSub for Socket.IO**.
37+
38+
:::image type="content" source="./media/socketio-quickstart/search.png" alt-text="Screenshot of searching the Web PubSub for Socket.IO service in the Azure portal.":::
39+
40+
- Search from Marketplace
41+
42+
1. Go to the [Azure portal](https://portal.azure.com/).
43+
44+
1. Select the **Create a resource** button found on the upper left-hand corner of the Azure portal. Type **socket.io** in the search box and press enter. Select the **Web PubSub for Socket.IO** in the search result.
45+
46+
:::image type="content" source="./media/socketio-quickstart/marketplace.png" alt-text="Screenshot of the Web PubSub for Socket.IO service in the marketplace.":::
47+
48+
1. Click **Create** in the pop out page.
49+
50+
:::image type="content" source="./media/socketio-migrate-from-self-hosted/create-resource.png" alt-text="Screenshot of the Web PubSub for Socket.IO service in the Azure portal.":::
51+
52+
## Sending messages with Socket.IO libraries and Web PubSub for Socket.IO
53+
54+
In the following steps, you create a Socket.IO project and integrate with Web PubSub for Socket.IO.
55+
56+
### Initialize a Node project and install required packages
3357

3458
```bash
3559
mkdir quickstart
@@ -38,83 +62,77 @@ npm init
3862
npm install @azure/web-pubsub-socket.io socket.io-client
3963
```
4064

41-
## Write server code
65+
### Write server code
4266

43-
1. Import required packages and create a configuration for Web PubSub:
67+
Create a `server.js` file and add following code to create a Socket.IO server and integrate with Web PubSub for Socket.IO.
4468

45-
```javascript
46-
/*server.js*/
47-
const { Server } = require("socket.io");
48-
const { useAzureSocketIO } = require("@azure/web-pubsub-socket.io");
69+
```javascript
70+
/*server.js*/
71+
const { Server } = require("socket.io");
72+
const { useAzureSocketIO } = require("@azure/web-pubsub-socket.io");
4973

50-
// Add a Web PubSub option
51-
const wpsOptions = {
52-
hub: "eio_hub", // The hub name can be any valid string.
53-
connectionString: process.argv[2] || process.env.WebPubSubConnectionString
54-
}
55-
```
74+
let io = new Server(3000);
5675

57-
2. Create a Socket.IO server that Web PubSub for Socket.IO supports:
76+
// Use the following line to integrate with Web PubSub for Socket.IO
77+
useAzureSocketIO(io, {
78+
hub: "Hub", // The hub name can be any valid string.
79+
connectionString: process.argv[2]
80+
});
5881

59-
```javascript
60-
/*server.js*/
61-
let io = new Server(3000);
62-
useAzureSocketIO(io, wpsOptions);
63-
```
82+
io.on("connection", (socket) => {
83+
// Sends a message to the client
84+
socket.emit("hello", "world");
6485

65-
3. Write server logic:
86+
// Receives a message from the client
87+
socket.on("howdy", (arg) => {
88+
console.log(arg); // Prints "stranger"
89+
})
90+
});
91+
```
6692

67-
```javascript
68-
/*server.js*/
69-
io.on("connection", (socket) => {
70-
// Sends a message to the client
71-
socket.emit("hello", "world");
93+
### Write client code
7294

73-
// Receives a message from the client
74-
socket.on("howdy", (arg) => {
75-
console.log(arg); // Prints "stranger"
76-
})
77-
});
78-
```
95+
Create a `client.js` file and add following code to connect the client with Web PubSub for Socket.IO.
7996

80-
## Write client code
97+
```javascript
98+
/*client.js*/
99+
const io = require("socket.io-client");
81100

82-
1. Create a Socket.IO client:
101+
const socket = io("<web-pubsub-socketio-endpoint>", {
102+
path: "/clients/socketio/hubs/Hub",
103+
});
83104

84-
```javascript
85-
/*client.js*/
86-
const io = require("socket.io-client");
105+
// Receives a message from the server
106+
socket.on("hello", (arg) => {
107+
console.log(arg);
108+
});
87109

88-
const webPubSubEndpoint = process.argv[2] || "<web-pubsub-socketio-endpoint>";
89-
const socket = io(webPubSubEndpoint, {
90-
path: "/clients/socketio/hubs/eio_hub",
91-
});
92-
```
110+
// Sends a message to the server
111+
socket.emit("howdy", "stranger")
112+
```
93113

94-
2. Define the client behavior:
114+
When you use Web PubSub for Socket.IO, `<web-pubsub-socketio-endpoint>` and `path` are required for the client to connect to the service. The `<web-pubsub-socketio-endpoint>` and `path` can be found in Azure portal.
95115

96-
```javascript
97-
/*client.js*/
116+
1. Go to the **key** blade of Web PubSub for Socket.IO
98117

99-
// Receives a message from the server
100-
socket.on("hello", (arg) => {
101-
console.log(arg);
102-
});
118+
1. Type in your hub name and copy the **Client Endpoint** and **Client Path**
103119

104-
// Sends a message to the server
105-
socket.emit("howdy", "stranger")
106-
```
120+
:::image type="content" source="./media/socketio-quickstart/client-url.png" alt-text="Screenshot of the Web PubSub for Socket.IO service in the Azure portal client endpoints blade.":::
107121

108122
## Run the app
109123

110124
1. Run the server app:
111125

112126
```bash
113-
node server.js "<web-pubsub-connection-string>"
127+
node server.js "<connection-string>"
114128
```
115129

130+
The `<connection-string>` is the connection string that contains the endpoint and keys to access your Web PubSub for Socket.IO resource. You can also find the connection string in Azure portal
131+
132+
:::image type="content" source="./media/socketio-quickstart/connection-string.png" alt-text="Screenshot of the Web PubSub for Socket.IO service in the Azure portal connection string blade.":::
133+
116134
2. Run the client app in another terminal:
117135

118136
```bash
119-
node client.js "<web-pubsub-endpoint>"
137+
node client.js
120138
```

articles/azure-web-pubsub/socketio-service-internal.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: How does Azure Web PubSub support the Socket.IO library?
33
description: This article explains how Azure Web PubSub supports the Socket.IO library.
4-
keywords: Socket.IO, Socket.IO on Azure, multi-node Socket.IO, scaling Socket.IO
4+
keywords: Socket.IO, Socket.IO on Azure, multi-node Socket.IO, scaling Socket.IO, socketio, azure socketio
55
author: kevinguo-ed
66
ms.author: kevinguo
77
ms.date: 08/1/2023

articles/azure-web-pubsub/socketio-supported-server-apis.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Supported server APIs of Socket.IO
33
description: This article lists Socket.IO server APIs that are partially supported or unsupported in Web PubSub for Socket.IO.
4-
keywords: Socket.IO, Socket.IO on Azure, multi-node Socket.IO, scaling Socket.IO, Socket.IO APIs
4+
keywords: Socket.IO, Socket.IO on Azure, multi-node Socket.IO, scaling Socket.IO, Socket.IO APIs, socketio, azure socketio
55
author: kevinguo-ed
66
ms.author: kevinguo
77
ms.date: 07/27/2023

articles/azure-web-pubsub/socketio-troubleshoot-common-issues.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Troubleshoot Socket.IO common problems
33
description: Learn how to troubleshoot common problems with the Socket.IO library and the Azure Web PubSub service.
4-
keywords: Socket.IO, Socket.IO on Azure, multi-node Socket.IO, scaling Socket.IO, Socket.IO issues
4+
keywords: Socket.IO, Socket.IO on Azure, multi-node Socket.IO, scaling Socket.IO, Socket.IO issues, socketio, azure socketio
55
author: xingsy97
66
ms.author: siyuanxing
77
ms.date: 08/01/2023

articles/azure-web-pubsub/socketio-troubleshoot-logging.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Collect logs in Web PubSub for Socket.IO
33
description: This article explains how to collect logs when you're using Web PubSub for Socket.IO.
4-
keywords: Socket.IO, Socket.IO on Azure, multi-node Socket.IO, scaling Socket.IO, Socket.IO logging, Socket.IO debugging
4+
keywords: Socket.IO, Socket.IO on Azure, multi-node Socket.IO, scaling Socket.IO, Socket.IO logging, Socket.IO debugging, socketio, azure socketio
55
author: xingsy97
66
ms.author: siyuanxing
77
ms.date: 08/01/2023

0 commit comments

Comments
 (0)