@azure/web-pubsub-express 1.0.6-alpha.20250108.1 → 1.0.6-alpha.20250110.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +21 -18
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [Azure Web PubSub service](https://aka.ms/awps/doc) is an Azure-managed service that helps developers easily build web applications with real-time features and publish-subscribe pattern. Any scenario that requires real-time publish-subscribe messaging between server and clients or among clients can use Azure Web PubSub service. Traditional real-time features that often require polling from server or submitting HTTP requests can also use Azure Web PubSub service.
4
4
 
5
- When a WebSocket connection connects, the Web PubSub service transforms the connection lifecycle and messages into [events in CloudEvents format](https://docs.microsoft.com/azure/azure-web-pubsub/concept-service-internals#workflow). This library provides an express middleware to handle events representing the WebSocket connection's lifecycle and messages, as shown in below diagram:
5
+ When a WebSocket connection connects, the Web PubSub service transforms the connection lifecycle and messages into [events in CloudEvents format](https://learn.microsoft.com/azure/azure-web-pubsub/concept-service-internals#workflow). This library provides an express middleware to handle events representing the WebSocket connection's lifecycle and messages, as shown in below diagram:
6
6
 
7
7
  ![cloudevents](https://user-images.githubusercontent.com/668244/140321213-6442b3b8-72ee-4c28-aec1-127f9ea8f5d9.png)
8
8
 
@@ -45,7 +45,7 @@ const app = express();
45
45
  app.use(handler.getMiddleware());
46
46
 
47
47
  app.listen(3000, () =>
48
- console.log(`Azure WebPubSub Upstream ready at http://localhost:3000${handler.path}`)
48
+ console.log(`Azure WebPubSub Upstream ready at http://localhost:3000${handler.path}`),
49
49
  );
50
50
  ```
51
51
 
@@ -87,10 +87,10 @@ const handler = new WebPubSubEventHandler("chat", {
87
87
  handleConnect: (req, res) => {
88
88
  // auth the connection and set the userId of the connection
89
89
  res.success({
90
- userId: "<userId>"
90
+ userId: "<userId>",
91
91
  });
92
92
  },
93
- allowedEndpoints: ["https://<yourAllowedService>.webpubsub.azure.com"]
93
+ allowedEndpoints: ["https://<yourAllowedService>.webpubsub.azure.com"],
94
94
  });
95
95
 
96
96
  const app = express();
@@ -98,11 +98,12 @@ const app = express();
98
98
  app.use(handler.getMiddleware());
99
99
 
100
100
  app.listen(3000, () =>
101
- console.log(`Azure WebPubSub Upstream ready at http://localhost:3000${handler.path}`)
101
+ console.log(`Azure WebPubSub Upstream ready at http://localhost:3000${handler.path}`),
102
102
  );
103
103
  ```
104
104
 
105
105
  ### Handle the `connect` request and reject the connection if auth failed
106
+
106
107
  ```js
107
108
  const express = require("express");
108
109
 
@@ -114,7 +115,7 @@ const handler = new WebPubSubEventHandler("chat", {
114
115
  // the following method is also a valid approach
115
116
  // res.failWith({ code: 401, detail: "Unauthorized" });
116
117
  },
117
- allowedEndpoints: ["https://<yourAllowedService>.webpubsub.azure.com"]
118
+ allowedEndpoints: ["https://<yourAllowedService>.webpubsub.azure.com"],
118
119
  });
119
120
 
120
121
  const app = express();
@@ -122,7 +123,7 @@ const app = express();
122
123
  app.use(handler.getMiddleware());
123
124
 
124
125
  app.listen(3000, () =>
125
- console.log(`Azure WebPubSub Upstream ready at http://localhost:3000${handler.path}`)
126
+ console.log(`Azure WebPubSub Upstream ready at http://localhost:3000${handler.path}`),
126
127
  );
127
128
  ```
128
129
 
@@ -136,7 +137,7 @@ const handler = new WebPubSubEventHandler("chat", {
136
137
  onConnected: (connectedRequest) => {
137
138
  // Your onConnected logic goes here
138
139
  },
139
- allowedEndpoints: ["https://<yourAllowedService>.webpubsub.azure.com"]
140
+ allowedEndpoints: ["https://<yourAllowedService>.webpubsub.azure.com"],
140
141
  });
141
142
 
142
143
  const app = express();
@@ -144,7 +145,7 @@ const app = express();
144
145
  app.use(handler.getMiddleware());
145
146
 
146
147
  app.listen(3000, () =>
147
- console.log(`Azure WebPubSub Upstream ready at http://localhost:3000${handler.path}`)
148
+ console.log(`Azure WebPubSub Upstream ready at http://localhost:3000${handler.path}`),
148
149
  );
149
150
  ```
150
151
 
@@ -158,7 +159,7 @@ const handler = new WebPubSubEventHandler("chat", {
158
159
  onDisconnected: (disconnectedRequest) => {
159
160
  // Your onDisconnected logic goes here
160
161
  },
161
- allowedEndpoints: ["https://<yourAllowedService>.webpubsub.azure.com"]
162
+ allowedEndpoints: ["https://<yourAllowedService>.webpubsub.azure.com"],
162
163
  });
163
164
 
164
165
  const app = express();
@@ -166,11 +167,12 @@ const app = express();
166
167
  app.use(handler.getMiddleware());
167
168
 
168
169
  app.listen(3000, () =>
169
- console.log(`Azure WebPubSub Upstream ready at http://localhost:3000${handler.path}`)
170
+ console.log(`Azure WebPubSub Upstream ready at http://localhost:3000${handler.path}`),
170
171
  );
171
172
  ```
172
173
 
173
174
  ### Handle the `connect` request for mqtt and assign `<userId>` and `<mqtt>` properties
175
+
174
176
  ```js
175
177
  const express = require("express");
176
178
 
@@ -206,6 +208,7 @@ app.listen(3000, () =>
206
208
  ```
207
209
 
208
210
  ### Handle the `connect` request for mqtt and reject the connection if auth failed
211
+
209
212
  ```js
210
213
  const express = require("express");
211
214
 
@@ -276,8 +279,8 @@ const { WebPubSubEventHandler } = require("@azure/web-pubsub-express");
276
279
  const handler = new WebPubSubEventHandler("chat", {
277
280
  allowedEndpoints: [
278
281
  "https://<yourAllowedService1>.webpubsub.azure.com",
279
- "https://<yourAllowedService2>.webpubsub.azure.com"
280
- ]
282
+ "https://<yourAllowedService2>.webpubsub.azure.com",
283
+ ],
281
284
  });
282
285
 
283
286
  const app = express();
@@ -285,7 +288,7 @@ const app = express();
285
288
  app.use(handler.getMiddleware());
286
289
 
287
290
  app.listen(3000, () =>
288
- console.log(`Azure WebPubSub Upstream ready at http://localhost:3000${handler.path}`)
291
+ console.log(`Azure WebPubSub Upstream ready at http://localhost:3000${handler.path}`),
289
292
  );
290
293
  ```
291
294
 
@@ -296,7 +299,7 @@ const express = require("express");
296
299
 
297
300
  const { WebPubSubEventHandler } = require("@azure/web-pubsub-express");
298
301
  const handler = new WebPubSubEventHandler("chat", {
299
- path: "/customPath1"
302
+ path: "/customPath1",
300
303
  });
301
304
 
302
305
  const app = express();
@@ -305,7 +308,7 @@ app.use(handler.getMiddleware());
305
308
 
306
309
  app.listen(3000, () =>
307
310
  // Azure WebPubSub Upstream ready at http://localhost:3000/customPath1
308
- console.log(`Azure WebPubSub Upstream ready at http://localhost:3000${handler.path}`)
311
+ console.log(`Azure WebPubSub Upstream ready at http://localhost:3000${handler.path}`),
309
312
  );
310
313
  ```
311
314
 
@@ -328,7 +331,7 @@ const handler = new WebPubSubEventHandler("chat", {
328
331
  // You can also set the state here
329
332
  res.setState("calledTime", calledTime);
330
333
  res.success();
331
- }
334
+ },
332
335
  });
333
336
 
334
337
  const app = express();
@@ -336,7 +339,7 @@ const app = express();
336
339
  app.use(handler.getMiddleware());
337
340
 
338
341
  app.listen(3000, () =>
339
- console.log(`Azure WebPubSub Upstream ready at http://localhost:3000${handler.path}`)
342
+ console.log(`Azure WebPubSub Upstream ready at http://localhost:3000${handler.path}`),
340
343
  );
341
344
  ```
342
345
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azure/web-pubsub-express",
3
- "version": "1.0.6-alpha.20250108.1",
3
+ "version": "1.0.6-alpha.20250110.1",
4
4
  "description": "Azure Web PubSub CloudEvents handlers",
5
5
  "sdk-type": "client",
6
6
  "scripts": {