You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/azure-web-pubsub/includes/reference-json-requests.md
+33-20Lines changed: 33 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,7 +18,7 @@ Format:
18
18
}
19
19
```
20
20
21
-
*`ackId` is the identity of each request and should be unique. The service sends a [ack response message](#ack-response) to notify the process result of the request. More details can be found at[AckId and Ack Response](../concept-client-protocols.md#ackid-and-ack-response)
21
+
*`ackId` is the identity of each request and should be unique. The service sends a [ack response message](#ack-response) to notify the process result of the request. For details, see [AckId and Ack Response](../concept-client-protocols.md#ackid-and-ack-response)
22
22
23
23
### Leave groups
24
24
@@ -32,7 +32,7 @@ Format:
32
32
}
33
33
```
34
34
35
-
*`ackId` is the identity of each request and should be unique. The service sends a [ack response message](#ack-response) to notify the process result of the request. More details can be found at[AckId and Ack Response](../concept-client-protocols.md#ackid-and-ack-response)
35
+
*`ackId` is the identity of each request and should be unique. The service sends a [ack response message](#ack-response) to notify the process result of the request. For details, see[AckId and Ack Response](../concept-client-protocols.md#ackid-and-ack-response)
36
36
37
37
### Publish messages
38
38
@@ -49,14 +49,15 @@ Format:
49
49
}
50
50
```
51
51
52
-
*`ackId` is the identity of each request and should be unique. The service sends a [ack response message](#ack-response) to notify the process result of the request. More details can be found at[AckId and Ack Response](../concept-client-protocols.md#ackid-and-ack-response)
53
-
*`noEcho` is optional. If set to true, this message is not echoed back to the same connection. If not set, the default value is false.
54
-
*`dataType` can be one of`json`, `text`, or `binary`:
52
+
*`ackId` is the identity of each request and should be unique. The service sends a [ack response message](#ack-response) to notify the process result of the request. For details, see[AckId and Ack Response](../concept-client-protocols.md#ackid-and-ack-response)
53
+
*`noEcho` is optional. If set to true, this message isn't echoed back to the same connection. If not set, the default value is false.
54
+
*`dataType` can be set to`json`, `text`, or `binary`:
55
55
*`json`: `data` can be any type that JSON supports and will be published as what it is; If `dataType` isn't specified, it defaults to `json`.
56
56
*`text`: `data` should be in string format, and the string data will be published;
57
57
*`binary`: `data` should be in base64 format, and the binary data will be published;
58
58
59
59
#### Case 1: publish text data:
60
+
60
61
```json
61
62
{
62
63
"type": "sendToGroup",
@@ -67,7 +68,8 @@ Format:
67
68
}
68
69
```
69
70
70
-
* What subprotocol client in this group `<group_name>` receives:
71
+
* The subprotocol clients in `<group_name>` receive:
72
+
71
73
```json
72
74
{
73
75
"type": "message",
@@ -77,9 +79,11 @@ Format:
77
79
"data" : "text data"
78
80
}
79
81
```
80
-
* What the raw client in this group `<group_name>` receives is string data `text data`.
82
+
83
+
* The raw clients in `<group_name>` receive the string `text data`.
81
84
82
85
#### Case 2: publish JSON data:
86
+
83
87
```json
84
88
{
85
89
"type": "sendToGroup",
@@ -91,7 +95,8 @@ Format:
91
95
}
92
96
```
93
97
94
-
* What subprotocol client in this group `<group_name>` receives:
98
+
* The subprotocol clients in `<group_name>` receive:
99
+
95
100
```json
96
101
{
97
102
"type": "message",
@@ -103,10 +108,11 @@ Format:
103
108
}
104
109
}
105
110
```
106
-
* What the raw client in this group `<group_name>` receives is serialized string data `{"hello": "world"}`.
107
111
112
+
* The raw clients in `<group_name>` receive the serialized string `{"hello": "world"}`.
108
113
109
114
#### Case 3: publish binary data:
115
+
110
116
```json
111
117
{
112
118
"type": "sendToGroup",
@@ -117,7 +123,8 @@ Format:
117
123
}
118
124
```
119
125
120
-
* What subprotocol client in this group `<group_name>` receives:
126
+
* The subprotocol clients in `<group_name>` receive:
127
+
121
128
```json
122
129
{
123
130
"type": "message",
@@ -127,7 +134,8 @@ Format:
127
134
"data" : "<base64_binary>",
128
135
}
129
136
```
130
-
* What the raw client in this group `<group_name>` receives is the **binary** data in the binary frame.
137
+
138
+
* The raw clients in `<group_name>` receive the **binary** data in the binary frame.
131
139
132
140
### Send custom events
133
141
@@ -143,14 +151,15 @@ Format:
143
151
}
144
152
```
145
153
146
-
*`ackId` is the identity of each request and should be unique. The service sends a [ack response message](#ack-response) to notify the process result of the request. More details can be found at[AckId and Ack Response](../concept-client-protocols.md#ackid-and-ack-response)
154
+
*`ackId` is the identity of each request and should be unique. The service sends a [ack response message](#ack-response) to notify the process result of the request. For details, see[AckId and Ack Response](../concept-client-protocols.md#ackid-and-ack-response)
147
155
148
156
`dataType` can be one of `text`, `binary`, or `json`:
149
-
*`json`: data can be any type json supports and will be published as what it is; If `dataType` is not specified, it defaults to`json`.
150
-
*`text`: data should be in string format, and the string data will be published;
151
-
*`binary`: data should be in base64 format, and the binary data will be published;
157
+
*`json`: data can be any type json supports and will be published as what it is; The default is `json`.
158
+
*`text`: data is in string format, and the string data will be published;
159
+
*`binary`: data is in base64 format, and the binary data will be published;
152
160
153
161
#### Case 1: send event with text data:
162
+
154
163
```json
155
164
{
156
165
"type": "event",
@@ -161,7 +170,7 @@ Format:
161
170
}
162
171
```
163
172
164
-
What the upstream event handler receives like below, the `Content-Type` for the CloudEvents HTTP request is `text/plain` for `dataType`=`text`
173
+
The upstream event handler receives data similar to:
165
174
166
175
```HTTP
167
176
POST /upstream HTTP/1.1
@@ -184,6 +193,8 @@ text data
184
193
185
194
```
186
195
196
+
The `Content-Type` for the CloudEvents HTTP request is `text/plain` when `dataType` is `text`.
197
+
187
198
#### Case 2: send event with JSON data:
188
199
```json
189
200
{
@@ -197,7 +208,7 @@ text data
197
208
}
198
209
```
199
210
200
-
What the upstream event handler receives like below, the `Content-Type` for the CloudEvents HTTP request is `application/json` for `dataType`=`json`
211
+
The upstream event handler receives data similar to:
201
212
202
213
```HTTP
203
214
POST /upstream HTTP/1.1
@@ -222,6 +233,8 @@ ce-eventName: <event_name>
222
233
223
234
```
224
235
236
+
The `Content-Type` for the CloudEvents HTTP request is `application/json` when `dataType` is `json`
237
+
225
238
#### Case 3: send event with binary data:
226
239
```json
227
240
{
@@ -233,7 +246,7 @@ ce-eventName: <event_name>
233
246
}
234
247
```
235
248
236
-
What the upstream event handler receives like below, the `Content-Type` for the CloudEvents HTTP request is `application/octet-stream` for `dataType`=`binary`
249
+
The upstream event handler receives data similar to:
237
250
238
251
```HTTP
239
252
POST /upstream HTTP/1.1
@@ -256,6 +269,6 @@ binary
256
269
257
270
```
258
271
259
-
The WebSocket frame can be `text` format for text message frames or UTF8 encoded binaries for `binary` message frames.
272
+
The `Content-Type` for the CloudEvents HTTP request is `application/octet-stream` when `dataType` is `binary`. The WebSocket frame can be `text` format for text message frames or UTF8 encoded binaries for `binary` message frames.
260
273
261
-
Service declines the client if the message does not match the described format.
274
+
The Web PubSub service declines the client if the message doesn't match the described format.
Copy file name to clipboardExpand all lines: articles/azure-web-pubsub/includes/reference-permission.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,14 +8,14 @@ ms.date: 08/06/2021
8
8
9
9
## Permissions
10
10
11
-
You may have noticed that when we describe the PubSub WebSocket clients, a client can publish to other clients only when it's *authorized* to. The `role`s of the client determines the *initial* permissions the client have:
11
+
A Web PubSub WebSocket client can only publish to other clients when it's authorized to. The `roles` assigned to the client determine the initial permissions granted to the client:
12
12
13
13
| Role | Permission |
14
14
|---|---|
15
15
| Not specified | The client can send event requests.
16
16
| `webpubsub.joinLeaveGroup` | The client can join/leave any group.
17
17
| `webpubsub.sendToGroup` | The client can publish messages to any group.
18
-
| `webpubsub.joinLeaveGroup.<group>` | The client can join/leave group `<group>`.
19
-
| `webpubsub.sendToGroup.<group>` | The client can publish messages to group `<group>`.
18
+
| `webpubsub.joinLeaveGroup.<group>` | The client can join/leave the group `<group>`.
19
+
| `webpubsub.sendToGroup.<group>` | The client can publish messages to the group `<group>`.
20
20
21
-
The server-side can also grant or revoke permissions of the client dynamically through REST APIs or server SDKs.
21
+
The server can also dynamically grant or revoke permissions from the client through REST APIs or server SDKs.
Copy file name to clipboardExpand all lines: articles/azure-web-pubsub/reference-json-reliable-webpubsub-subprotocol.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ author: zackliu
5
5
ms.author: chenyl
6
6
ms.service: azure-web-pubsub
7
7
ms.topic: conceptual
8
-
ms.date: 11/06/2021
8
+
ms.date: 01/04/2023
9
9
---
10
10
11
11
# Azure Web PubSub supported Reliable JSON WebSocket subprotocol
@@ -26,7 +26,7 @@ For example, in JS, a Reliable PubSub WebSocket client can be created using:
26
26
var pubsub =newWebSocket('wss://test.webpubsub.azure.com/client/hubs/hub1', 'json.reliable.webpubsub.azure.v1');
27
27
```
28
28
29
-
When using `json.reliable.webpubsub.azure.v1` subprotocol, the client must follow the [How to create reliable clients](./howto-develop-reliable-clients.md) to implement reconnection, publisher and subscriber.
29
+
When using `json.reliable.webpubsub.azure.v1` subprotocol, see [How to create reliable clients](./howto-develop-reliable-clients.md) to implement reconnection, publisher and subscriber for clients.
Reliable PubSub WebSocket client must send sequence ack message once it received a message from the service. Find more in [How to create reliable clients](./howto-develop-reliable-clients.md#subscriber)
48
+
Reliable PubSub WebSocket client must send a sequence ack message once it receives a message from the service. Find more in [How to create reliable clients](./howto-develop-reliable-clients.md#subscriber)
49
49
50
50
*`sequenceId` is a incremental uint64 number from the message received.
51
51
52
52
## Responses
53
53
54
-
Messages received by the client can be several types: `ack`, `message`, and `system`. Messages with type `message` have `sequenceId` property. Client must send [Sequence Ack](#sequence-ack) to the service once it receives a message.
54
+
Messages received by the client can be several types: `ack`, `message`, and `system`. Messages with type `message` have `sequenceId` property. Client must send a [Sequence Ack](#sequence-ack) to the service once it receives a message.
Copy file name to clipboardExpand all lines: articles/azure-web-pubsub/reference-json-webpubsub-subprotocol.md
+41-25Lines changed: 41 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,26 +4,30 @@ description: The reference describes Azure Web PubSub supported WebSocket subpro
4
4
author: vicancy
5
5
ms.author: lianwei
6
6
ms.service: azure-web-pubsub
7
-
ms.topic: conceptual
8
-
ms.date: 11/06/2021
7
+
ms.topic: reference
8
+
ms.date: 01/06/2023
9
9
---
10
10
11
-
# Azure Web PubSub supported JSON WebSocket subprotocol
12
-
13
-
This document describes the subprotocol `json.webpubsub.azure.v1`.
11
+
# Azure Web PubSub supported JSON WebSocket subprotocol
12
+
13
+
The JSON WebSocket subprotocol, `json.webpubsub.azure.v1`, enables the exchange of publish/subscribe messages directly between clients. A WebSocket connection using the `json.webpubsub.azure.v1` subprotocol is called a PubSub WebSocket client.
14
14
15
-
When the client is using this subprotocol, both outgoing data frame and incoming data frame are expected to be **JSON** payloads.
15
+
This document describes the subprotocol`json.webpubsub.azure.v1`.
16
16
17
17
## Overview
18
18
19
-
Subprotocol `json.webpubsub.azure.v1` empowers the clients to do publish/subscribe directly instead of a round trip to the upstream server. We call the WebSocket connection with `json.webpubsub.azure.v1` subprotocol a PubSub WebSocket client.
19
+
In a simple native WebSocket client, a *server* role is required to handle events from clients. A simple WebSocket connection triggers a `message` event when it sends messages, and relies on the server-side to process messages and do other operations.
20
+
21
+
When you use the `json.webpubsub.azure.v1` subprotocol, an authorized client can join a group using [join requests](#join-groups) and publish messages directly to a group using [publish requests](#publish-messages). The client can also route messages directly to upstream event handlers using [event requests](#send-custom-events).
20
22
21
-
For example, in JS, a PubSub WebSocket client can be created using:
22
-
```js
23
+
In JavaScript, a PubSub WebSocket client can be created using:
24
+
25
+
```javascript
23
26
// PubSub WebSocket client
24
27
var pubsub =newWebSocket('wss://test.webpubsub.azure.com/client/hubs/hub1', 'json.webpubsub.azure.v1');
25
28
```
26
-
For a simple WebSocket client, the *server* is a MUST HAVE role to handle the events from clients. A simple WebSocket connection always triggers a `message` event when it sends messages, and always relies on the server-side to process messages and do other operations. With the help of the `json.webpubsub.azure.v1` subprotocol, an authorized client can join a group using [join requests](#join-groups) and publish messages to a group using [publish requests](#publish-messages) directly. It can also route messages to different upstream (event handlers) by customizing the *event* the message belongs using [event requests](#send-custom-events).
29
+
30
+
The following information describes the subprotocol requests and responses. Both incoming and outgoing data frames must contain JSON payloads.
@@ -33,13 +37,18 @@ For a simple WebSocket client, the *server* is a MUST HAVE role to handle the ev
33
37
34
38
## Responses
35
39
36
-
Messages received by the client can be several types: `ack`, `message`, and `system`:
40
+
Messages received by the client can be `ack`, `message`, and `system`:
41
+
42
+
* ack - The response to a request containing an `ackId`.
43
+
* message - Messages from the group or server.
44
+
* system - Responses from the Web PubSub service to system related client requests.
37
45
38
46
### Ack response
39
47
40
-
If the request contains `ackId`, the service will return an ack response for this request. The client implementation should handle this ack mechanism, including waiting for the ack response for an `async``await` operation, and having a timeout check when the ack response is not received during a certain period.
48
+
When the client request contains `ackId`, the service will return an ack response for the request. The client should handle the ack mechanism, by waiting for the ack response with an `async``await` operation and a using a timeout operation when the ack response isn't received in a certain period.
41
49
42
50
Format:
51
+
43
52
```json
44
53
{
45
54
"type": "ack",
@@ -52,11 +61,11 @@ Format:
52
61
}
53
62
```
54
63
55
-
The client implementation SHOULD always check if the `success` is `true` or `false` first. Only when `success` is `false` the client reads from `error`.
64
+
The client implementation SHOULD always check if the `success` is `true` or `false` first, then only read the error when `success` is `false`.
56
65
57
66
### Message response
58
67
59
-
Clients can receive messages published from one group the client joined, or from the server management role that the server sends messages to the specific client or the specific user.
68
+
Clients can receive messages published from a group the client has joined or from the server.
60
69
61
70
1. When the message is from a group
62
71
@@ -71,7 +80,7 @@ Clients can receive messages published from one group the client joined, or from
71
80
}
72
81
```
73
82
74
-
1. When The message is from the server.
83
+
1. When the message is from the server.
75
84
76
85
```json
77
86
{
@@ -83,8 +92,11 @@ Clients can receive messages published from one group the client joined, or from
83
92
```
84
93
85
94
#### Case 1: Sending data `Hello World` to the connection through REST API with `Content-Type`=`text/plain`
86
-
* What a simple WebSocket client receives is a text WebSocket frame with data: `Hello World`;
87
-
* What a PubSub WebSocket client receives is as follows:
95
+
96
+
97
+
* A simple WebSocket client receives a text WebSocket frame with data: `Hello World`;
98
+
* A PubSub WebSocket client receives:
99
+
88
100
```json
89
101
{
90
102
"type": "message",
@@ -95,8 +107,10 @@ Clients can receive messages published from one group the client joined, or from
95
107
```
96
108
97
109
#### Case 2: Sending data `{ "Hello" : "World"}` to the connection through REST API with `Content-Type`=`application/json`
98
-
* What a simple WebSocket client receives is a text WebSocket frame with stringified data: `{ "Hello" : "World"}`;
99
-
* What a PubSub WebSocket client receives is as follows:
110
+
111
+
* A simple WebSocket client receives a text WebSocket frame with stringified data: `{ "Hello" : "World"}`.
112
+
* A PubSub WebSocket client receives:
113
+
100
114
```json
101
115
{
102
116
"type": "message",
@@ -108,11 +122,13 @@ Clients can receive messages published from one group the client joined, or from
108
122
}
109
123
```
110
124
111
-
If the REST API is sending a string `Hello World` using `application/json` content type, what the simple WebSocket client receives is a JSON string, which is `"Hello World"` that wraps the string with `"`.
125
+
If the REST API is sending a string `Hello World` using `application/json` content type, the simple WebSocket client receives a JSON string, which is `"Hello World"` wrapped with double quotes (`"`).
112
126
113
127
#### Case 3: Sending binary data to the connection through REST API with `Content-Type`=`application/octet-stream`
114
-
* What a simple WebSocket client receives is a binary WebSocket frame with the binary data.
115
-
* What a PubSub WebSocket client receives is as follows:
128
+
129
+
* A simple WebSocket client receives a binary WebSocket frame with the binary data.
130
+
* A PubSub WebSocket client receives:
131
+
116
132
```json
117
133
{
118
134
"type": "message",
@@ -124,11 +140,11 @@ If the REST API is sending a string `Hello World` using `application/json` conte
124
140
125
141
### System response
126
142
127
-
The Web PubSub service can also send system-related responses to the client.
143
+
The Web PubSub service sends systemrelated responses to client requests.
128
144
129
145
#### Connected
130
146
131
-
When the connection connects to service.
147
+
The responses when the client connects to service.
132
148
133
149
```json
134
150
{
@@ -141,7 +157,7 @@ When the connection connects to service.
141
157
142
158
#### Disconnected
143
159
144
-
When the server closes the connection, or when the service declines the client.
160
+
The response when the server closes the connection, or when the service declines the client.
0 commit comments