@azure/web-pubsub 1.0.0-beta.2 → 1.0.1-alpha.20211215.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 +40 -0
- package/README.md +118 -31
- package/dist/index.js +1315 -567
- package/dist/index.js.map +1 -1
- package/dist-esm/samples-dev/broadcasting.js +16 -16
- package/dist-esm/samples-dev/broadcasting.js.map +1 -1
- package/dist-esm/samples-dev/directMessage.js +9 -9
- package/dist-esm/samples-dev/directMessage.js.map +1 -1
- package/dist-esm/samples-dev/managingGroups.js +11 -12
- package/dist-esm/samples-dev/managingGroups.js.map +1 -1
- package/dist-esm/src/generated/generatedClient.js +23 -0
- package/dist-esm/src/generated/generatedClient.js.map +1 -0
- package/dist-esm/src/generated/generatedClientContext.js +41 -0
- package/dist-esm/src/generated/generatedClientContext.js.map +1 -0
- package/dist-esm/src/generated/index.js +10 -2
- package/dist-esm/src/generated/index.js.map +1 -1
- package/dist-esm/src/generated/models/index.js +13 -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 +124 -43
- package/dist-esm/src/generated/models/parameters.js.map +1 -1
- package/dist-esm/src/generated/operations/healthApi.js +16 -11
- package/dist-esm/src/generated/operations/healthApi.js.map +1 -1
- package/dist-esm/src/generated/operations/index.js +7 -0
- package/dist-esm/src/generated/operations/index.js.map +1 -1
- package/dist-esm/src/generated/operations/webPubSub.js +341 -175
- package/dist-esm/src/generated/operations/webPubSub.js.map +1 -1
- package/dist-esm/src/generated/operationsInterfaces/healthApi.js +9 -0
- package/dist-esm/src/generated/operationsInterfaces/healthApi.js.map +1 -0
- package/dist-esm/src/generated/operationsInterfaces/index.js +10 -0
- package/dist-esm/src/generated/operationsInterfaces/index.js.map +1 -0
- package/dist-esm/src/generated/operationsInterfaces/webPubSub.js +9 -0
- package/dist-esm/src/generated/operationsInterfaces/webPubSub.js.map +1 -0
- package/dist-esm/src/groupClient.js +74 -92
- package/dist-esm/src/groupClient.js.map +1 -1
- package/dist-esm/src/hubClient.js +280 -196
- package/dist-esm/src/hubClient.js.map +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/utils.js +8 -6
- package/dist-esm/src/utils.js.map +1 -1
- package/dist-esm/src/webPubSubCredentialPolicy.js +18 -18
- package/dist-esm/src/webPubSubCredentialPolicy.js.map +1 -1
- package/dist-esm/test/conn.spec.js +7 -8
- package/dist-esm/test/conn.spec.js.map +1 -1
- package/dist-esm/test/groups.spec.js +39 -38
- package/dist-esm/test/groups.spec.js.map +1 -1
- package/dist-esm/test/hubs.spec.js +95 -49
- 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 +5 -1
- package/dist-esm/test/testEnv.js.map +1 -1
- package/package.json +37 -36
- package/types/web-pubsub.d.ts +186 -138
- package/dist-esm/src/generated/azureWebPubSubServiceRestAPI.js +0 -15
- package/dist-esm/src/generated/azureWebPubSubServiceRestAPI.js.map +0 -1
- package/dist-esm/src/generated/azureWebPubSubServiceRestAPIContext.js +0 -34
- package/dist-esm/src/generated/azureWebPubSubServiceRestAPIContext.js.map +0 -1
- package/dist-esm/src/normalizeOptions.js +0 -8
- package/dist-esm/src/normalizeOptions.js.map +0 -1
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,45 @@
|
|
1
1
|
# Release History
|
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
|
+
|
34
|
+
## 1.0.0-beta.3 (2021-07-07)
|
35
|
+
|
36
|
+
### Breaking Changes
|
37
|
+
|
38
|
+
- `hasUser` has been removed from `GroupClient` as that operation is no longer supported by the service.
|
39
|
+
- Updated to have void returns for most operations. If you were previously using `RestResponse`, you can instead use the `onResponse` callback in the operation options. See README for an example.
|
40
|
+
|
2
41
|
## 1.0.0-beta.2 (2021-05-19)
|
42
|
+
|
3
43
|
Remove "url" dependency
|
4
44
|
|
5
45
|
## 1.0.0-beta.1 (2021-04-23)
|
package/README.md
CHANGED
@@ -1,31 +1,20 @@
|
|
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
|
-
[
|
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) |
|
29
18
|
[Package (NPM)](https://www.npmjs.com/package/@azure/web-pubsub) |
|
30
19
|
[API reference documentation](https://aka.ms/awps/sdk/js) |
|
31
20
|
[Product documentation](https://aka.ms/awps/doc) |
|
@@ -35,7 +24,7 @@ Use the library to:
|
|
35
24
|
|
36
25
|
### Currently supported environments
|
37
26
|
|
38
|
-
- [Node.js](https://nodejs.org/)
|
27
|
+
- [LTS versions of Node.js](https://nodejs.org/about/releases/)
|
39
28
|
|
40
29
|
### Prerequisites
|
41
30
|
|
@@ -65,19 +54,37 @@ const key = new AzureKeyCredential("<Key>");
|
|
65
54
|
const serviceClient = new WebPubSubServiceClient("<Endpoint>", key, "<hubName>");
|
66
55
|
```
|
67
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
|
+
|
68
75
|
## Key concepts
|
69
76
|
|
70
77
|
### Connection
|
71
78
|
|
72
|
-
|
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.
|
73
80
|
|
74
81
|
### Hub
|
75
82
|
|
76
|
-
|
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.
|
77
84
|
|
78
85
|
### Group
|
79
86
|
|
80
|
-
|
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.
|
81
88
|
|
82
89
|
### User
|
83
90
|
|
@@ -85,37 +92,112 @@ Connections to Web PubSub can belong to one user. A user might have multiple con
|
|
85
92
|
|
86
93
|
### Message
|
87
94
|
|
88
|
-
|
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.
|
89
96
|
|
90
97
|
## Examples
|
91
98
|
|
92
|
-
###
|
99
|
+
### Get the access token for a client to start the WebSocket connection
|
93
100
|
|
94
101
|
```js
|
95
102
|
const { WebPubSubServiceClient } = require("@azure/web-pubsub");
|
96
103
|
|
97
104
|
const serviceClient = new WebPubSubServiceClient("<ConnectionString>", "<hubName>");
|
98
|
-
|
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
|
99
113
|
```
|
100
114
|
|
101
|
-
### Broadcast
|
115
|
+
### Broadcast messages to all connections in a hub
|
102
116
|
|
103
117
|
```js
|
104
118
|
const { WebPubSubServiceClient } = require("@azure/web-pubsub");
|
105
119
|
|
106
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
|
107
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);
|
108
131
|
```
|
109
132
|
|
110
|
-
###
|
133
|
+
### Send messages to all connections in a group
|
111
134
|
|
112
135
|
```js
|
113
136
|
const { WebPubSubServiceClient } = require("@azure/web-pubsub");
|
114
137
|
|
115
138
|
const serviceClient = new WebPubSubServiceClient("<ConnectionString>", "<hubName>");
|
116
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
|
117
152
|
const payload = new Uint8Array(10);
|
118
|
-
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>");
|
189
|
+
```
|
190
|
+
|
191
|
+
### Access the raw HTTP response for an operation
|
192
|
+
|
193
|
+
```js
|
194
|
+
const { WebPubSubServiceClient } = require("@azure/web-pubsub");
|
195
|
+
|
196
|
+
function onResponse(rawResponse) {
|
197
|
+
console.log(rawResponse);
|
198
|
+
}
|
199
|
+
const serviceClient = new WebPubSubServiceClient("<ConnectionString>", "<hubName>");
|
200
|
+
await serviceClient.sendToAll({ message: "Hello world!" }, { onResponse });
|
119
201
|
```
|
120
202
|
|
121
203
|
## Troubleshooting
|
@@ -130,7 +212,11 @@ You can set the following environment variable to get the debug logs when using
|
|
130
212
|
export AZURE_LOG_LEVEL=verbose
|
131
213
|
```
|
132
214
|
|
133
|
-
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/
|
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).
|
216
|
+
|
217
|
+
### Live Trace
|
218
|
+
|
219
|
+
Use **Live Trace** from the Web PubSub service portal to view the live traffic.
|
134
220
|
|
135
221
|
## Next steps
|
136
222
|
|
@@ -140,11 +226,12 @@ directory for detailed examples on how to use this library.
|
|
140
226
|
|
141
227
|
## Contributing
|
142
228
|
|
143
|
-
If you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/
|
229
|
+
If you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) to learn more about how to build and test the code.
|
144
230
|
|
145
231
|
## Related projects
|
146
232
|
|
147
233
|
- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)
|
148
234
|
|
149
235
|
[azure_sub]: https://azure.microsoft.com/free/
|
150
|
-
[samples_ref]: https://github.com/Azure/azure-sdk-for-js/tree/
|
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
|