@azure/web-pubsub-client-protobuf 1.0.0-alpha.20250224.1 → 1.0.0-alpha.20250228.1
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/README.md +23 -8
- package/dist/browser/index.d.ts +10 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.js +17 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/browser/logger.d.ts +5 -0
- package/dist/browser/logger.d.ts.map +1 -0
- package/dist/browser/logger.js +8 -0
- package/dist/browser/logger.js.map +1 -0
- package/dist/browser/package.json +3 -0
- package/dist/browser/webPubSubProtobufProtocol.d.ts +25 -0
- package/dist/browser/webPubSubProtobufProtocol.d.ts.map +1 -0
- package/dist/browser/webPubSubProtobufProtocol.js +33 -0
- package/dist/browser/webPubSubProtobufProtocol.js.map +1 -0
- package/dist/browser/webPubSubProtobufProtocolBase.d.ts +20 -0
- package/dist/browser/webPubSubProtobufProtocolBase.d.ts.map +1 -0
- package/dist/browser/webPubSubProtobufProtocolBase.js +187 -0
- package/dist/browser/webPubSubProtobufProtocolBase.js.map +1 -0
- package/dist/browser/webPubSubProtobufReliableProtocol.d.ts +25 -0
- package/dist/browser/webPubSubProtobufReliableProtocol.d.ts.map +1 -0
- package/dist/browser/webPubSubProtobufReliableProtocol.js +33 -0
- package/dist/browser/webPubSubProtobufReliableProtocol.js.map +1 -0
- package/dist/react-native/index.d.ts +10 -0
- package/dist/react-native/index.d.ts.map +1 -0
- package/dist/react-native/index.js +17 -0
- package/dist/react-native/index.js.map +1 -0
- package/dist/react-native/logger.d.ts +5 -0
- package/dist/react-native/logger.d.ts.map +1 -0
- package/dist/react-native/logger.js +8 -0
- package/dist/react-native/logger.js.map +1 -0
- package/dist/react-native/package.json +3 -0
- package/dist/react-native/webPubSubProtobufProtocol.d.ts +25 -0
- package/dist/react-native/webPubSubProtobufProtocol.d.ts.map +1 -0
- package/dist/react-native/webPubSubProtobufProtocol.js +33 -0
- package/dist/react-native/webPubSubProtobufProtocol.js.map +1 -0
- package/dist/react-native/webPubSubProtobufProtocolBase.d.ts +20 -0
- package/dist/react-native/webPubSubProtobufProtocolBase.d.ts.map +1 -0
- package/dist/react-native/webPubSubProtobufProtocolBase.js +187 -0
- package/dist/react-native/webPubSubProtobufProtocolBase.js.map +1 -0
- package/dist/react-native/webPubSubProtobufReliableProtocol.d.ts +25 -0
- package/dist/react-native/webPubSubProtobufReliableProtocol.d.ts.map +1 -0
- package/dist/react-native/webPubSubProtobufReliableProtocol.js +33 -0
- package/dist/react-native/webPubSubProtobufReliableProtocol.js.map +1 -0
- package/package.json +27 -16
package/README.md
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
# Web PubSub client protobuf protocol library for JavaScript
|
|
2
2
|
|
|
3
|
-
[Azure Web PubSub](https://aka.ms/awps/doc) is a cloud service that helps developers easily build real-time features in web applications with publish-subscribe patterns at scale.
|
|
3
|
+
[Azure Web PubSub](https://aka.ms/awps/doc) is a cloud service that helps developers easily build real-time features in web applications with publish-subscribe patterns at scale.
|
|
4
4
|
|
|
5
5
|
You can use this library to add protobuf subprotocols including `protobuf.reliable.webpubsub.azure.v1` and `protobuf.webpubsub.azure.v1` support to `@azure/web-pubsub-client` library.
|
|
6
6
|
|
|
7
|
-
|
|
8
7
|
## Getting started
|
|
9
8
|
|
|
10
9
|
### Currently supported environments
|
|
@@ -24,39 +23,55 @@ npm install @azure/web-pubsub-client-protobuf
|
|
|
24
23
|
|
|
25
24
|
### 2. Use Protobuf protocols
|
|
26
25
|
|
|
27
|
-
```
|
|
28
|
-
|
|
26
|
+
```ts snippet:ReadmeSampleCreateClient
|
|
27
|
+
import { WebPubSubClient } from "@azure/web-pubsub-client";
|
|
28
|
+
import { WebPubSubProtobufReliableProtocol } from "@azure/web-pubsub-client-protobuf";
|
|
29
|
+
|
|
30
|
+
const client = new WebPubSubClient("client-access-url", {
|
|
31
|
+
protocol: WebPubSubProtobufReliableProtocol(),
|
|
32
|
+
});
|
|
29
33
|
```
|
|
30
34
|
|
|
31
35
|
## Troubleshooting
|
|
32
36
|
|
|
33
|
-
|
|
37
|
+
### Enable logs
|
|
34
38
|
|
|
35
|
-
|
|
39
|
+
Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`.
|
|
36
40
|
|
|
37
41
|
```bash
|
|
38
42
|
export AZURE_LOG_LEVEL=verbose
|
|
39
43
|
```
|
|
40
44
|
|
|
45
|
+
Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:
|
|
46
|
+
|
|
47
|
+
```ts snippet:SetLogLevel
|
|
48
|
+
import { setLogLevel } from "@azure/logger";
|
|
49
|
+
|
|
50
|
+
setLogLevel("info");
|
|
51
|
+
```
|
|
52
|
+
|
|
41
53
|
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).
|
|
42
54
|
|
|
43
55
|
- ### Live Trace
|
|
44
56
|
|
|
45
57
|
Use [Live Trace tool][live_trace] from Web PubSub portal to view the live traffic.
|
|
58
|
+
|
|
46
59
|
---
|
|
60
|
+
|
|
47
61
|
## Additional resources
|
|
62
|
+
|
|
48
63
|
- Learn more about client permission, see [permissions](https://learn.microsoft.com/azure/azure-web-pubsub/reference-json-reliable-webpubsub-subprotocol#permissions)
|
|
49
64
|
|
|
50
|
-
- [Server SDK - JavaScript documentation](https://aka.ms/awps/sdk/js)
|
|
65
|
+
- [Server SDK - JavaScript documentation](https://aka.ms/awps/sdk/js)
|
|
51
66
|
- [Product documentation](https://aka.ms/awps/doc)
|
|
52
67
|
- [Samples][samples_ref]
|
|
53
68
|
|
|
54
69
|
---
|
|
70
|
+
|
|
55
71
|
## Contributing
|
|
56
72
|
|
|
57
73
|
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.
|
|
58
74
|
|
|
59
|
-
|
|
60
75
|
[azure_sub]: https://azure.microsoft.com/free/
|
|
61
76
|
[samples_ref]: https://github.com/Azure/azure-webpubsub/tree/main/samples/javascript/
|
|
62
77
|
[create_instance]: https://learn.microsoft.com/azure/azure-web-pubsub/howto-develop-create-instance
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { WebPubSubClientProtocol } from "@azure/web-pubsub-client";
|
|
2
|
+
/**
|
|
3
|
+
* Return the "protobuf.webpubsub.azure.v1" protocol
|
|
4
|
+
*/
|
|
5
|
+
export declare const WebPubSubProtobufProtocol: () => WebPubSubClientProtocol;
|
|
6
|
+
/**
|
|
7
|
+
* Return the "protobuf.reliable.webpubsub.azure.v1" protocol
|
|
8
|
+
*/
|
|
9
|
+
export declare const WebPubSubProtobufReliableProtocol: () => WebPubSubClientProtocol;
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAIxE;;GAEG;AACH,eAAO,MAAM,yBAAyB,QAAO,uBAE5C,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iCAAiC,QAAO,uBAEpD,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
import { WebPubSubProtobufProtocolImpl } from "./webPubSubProtobufProtocol.js";
|
|
4
|
+
import { WebPubSubProtobufReliableProtocolImpl } from "./webPubSubProtobufReliableProtocol.js";
|
|
5
|
+
/**
|
|
6
|
+
* Return the "protobuf.webpubsub.azure.v1" protocol
|
|
7
|
+
*/
|
|
8
|
+
export const WebPubSubProtobufProtocol = () => {
|
|
9
|
+
return new WebPubSubProtobufProtocolImpl();
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Return the "protobuf.reliable.webpubsub.azure.v1" protocol
|
|
13
|
+
*/
|
|
14
|
+
export const WebPubSubProtobufReliableProtocol = () => {
|
|
15
|
+
return new WebPubSubProtobufReliableProtocolImpl();
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,6BAA6B,EAAE,MAAM,gCAAgC,CAAC;AAC/E,OAAO,EAAE,qCAAqC,EAAE,MAAM,wCAAwC,CAAC;AAE/F;;GAEG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,GAA4B,EAAE;IACrE,OAAO,IAAI,6BAA6B,EAAE,CAAC;AAC7C,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,iCAAiC,GAAG,GAA4B,EAAE;IAC7E,OAAO,IAAI,qCAAqC,EAAE,CAAC;AACrD,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { WebPubSubClientProtocol } from \"@azure/web-pubsub-client\";\nimport { WebPubSubProtobufProtocolImpl } from \"./webPubSubProtobufProtocol.js\";\nimport { WebPubSubProtobufReliableProtocolImpl } from \"./webPubSubProtobufReliableProtocol.js\";\n\n/**\n * Return the \"protobuf.webpubsub.azure.v1\" protocol\n */\nexport const WebPubSubProtobufProtocol = (): WebPubSubClientProtocol => {\n return new WebPubSubProtobufProtocolImpl();\n};\n\n/**\n * Return the \"protobuf.reliable.webpubsub.azure.v1\" protocol\n */\nexport const WebPubSubProtobufReliableProtocol = (): WebPubSubClientProtocol => {\n return new WebPubSubProtobufReliableProtocolImpl();\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,eAAO,MAAM,MAAM,qCAAmD,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
import { createClientLogger } from "@azure/logger";
|
|
4
|
+
/**
|
|
5
|
+
* The \@azure\/logger configuration for this package.
|
|
6
|
+
*/
|
|
7
|
+
export const logger = createClientLogger("web-pubsub-client-protobuf");
|
|
8
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnD;;GAEG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,kBAAkB,CAAC,4BAA4B,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { createClientLogger } from \"@azure/logger\";\n\n/**\n * The \\@azure\\/logger configuration for this package.\n */\nexport const logger = createClientLogger(\"web-pubsub-client-protobuf\");\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { WebPubSubMessage, WebPubSubClientProtocol } from "@azure/web-pubsub-client";
|
|
2
|
+
/**
|
|
3
|
+
* The "protobuf.reliable.webpubsub.azure.v1" protocol
|
|
4
|
+
*/
|
|
5
|
+
export declare class WebPubSubProtobufProtocolImpl implements WebPubSubClientProtocol {
|
|
6
|
+
/**
|
|
7
|
+
* True if the protocol supports reliable features
|
|
8
|
+
*/
|
|
9
|
+
readonly isReliableSubProtocol = false;
|
|
10
|
+
/**
|
|
11
|
+
* The name of subprotocol. Name will be used in websocket subprotocol
|
|
12
|
+
*/
|
|
13
|
+
readonly name = "protobuf.webpubsub.azure.v1";
|
|
14
|
+
/**
|
|
15
|
+
* Creates WebPubSubMessage objects from the specified serialized representation.
|
|
16
|
+
* @param input - The serialized representation
|
|
17
|
+
*/
|
|
18
|
+
parseMessages(input: ArrayBuffer): WebPubSubMessage | null;
|
|
19
|
+
/**
|
|
20
|
+
* Write WebPubSubMessage to string
|
|
21
|
+
* @param message - The message to be written
|
|
22
|
+
*/
|
|
23
|
+
writeMessage(message: WebPubSubMessage): ArrayBuffer;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=webPubSubProtobufProtocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webPubSubProtobufProtocol.d.ts","sourceRoot":"","sources":["../../src/webPubSubProtobufProtocol.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAG1F;;GAEG;AACH,qBAAa,6BAA8B,YAAW,uBAAuB;IAC3E;;OAEG;IACH,SAAgB,qBAAqB,SAAS;IAE9C;;OAEG;IACH,SAAgB,IAAI,iCAAiC;IAErD;;;OAGG;IACI,aAAa,CAAC,KAAK,EAAE,WAAW,GAAG,gBAAgB,GAAG,IAAI;IAIjE;;;OAGG;IACI,YAAY,CAAC,OAAO,EAAE,gBAAgB,GAAG,WAAW;CAG5D"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
import { WebPubSubProtobufProtocolBase } from "./webPubSubProtobufProtocolBase.js";
|
|
4
|
+
/**
|
|
5
|
+
* The "protobuf.reliable.webpubsub.azure.v1" protocol
|
|
6
|
+
*/
|
|
7
|
+
export class WebPubSubProtobufProtocolImpl {
|
|
8
|
+
constructor() {
|
|
9
|
+
/**
|
|
10
|
+
* True if the protocol supports reliable features
|
|
11
|
+
*/
|
|
12
|
+
this.isReliableSubProtocol = false;
|
|
13
|
+
/**
|
|
14
|
+
* The name of subprotocol. Name will be used in websocket subprotocol
|
|
15
|
+
*/
|
|
16
|
+
this.name = "protobuf.webpubsub.azure.v1";
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Creates WebPubSubMessage objects from the specified serialized representation.
|
|
20
|
+
* @param input - The serialized representation
|
|
21
|
+
*/
|
|
22
|
+
parseMessages(input) {
|
|
23
|
+
return WebPubSubProtobufProtocolBase.parseMessages(input);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Write WebPubSubMessage to string
|
|
27
|
+
* @param message - The message to be written
|
|
28
|
+
*/
|
|
29
|
+
writeMessage(message) {
|
|
30
|
+
return WebPubSubProtobufProtocolBase.writeMessage(message);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=webPubSubProtobufProtocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webPubSubProtobufProtocol.js","sourceRoot":"","sources":["../../src/webPubSubProtobufProtocol.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,6BAA6B,EAAE,MAAM,oCAAoC,CAAC;AAEnF;;GAEG;AACH,MAAM,OAAO,6BAA6B;IAA1C;QACE;;WAEG;QACa,0BAAqB,GAAG,KAAK,CAAC;QAE9C;;WAEG;QACa,SAAI,GAAG,6BAA6B,CAAC;IAiBvD,CAAC;IAfC;;;OAGG;IACI,aAAa,CAAC,KAAkB;QACrC,OAAO,6BAA6B,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IAC5D,CAAC;IAED;;;OAGG;IACI,YAAY,CAAC,OAAyB;QAC3C,OAAO,6BAA6B,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IAC7D,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { WebPubSubMessage, WebPubSubClientProtocol } from \"@azure/web-pubsub-client\";\nimport { WebPubSubProtobufProtocolBase } from \"./webPubSubProtobufProtocolBase.js\";\n\n/**\n * The \"protobuf.reliable.webpubsub.azure.v1\" protocol\n */\nexport class WebPubSubProtobufProtocolImpl implements WebPubSubClientProtocol {\n /**\n * True if the protocol supports reliable features\n */\n public readonly isReliableSubProtocol = false;\n\n /**\n * The name of subprotocol. Name will be used in websocket subprotocol\n */\n public readonly name = \"protobuf.webpubsub.azure.v1\";\n\n /**\n * Creates WebPubSubMessage objects from the specified serialized representation.\n * @param input - The serialized representation\n */\n public parseMessages(input: ArrayBuffer): WebPubSubMessage | null {\n return WebPubSubProtobufProtocolBase.parseMessages(input);\n }\n\n /**\n * Write WebPubSubMessage to string\n * @param message - The message to be written\n */\n public writeMessage(message: WebPubSubMessage): ArrayBuffer {\n return WebPubSubProtobufProtocolBase.writeMessage(message);\n }\n}\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { WebPubSubMessage } from "@azure/web-pubsub-client";
|
|
2
|
+
/**
|
|
3
|
+
* The "protobuf.reliable.webpubsub.azure.v1" protocol
|
|
4
|
+
*/
|
|
5
|
+
export declare class WebPubSubProtobufProtocolBase {
|
|
6
|
+
/**
|
|
7
|
+
* Creates WebPubSubMessage objects from the specified serialized representation.
|
|
8
|
+
* @param input - The serialized representation
|
|
9
|
+
*/
|
|
10
|
+
static parseMessages(input: ArrayBuffer): WebPubSubMessage | null;
|
|
11
|
+
/**
|
|
12
|
+
* Write WebPubSubMessage to string
|
|
13
|
+
* @param message - The message to be written
|
|
14
|
+
*/
|
|
15
|
+
static writeMessage(message: WebPubSubMessage): ArrayBuffer;
|
|
16
|
+
private static _getIMessageData;
|
|
17
|
+
private static _getNumber;
|
|
18
|
+
private static _isIAny;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=webPubSubProtobufProtocolBase.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webPubSubProtobufProtocolBase.d.ts","sourceRoot":"","sources":["../../src/webPubSubProtobufProtocolBase.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAQV,gBAAgB,EAEjB,MAAM,0BAA0B,CAAC;AAUlC;;GAEG;AACH,qBAAa,6BAA6B;IACxC;;;OAGG;WACW,aAAa,CAAC,KAAK,EAAE,WAAW,GAAG,gBAAgB,GAAG,IAAI;IA6ExE;;;OAGG;WACW,YAAY,CAAC,OAAO,EAAE,gBAAgB,GAAG,WAAW;IAoDlE,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAgC/B,OAAO,CAAC,MAAM,CAAC,UAAU;IAOzB,OAAO,CAAC,MAAM,CAAC,OAAO;CAGvB"}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
import { DownstreamMessage, MessageData, UpstreamMessage, google, } from "./generated/clientProto.js";
|
|
4
|
+
/**
|
|
5
|
+
* The "protobuf.reliable.webpubsub.azure.v1" protocol
|
|
6
|
+
*/
|
|
7
|
+
export class WebPubSubProtobufProtocolBase {
|
|
8
|
+
/**
|
|
9
|
+
* Creates WebPubSubMessage objects from the specified serialized representation.
|
|
10
|
+
* @param input - The serialized representation
|
|
11
|
+
*/
|
|
12
|
+
static parseMessages(input) {
|
|
13
|
+
const downstream = DownstreamMessage.decode(new Uint8Array(input));
|
|
14
|
+
if (downstream.ackMessage) {
|
|
15
|
+
const ack = {
|
|
16
|
+
kind: "ack",
|
|
17
|
+
ackId: this._getNumber(downstream.ackMessage.ackId),
|
|
18
|
+
success: downstream.ackMessage.success,
|
|
19
|
+
};
|
|
20
|
+
if (downstream.ackMessage.error) {
|
|
21
|
+
ack.error = {
|
|
22
|
+
name: downstream.ackMessage.error.name,
|
|
23
|
+
message: downstream.ackMessage.error.message,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
return ack;
|
|
27
|
+
}
|
|
28
|
+
else if (downstream.systemMessage) {
|
|
29
|
+
if (downstream.systemMessage.connectedMessage) {
|
|
30
|
+
const msg = downstream.systemMessage.connectedMessage;
|
|
31
|
+
return {
|
|
32
|
+
kind: "connected",
|
|
33
|
+
connectionId: msg.connectionId,
|
|
34
|
+
userId: msg.userId,
|
|
35
|
+
reconnectionToken: msg.reconnectionToken,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
else if (downstream.systemMessage.disconnectedMessage) {
|
|
39
|
+
const msg = downstream.systemMessage.disconnectedMessage;
|
|
40
|
+
return { kind: "disconnected", message: msg.reason };
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else if (downstream.dataMessage) {
|
|
47
|
+
const sequenceId = this._getNumber(downstream.dataMessage.sequenceId);
|
|
48
|
+
const messageData = downstream.dataMessage.data;
|
|
49
|
+
let dataType;
|
|
50
|
+
let data;
|
|
51
|
+
if (messageData.textData) {
|
|
52
|
+
dataType = "text";
|
|
53
|
+
data = messageData.textData;
|
|
54
|
+
}
|
|
55
|
+
else if (messageData.jsonData) {
|
|
56
|
+
dataType = "json";
|
|
57
|
+
data = JSON.parse(messageData.jsonData);
|
|
58
|
+
}
|
|
59
|
+
else if (messageData.binaryData) {
|
|
60
|
+
dataType = "binary";
|
|
61
|
+
data = messageData.binaryData.buffer.slice(messageData.binaryData.byteOffset, messageData.binaryData.byteLength + messageData.binaryData.byteOffset);
|
|
62
|
+
}
|
|
63
|
+
else if (messageData.protobufData) {
|
|
64
|
+
dataType = "protobuf";
|
|
65
|
+
data = messageData.protobufData;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
if (downstream.dataMessage.from === "group") {
|
|
71
|
+
return {
|
|
72
|
+
kind: "groupData",
|
|
73
|
+
dataType: dataType,
|
|
74
|
+
data: data,
|
|
75
|
+
sequenceId: sequenceId,
|
|
76
|
+
group: downstream.dataMessage.group,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
else if (downstream.dataMessage.from === "server") {
|
|
80
|
+
return {
|
|
81
|
+
kind: "serverData",
|
|
82
|
+
dataType: dataType,
|
|
83
|
+
data: data,
|
|
84
|
+
sequenceId: sequenceId,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Write WebPubSubMessage to string
|
|
97
|
+
* @param message - The message to be written
|
|
98
|
+
*/
|
|
99
|
+
static writeMessage(message) {
|
|
100
|
+
let upstream;
|
|
101
|
+
switch (message.kind) {
|
|
102
|
+
case "joinGroup": {
|
|
103
|
+
const joinGroup = UpstreamMessage.JoinGroupMessage.create({
|
|
104
|
+
group: message.group,
|
|
105
|
+
ackId: message.ackId,
|
|
106
|
+
});
|
|
107
|
+
upstream = UpstreamMessage.create({ joinGroupMessage: joinGroup });
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
case "leaveGroup": {
|
|
111
|
+
const leaveGroup = UpstreamMessage.LeaveGroupMessage.create({
|
|
112
|
+
group: message.group,
|
|
113
|
+
ackId: message.ackId,
|
|
114
|
+
});
|
|
115
|
+
upstream = UpstreamMessage.create({ leaveGroupMessage: leaveGroup });
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
case "sendToGroup": {
|
|
119
|
+
const sendToGroup = UpstreamMessage.SendToGroupMessage.create({
|
|
120
|
+
group: message.group,
|
|
121
|
+
ackId: message.ackId,
|
|
122
|
+
data: this._getIMessageData(message.data, message.dataType),
|
|
123
|
+
noEcho: message.noEcho,
|
|
124
|
+
});
|
|
125
|
+
upstream = UpstreamMessage.create({ sendToGroupMessage: sendToGroup });
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
case "sendEvent": {
|
|
129
|
+
const sendEvent = UpstreamMessage.EventMessage.create({
|
|
130
|
+
event: message.event,
|
|
131
|
+
ackId: message.ackId,
|
|
132
|
+
data: this._getIMessageData(message.data, message.dataType),
|
|
133
|
+
});
|
|
134
|
+
upstream = UpstreamMessage.create({ eventMessage: sendEvent });
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
case "sequenceAck": {
|
|
138
|
+
const sequenceAck = UpstreamMessage.SequenceAckMessage.create({
|
|
139
|
+
sequenceId: message.sequenceId,
|
|
140
|
+
});
|
|
141
|
+
upstream = UpstreamMessage.create({ sequenceAckMessage: sequenceAck });
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
default:
|
|
145
|
+
throw new TypeError(`kind is not supported: ${message.kind}`);
|
|
146
|
+
}
|
|
147
|
+
return UpstreamMessage.encode(upstream).finish();
|
|
148
|
+
}
|
|
149
|
+
static _getIMessageData(data, dataType) {
|
|
150
|
+
switch (dataType) {
|
|
151
|
+
case "binary":
|
|
152
|
+
if (!(data instanceof ArrayBuffer)) {
|
|
153
|
+
throw new TypeError("Message must be a ArrayBuffer.");
|
|
154
|
+
}
|
|
155
|
+
return MessageData.create({ binaryData: new Uint8Array(data) });
|
|
156
|
+
case "protobuf":
|
|
157
|
+
if (WebPubSubProtobufProtocolBase._isIAny(data)) {
|
|
158
|
+
return MessageData.create({
|
|
159
|
+
protobufData: google.protobuf.Any.create({
|
|
160
|
+
type_url: data.type_url,
|
|
161
|
+
value: new Uint8Array(data.value),
|
|
162
|
+
}),
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
throw new TypeError("Message must be a google.protobuf.Any.");
|
|
166
|
+
case "text":
|
|
167
|
+
if (typeof data !== "string") {
|
|
168
|
+
throw new TypeError("Message must be a string.");
|
|
169
|
+
}
|
|
170
|
+
return MessageData.create({ textData: data });
|
|
171
|
+
case "json":
|
|
172
|
+
return MessageData.create({ jsonData: JSON.stringify(data) });
|
|
173
|
+
default:
|
|
174
|
+
throw new TypeError(`dataType is not supported: ${dataType}`);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
static _getNumber(value) {
|
|
178
|
+
if (value === null || value === undefined || typeof value === "number") {
|
|
179
|
+
return value;
|
|
180
|
+
}
|
|
181
|
+
return value.toNumber();
|
|
182
|
+
}
|
|
183
|
+
static _isIAny(obj) {
|
|
184
|
+
return "type_url" in obj && "value" in obj;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
//# sourceMappingURL=webPubSubProtobufProtocolBase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webPubSubProtobufProtocolBase.js","sourceRoot":"","sources":["../../src/webPubSubProtobufProtocolBase.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAclC,OAAO,EACL,iBAAiB,EACjB,WAAW,EACX,eAAe,EACf,MAAM,GACP,MAAM,4BAA4B,CAAC;AAGpC;;GAEG;AACH,MAAM,OAAO,6BAA6B;IACxC;;;OAGG;IACI,MAAM,CAAC,aAAa,CAAC,KAAkB;QAC5C,MAAM,UAAU,GAAG,iBAAiB,CAAC,MAAM,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;QACnE,IAAI,UAAU,CAAC,UAAU,EAAE,CAAC;YAC1B,MAAM,GAAG,GAAG;gBACV,IAAI,EAAE,KAAK;gBACX,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,UAAU,CAAC,KAAK,CAAC;gBACnD,OAAO,EAAE,UAAU,CAAC,UAAU,CAAC,OAAO;aACzB,CAAC;YAChB,IAAI,UAAU,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;gBAChC,GAAG,CAAC,KAAK,GAAG;oBACV,IAAI,EAAE,UAAU,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI;oBACtC,OAAO,EAAE,UAAU,CAAC,UAAU,CAAC,KAAK,CAAC,OAAO;iBAC1B,CAAC;YACvB,CAAC;YACD,OAAO,GAAG,CAAC;QACb,CAAC;aAAM,IAAI,UAAU,CAAC,aAAa,EAAE,CAAC;YACpC,IAAI,UAAU,CAAC,aAAa,CAAC,gBAAgB,EAAE,CAAC;gBAC9C,MAAM,GA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,CAAC,CAAC;gBACnD,CAAC;gBACD,OAAO,WAAW,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAkB,CAAC,CAAC;YAChE,KAAK,MAAM;gBACT,OAAO,WAAW,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAkB,CAAC,CAAC;YAChF;gBACE,MAAM,IAAI,SAAS,CAAC,8BAA8B,QAAQ,EAAE,CAAC,CAAC;QAClE,CAAC;IACH,CAAC;IAEO,MAAM,CAAC,UAAU,CAAC,KAAuC;QAC/D,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YACvE,OAAO,KAAK,CAAC;QACf,CAAC;QACD,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;IAC1B,CAAC;IAEO,MAAM,CAAC,OAAO,CAAC,GAAQ;QAC7B,OAAO,UAAU,IAAI,GAAG,IAAI,OAAO,IAAI,GAAG,CAAC;IAC7C,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n AckMessage,\n AckMessageError,\n ConnectedMessage,\n DisconnectedMessage,\n GroupDataMessage,\n ServerDataMessage,\n WebPubSubDataType,\n WebPubSubMessage,\n JSONTypes,\n} from \"@azure/web-pubsub-client\";\nimport type { IMessageData, IUpstreamMessage } from \"./generated/clientProto.js\";\nimport {\n DownstreamMessage,\n MessageData,\n UpstreamMessage,\n google,\n} from \"./generated/clientProto.js\";\nimport type Long from \"long\";\n\n/**\n * The \"protobuf.reliable.webpubsub.azure.v1\" protocol\n */\nexport class WebPubSubProtobufProtocolBase {\n /**\n * Creates WebPubSubMessage objects from the specified serialized representation.\n * @param input - The serialized representation\n */\n public static parseMessages(input: ArrayBuffer): WebPubSubMessage | null {\n const downstream = DownstreamMessage.decode(new Uint8Array(input));\n if (downstream.ackMessage) {\n const ack = {\n kind: \"ack\",\n ackId: this._getNumber(downstream.ackMessage.ackId),\n success: downstream.ackMessage.success,\n } as AckMessage;\n if (downstream.ackMessage.error) {\n ack.error = {\n name: downstream.ackMessage.error.name,\n message: downstream.ackMessage.error.message,\n } as AckMessageError;\n }\n return ack;\n } else if (downstream.systemMessage) {\n if (downstream.systemMessage.connectedMessage) {\n const msg = downstream.systemMessage.connectedMessage;\n return {\n kind: \"connected\",\n connectionId: msg.connectionId,\n userId: msg.userId,\n reconnectionToken: msg.reconnectionToken,\n } as ConnectedMessage;\n } else if (downstream.systemMessage.disconnectedMessage) {\n const msg = downstream.systemMessage.disconnectedMessage;\n return { kind: \"disconnected\", message: msg.reason } as DisconnectedMessage;\n } else {\n return null;\n }\n } else if (downstream.dataMessage) {\n const sequenceId = this._getNumber(downstream.dataMessage.sequenceId);\n const messageData = downstream.dataMessage.data!;\n let dataType: WebPubSubDataType;\n let data: string | ArrayBuffer | object;\n if (messageData.textData) {\n dataType = \"text\";\n data = messageData.textData;\n } else if (messageData.jsonData) {\n dataType = \"json\";\n data = JSON.parse(messageData.jsonData);\n } else if (messageData.binaryData) {\n dataType = \"binary\";\n data = messageData.binaryData.buffer.slice(\n messageData.binaryData.byteOffset,\n messageData.binaryData.byteLength + messageData.binaryData.byteOffset,\n );\n } else if (messageData.protobufData) {\n dataType = \"protobuf\";\n data = messageData.protobufData;\n } else {\n return null;\n }\n\n if (downstream.dataMessage.from === \"group\") {\n return {\n kind: \"groupData\",\n dataType: dataType,\n data: data,\n sequenceId: sequenceId,\n group: downstream.dataMessage.group,\n } as GroupDataMessage;\n } else if (downstream.dataMessage.from === \"server\") {\n return {\n kind: \"serverData\",\n dataType: dataType,\n data: data,\n sequenceId: sequenceId,\n } as ServerDataMessage;\n } else {\n return null;\n }\n } else {\n return null;\n }\n }\n\n /**\n * Write WebPubSubMessage to string\n * @param message - The message to be written\n */\n public static writeMessage(message: WebPubSubMessage): ArrayBuffer {\n let upstream: UpstreamMessage;\n switch (message.kind) {\n case \"joinGroup\": {\n const joinGroup = UpstreamMessage.JoinGroupMessage.create({\n group: message.group,\n ackId: message.ackId,\n } as UpstreamMessage.IJoinGroupMessage);\n upstream = UpstreamMessage.create({ joinGroupMessage: joinGroup } as IUpstreamMessage);\n break;\n }\n case \"leaveGroup\": {\n const leaveGroup = UpstreamMessage.LeaveGroupMessage.create({\n group: message.group,\n ackId: message.ackId,\n } as UpstreamMessage.ILeaveGroupMessage);\n upstream = UpstreamMessage.create({ leaveGroupMessage: leaveGroup } as IUpstreamMessage);\n break;\n }\n case \"sendToGroup\": {\n const sendToGroup = UpstreamMessage.SendToGroupMessage.create({\n group: message.group,\n ackId: message.ackId,\n data: this._getIMessageData(message.data, message.dataType),\n noEcho: message.noEcho,\n } as UpstreamMessage.ISendToGroupMessage);\n upstream = UpstreamMessage.create({ sendToGroupMessage: sendToGroup } as IUpstreamMessage);\n break;\n }\n case \"sendEvent\": {\n const sendEvent = UpstreamMessage.EventMessage.create({\n event: message.event,\n ackId: message.ackId,\n data: this._getIMessageData(message.data, message.dataType),\n } as UpstreamMessage.IEventMessage);\n upstream = UpstreamMessage.create({ eventMessage: sendEvent } as IUpstreamMessage);\n break;\n }\n case \"sequenceAck\": {\n const sequenceAck = UpstreamMessage.SequenceAckMessage.create({\n sequenceId: message.sequenceId,\n } as UpstreamMessage.ISequenceAckMessage);\n upstream = UpstreamMessage.create({ sequenceAckMessage: sequenceAck } as IUpstreamMessage);\n break;\n }\n default:\n throw new TypeError(`kind is not supported: ${message.kind}`);\n }\n\n return UpstreamMessage.encode(upstream).finish();\n }\n\n private static _getIMessageData(\n data: JSONTypes | ArrayBuffer,\n dataType: WebPubSubDataType,\n ): IMessageData {\n switch (dataType) {\n case \"binary\":\n if (!(data instanceof ArrayBuffer)) {\n throw new TypeError(\"Message must be a ArrayBuffer.\");\n }\n return MessageData.create({ binaryData: new Uint8Array(data) } as IMessageData);\n case \"protobuf\":\n if (WebPubSubProtobufProtocolBase._isIAny(data)) {\n return MessageData.create({\n protobufData: google.protobuf.Any.create({\n type_url: data.type_url!,\n value: new Uint8Array(data.value!),\n } as google.protobuf.IAny),\n } as IMessageData);\n }\n throw new TypeError(\"Message must be a google.protobuf.Any.\");\n case \"text\":\n if (typeof data !== \"string\") {\n throw new TypeError(\"Message must be a string.\");\n }\n return MessageData.create({ textData: data } as IMessageData);\n case \"json\":\n return MessageData.create({ jsonData: JSON.stringify(data) } as IMessageData);\n default:\n throw new TypeError(`dataType is not supported: ${dataType}`);\n }\n }\n\n private static _getNumber(value: number | Long | null | undefined): number | null | undefined {\n if (value === null || value === undefined || typeof value === \"number\") {\n return value;\n }\n return value.toNumber();\n }\n\n private static _isIAny(obj: any): obj is google.protobuf.IAny {\n return \"type_url\" in obj && \"value\" in obj;\n }\n}\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { WebPubSubMessage, WebPubSubClientProtocol } from "@azure/web-pubsub-client";
|
|
2
|
+
/**
|
|
3
|
+
* The "protobuf.reliable.webpubsub.azure.v1" protocol
|
|
4
|
+
*/
|
|
5
|
+
export declare class WebPubSubProtobufReliableProtocolImpl implements WebPubSubClientProtocol {
|
|
6
|
+
/**
|
|
7
|
+
* True if the protocol supports reliable features
|
|
8
|
+
*/
|
|
9
|
+
readonly isReliableSubProtocol = true;
|
|
10
|
+
/**
|
|
11
|
+
* The name of subprotocol. Name will be used in websocket subprotocol
|
|
12
|
+
*/
|
|
13
|
+
readonly name = "protobuf.reliable.webpubsub.azure.v1";
|
|
14
|
+
/**
|
|
15
|
+
* Creates WebPubSubMessage objects from the specified serialized representation.
|
|
16
|
+
* @param input - The serialized representation
|
|
17
|
+
*/
|
|
18
|
+
parseMessages(input: ArrayBuffer): WebPubSubMessage | null;
|
|
19
|
+
/**
|
|
20
|
+
* Write WebPubSubMessage to string
|
|
21
|
+
* @param message - The message to be written
|
|
22
|
+
*/
|
|
23
|
+
writeMessage(message: WebPubSubMessage): ArrayBuffer;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=webPubSubProtobufReliableProtocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webPubSubProtobufReliableProtocol.d.ts","sourceRoot":"","sources":["../../src/webPubSubProtobufReliableProtocol.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAG1F;;GAEG;AACH,qBAAa,qCAAsC,YAAW,uBAAuB;IACnF;;OAEG;IACH,SAAgB,qBAAqB,QAAQ;IAE7C;;OAEG;IACH,SAAgB,IAAI,0CAA0C;IAE9D;;;OAGG;IACI,aAAa,CAAC,KAAK,EAAE,WAAW,GAAG,gBAAgB,GAAG,IAAI;IAIjE;;;OAGG;IACI,YAAY,CAAC,OAAO,EAAE,gBAAgB,GAAG,WAAW;CAG5D"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
import { WebPubSubProtobufProtocolBase } from "./webPubSubProtobufProtocolBase.js";
|
|
4
|
+
/**
|
|
5
|
+
* The "protobuf.reliable.webpubsub.azure.v1" protocol
|
|
6
|
+
*/
|
|
7
|
+
export class WebPubSubProtobufReliableProtocolImpl {
|
|
8
|
+
constructor() {
|
|
9
|
+
/**
|
|
10
|
+
* True if the protocol supports reliable features
|
|
11
|
+
*/
|
|
12
|
+
this.isReliableSubProtocol = true;
|
|
13
|
+
/**
|
|
14
|
+
* The name of subprotocol. Name will be used in websocket subprotocol
|
|
15
|
+
*/
|
|
16
|
+
this.name = "protobuf.reliable.webpubsub.azure.v1";
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Creates WebPubSubMessage objects from the specified serialized representation.
|
|
20
|
+
* @param input - The serialized representation
|
|
21
|
+
*/
|
|
22
|
+
parseMessages(input) {
|
|
23
|
+
return WebPubSubProtobufProtocolBase.parseMessages(input);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Write WebPubSubMessage to string
|
|
27
|
+
* @param message - The message to be written
|
|
28
|
+
*/
|
|
29
|
+
writeMessage(message) {
|
|
30
|
+
return WebPubSubProtobufProtocolBase.writeMessage(message);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=webPubSubProtobufReliableProtocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webPubSubProtobufReliableProtocol.js","sourceRoot":"","sources":["../../src/webPubSubProtobufReliableProtocol.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,6BAA6B,EAAE,MAAM,oCAAoC,CAAC;AAEnF;;GAEG;AACH,MAAM,OAAO,qCAAqC;IAAlD;QACE;;WAEG;QACa,0BAAqB,GAAG,IAAI,CAAC;QAE7C;;WAEG;QACa,SAAI,GAAG,sCAAsC,CAAC;IAiBhE,CAAC;IAfC;;;OAGG;IACI,aAAa,CAAC,KAAkB;QACrC,OAAO,6BAA6B,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IAC5D,CAAC;IAED;;;OAGG;IACI,YAAY,CAAC,OAAyB;QAC3C,OAAO,6BAA6B,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IAC7D,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { WebPubSubMessage, WebPubSubClientProtocol } from \"@azure/web-pubsub-client\";\nimport { WebPubSubProtobufProtocolBase } from \"./webPubSubProtobufProtocolBase.js\";\n\n/**\n * The \"protobuf.reliable.webpubsub.azure.v1\" protocol\n */\nexport class WebPubSubProtobufReliableProtocolImpl implements WebPubSubClientProtocol {\n /**\n * True if the protocol supports reliable features\n */\n public readonly isReliableSubProtocol = true;\n\n /**\n * The name of subprotocol. Name will be used in websocket subprotocol\n */\n public readonly name = \"protobuf.reliable.webpubsub.azure.v1\";\n\n /**\n * Creates WebPubSubMessage objects from the specified serialized representation.\n * @param input - The serialized representation\n */\n public parseMessages(input: ArrayBuffer): WebPubSubMessage | null {\n return WebPubSubProtobufProtocolBase.parseMessages(input);\n }\n\n /**\n * Write WebPubSubMessage to string\n * @param message - The message to be written\n */\n public writeMessage(message: WebPubSubMessage): ArrayBuffer {\n return WebPubSubProtobufProtocolBase.writeMessage(message);\n }\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { WebPubSubClientProtocol } from "@azure/web-pubsub-client";
|
|
2
|
+
/**
|
|
3
|
+
* Return the "protobuf.webpubsub.azure.v1" protocol
|
|
4
|
+
*/
|
|
5
|
+
export declare const WebPubSubProtobufProtocol: () => WebPubSubClientProtocol;
|
|
6
|
+
/**
|
|
7
|
+
* Return the "protobuf.reliable.webpubsub.azure.v1" protocol
|
|
8
|
+
*/
|
|
9
|
+
export declare const WebPubSubProtobufReliableProtocol: () => WebPubSubClientProtocol;
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAIxE;;GAEG;AACH,eAAO,MAAM,yBAAyB,QAAO,uBAE5C,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iCAAiC,QAAO,uBAEpD,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
import { WebPubSubProtobufProtocolImpl } from "./webPubSubProtobufProtocol.js";
|
|
4
|
+
import { WebPubSubProtobufReliableProtocolImpl } from "./webPubSubProtobufReliableProtocol.js";
|
|
5
|
+
/**
|
|
6
|
+
* Return the "protobuf.webpubsub.azure.v1" protocol
|
|
7
|
+
*/
|
|
8
|
+
export const WebPubSubProtobufProtocol = () => {
|
|
9
|
+
return new WebPubSubProtobufProtocolImpl();
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Return the "protobuf.reliable.webpubsub.azure.v1" protocol
|
|
13
|
+
*/
|
|
14
|
+
export const WebPubSubProtobufReliableProtocol = () => {
|
|
15
|
+
return new WebPubSubProtobufReliableProtocolImpl();
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,6BAA6B,EAAE,MAAM,gCAAgC,CAAC;AAC/E,OAAO,EAAE,qCAAqC,EAAE,MAAM,wCAAwC,CAAC;AAE/F;;GAEG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,GAA4B,EAAE;IACrE,OAAO,IAAI,6BAA6B,EAAE,CAAC;AAC7C,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,iCAAiC,GAAG,GAA4B,EAAE;IAC7E,OAAO,IAAI,qCAAqC,EAAE,CAAC;AACrD,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { WebPubSubClientProtocol } from \"@azure/web-pubsub-client\";\nimport { WebPubSubProtobufProtocolImpl } from \"./webPubSubProtobufProtocol.js\";\nimport { WebPubSubProtobufReliableProtocolImpl } from \"./webPubSubProtobufReliableProtocol.js\";\n\n/**\n * Return the \"protobuf.webpubsub.azure.v1\" protocol\n */\nexport const WebPubSubProtobufProtocol = (): WebPubSubClientProtocol => {\n return new WebPubSubProtobufProtocolImpl();\n};\n\n/**\n * Return the \"protobuf.reliable.webpubsub.azure.v1\" protocol\n */\nexport const WebPubSubProtobufReliableProtocol = (): WebPubSubClientProtocol => {\n return new WebPubSubProtobufReliableProtocolImpl();\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,eAAO,MAAM,MAAM,qCAAmD,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
import { createClientLogger } from "@azure/logger";
|
|
4
|
+
/**
|
|
5
|
+
* The \@azure\/logger configuration for this package.
|
|
6
|
+
*/
|
|
7
|
+
export const logger = createClientLogger("web-pubsub-client-protobuf");
|
|
8
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnD;;GAEG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,kBAAkB,CAAC,4BAA4B,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { createClientLogger } from \"@azure/logger\";\n\n/**\n * The \\@azure\\/logger configuration for this package.\n */\nexport const logger = createClientLogger(\"web-pubsub-client-protobuf\");\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { WebPubSubMessage, WebPubSubClientProtocol } from "@azure/web-pubsub-client";
|
|
2
|
+
/**
|
|
3
|
+
* The "protobuf.reliable.webpubsub.azure.v1" protocol
|
|
4
|
+
*/
|
|
5
|
+
export declare class WebPubSubProtobufProtocolImpl implements WebPubSubClientProtocol {
|
|
6
|
+
/**
|
|
7
|
+
* True if the protocol supports reliable features
|
|
8
|
+
*/
|
|
9
|
+
readonly isReliableSubProtocol = false;
|
|
10
|
+
/**
|
|
11
|
+
* The name of subprotocol. Name will be used in websocket subprotocol
|
|
12
|
+
*/
|
|
13
|
+
readonly name = "protobuf.webpubsub.azure.v1";
|
|
14
|
+
/**
|
|
15
|
+
* Creates WebPubSubMessage objects from the specified serialized representation.
|
|
16
|
+
* @param input - The serialized representation
|
|
17
|
+
*/
|
|
18
|
+
parseMessages(input: ArrayBuffer): WebPubSubMessage | null;
|
|
19
|
+
/**
|
|
20
|
+
* Write WebPubSubMessage to string
|
|
21
|
+
* @param message - The message to be written
|
|
22
|
+
*/
|
|
23
|
+
writeMessage(message: WebPubSubMessage): ArrayBuffer;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=webPubSubProtobufProtocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webPubSubProtobufProtocol.d.ts","sourceRoot":"","sources":["../../src/webPubSubProtobufProtocol.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAG1F;;GAEG;AACH,qBAAa,6BAA8B,YAAW,uBAAuB;IAC3E;;OAEG;IACH,SAAgB,qBAAqB,SAAS;IAE9C;;OAEG;IACH,SAAgB,IAAI,iCAAiC;IAErD;;;OAGG;IACI,aAAa,CAAC,KAAK,EAAE,WAAW,GAAG,gBAAgB,GAAG,IAAI;IAIjE;;;OAGG;IACI,YAAY,CAAC,OAAO,EAAE,gBAAgB,GAAG,WAAW;CAG5D"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
import { WebPubSubProtobufProtocolBase } from "./webPubSubProtobufProtocolBase.js";
|
|
4
|
+
/**
|
|
5
|
+
* The "protobuf.reliable.webpubsub.azure.v1" protocol
|
|
6
|
+
*/
|
|
7
|
+
export class WebPubSubProtobufProtocolImpl {
|
|
8
|
+
constructor() {
|
|
9
|
+
/**
|
|
10
|
+
* True if the protocol supports reliable features
|
|
11
|
+
*/
|
|
12
|
+
this.isReliableSubProtocol = false;
|
|
13
|
+
/**
|
|
14
|
+
* The name of subprotocol. Name will be used in websocket subprotocol
|
|
15
|
+
*/
|
|
16
|
+
this.name = "protobuf.webpubsub.azure.v1";
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Creates WebPubSubMessage objects from the specified serialized representation.
|
|
20
|
+
* @param input - The serialized representation
|
|
21
|
+
*/
|
|
22
|
+
parseMessages(input) {
|
|
23
|
+
return WebPubSubProtobufProtocolBase.parseMessages(input);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Write WebPubSubMessage to string
|
|
27
|
+
* @param message - The message to be written
|
|
28
|
+
*/
|
|
29
|
+
writeMessage(message) {
|
|
30
|
+
return WebPubSubProtobufProtocolBase.writeMessage(message);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=webPubSubProtobufProtocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webPubSubProtobufProtocol.js","sourceRoot":"","sources":["../../src/webPubSubProtobufProtocol.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,6BAA6B,EAAE,MAAM,oCAAoC,CAAC;AAEnF;;GAEG;AACH,MAAM,OAAO,6BAA6B;IAA1C;QACE;;WAEG;QACa,0BAAqB,GAAG,KAAK,CAAC;QAE9C;;WAEG;QACa,SAAI,GAAG,6BAA6B,CAAC;IAiBvD,CAAC;IAfC;;;OAGG;IACI,aAAa,CAAC,KAAkB;QACrC,OAAO,6BAA6B,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IAC5D,CAAC;IAED;;;OAGG;IACI,YAAY,CAAC,OAAyB;QAC3C,OAAO,6BAA6B,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IAC7D,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { WebPubSubMessage, WebPubSubClientProtocol } from \"@azure/web-pubsub-client\";\nimport { WebPubSubProtobufProtocolBase } from \"./webPubSubProtobufProtocolBase.js\";\n\n/**\n * The \"protobuf.reliable.webpubsub.azure.v1\" protocol\n */\nexport class WebPubSubProtobufProtocolImpl implements WebPubSubClientProtocol {\n /**\n * True if the protocol supports reliable features\n */\n public readonly isReliableSubProtocol = false;\n\n /**\n * The name of subprotocol. Name will be used in websocket subprotocol\n */\n public readonly name = \"protobuf.webpubsub.azure.v1\";\n\n /**\n * Creates WebPubSubMessage objects from the specified serialized representation.\n * @param input - The serialized representation\n */\n public parseMessages(input: ArrayBuffer): WebPubSubMessage | null {\n return WebPubSubProtobufProtocolBase.parseMessages(input);\n }\n\n /**\n * Write WebPubSubMessage to string\n * @param message - The message to be written\n */\n public writeMessage(message: WebPubSubMessage): ArrayBuffer {\n return WebPubSubProtobufProtocolBase.writeMessage(message);\n }\n}\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { WebPubSubMessage } from "@azure/web-pubsub-client";
|
|
2
|
+
/**
|
|
3
|
+
* The "protobuf.reliable.webpubsub.azure.v1" protocol
|
|
4
|
+
*/
|
|
5
|
+
export declare class WebPubSubProtobufProtocolBase {
|
|
6
|
+
/**
|
|
7
|
+
* Creates WebPubSubMessage objects from the specified serialized representation.
|
|
8
|
+
* @param input - The serialized representation
|
|
9
|
+
*/
|
|
10
|
+
static parseMessages(input: ArrayBuffer): WebPubSubMessage | null;
|
|
11
|
+
/**
|
|
12
|
+
* Write WebPubSubMessage to string
|
|
13
|
+
* @param message - The message to be written
|
|
14
|
+
*/
|
|
15
|
+
static writeMessage(message: WebPubSubMessage): ArrayBuffer;
|
|
16
|
+
private static _getIMessageData;
|
|
17
|
+
private static _getNumber;
|
|
18
|
+
private static _isIAny;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=webPubSubProtobufProtocolBase.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webPubSubProtobufProtocolBase.d.ts","sourceRoot":"","sources":["../../src/webPubSubProtobufProtocolBase.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAQV,gBAAgB,EAEjB,MAAM,0BAA0B,CAAC;AAUlC;;GAEG;AACH,qBAAa,6BAA6B;IACxC;;;OAGG;WACW,aAAa,CAAC,KAAK,EAAE,WAAW,GAAG,gBAAgB,GAAG,IAAI;IA6ExE;;;OAGG;WACW,YAAY,CAAC,OAAO,EAAE,gBAAgB,GAAG,WAAW;IAoDlE,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAgC/B,OAAO,CAAC,MAAM,CAAC,UAAU;IAOzB,OAAO,CAAC,MAAM,CAAC,OAAO;CAGvB"}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
import { DownstreamMessage, MessageData, UpstreamMessage, google, } from "./generated/clientProto.js";
|
|
4
|
+
/**
|
|
5
|
+
* The "protobuf.reliable.webpubsub.azure.v1" protocol
|
|
6
|
+
*/
|
|
7
|
+
export class WebPubSubProtobufProtocolBase {
|
|
8
|
+
/**
|
|
9
|
+
* Creates WebPubSubMessage objects from the specified serialized representation.
|
|
10
|
+
* @param input - The serialized representation
|
|
11
|
+
*/
|
|
12
|
+
static parseMessages(input) {
|
|
13
|
+
const downstream = DownstreamMessage.decode(new Uint8Array(input));
|
|
14
|
+
if (downstream.ackMessage) {
|
|
15
|
+
const ack = {
|
|
16
|
+
kind: "ack",
|
|
17
|
+
ackId: this._getNumber(downstream.ackMessage.ackId),
|
|
18
|
+
success: downstream.ackMessage.success,
|
|
19
|
+
};
|
|
20
|
+
if (downstream.ackMessage.error) {
|
|
21
|
+
ack.error = {
|
|
22
|
+
name: downstream.ackMessage.error.name,
|
|
23
|
+
message: downstream.ackMessage.error.message,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
return ack;
|
|
27
|
+
}
|
|
28
|
+
else if (downstream.systemMessage) {
|
|
29
|
+
if (downstream.systemMessage.connectedMessage) {
|
|
30
|
+
const msg = downstream.systemMessage.connectedMessage;
|
|
31
|
+
return {
|
|
32
|
+
kind: "connected",
|
|
33
|
+
connectionId: msg.connectionId,
|
|
34
|
+
userId: msg.userId,
|
|
35
|
+
reconnectionToken: msg.reconnectionToken,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
else if (downstream.systemMessage.disconnectedMessage) {
|
|
39
|
+
const msg = downstream.systemMessage.disconnectedMessage;
|
|
40
|
+
return { kind: "disconnected", message: msg.reason };
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else if (downstream.dataMessage) {
|
|
47
|
+
const sequenceId = this._getNumber(downstream.dataMessage.sequenceId);
|
|
48
|
+
const messageData = downstream.dataMessage.data;
|
|
49
|
+
let dataType;
|
|
50
|
+
let data;
|
|
51
|
+
if (messageData.textData) {
|
|
52
|
+
dataType = "text";
|
|
53
|
+
data = messageData.textData;
|
|
54
|
+
}
|
|
55
|
+
else if (messageData.jsonData) {
|
|
56
|
+
dataType = "json";
|
|
57
|
+
data = JSON.parse(messageData.jsonData);
|
|
58
|
+
}
|
|
59
|
+
else if (messageData.binaryData) {
|
|
60
|
+
dataType = "binary";
|
|
61
|
+
data = messageData.binaryData.buffer.slice(messageData.binaryData.byteOffset, messageData.binaryData.byteLength + messageData.binaryData.byteOffset);
|
|
62
|
+
}
|
|
63
|
+
else if (messageData.protobufData) {
|
|
64
|
+
dataType = "protobuf";
|
|
65
|
+
data = messageData.protobufData;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
if (downstream.dataMessage.from === "group") {
|
|
71
|
+
return {
|
|
72
|
+
kind: "groupData",
|
|
73
|
+
dataType: dataType,
|
|
74
|
+
data: data,
|
|
75
|
+
sequenceId: sequenceId,
|
|
76
|
+
group: downstream.dataMessage.group,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
else if (downstream.dataMessage.from === "server") {
|
|
80
|
+
return {
|
|
81
|
+
kind: "serverData",
|
|
82
|
+
dataType: dataType,
|
|
83
|
+
data: data,
|
|
84
|
+
sequenceId: sequenceId,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Write WebPubSubMessage to string
|
|
97
|
+
* @param message - The message to be written
|
|
98
|
+
*/
|
|
99
|
+
static writeMessage(message) {
|
|
100
|
+
let upstream;
|
|
101
|
+
switch (message.kind) {
|
|
102
|
+
case "joinGroup": {
|
|
103
|
+
const joinGroup = UpstreamMessage.JoinGroupMessage.create({
|
|
104
|
+
group: message.group,
|
|
105
|
+
ackId: message.ackId,
|
|
106
|
+
});
|
|
107
|
+
upstream = UpstreamMessage.create({ joinGroupMessage: joinGroup });
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
case "leaveGroup": {
|
|
111
|
+
const leaveGroup = UpstreamMessage.LeaveGroupMessage.create({
|
|
112
|
+
group: message.group,
|
|
113
|
+
ackId: message.ackId,
|
|
114
|
+
});
|
|
115
|
+
upstream = UpstreamMessage.create({ leaveGroupMessage: leaveGroup });
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
case "sendToGroup": {
|
|
119
|
+
const sendToGroup = UpstreamMessage.SendToGroupMessage.create({
|
|
120
|
+
group: message.group,
|
|
121
|
+
ackId: message.ackId,
|
|
122
|
+
data: this._getIMessageData(message.data, message.dataType),
|
|
123
|
+
noEcho: message.noEcho,
|
|
124
|
+
});
|
|
125
|
+
upstream = UpstreamMessage.create({ sendToGroupMessage: sendToGroup });
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
case "sendEvent": {
|
|
129
|
+
const sendEvent = UpstreamMessage.EventMessage.create({
|
|
130
|
+
event: message.event,
|
|
131
|
+
ackId: message.ackId,
|
|
132
|
+
data: this._getIMessageData(message.data, message.dataType),
|
|
133
|
+
});
|
|
134
|
+
upstream = UpstreamMessage.create({ eventMessage: sendEvent });
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
case "sequenceAck": {
|
|
138
|
+
const sequenceAck = UpstreamMessage.SequenceAckMessage.create({
|
|
139
|
+
sequenceId: message.sequenceId,
|
|
140
|
+
});
|
|
141
|
+
upstream = UpstreamMessage.create({ sequenceAckMessage: sequenceAck });
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
default:
|
|
145
|
+
throw new TypeError(`kind is not supported: ${message.kind}`);
|
|
146
|
+
}
|
|
147
|
+
return UpstreamMessage.encode(upstream).finish();
|
|
148
|
+
}
|
|
149
|
+
static _getIMessageData(data, dataType) {
|
|
150
|
+
switch (dataType) {
|
|
151
|
+
case "binary":
|
|
152
|
+
if (!(data instanceof ArrayBuffer)) {
|
|
153
|
+
throw new TypeError("Message must be a ArrayBuffer.");
|
|
154
|
+
}
|
|
155
|
+
return MessageData.create({ binaryData: new Uint8Array(data) });
|
|
156
|
+
case "protobuf":
|
|
157
|
+
if (WebPubSubProtobufProtocolBase._isIAny(data)) {
|
|
158
|
+
return MessageData.create({
|
|
159
|
+
protobufData: google.protobuf.Any.create({
|
|
160
|
+
type_url: data.type_url,
|
|
161
|
+
value: new Uint8Array(data.value),
|
|
162
|
+
}),
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
throw new TypeError("Message must be a google.protobuf.Any.");
|
|
166
|
+
case "text":
|
|
167
|
+
if (typeof data !== "string") {
|
|
168
|
+
throw new TypeError("Message must be a string.");
|
|
169
|
+
}
|
|
170
|
+
return MessageData.create({ textData: data });
|
|
171
|
+
case "json":
|
|
172
|
+
return MessageData.create({ jsonData: JSON.stringify(data) });
|
|
173
|
+
default:
|
|
174
|
+
throw new TypeError(`dataType is not supported: ${dataType}`);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
static _getNumber(value) {
|
|
178
|
+
if (value === null || value === undefined || typeof value === "number") {
|
|
179
|
+
return value;
|
|
180
|
+
}
|
|
181
|
+
return value.toNumber();
|
|
182
|
+
}
|
|
183
|
+
static _isIAny(obj) {
|
|
184
|
+
return "type_url" in obj && "value" in obj;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
//# sourceMappingURL=webPubSubProtobufProtocolBase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webPubSubProtobufProtocolBase.js","sourceRoot":"","sources":["../../src/webPubSubProtobufProtocolBase.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAclC,OAAO,EACL,iBAAiB,EACjB,WAAW,EACX,eAAe,EACf,MAAM,GACP,MAAM,4BAA4B,CAAC;AAGpC;;GAEG;AACH,MAAM,OAAO,6BAA6B;IACxC;;;OAGG;IACI,MAAM,CAAC,aAAa,CAAC,KAAkB;QAC5C,MAAM,UAAU,GAAG,iBAAiB,CAAC,MAAM,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;QACnE,IAAI,UAAU,CAAC,UAAU,EAAE,CAAC;YAC1B,MAAM,GAAG,GAAG;gBACV,IAAI,EAAE,KAAK;gBACX,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,UAAU,CAAC,KAAK,CAAC;gBACnD,OAAO,EAAE,UAAU,CAAC,UAAU,CAAC,OAAO;aACzB,CAAC;YAChB,IAAI,UAAU,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;gBAChC,GAAG,CAAC,KAAK,GAAG;oBACV,IAAI,EAAE,UAAU,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI;oBACtC,OAAO,EAAE,UAAU,CAAC,UAAU,CAAC,KAAK,CAAC,OAAO;iBAC1B,CAAC;YACvB,CAAC;YACD,OAAO,GAAG,CAAC;QACb,CAAC;aAAM,IAAI,UAAU,CAAC,aAAa,EAAE,CAAC;YACpC,IAAI,UAAU,CAAC,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AE,CAAC;oBAC7B,MAAM,IAAI,SAAS,CAAC,2BAA2B,CAAC,CAAC;gBACnD,CAAC;gBACD,OAAO,WAAW,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAkB,CAAC,CAAC;YAChE,KAAK,MAAM;gBACT,OAAO,WAAW,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAkB,CAAC,CAAC;YAChF;gBACE,MAAM,IAAI,SAAS,CAAC,8BAA8B,QAAQ,EAAE,CAAC,CAAC;QAClE,CAAC;IACH,CAAC;IAEO,MAAM,CAAC,UAAU,CAAC,KAAuC;QAC/D,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YACvE,OAAO,KAAK,CAAC;QACf,CAAC;QACD,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;IAC1B,CAAC;IAEO,MAAM,CAAC,OAAO,CAAC,GAAQ;QAC7B,OAAO,UAAU,IAAI,GAAG,IAAI,OAAO,IAAI,GAAG,CAAC;IAC7C,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n AckMessage,\n AckMessageError,\n ConnectedMessage,\n DisconnectedMessage,\n GroupDataMessage,\n ServerDataMessage,\n WebPubSubDataType,\n WebPubSubMessage,\n JSONTypes,\n} from \"@azure/web-pubsub-client\";\nimport type { IMessageData, IUpstreamMessage } from \"./generated/clientProto.js\";\nimport {\n DownstreamMessage,\n MessageData,\n UpstreamMessage,\n google,\n} from \"./generated/clientProto.js\";\nimport type Long from \"long\";\n\n/**\n * The \"protobuf.reliable.webpubsub.azure.v1\" protocol\n */\nexport class WebPubSubProtobufProtocolBase {\n /**\n * Creates WebPubSubMessage objects from the specified serialized representation.\n * @param input - The serialized representation\n */\n public static parseMessages(input: ArrayBuffer): WebPubSubMessage | null {\n const downstream = DownstreamMessage.decode(new Uint8Array(input));\n if (downstream.ackMessage) {\n const ack = {\n kind: \"ack\",\n ackId: this._getNumber(downstream.ackMessage.ackId),\n success: downstream.ackMessage.success,\n } as AckMessage;\n if (downstream.ackMessage.error) {\n ack.error = {\n name: downstream.ackMessage.error.name,\n message: downstream.ackMessage.error.message,\n } as AckMessageError;\n }\n return ack;\n } else if (downstream.systemMessage) {\n if (downstream.systemMessage.connectedMessage) {\n const msg = downstream.systemMessage.connectedMessage;\n return {\n kind: \"connected\",\n connectionId: msg.connectionId,\n userId: msg.userId,\n reconnectionToken: msg.reconnectionToken,\n } as ConnectedMessage;\n } else if (downstream.systemMessage.disconnectedMessage) {\n const msg = downstream.systemMessage.disconnectedMessage;\n return { kind: \"disconnected\", message: msg.reason } as DisconnectedMessage;\n } else {\n return null;\n }\n } else if (downstream.dataMessage) {\n const sequenceId = this._getNumber(downstream.dataMessage.sequenceId);\n const messageData = downstream.dataMessage.data!;\n let dataType: WebPubSubDataType;\n let data: string | ArrayBuffer | object;\n if (messageData.textData) {\n dataType = \"text\";\n data = messageData.textData;\n } else if (messageData.jsonData) {\n dataType = \"json\";\n data = JSON.parse(messageData.jsonData);\n } else if (messageData.binaryData) {\n dataType = \"binary\";\n data = messageData.binaryData.buffer.slice(\n messageData.binaryData.byteOffset,\n messageData.binaryData.byteLength + messageData.binaryData.byteOffset,\n );\n } else if (messageData.protobufData) {\n dataType = \"protobuf\";\n data = messageData.protobufData;\n } else {\n return null;\n }\n\n if (downstream.dataMessage.from === \"group\") {\n return {\n kind: \"groupData\",\n dataType: dataType,\n data: data,\n sequenceId: sequenceId,\n group: downstream.dataMessage.group,\n } as GroupDataMessage;\n } else if (downstream.dataMessage.from === \"server\") {\n return {\n kind: \"serverData\",\n dataType: dataType,\n data: data,\n sequenceId: sequenceId,\n } as ServerDataMessage;\n } else {\n return null;\n }\n } else {\n return null;\n }\n }\n\n /**\n * Write WebPubSubMessage to string\n * @param message - The message to be written\n */\n public static writeMessage(message: WebPubSubMessage): ArrayBuffer {\n let upstream: UpstreamMessage;\n switch (message.kind) {\n case \"joinGroup\": {\n const joinGroup = UpstreamMessage.JoinGroupMessage.create({\n group: message.group,\n ackId: message.ackId,\n } as UpstreamMessage.IJoinGroupMessage);\n upstream = UpstreamMessage.create({ joinGroupMessage: joinGroup } as IUpstreamMessage);\n break;\n }\n case \"leaveGroup\": {\n const leaveGroup = UpstreamMessage.LeaveGroupMessage.create({\n group: message.group,\n ackId: message.ackId,\n } as UpstreamMessage.ILeaveGroupMessage);\n upstream = UpstreamMessage.create({ leaveGroupMessage: leaveGroup } as IUpstreamMessage);\n break;\n }\n case \"sendToGroup\": {\n const sendToGroup = UpstreamMessage.SendToGroupMessage.create({\n group: message.group,\n ackId: message.ackId,\n data: this._getIMessageData(message.data, message.dataType),\n noEcho: message.noEcho,\n } as UpstreamMessage.ISendToGroupMessage);\n upstream = UpstreamMessage.create({ sendToGroupMessage: sendToGroup } as IUpstreamMessage);\n break;\n }\n case \"sendEvent\": {\n const sendEvent = UpstreamMessage.EventMessage.create({\n event: message.event,\n ackId: message.ackId,\n data: this._getIMessageData(message.data, message.dataType),\n } as UpstreamMessage.IEventMessage);\n upstream = UpstreamMessage.create({ eventMessage: sendEvent } as IUpstreamMessage);\n break;\n }\n case \"sequenceAck\": {\n const sequenceAck = UpstreamMessage.SequenceAckMessage.create({\n sequenceId: message.sequenceId,\n } as UpstreamMessage.ISequenceAckMessage);\n upstream = UpstreamMessage.create({ sequenceAckMessage: sequenceAck } as IUpstreamMessage);\n break;\n }\n default:\n throw new TypeError(`kind is not supported: ${message.kind}`);\n }\n\n return UpstreamMessage.encode(upstream).finish();\n }\n\n private static _getIMessageData(\n data: JSONTypes | ArrayBuffer,\n dataType: WebPubSubDataType,\n ): IMessageData {\n switch (dataType) {\n case \"binary\":\n if (!(data instanceof ArrayBuffer)) {\n throw new TypeError(\"Message must be a ArrayBuffer.\");\n }\n return MessageData.create({ binaryData: new Uint8Array(data) } as IMessageData);\n case \"protobuf\":\n if (WebPubSubProtobufProtocolBase._isIAny(data)) {\n return MessageData.create({\n protobufData: google.protobuf.Any.create({\n type_url: data.type_url!,\n value: new Uint8Array(data.value!),\n } as google.protobuf.IAny),\n } as IMessageData);\n }\n throw new TypeError(\"Message must be a google.protobuf.Any.\");\n case \"text\":\n if (typeof data !== \"string\") {\n throw new TypeError(\"Message must be a string.\");\n }\n return MessageData.create({ textData: data } as IMessageData);\n case \"json\":\n return MessageData.create({ jsonData: JSON.stringify(data) } as IMessageData);\n default:\n throw new TypeError(`dataType is not supported: ${dataType}`);\n }\n }\n\n private static _getNumber(value: number | Long | null | undefined): number | null | undefined {\n if (value === null || value === undefined || typeof value === \"number\") {\n return value;\n }\n return value.toNumber();\n }\n\n private static _isIAny(obj: any): obj is google.protobuf.IAny {\n return \"type_url\" in obj && \"value\" in obj;\n }\n}\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { WebPubSubMessage, WebPubSubClientProtocol } from "@azure/web-pubsub-client";
|
|
2
|
+
/**
|
|
3
|
+
* The "protobuf.reliable.webpubsub.azure.v1" protocol
|
|
4
|
+
*/
|
|
5
|
+
export declare class WebPubSubProtobufReliableProtocolImpl implements WebPubSubClientProtocol {
|
|
6
|
+
/**
|
|
7
|
+
* True if the protocol supports reliable features
|
|
8
|
+
*/
|
|
9
|
+
readonly isReliableSubProtocol = true;
|
|
10
|
+
/**
|
|
11
|
+
* The name of subprotocol. Name will be used in websocket subprotocol
|
|
12
|
+
*/
|
|
13
|
+
readonly name = "protobuf.reliable.webpubsub.azure.v1";
|
|
14
|
+
/**
|
|
15
|
+
* Creates WebPubSubMessage objects from the specified serialized representation.
|
|
16
|
+
* @param input - The serialized representation
|
|
17
|
+
*/
|
|
18
|
+
parseMessages(input: ArrayBuffer): WebPubSubMessage | null;
|
|
19
|
+
/**
|
|
20
|
+
* Write WebPubSubMessage to string
|
|
21
|
+
* @param message - The message to be written
|
|
22
|
+
*/
|
|
23
|
+
writeMessage(message: WebPubSubMessage): ArrayBuffer;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=webPubSubProtobufReliableProtocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webPubSubProtobufReliableProtocol.d.ts","sourceRoot":"","sources":["../../src/webPubSubProtobufReliableProtocol.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAG1F;;GAEG;AACH,qBAAa,qCAAsC,YAAW,uBAAuB;IACnF;;OAEG;IACH,SAAgB,qBAAqB,QAAQ;IAE7C;;OAEG;IACH,SAAgB,IAAI,0CAA0C;IAE9D;;;OAGG;IACI,aAAa,CAAC,KAAK,EAAE,WAAW,GAAG,gBAAgB,GAAG,IAAI;IAIjE;;;OAGG;IACI,YAAY,CAAC,OAAO,EAAE,gBAAgB,GAAG,WAAW;CAG5D"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
import { WebPubSubProtobufProtocolBase } from "./webPubSubProtobufProtocolBase.js";
|
|
4
|
+
/**
|
|
5
|
+
* The "protobuf.reliable.webpubsub.azure.v1" protocol
|
|
6
|
+
*/
|
|
7
|
+
export class WebPubSubProtobufReliableProtocolImpl {
|
|
8
|
+
constructor() {
|
|
9
|
+
/**
|
|
10
|
+
* True if the protocol supports reliable features
|
|
11
|
+
*/
|
|
12
|
+
this.isReliableSubProtocol = true;
|
|
13
|
+
/**
|
|
14
|
+
* The name of subprotocol. Name will be used in websocket subprotocol
|
|
15
|
+
*/
|
|
16
|
+
this.name = "protobuf.reliable.webpubsub.azure.v1";
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Creates WebPubSubMessage objects from the specified serialized representation.
|
|
20
|
+
* @param input - The serialized representation
|
|
21
|
+
*/
|
|
22
|
+
parseMessages(input) {
|
|
23
|
+
return WebPubSubProtobufProtocolBase.parseMessages(input);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Write WebPubSubMessage to string
|
|
27
|
+
* @param message - The message to be written
|
|
28
|
+
*/
|
|
29
|
+
writeMessage(message) {
|
|
30
|
+
return WebPubSubProtobufProtocolBase.writeMessage(message);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=webPubSubProtobufReliableProtocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webPubSubProtobufReliableProtocol.js","sourceRoot":"","sources":["../../src/webPubSubProtobufReliableProtocol.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,6BAA6B,EAAE,MAAM,oCAAoC,CAAC;AAEnF;;GAEG;AACH,MAAM,OAAO,qCAAqC;IAAlD;QACE;;WAEG;QACa,0BAAqB,GAAG,IAAI,CAAC;QAE7C;;WAEG;QACa,SAAI,GAAG,sCAAsC,CAAC;IAiBhE,CAAC;IAfC;;;OAGG;IACI,aAAa,CAAC,KAAkB;QACrC,OAAO,6BAA6B,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IAC5D,CAAC;IAED;;;OAGG;IACI,YAAY,CAAC,OAAyB;QAC3C,OAAO,6BAA6B,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IAC7D,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { WebPubSubMessage, WebPubSubClientProtocol } from \"@azure/web-pubsub-client\";\nimport { WebPubSubProtobufProtocolBase } from \"./webPubSubProtobufProtocolBase.js\";\n\n/**\n * The \"protobuf.reliable.webpubsub.azure.v1\" protocol\n */\nexport class WebPubSubProtobufReliableProtocolImpl implements WebPubSubClientProtocol {\n /**\n * True if the protocol supports reliable features\n */\n public readonly isReliableSubProtocol = true;\n\n /**\n * The name of subprotocol. Name will be used in websocket subprotocol\n */\n public readonly name = \"protobuf.reliable.webpubsub.azure.v1\";\n\n /**\n * Creates WebPubSubMessage objects from the specified serialized representation.\n * @param input - The serialized representation\n */\n public parseMessages(input: ArrayBuffer): WebPubSubMessage | null {\n return WebPubSubProtobufProtocolBase.parseMessages(input);\n }\n\n /**\n * Write WebPubSubMessage to string\n * @param message - The message to be written\n */\n public writeMessage(message: WebPubSubMessage): ArrayBuffer {\n return WebPubSubProtobufProtocolBase.writeMessage(message);\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@azure/web-pubsub-client-protobuf",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.20250228.1",
|
|
4
4
|
"description": "Azure Web PubSub Client Protobuf",
|
|
5
5
|
"sdk-type": "client",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/commonjs/index.js",
|
|
8
8
|
"module": "./dist/esm/index.js",
|
|
9
|
-
"browser":
|
|
10
|
-
"buffer": "buffer",
|
|
11
|
-
"default": "dist/browser/index.js"
|
|
12
|
-
},
|
|
9
|
+
"browser": "./dist/browser/index.js",
|
|
13
10
|
"types": "./dist/commonjs/index.d.ts",
|
|
14
11
|
"scripts": {
|
|
15
12
|
"build": "npm run clean && npm run build-protobuf && dev-tool run build-package && npm run copy-files && dev-tool run extract-api",
|
|
@@ -39,13 +36,11 @@
|
|
|
39
36
|
"test:node": "npm run build:test && npm run unit-test:node && npm run integration-test:node",
|
|
40
37
|
"unit-test": "npm run unit-test:node && npm run unit-test:browser",
|
|
41
38
|
"unit-test:browser": "echo skipped",
|
|
42
|
-
"unit-test:node": "dev-tool run test:vitest
|
|
43
|
-
"update-snippets": "
|
|
39
|
+
"unit-test:node": "dev-tool run test:vitest",
|
|
40
|
+
"update-snippets": "dev-tool run update-snippets"
|
|
44
41
|
},
|
|
45
42
|
"files": [
|
|
46
43
|
"dist/",
|
|
47
|
-
"types/web-pubsub-client-protobuf.d.ts",
|
|
48
|
-
"types/web-pubsub-client-protobuf.d.ts.map",
|
|
49
44
|
"README.md",
|
|
50
45
|
"LICENSE"
|
|
51
46
|
],
|
|
@@ -65,25 +60,28 @@
|
|
|
65
60
|
"homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/web-pubsub/web-pubsub-client/README.md",
|
|
66
61
|
"sideEffects": false,
|
|
67
62
|
"dependencies": {
|
|
68
|
-
"@azure/logger": "^1.
|
|
63
|
+
"@azure/logger": "^1.1.4",
|
|
69
64
|
"@azure/web-pubsub-client": "1.0.0-beta.2",
|
|
70
65
|
"long": "^5.3.1",
|
|
71
66
|
"protobufjs": "^7.4.0",
|
|
72
|
-
"tslib": "^2.
|
|
67
|
+
"tslib": "^2.8.1"
|
|
73
68
|
},
|
|
74
69
|
"devDependencies": {
|
|
70
|
+
"@azure-tools/test-utils-vitest": ">=1.0.0-alpha <1.0.0-alphb",
|
|
75
71
|
"@azure/dev-tool": ">=1.0.0-alpha <1.0.0-alphb",
|
|
76
72
|
"@azure/eslint-plugin-azure-sdk": ">=3.0.0-alpha <3.0.0-alphb",
|
|
77
73
|
"@azure/web-pubsub": "^1.1.0",
|
|
78
74
|
"@types/node": "^18.0.0",
|
|
79
|
-
"@vitest/
|
|
75
|
+
"@vitest/browser": "^3.0.6",
|
|
76
|
+
"@vitest/coverage-istanbul": "^3.0.6",
|
|
80
77
|
"cpy-cli": "^5.0.0",
|
|
81
78
|
"dotenv": "^16.0.0",
|
|
82
79
|
"eslint": "^9.9.0",
|
|
83
80
|
"move-file-cli": "^3.0.0",
|
|
81
|
+
"playwright": "^1.50.1",
|
|
84
82
|
"protobufjs-cli": "^1.1.3",
|
|
85
83
|
"typescript": "~5.7.2",
|
|
86
|
-
"vitest": "^3.0.
|
|
84
|
+
"vitest": "^3.0.6"
|
|
87
85
|
},
|
|
88
86
|
"//sampleConfiguration": {
|
|
89
87
|
"productName": "Azure Web PubSub Client",
|
|
@@ -92,6 +90,7 @@
|
|
|
92
90
|
]
|
|
93
91
|
},
|
|
94
92
|
"tshy": {
|
|
93
|
+
"project": "./tsconfig.src.json",
|
|
95
94
|
"exports": {
|
|
96
95
|
"./package.json": "./package.json",
|
|
97
96
|
".": "./src/index.ts"
|
|
@@ -100,12 +99,23 @@
|
|
|
100
99
|
"esm",
|
|
101
100
|
"commonjs"
|
|
102
101
|
],
|
|
103
|
-
"
|
|
104
|
-
|
|
102
|
+
"esmDialects": [
|
|
103
|
+
"browser",
|
|
104
|
+
"react-native"
|
|
105
|
+
],
|
|
106
|
+
"selfLink": false
|
|
105
107
|
},
|
|
106
108
|
"exports": {
|
|
107
109
|
"./package.json": "./package.json",
|
|
108
110
|
".": {
|
|
111
|
+
"browser": {
|
|
112
|
+
"types": "./dist/browser/index.d.ts",
|
|
113
|
+
"default": "./dist/browser/index.js"
|
|
114
|
+
},
|
|
115
|
+
"react-native": {
|
|
116
|
+
"types": "./dist/react-native/index.d.ts",
|
|
117
|
+
"default": "./dist/react-native/index.js"
|
|
118
|
+
},
|
|
109
119
|
"import": {
|
|
110
120
|
"types": "./dist/esm/index.d.ts",
|
|
111
121
|
"default": "./dist/esm/index.js"
|
|
@@ -115,5 +125,6 @@
|
|
|
115
125
|
"default": "./dist/commonjs/index.js"
|
|
116
126
|
}
|
|
117
127
|
}
|
|
118
|
-
}
|
|
128
|
+
},
|
|
129
|
+
"react-native": "./dist/react-native/index.js"
|
|
119
130
|
}
|