@azure/web-pubsub-client-protobuf 1.0.0-beta.2 → 1.0.0-beta.3
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/LICENSE +21 -0
- package/README.md +24 -9
- package/{types/web-pubsub-client-protobuf.d.ts → dist/browser/index.d.ts} +10 -13
- package/dist/browser/index.d.ts.map +1 -0
- package/{dist-esm/src → dist/browser}/index.js +3 -3
- 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-esm/src → dist/browser}/logger.js +1 -1
- package/{dist-esm/src → dist/browser}/logger.js.map +1 -1
- 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-esm/src → dist/browser}/webPubSubProtobufProtocol.js +10 -12
- 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-esm/src → dist/browser}/webPubSubProtobufProtocolBase.js +2 -2
- 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-esm/src → dist/browser}/webPubSubProtobufReliableProtocol.js +10 -12
- package/dist/browser/webPubSubProtobufReliableProtocol.js.map +1 -0
- package/dist/{index.js → commonjs/generated/clientProto.js} +192 -3095
- package/dist/commonjs/index.d.ts +10 -0
- package/dist/commonjs/index.d.ts.map +1 -0
- package/dist/commonjs/index.js +22 -0
- package/dist/commonjs/index.js.map +1 -0
- package/dist/commonjs/logger.d.ts +5 -0
- package/dist/commonjs/logger.d.ts.map +1 -0
- package/dist/commonjs/logger.js +11 -0
- package/dist/commonjs/logger.js.map +1 -0
- package/dist/commonjs/package.json +3 -0
- package/dist/commonjs/tsdoc-metadata.json +11 -0
- package/dist/commonjs/webPubSubProtobufProtocol.d.ts +25 -0
- package/dist/commonjs/webPubSubProtobufProtocol.d.ts.map +1 -0
- package/dist/commonjs/webPubSubProtobufProtocol.js +35 -0
- package/dist/commonjs/webPubSubProtobufProtocol.js.map +1 -0
- package/dist/commonjs/webPubSubProtobufProtocolBase.d.ts +20 -0
- package/dist/commonjs/webPubSubProtobufProtocolBase.d.ts.map +1 -0
- package/dist/commonjs/webPubSubProtobufProtocolBase.js +191 -0
- package/dist/commonjs/webPubSubProtobufProtocolBase.js.map +1 -0
- package/dist/commonjs/webPubSubProtobufReliableProtocol.d.ts +25 -0
- package/dist/commonjs/webPubSubProtobufReliableProtocol.d.ts.map +1 -0
- package/dist/commonjs/webPubSubProtobufReliableProtocol.js +35 -0
- package/dist/commonjs/webPubSubProtobufReliableProtocol.js.map +1 -0
- package/dist/esm/generated/clientProto.d.ts +1668 -0
- package/{dist-esm/src → dist/esm}/generated/clientProto.js +45 -15
- package/dist/esm/index.d.ts +10 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +17 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/logger.d.ts +5 -0
- package/dist/esm/logger.d.ts.map +1 -0
- package/dist/esm/logger.js +8 -0
- package/dist/esm/logger.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/webPubSubProtobufProtocol.d.ts +25 -0
- package/dist/esm/webPubSubProtobufProtocol.d.ts.map +1 -0
- package/dist/esm/webPubSubProtobufProtocol.js +31 -0
- package/dist/esm/webPubSubProtobufProtocol.js.map +1 -0
- package/dist/esm/webPubSubProtobufProtocolBase.d.ts +20 -0
- package/dist/esm/webPubSubProtobufProtocolBase.d.ts.map +1 -0
- package/dist/esm/webPubSubProtobufProtocolBase.js +187 -0
- package/dist/esm/webPubSubProtobufProtocolBase.js.map +1 -0
- package/dist/esm/webPubSubProtobufReliableProtocol.d.ts +25 -0
- package/dist/esm/webPubSubProtobufReliableProtocol.d.ts.map +1 -0
- package/dist/esm/webPubSubProtobufReliableProtocol.js +31 -0
- package/dist/esm/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 +31 -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 +31 -0
- package/dist/react-native/webPubSubProtobufReliableProtocol.js.map +1 -0
- package/package.json +88 -90
- package/dist/index.js.map +0 -1
- package/dist-esm/samples-dev/basicusage.js +0 -63
- package/dist-esm/samples-dev/basicusage.js.map +0 -1
- package/dist-esm/src/index.js.map +0 -1
- package/dist-esm/src/webPubSubProtobufProtocol.js.map +0 -1
- package/dist-esm/src/webPubSubProtobufProtocolBase.js.map +0 -1
- package/dist-esm/src/webPubSubProtobufReliableProtocol.js.map +0 -1
- package/dist-esm/test/client.spec.js +0 -294
- package/dist-esm/test/client.spec.js.map +0 -1
|
@@ -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,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation.
|
|
3
|
+
// Licensed under the MIT License.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.WebPubSubProtobufReliableProtocol = exports.WebPubSubProtobufProtocol = void 0;
|
|
6
|
+
const webPubSubProtobufProtocol_js_1 = require("./webPubSubProtobufProtocol.js");
|
|
7
|
+
const webPubSubProtobufReliableProtocol_js_1 = require("./webPubSubProtobufReliableProtocol.js");
|
|
8
|
+
/**
|
|
9
|
+
* Return the "protobuf.webpubsub.azure.v1" protocol
|
|
10
|
+
*/
|
|
11
|
+
const WebPubSubProtobufProtocol = () => {
|
|
12
|
+
return new webPubSubProtobufProtocol_js_1.WebPubSubProtobufProtocolImpl();
|
|
13
|
+
};
|
|
14
|
+
exports.WebPubSubProtobufProtocol = WebPubSubProtobufProtocol;
|
|
15
|
+
/**
|
|
16
|
+
* Return the "protobuf.reliable.webpubsub.azure.v1" protocol
|
|
17
|
+
*/
|
|
18
|
+
const WebPubSubProtobufReliableProtocol = () => {
|
|
19
|
+
return new webPubSubProtobufReliableProtocol_js_1.WebPubSubProtobufReliableProtocolImpl();
|
|
20
|
+
};
|
|
21
|
+
exports.WebPubSubProtobufReliableProtocol = WebPubSubProtobufReliableProtocol;
|
|
22
|
+
//# 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,iFAA+E;AAC/E,iGAA+F;AAE/F;;GAEG;AACI,MAAM,yBAAyB,GAAG,GAA4B,EAAE;IACrE,OAAO,IAAI,4DAA6B,EAAE,CAAC;AAC7C,CAAC,CAAC;AAFW,QAAA,yBAAyB,6BAEpC;AAEF;;GAEG;AACI,MAAM,iCAAiC,GAAG,GAA4B,EAAE;IAC7E,OAAO,IAAI,4EAAqC,EAAE,CAAC;AACrD,CAAC,CAAC;AAFW,QAAA,iCAAiC,qCAE5C","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,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation.
|
|
3
|
+
// Licensed under the MIT License.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.logger = void 0;
|
|
6
|
+
const logger_1 = require("@azure/logger");
|
|
7
|
+
/**
|
|
8
|
+
* The \@azure\/logger configuration for this package.
|
|
9
|
+
*/
|
|
10
|
+
exports.logger = (0, logger_1.createClientLogger)("web-pubsub-client-protobuf");
|
|
11
|
+
//# 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,0CAAmD;AAEnD;;GAEG;AACU,QAAA,MAAM,GAAG,IAAA,2BAAkB,EAAC,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,11 @@
|
|
|
1
|
+
// This file is read by tools that parse documentation comments conforming to the TSDoc standard.
|
|
2
|
+
// It should be published with your NPM package. It should not be tracked by Git.
|
|
3
|
+
{
|
|
4
|
+
"tsdocVersion": "0.12",
|
|
5
|
+
"toolPackages": [
|
|
6
|
+
{
|
|
7
|
+
"packageName": "@microsoft/api-extractor",
|
|
8
|
+
"packageVersion": "7.52.10"
|
|
9
|
+
}
|
|
10
|
+
]
|
|
11
|
+
}
|
|
@@ -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,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation.
|
|
3
|
+
// Licensed under the MIT License.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.WebPubSubProtobufProtocolImpl = void 0;
|
|
6
|
+
const webPubSubProtobufProtocolBase_js_1 = require("./webPubSubProtobufProtocolBase.js");
|
|
7
|
+
/**
|
|
8
|
+
* The "protobuf.reliable.webpubsub.azure.v1" protocol
|
|
9
|
+
*/
|
|
10
|
+
class WebPubSubProtobufProtocolImpl {
|
|
11
|
+
/**
|
|
12
|
+
* True if the protocol supports reliable features
|
|
13
|
+
*/
|
|
14
|
+
isReliableSubProtocol = false;
|
|
15
|
+
/**
|
|
16
|
+
* The name of subprotocol. Name will be used in websocket subprotocol
|
|
17
|
+
*/
|
|
18
|
+
name = "protobuf.webpubsub.azure.v1";
|
|
19
|
+
/**
|
|
20
|
+
* Creates WebPubSubMessage objects from the specified serialized representation.
|
|
21
|
+
* @param input - The serialized representation
|
|
22
|
+
*/
|
|
23
|
+
parseMessages(input) {
|
|
24
|
+
return webPubSubProtobufProtocolBase_js_1.WebPubSubProtobufProtocolBase.parseMessages(input);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Write WebPubSubMessage to string
|
|
28
|
+
* @param message - The message to be written
|
|
29
|
+
*/
|
|
30
|
+
writeMessage(message) {
|
|
31
|
+
return webPubSubProtobufProtocolBase_js_1.WebPubSubProtobufProtocolBase.writeMessage(message);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.WebPubSubProtobufProtocolImpl = WebPubSubProtobufProtocolImpl;
|
|
35
|
+
//# 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,yFAAmF;AAEnF;;GAEG;AACH,MAAa,6BAA6B;IACxC;;OAEG;IACa,qBAAqB,GAAG,KAAK,CAAC;IAE9C;;OAEG;IACa,IAAI,GAAG,6BAA6B,CAAC;IAErD;;;OAGG;IACI,aAAa,CAAC,KAAkB;QACrC,OAAO,gEAA6B,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IAC5D,CAAC;IAED;;;OAGG;IACI,YAAY,CAAC,OAAyB;QAC3C,OAAO,gEAA6B,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IAC7D,CAAC;CACF;AA1BD,sEA0BC","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,191 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation.
|
|
3
|
+
// Licensed under the MIT License.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.WebPubSubProtobufProtocolBase = void 0;
|
|
6
|
+
const clientProto_js_1 = require("./generated/clientProto.js");
|
|
7
|
+
/**
|
|
8
|
+
* The "protobuf.reliable.webpubsub.azure.v1" protocol
|
|
9
|
+
*/
|
|
10
|
+
class WebPubSubProtobufProtocolBase {
|
|
11
|
+
/**
|
|
12
|
+
* Creates WebPubSubMessage objects from the specified serialized representation.
|
|
13
|
+
* @param input - The serialized representation
|
|
14
|
+
*/
|
|
15
|
+
static parseMessages(input) {
|
|
16
|
+
const downstream = clientProto_js_1.DownstreamMessage.decode(new Uint8Array(input));
|
|
17
|
+
if (downstream.ackMessage) {
|
|
18
|
+
const ack = {
|
|
19
|
+
kind: "ack",
|
|
20
|
+
ackId: this._getNumber(downstream.ackMessage.ackId),
|
|
21
|
+
success: downstream.ackMessage.success,
|
|
22
|
+
};
|
|
23
|
+
if (downstream.ackMessage.error) {
|
|
24
|
+
ack.error = {
|
|
25
|
+
name: downstream.ackMessage.error.name,
|
|
26
|
+
message: downstream.ackMessage.error.message,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
return ack;
|
|
30
|
+
}
|
|
31
|
+
else if (downstream.systemMessage) {
|
|
32
|
+
if (downstream.systemMessage.connectedMessage) {
|
|
33
|
+
const msg = downstream.systemMessage.connectedMessage;
|
|
34
|
+
return {
|
|
35
|
+
kind: "connected",
|
|
36
|
+
connectionId: msg.connectionId,
|
|
37
|
+
userId: msg.userId,
|
|
38
|
+
reconnectionToken: msg.reconnectionToken,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
else if (downstream.systemMessage.disconnectedMessage) {
|
|
42
|
+
const msg = downstream.systemMessage.disconnectedMessage;
|
|
43
|
+
return { kind: "disconnected", message: msg.reason };
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else if (downstream.dataMessage) {
|
|
50
|
+
const sequenceId = this._getNumber(downstream.dataMessage.sequenceId);
|
|
51
|
+
const messageData = downstream.dataMessage.data;
|
|
52
|
+
let dataType;
|
|
53
|
+
let data;
|
|
54
|
+
if (messageData.textData) {
|
|
55
|
+
dataType = "text";
|
|
56
|
+
data = messageData.textData;
|
|
57
|
+
}
|
|
58
|
+
else if (messageData.jsonData) {
|
|
59
|
+
dataType = "json";
|
|
60
|
+
data = JSON.parse(messageData.jsonData);
|
|
61
|
+
}
|
|
62
|
+
else if (messageData.binaryData) {
|
|
63
|
+
dataType = "binary";
|
|
64
|
+
data = messageData.binaryData.buffer.slice(messageData.binaryData.byteOffset, messageData.binaryData.byteLength + messageData.binaryData.byteOffset);
|
|
65
|
+
}
|
|
66
|
+
else if (messageData.protobufData) {
|
|
67
|
+
dataType = "protobuf";
|
|
68
|
+
data = messageData.protobufData;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
if (downstream.dataMessage.from === "group") {
|
|
74
|
+
return {
|
|
75
|
+
kind: "groupData",
|
|
76
|
+
dataType: dataType,
|
|
77
|
+
data: data,
|
|
78
|
+
sequenceId: sequenceId,
|
|
79
|
+
group: downstream.dataMessage.group,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
else if (downstream.dataMessage.from === "server") {
|
|
83
|
+
return {
|
|
84
|
+
kind: "serverData",
|
|
85
|
+
dataType: dataType,
|
|
86
|
+
data: data,
|
|
87
|
+
sequenceId: sequenceId,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Write WebPubSubMessage to string
|
|
100
|
+
* @param message - The message to be written
|
|
101
|
+
*/
|
|
102
|
+
static writeMessage(message) {
|
|
103
|
+
let upstream;
|
|
104
|
+
switch (message.kind) {
|
|
105
|
+
case "joinGroup": {
|
|
106
|
+
const joinGroup = clientProto_js_1.UpstreamMessage.JoinGroupMessage.create({
|
|
107
|
+
group: message.group,
|
|
108
|
+
ackId: message.ackId,
|
|
109
|
+
});
|
|
110
|
+
upstream = clientProto_js_1.UpstreamMessage.create({ joinGroupMessage: joinGroup });
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
case "leaveGroup": {
|
|
114
|
+
const leaveGroup = clientProto_js_1.UpstreamMessage.LeaveGroupMessage.create({
|
|
115
|
+
group: message.group,
|
|
116
|
+
ackId: message.ackId,
|
|
117
|
+
});
|
|
118
|
+
upstream = clientProto_js_1.UpstreamMessage.create({ leaveGroupMessage: leaveGroup });
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
case "sendToGroup": {
|
|
122
|
+
const sendToGroup = clientProto_js_1.UpstreamMessage.SendToGroupMessage.create({
|
|
123
|
+
group: message.group,
|
|
124
|
+
ackId: message.ackId,
|
|
125
|
+
data: this._getIMessageData(message.data, message.dataType),
|
|
126
|
+
noEcho: message.noEcho,
|
|
127
|
+
});
|
|
128
|
+
upstream = clientProto_js_1.UpstreamMessage.create({ sendToGroupMessage: sendToGroup });
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
case "sendEvent": {
|
|
132
|
+
const sendEvent = clientProto_js_1.UpstreamMessage.EventMessage.create({
|
|
133
|
+
event: message.event,
|
|
134
|
+
ackId: message.ackId,
|
|
135
|
+
data: this._getIMessageData(message.data, message.dataType),
|
|
136
|
+
});
|
|
137
|
+
upstream = clientProto_js_1.UpstreamMessage.create({ eventMessage: sendEvent });
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
case "sequenceAck": {
|
|
141
|
+
const sequenceAck = clientProto_js_1.UpstreamMessage.SequenceAckMessage.create({
|
|
142
|
+
sequenceId: message.sequenceId,
|
|
143
|
+
});
|
|
144
|
+
upstream = clientProto_js_1.UpstreamMessage.create({ sequenceAckMessage: sequenceAck });
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
default:
|
|
148
|
+
throw new TypeError(`kind is not supported: ${message.kind}`);
|
|
149
|
+
}
|
|
150
|
+
return clientProto_js_1.UpstreamMessage.encode(upstream).finish();
|
|
151
|
+
}
|
|
152
|
+
static _getIMessageData(data, dataType) {
|
|
153
|
+
switch (dataType) {
|
|
154
|
+
case "binary":
|
|
155
|
+
if (!(data instanceof ArrayBuffer)) {
|
|
156
|
+
throw new TypeError("Message must be a ArrayBuffer.");
|
|
157
|
+
}
|
|
158
|
+
return clientProto_js_1.MessageData.create({ binaryData: new Uint8Array(data) });
|
|
159
|
+
case "protobuf":
|
|
160
|
+
if (WebPubSubProtobufProtocolBase._isIAny(data)) {
|
|
161
|
+
return clientProto_js_1.MessageData.create({
|
|
162
|
+
protobufData: clientProto_js_1.google.protobuf.Any.create({
|
|
163
|
+
type_url: data.type_url,
|
|
164
|
+
value: new Uint8Array(data.value),
|
|
165
|
+
}),
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
throw new TypeError("Message must be a google.protobuf.Any.");
|
|
169
|
+
case "text":
|
|
170
|
+
if (typeof data !== "string") {
|
|
171
|
+
throw new TypeError("Message must be a string.");
|
|
172
|
+
}
|
|
173
|
+
return clientProto_js_1.MessageData.create({ textData: data });
|
|
174
|
+
case "json":
|
|
175
|
+
return clientProto_js_1.MessageData.create({ jsonData: JSON.stringify(data) });
|
|
176
|
+
default:
|
|
177
|
+
throw new TypeError(`dataType is not supported: ${dataType}`);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
static _getNumber(value) {
|
|
181
|
+
if (value === null || value === undefined || typeof value === "number") {
|
|
182
|
+
return value;
|
|
183
|
+
}
|
|
184
|
+
return value.toNumber();
|
|
185
|
+
}
|
|
186
|
+
static _isIAny(obj) {
|
|
187
|
+
return "type_url" in obj && "value" in obj;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
exports.WebPubSubProtobufProtocolBase = WebPubSubProtobufProtocolBase;
|
|
191
|
+
//# 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,+DAKoC;AAGpC;;GAEG;AACH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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;AApLD,sEAoLC","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,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation.
|
|
3
|
+
// Licensed under the MIT License.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.WebPubSubProtobufReliableProtocolImpl = void 0;
|
|
6
|
+
const webPubSubProtobufProtocolBase_js_1 = require("./webPubSubProtobufProtocolBase.js");
|
|
7
|
+
/**
|
|
8
|
+
* The "protobuf.reliable.webpubsub.azure.v1" protocol
|
|
9
|
+
*/
|
|
10
|
+
class WebPubSubProtobufReliableProtocolImpl {
|
|
11
|
+
/**
|
|
12
|
+
* True if the protocol supports reliable features
|
|
13
|
+
*/
|
|
14
|
+
isReliableSubProtocol = true;
|
|
15
|
+
/**
|
|
16
|
+
* The name of subprotocol. Name will be used in websocket subprotocol
|
|
17
|
+
*/
|
|
18
|
+
name = "protobuf.reliable.webpubsub.azure.v1";
|
|
19
|
+
/**
|
|
20
|
+
* Creates WebPubSubMessage objects from the specified serialized representation.
|
|
21
|
+
* @param input - The serialized representation
|
|
22
|
+
*/
|
|
23
|
+
parseMessages(input) {
|
|
24
|
+
return webPubSubProtobufProtocolBase_js_1.WebPubSubProtobufProtocolBase.parseMessages(input);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Write WebPubSubMessage to string
|
|
28
|
+
* @param message - The message to be written
|
|
29
|
+
*/
|
|
30
|
+
writeMessage(message) {
|
|
31
|
+
return webPubSubProtobufProtocolBase_js_1.WebPubSubProtobufProtocolBase.writeMessage(message);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.WebPubSubProtobufReliableProtocolImpl = WebPubSubProtobufReliableProtocolImpl;
|
|
35
|
+
//# 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,yFAAmF;AAEnF;;GAEG;AACH,MAAa,qCAAqC;IAChD;;OAEG;IACa,qBAAqB,GAAG,IAAI,CAAC;IAE7C;;OAEG;IACa,IAAI,GAAG,sCAAsC,CAAC;IAE9D;;;OAGG;IACI,aAAa,CAAC,KAAkB;QACrC,OAAO,gEAA6B,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IAC5D,CAAC;IAED;;;OAGG;IACI,YAAY,CAAC,OAAyB;QAC3C,OAAO,gEAA6B,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IAC7D,CAAC;CACF;AA1BD,sFA0BC","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"]}
|