@azure/web-pubsub 1.0.0-beta.3 → 1.0.1-alpha.20220103.2
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.
- package/CHANGELOG.md +31 -0
- package/README.md +107 -33
- package/dist/index.js +1048 -233
- package/dist/index.js.map +1 -1
- package/dist-esm/samples-dev/directMessage.js +1 -1
- package/dist-esm/samples-dev/directMessage.js.map +1 -1
- package/dist-esm/src/generated/generatedClient.js +3 -3
- package/dist-esm/src/generated/generatedClient.js.map +1 -1
- package/dist-esm/src/generated/generatedClientContext.js +8 -8
- package/dist-esm/src/generated/generatedClientContext.js.map +1 -1
- package/dist-esm/src/generated/models/index.js +6 -1
- package/dist-esm/src/generated/models/index.js.map +1 -1
- package/dist-esm/src/generated/models/mappers.js +368 -0
- package/dist-esm/src/generated/models/mappers.js.map +1 -0
- package/dist-esm/src/generated/models/parameters.js +105 -23
- package/dist-esm/src/generated/models/parameters.js.map +1 -1
- package/dist-esm/src/generated/operations/healthApi.js +4 -3
- package/dist-esm/src/generated/operations/healthApi.js.map +1 -1
- package/dist-esm/src/generated/operations/webPubSub.js +315 -59
- package/dist-esm/src/generated/operations/webPubSub.js.map +1 -1
- package/dist-esm/src/generated/operationsInterfaces/webPubSub.js.map +1 -1
- package/dist-esm/src/groupClient.js +32 -21
- package/dist-esm/src/groupClient.js.map +1 -1
- package/dist-esm/src/hubClient.js +162 -107
- package/dist-esm/src/hubClient.js.map +1 -1
- package/dist-esm/src/index.js +1 -1
- package/dist-esm/src/index.js.map +1 -1
- package/dist-esm/src/logger.js +1 -1
- package/dist-esm/src/logger.js.map +1 -1
- package/dist-esm/src/parseConnectionString.js +3 -1
- package/dist-esm/src/parseConnectionString.js.map +1 -1
- package/dist-esm/src/reverseProxyPolicy.js +21 -0
- package/dist-esm/src/reverseProxyPolicy.js.map +1 -0
- package/dist-esm/src/tracing.js +1 -1
- package/dist-esm/src/tracing.js.map +1 -1
- package/dist-esm/src/utils.js +2 -0
- package/dist-esm/src/utils.js.map +1 -1
- package/dist-esm/src/webPubSubCredentialPolicy.js +2 -2
- package/dist-esm/src/webPubSubCredentialPolicy.js.map +1 -1
- package/dist-esm/test/conn.spec.js +2 -2
- package/dist-esm/test/conn.spec.js.map +1 -1
- package/dist-esm/test/groups.spec.js +14 -6
- package/dist-esm/test/groups.spec.js.map +1 -1
- package/dist-esm/test/hubs.spec.js +53 -10
- package/dist-esm/test/hubs.spec.js.map +1 -1
- package/dist-esm/test/integration.spec.js +128 -0
- package/dist-esm/test/integration.spec.js.map +1 -0
- package/dist-esm/test/testEnv.js +6 -2
- package/dist-esm/test/testEnv.js.map +1 -1
- package/package.json +32 -32
- package/types/web-pubsub.d.ts +165 -109
- package/dist-esm/src/normalizeOptions.js +0 -8
- package/dist-esm/src/normalizeOptions.js.map +0 -1
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,36 @@
|
|
1
1
|
# Release History
|
2
2
|
|
3
|
+
## 1.0.1 (Unreleased)
|
4
|
+
|
5
|
+
### Features Added
|
6
|
+
|
7
|
+
### Breaking Changes
|
8
|
+
|
9
|
+
### Bugs Fixed
|
10
|
+
|
11
|
+
### Other Changes
|
12
|
+
|
13
|
+
## 1.0.0 (2021-11-11)
|
14
|
+
|
15
|
+
No changes.
|
16
|
+
|
17
|
+
## 1.0.0-beta.4 (2021-11-09)
|
18
|
+
|
19
|
+
### Features Added
|
20
|
+
|
21
|
+
- Support for DefaultAzureCredential
|
22
|
+
- Added support for reverse proxies, enabling usage of Web Pubsub with Azure API Management.
|
23
|
+
- Added method to close all connections in a hub `serviceClient.closeAllConnections`,
|
24
|
+
- Added method to close all connections in a group `groupClient.closeAllConnections`
|
25
|
+
- Added method to close all connections for a user `serviceClient.closeUserConnections`.
|
26
|
+
|
27
|
+
### Breaking Changes
|
28
|
+
|
29
|
+
- Renamed method `getAuthenticationToken` to `getClientAccessToken`
|
30
|
+
- Renamed method `hasUser` to `userExists`
|
31
|
+
- Renamed method `hasGroup` to `groupExists`
|
32
|
+
- Renamed method `hasConnection` to `connnectionExists`
|
33
|
+
|
3
34
|
## 1.0.0-beta.3 (2021-07-07)
|
4
35
|
|
5
36
|
### Breaking Changes
|
package/README.md
CHANGED
@@ -1,36 +1,24 @@
|
|
1
1
|
# Azure Web PubSub service client library for JavaScript
|
2
2
|
|
3
|
-
[Azure Web PubSub](https://aka.ms/awps/doc) is
|
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
|
-
|
5
|
+
You can use this library in your app server side to manage the WebSocket client connections, as shown in below diagram:
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
- **High frequency data updates:** gaming, voting, polling, auction.
|
10
|
-
- **Live dashboards and monitoring:** company dashboard, financial market data, instant sales update, multi-player game leader board, and IoT monitoring.
|
11
|
-
- **Cross-platform live chat:** live chat room, chat bot, on-line customer support, real-time shopping assistant, messenger, in-game chat, and so on.
|
12
|
-
- **Real-time location on map:** logistic tracking, delivery status tracking, transportation status updates, GPS apps.
|
13
|
-
- **Real-time targeted ads:** personalized real-time push ads and offers, interactive ads.
|
14
|
-
- **Collaborative apps:** coauthoring, whiteboard apps and team meeting software.
|
15
|
-
- **Push instant notifications:** social network, email, game, travel alert.
|
16
|
-
- **Real-time broadcasting:** live audio/video broadcasting, live captioning, translating, events/news broadcasting.
|
17
|
-
- **IoT and connected devices:** real-time IoT metrics, remote control, real-time status, and location tracking.
|
18
|
-
- **Automation:** real-time trigger from upstream events.
|
19
|
-
|
20
|
-
Use the library to:
|
7
|
+
.
|
21
8
|
|
22
9
|
- Send messages to hubs and groups.
|
23
10
|
- Send messages to particular users and connections.
|
24
11
|
- Organize users and connections into groups.
|
25
12
|
- Close connections
|
26
|
-
- Grant
|
13
|
+
- Grant, revoke, and check permissions for an existing connection
|
27
14
|
|
28
|
-
Key
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
15
|
+
Details about the terms used here are described in [Key concepts](#key-concepts) section.
|
16
|
+
|
17
|
+
[Source code](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/web-pubsub/web-pubsub) |
|
18
|
+
[Package (NPM)](https://www.npmjs.com/package/@azure/web-pubsub) |
|
19
|
+
[API reference documentation](https://aka.ms/awps/sdk/js) |
|
20
|
+
[Product documentation](https://aka.ms/awps/doc) |
|
21
|
+
[Samples][samples_ref]
|
34
22
|
|
35
23
|
## Getting started
|
36
24
|
|
@@ -66,19 +54,37 @@ const key = new AzureKeyCredential("<Key>");
|
|
66
54
|
const serviceClient = new WebPubSubServiceClient("<Endpoint>", key, "<hubName>");
|
67
55
|
```
|
68
56
|
|
57
|
+
Or authenticate the `WebPubSubServiceClient` using [Azure Active Directory][aad_doc]
|
58
|
+
|
59
|
+
1. Install the `@azure/identity` dependency
|
60
|
+
|
61
|
+
```bash
|
62
|
+
npm install @azure/identity
|
63
|
+
```
|
64
|
+
|
65
|
+
2. Update the source code to use `DefaultAzureCredential`:
|
66
|
+
|
67
|
+
```js
|
68
|
+
const { WebPubSubServiceClient, AzureKeyCredential } = require("@azure/web-pubsub");
|
69
|
+
const { DefaultAzureCredential } = require("@azure/identity");
|
70
|
+
|
71
|
+
const key = new DefaultAzureCredential();
|
72
|
+
const serviceClient = new WebPubSubServiceClient("<Endpoint>", key, "<hubName>");
|
73
|
+
```
|
74
|
+
|
69
75
|
## Key concepts
|
70
76
|
|
71
77
|
### Connection
|
72
78
|
|
73
|
-
|
79
|
+
A connection, also known as a client or a client connection, represents an individual WebSocket connection connected to the Web PubSub service. When successfully connected, a unique connection ID is assigned to this connection by the Web PubSub service.
|
74
80
|
|
75
81
|
### Hub
|
76
82
|
|
77
|
-
|
83
|
+
A hub is a logical concept for a set of client connections. Usually you use one hub for one purpose, for example, a chat hub, or a notification hub. When a client connection is created, it connects to a hub, and during its lifetime, it belongs to that hub. Different applications can share one Azure Web PubSub service by using different hub names.
|
78
84
|
|
79
85
|
### Group
|
80
86
|
|
81
|
-
|
87
|
+
A group is a subset of connections to the hub. You can add a client connection to a group, or remove the client connection from the group, anytime you want. For example, when a client joins a chat room, or when a client leaves the chat room, this chat room can be considered to be a group. A client can join multiple groups, and a group can contain multiple clients.
|
82
88
|
|
83
89
|
### User
|
84
90
|
|
@@ -86,37 +92,100 @@ Connections to Web PubSub can belong to one user. A user might have multiple con
|
|
86
92
|
|
87
93
|
### Message
|
88
94
|
|
89
|
-
|
95
|
+
When the client is connected, it can send messages to the upstream application, or receive messages from the upstream application, through the WebSocket connection.
|
90
96
|
|
91
97
|
## Examples
|
92
98
|
|
93
|
-
###
|
99
|
+
### Get the access token for a client to start the WebSocket connection
|
94
100
|
|
95
101
|
```js
|
96
102
|
const { WebPubSubServiceClient } = require("@azure/web-pubsub");
|
97
103
|
|
98
104
|
const serviceClient = new WebPubSubServiceClient("<ConnectionString>", "<hubName>");
|
99
|
-
|
105
|
+
|
106
|
+
// Get the access token for the WebSocket client connection to use
|
107
|
+
let token = await serviceClient.getClientAccessToken();
|
108
|
+
|
109
|
+
// Or get the access token and assign the client a userId
|
110
|
+
token = await serviceClient.getClientAccessToken({ userId: "user1" });
|
111
|
+
|
112
|
+
// return the token to the WebSocket client
|
100
113
|
```
|
101
114
|
|
102
|
-
### Broadcast
|
115
|
+
### Broadcast messages to all connections in a hub
|
103
116
|
|
104
117
|
```js
|
105
118
|
const { WebPubSubServiceClient } = require("@azure/web-pubsub");
|
106
119
|
|
107
120
|
const serviceClient = new WebPubSubServiceClient("<ConnectionString>", "<hubName>");
|
121
|
+
|
122
|
+
// Send a JSON message
|
123
|
+
await serviceClient.sendToAll({ message: "Hello world!" });
|
124
|
+
|
125
|
+
// Send a plain text message
|
108
126
|
await serviceClient.sendToAll("Hi there!", { contentType: "text/plain" });
|
127
|
+
|
128
|
+
// Send a binary message
|
129
|
+
const payload = new Uint8Array(10);
|
130
|
+
await serviceClient.sendToAll(payload.buffer);
|
109
131
|
```
|
110
132
|
|
111
|
-
###
|
133
|
+
### Send messages to all connections in a group
|
112
134
|
|
113
135
|
```js
|
114
136
|
const { WebPubSubServiceClient } = require("@azure/web-pubsub");
|
115
137
|
|
116
138
|
const serviceClient = new WebPubSubServiceClient("<ConnectionString>", "<hubName>");
|
117
139
|
|
140
|
+
const groupClient = serviceClient.group("<groupName>");
|
141
|
+
|
142
|
+
// Add user to the group
|
143
|
+
await groupClient.addUser("user1");
|
144
|
+
|
145
|
+
// Send a JSON message
|
146
|
+
await groupClient.sendToAll({ message: "Hello world!" });
|
147
|
+
|
148
|
+
// Send a plain text message
|
149
|
+
await groupClient.sendToAll("Hi there!", { contentType: "text/plain" });
|
150
|
+
|
151
|
+
// Send a binary message
|
118
152
|
const payload = new Uint8Array(10);
|
119
|
-
await
|
153
|
+
await groupClient.sendToAll(payload.buffer);
|
154
|
+
```
|
155
|
+
|
156
|
+
### Send messages to all connections for a user
|
157
|
+
|
158
|
+
```js
|
159
|
+
const { WebPubSubServiceClient } = require("@azure/web-pubsub");
|
160
|
+
|
161
|
+
const serviceClient = new WebPubSubServiceClient("<ConnectionString>", "<hubName>");
|
162
|
+
|
163
|
+
// Send a JSON message
|
164
|
+
await serviceClient.sendToUser("user1", { message: "Hello world!" });
|
165
|
+
|
166
|
+
// Send a plain text message
|
167
|
+
await serviceClient.sendToUser("user1", "Hi there!", { contentType: "text/plain" });
|
168
|
+
|
169
|
+
// Send a binary message
|
170
|
+
const payload = new Uint8Array(10);
|
171
|
+
await serviceClient.sendToUser("user1", payload.buffer);
|
172
|
+
```
|
173
|
+
|
174
|
+
### Check if the group has any connection
|
175
|
+
|
176
|
+
```js
|
177
|
+
const { WebPubSubServiceClient } = require("@azure/web-pubsub");
|
178
|
+
const WebSocket = require("ws");
|
179
|
+
|
180
|
+
const serviceClient = new WebPubSubServiceClient("<ConnectionString>", "<hubName>");
|
181
|
+
|
182
|
+
const groupClient = serviceClient.group("<groupName>");
|
183
|
+
|
184
|
+
// close all the connections in the group
|
185
|
+
await groupClient.closeAllConnections({ reason: "<closeReason>" });
|
186
|
+
|
187
|
+
// check if the group has any connections
|
188
|
+
const hasConnections = await serviceClient.groupExists("<groupName>");
|
120
189
|
```
|
121
190
|
|
122
191
|
### Access the raw HTTP response for an operation
|
@@ -124,7 +193,7 @@ await serviceClient.sendToAll(payload.buffer);
|
|
124
193
|
```js
|
125
194
|
const { WebPubSubServiceClient } = require("@azure/web-pubsub");
|
126
195
|
|
127
|
-
function onResponse(rawResponse
|
196
|
+
function onResponse(rawResponse) {
|
128
197
|
console.log(rawResponse);
|
129
198
|
}
|
130
199
|
const serviceClient = new WebPubSubServiceClient("<ConnectionString>", "<hubName>");
|
@@ -145,6 +214,10 @@ export AZURE_LOG_LEVEL=verbose
|
|
145
214
|
|
146
215
|
For more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).
|
147
216
|
|
217
|
+
### Live Trace
|
218
|
+
|
219
|
+
Use **Live Trace** from the Web PubSub service portal to view the live traffic.
|
220
|
+
|
148
221
|
## Next steps
|
149
222
|
|
150
223
|
Please take a look at the
|
@@ -161,3 +234,4 @@ If you'd like to contribute to this library, please read the [contributing guide
|
|
161
234
|
|
162
235
|
[azure_sub]: https://azure.microsoft.com/free/
|
163
236
|
[samples_ref]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/web-pubsub/web-pubsub/samples
|
237
|
+
[aad_doc]: https://aka.ms/awps/aad
|