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/reference-cloud-events.md
+32-34Lines changed: 32 additions & 34 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -38,7 +38,7 @@ Or:
38
38
39
39
`WebHook-Allowed-Origin: xxx.webpubsub.azure.com`
40
40
41
-
For now, [WebHook-Request-Rate](https://github.com/cloudevents/spec/blob/v1.0/http-webhook.md#414-webhook-request-rate) and [WebHook-Request-Callback](https://github.com/cloudevents/spec/blob/v1.0/http-webhook.md#413-webhook-request-callback)are not supported.
41
+
For now, [WebHook-Request-Rate](https://github.com/cloudevents/spec/blob/v1.0/http-webhook.md#414-webhook-request-rate) and [WebHook-Request-Callback](https://github.com/cloudevents/spec/blob/v1.0/http-webhook.md#413-webhook-request-callback)aren't supported.
42
42
43
43
44
44
## Web PubSub CloudEvents attribute extension
@@ -57,12 +57,12 @@ This extension defines attributes used by Web PubSub for every event it produces
57
57
|`connectionId`|`string`| The connectionId is unique for the client connection ||
58
58
|`eventName`|`string`| The name of the event without prefix ||
59
59
|`subprotocol`|`string`| The subprotocol the client is using if any ||
60
-
|`connectionState`|`string`| Defines the state for the connection. You can use the same response header to reset the value of the state. Multiple `connectionState` headers are not allowed. Do base64 encode the string value if it contains complex characters inside, for example, you can`base64(jsonString)` to pass complex object using this attribute.||
61
-
|`signature`|`string`| The signature for the upstream webhook to validate if the incoming request is from the expected origin. The service calculates the value using both primary access key and secondary access key as the HMAC key: `Hex_encoded(HMAC_SHA256(accessKey, connectionId))`. The upstream should check if the request is valid before processing it. ||
60
+
|`connectionState`|`string`| Defines the state for the connection. You can use the same response header to reset the value of the state. Multiple `connectionState` headers aren't allowed. Do base64 encode the string value if it contains complex characters inside, for example, `base64(jsonString)` to pass complex object using this attribute.||
61
+
|`signature`|`string`| The signature for the upstream webhook to validate if the incoming request is from the expected origin. The service calculates the value using both primary access key and secondary access key as the `HMAC` key: `Hex_encoded(HMAC_SHA256(accessKey, connectionId))`. The upstream should check if the request is valid before processing it. ||
62
62
63
63
## Events
64
64
65
-
There are two types of events, one is *blocking* events that the service waits for the response of the event to continue. One is *unblocking* events that the service doesn't wait for the response of such event before processing the next message.
65
+
There are two types of events. One is *blocking* events that the service waits for the response of the event to continue. One is *unblocking* events that the service doesn't wait for the response of such event before processing the next message.
66
66
67
67
- Blocking events
68
68
-[System `connect` event](#connect)
@@ -111,11 +111,29 @@ ce-eventName: connect
111
111
```
112
112
113
113
#### Success response format:
114
+
* Header `ce-connectionState`: If this header exists, the connection state of this connection will be updated to the value of the header. Only *blocking* events can update the connection state. The below sample uses base64 encoded JSON string to store the complex state for the connection.
115
+
114
116
* Status code:
115
117
*`204`: Success, with no content.
116
118
*`200`: Success, the content SHOULD be a JSON format, with following properties allowed:
117
-
* Header `ce-connectionState`: If this header exists, the connection state of this connection will be updated to the value of the header. Please note that only *blocking* events can update the connection state. The below sample uses base64 encoded JSON string to store the complex state for the connection.
118
-
*
119
+
*`subprotocols`
120
+
121
+
The `connect` event forwards the subprotocol and authentication information to Upstream from the client. Web PubSub service uses the status code to determine if the request will be upgraded to WebSocket protocol.
122
+
123
+
If the request contains the `subprotocols` property, the server should return one subprotocol it supports. If the server doesn't want to use any subprotocols, it should **not** send the `subprotocol` property in response. [Sending a blank header is invalid](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_servers#Subprotocols).
124
+
125
+
*`userId`: `{auth-ed user ID}`
126
+
127
+
As the service allows anonymous connections, it's the `connect` event's responsibility to tell the service the user ID of the client connection. The service reads the user ID from the response payload `userId` if it exists. The connection is dropped if the user ID can't be read from the request claims nor the `connect` event's response payload.
128
+
129
+
*`groups`: `{groups to join}`
130
+
131
+
The property provides a convenient way for user to add this connection to one or multiple groups. In this way, there's no need to have another call to add this connection to some group.
132
+
133
+
*`roles`: `{roles the client has}`
134
+
135
+
The property provides a way for the upstream Webhook to authorize the client. There are different roles to grant initial permissions for PubSub WebSocket clients. Details about the permissions are described in [Client permissions](./concept-client-protocols.md#permissions).
The `connect` event forwards the subprotocol and authentication information to Upstream from the client. Web PubSub service uses the status code to determine if the request will be upgraded to WebSocket protocol.
135
-
136
-
If the request contains the `subprotocols` property, the server should return one subprotocol it supports. If the server doesn't want to use any subprotocols, it should **not** send the `subprotocol` property in response. [Sending a blank header is invalid](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_servers#Subprotocols).
137
-
138
-
*`userId`: `{auth-ed user ID}`
139
-
140
-
As the service allows anonymous connections, it's the `connect` event's responsibility to tell the service the user ID of the client connection. The service will read the user ID from the response payload `userId` if it exists. The connection will be dropped if the user ID cannot be read from the request claims nor the `connect` event's response payload.
141
-
142
-
<aname="connect_response_header_group"></a>
143
-
144
-
*`groups`: `{groups to join}`
145
-
146
-
The property provides a convenient way for user to add this connection to one or multiple groups. In this way, there's no need to have another call to add this connection to some group.
147
-
148
-
*`roles`: `{roles the client has}`
149
-
150
-
The property provides a way for the upstream Webhook to authorize the client. There are different roles to grant initial permissions for PubSub WebSocket clients. Details about the permissions are described in [Client permissions](./concept-client-protocols.md#permissions).
151
-
152
150
#### Error response format:
153
151
154
152
*`4xx`: Error, the response from Upstream will be returned as the response for the client request.
`disconnected` is an asynchronous event, when the response status code is not success, the service logs an error.
247
+
`disconnected` is an asynchronous event, when the response status code isn't success, the service logs an error.
250
248
251
249
```HTTP
252
250
HTTP/1.1 200 OK
@@ -293,7 +291,7 @@ UserPayload
293
291
*`200`: Success, the format of the `UserResponsePayload` depends on the `Content-Type` of the response.
294
292
*`Content-Type`: `application/octet-stream` for binary frame; `text/plain` for text frame;
295
293
* Header `Content-Type`: `application/octet-stream` for binary frame; `text/plain` for text frame;
296
-
* Header `ce-connectionState`: If this header exists, the connection state of this connection will be updated to the value of the header. Please note that only*blocking* events can update the connection state. The below sample uses base64 encoded JSON string to store complex state for the connection.
294
+
* Header `ce-connectionState`: If this header exists, the connection state of this connection will be updated to the value of the header. Only*blocking* events can update the connection state. The below sample uses base64 encoded JSON string to store complex state for the connection.
297
295
298
296
When the `Content-Type` is `application/octet-stream`, the service sends `UserResponsePayload` to the client using `binary` WebSocket frame. When the `Content-Type` is `text/plain`, the service sends `UserResponsePayload` to the client using `text` WebSocket frame.
299
297
@@ -307,7 +305,7 @@ UserResponsePayload
307
305
```
308
306
309
307
#### Error response format
310
-
When the status code is not success, it is considered to be error response. The connection would be **dropped** if the `message` response status code is not success.
308
+
When the status code isn't success, it's considered to be error response. The connection would be **dropped** if the `message` response status code isn't success.
311
309
312
310
### User custom event `{custom_event}` for PubSub WebSocket clients
313
311
<aname="custom_event"></a>
@@ -434,7 +432,7 @@ UserResponsePayload
434
432
* Status code
435
433
*`204`: Success, with no content.
436
434
*`200`: Success, data sending to the PubSub WebSocket client depends on the `Content-Type`;
437
-
* Header `ce-connectionState`: If this header exists, the connection state of this connection will be updated to the value of the header. Please note that only*blocking* events can update the connection state. The below sample uses base64 encoded JSON string to store the complex state for the connection.
435
+
* Header `ce-connectionState`: If this header exists, the connection state of this connection will be updated to the value of the header. Only*blocking* events can update the connection state. The below sample uses base64 encoded JSON string to store the complex state for the connection.
438
436
* When Header `Content-Type` is `application/octet-stream`, the service sends `UserResponsePayload` back to the client using `dataType` as `binary` with payload base64 encoded. A sample response:
439
437
```json
440
438
{
@@ -449,7 +447,7 @@ UserResponsePayload
449
447
450
448
451
449
#### Error response format
452
-
When the status code is not success, it is considered to be error response. The connection would be **dropped** if the `{custom_event}` response status code is not success.
450
+
When the status code isn't success, it's considered to be error response. The connection would be **dropped** if the `{custom_event}` response status code isn't success.
0 commit comments