| author | vicancy |
|---|---|
| ms.author | lianwei |
| ms.service | azure-web-pubsub |
| ms.topic | include |
| ms.date | 01/24/2023 |
Format:
{
"type": "joinGroup",
"group": "<group_name>",
"ackId" : 1
}ackIdis the identity of each request and should be unique. The service sends a ack response message to notify the process result of the request. For details, see AckId and Ack Response
Format:
{
"type": "leaveGroup",
"group": "<group_name>",
"ackId" : 1
}ackIdis the identity of each request and should be unique. The service sends a ack response message to notify the process result of the request. For details, see AckId and Ack Response
Format:
{
"type": "sendToGroup",
"group": "<group_name>",
"ackId" : 1,
"noEcho": true|false,
"dataType" : "json|text|binary",
"data": {}, // data can be string or valid json token depending on the dataType
}ackIdis the identity of each request and should be unique. The service sends a ack response message to notify the process result of the request. For details, see AckId and Ack ResponsenoEchois optional. If set to true, this message isn't echoed back to the same connection. If not set, the default value is false.dataTypecan be set tojson,text, orbinary:json:datacan be any type that JSON supports and will be published as what it is; IfdataTypeisn't specified, it defaults tojson.text:datashould be in string format, and the string data will be published;binary:datashould be in base64 format, and the binary data will be published;
{
"type": "sendToGroup",
"group": "<group_name>",
"dataType" : "text",
"data": "text data",
"ackId": 1
}- The subprotocol clients in
<group_name>receive:
{
"type": "message",
"from": "group",
"group": "<group_name>",
"dataType" : "text",
"data" : "text data"
}- The simple WebSocket clients in
<group_name>receive the stringtext data.
{
"type": "sendToGroup",
"group": "<group_name>",
"dataType" : "json",
"data": {
"hello": "world"
}
}- The subprotocol clients in
<group_name>receive:
{
"type": "message",
"from": "group",
"group": "<group_name>",
"dataType" : "json",
"data" : {
"hello": "world"
}
}- The simple WebSocket clients in
<group_name>receive the serialized string{"hello": "world"}.
{
"type": "sendToGroup",
"group": "<group_name>",
"dataType" : "binary",
"data": "<base64_binary>",
"ackId": 1
}- The subprotocol clients in
<group_name>receive:
{
"type": "message",
"from": "group",
"group": "<group_name>",
"dataType" : "binary",
"data" : "<base64_binary>",
}- The simple WebSocket clients in
<group_name>receive the binary data in the binary frame.
Format:
{
"type": "event",
"event": "<event_name>",
"ackId": 1,
"dataType" : "json|text|binary",
"data": {}, // data can be string or valid json token depending on the dataType
}ackIdis the identity of each request and should be unique. The service sends a ack response message to notify the process result of the request. For details, see AckId and Ack Response
dataType can be one of text, binary, or json:
json: data can be any type json supports and will be published as what it is; The default isjson.text: data is in string format, and the string data will be published;binary: data is in base64 format, and the binary data will be published;
{
"type": "event",
"event": "<event_name>",
"ackId": 1,
"dataType" : "text",
"data": "text data",
}The upstream event handler receives data similar to:
POST /upstream HTTP/1.1
Host: xxxxxx
WebHook-Request-Origin: xxx.webpubsub.azure.com
Content-Type: text/plain
Content-Length: nnnn
ce-specversion: 1.0
ce-type: azure.webpubsub.user.<event_name>
ce-source: /client/{connectionId}
ce-id: {eventId}
ce-time: 2021-01-01T00:00:00Z
ce-signature: sha256={connection-id-hash-primary},sha256={connection-id-hash-secondary}
ce-userId: {userId}
ce-connectionId: {connectionId}
ce-hub: {hub_name}
ce-eventName: <event_name>
text data
The Content-Type for the CloudEvents HTTP request is text/plain when dataType is text.
{
"type": "event",
"event": "<event_name>",
"ackId": 1,
"dataType" : "json",
"data": {
"hello": "world"
},
}The upstream event handler receives data similar to:
POST /upstream HTTP/1.1
Host: xxxxxx
WebHook-Request-Origin: xxx.webpubsub.azure.com
Content-Type: application/json
Content-Length: nnnn
ce-specversion: 1.0
ce-type: azure.webpubsub.user.<event_name>
ce-source: /client/{connectionId}
ce-id: {eventId}
ce-time: 2021-01-01T00:00:00Z
ce-signature: sha256={connection-id-hash-primary},sha256={connection-id-hash-secondary}
ce-userId: {userId}
ce-connectionId: {connectionId}
ce-hub: {hub_name}
ce-eventName: <event_name>
{
"hello": "world"
}
The Content-Type for the CloudEvents HTTP request is application/json when dataType is json
{
"type": "event",
"event": "<event_name>",
"ackId": 1,
"dataType" : "binary",
"data": "base64_binary",
}The upstream event handler receives data similar to:
POST /upstream HTTP/1.1
Host: xxxxxx
WebHook-Request-Origin: xxx.webpubsub.azure.com
Content-Type: application/octet-stream
Content-Length: nnnn
ce-specversion: 1.0
ce-type: azure.webpubsub.user.<event_name>
ce-source: /client/{connectionId}
ce-id: {eventId}
ce-time: 2021-01-01T00:00:00Z
ce-signature: sha256={connection-id-hash-primary},sha256={connection-id-hash-secondary}
ce-userId: {userId}
ce-connectionId: {connectionId}
ce-hub: {hub_name}
ce-eventName: <event_name>
binary
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.
The Web PubSub service declines the client if the message doesn't match the described format.
Format:
{
"type": "ping",
}The client can send a ping message to the service to enable the Web PubSub service to detect the client's liveness.