@azure/web-pubsub 1.0.0-beta.3 → 1.0.1-alpha.20220103.2
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +31 -0
- package/README.md +107 -33
- package/dist/index.js +1048 -233
- package/dist/index.js.map +1 -1
- package/dist-esm/samples-dev/directMessage.js +1 -1
- package/dist-esm/samples-dev/directMessage.js.map +1 -1
- package/dist-esm/src/generated/generatedClient.js +3 -3
- package/dist-esm/src/generated/generatedClient.js.map +1 -1
- package/dist-esm/src/generated/generatedClientContext.js +8 -8
- package/dist-esm/src/generated/generatedClientContext.js.map +1 -1
- package/dist-esm/src/generated/models/index.js +6 -1
- package/dist-esm/src/generated/models/index.js.map +1 -1
- package/dist-esm/src/generated/models/mappers.js +368 -0
- package/dist-esm/src/generated/models/mappers.js.map +1 -0
- package/dist-esm/src/generated/models/parameters.js +105 -23
- package/dist-esm/src/generated/models/parameters.js.map +1 -1
- package/dist-esm/src/generated/operations/healthApi.js +4 -3
- package/dist-esm/src/generated/operations/healthApi.js.map +1 -1
- package/dist-esm/src/generated/operations/webPubSub.js +315 -59
- package/dist-esm/src/generated/operations/webPubSub.js.map +1 -1
- package/dist-esm/src/generated/operationsInterfaces/webPubSub.js.map +1 -1
- package/dist-esm/src/groupClient.js +32 -21
- package/dist-esm/src/groupClient.js.map +1 -1
- package/dist-esm/src/hubClient.js +162 -107
- package/dist-esm/src/hubClient.js.map +1 -1
- package/dist-esm/src/index.js +1 -1
- package/dist-esm/src/index.js.map +1 -1
- package/dist-esm/src/logger.js +1 -1
- package/dist-esm/src/logger.js.map +1 -1
- package/dist-esm/src/parseConnectionString.js +3 -1
- package/dist-esm/src/parseConnectionString.js.map +1 -1
- package/dist-esm/src/reverseProxyPolicy.js +21 -0
- package/dist-esm/src/reverseProxyPolicy.js.map +1 -0
- package/dist-esm/src/tracing.js +1 -1
- package/dist-esm/src/tracing.js.map +1 -1
- package/dist-esm/src/utils.js +2 -0
- package/dist-esm/src/utils.js.map +1 -1
- package/dist-esm/src/webPubSubCredentialPolicy.js +2 -2
- package/dist-esm/src/webPubSubCredentialPolicy.js.map +1 -1
- package/dist-esm/test/conn.spec.js +2 -2
- package/dist-esm/test/conn.spec.js.map +1 -1
- package/dist-esm/test/groups.spec.js +14 -6
- package/dist-esm/test/groups.spec.js.map +1 -1
- package/dist-esm/test/hubs.spec.js +53 -10
- package/dist-esm/test/hubs.spec.js.map +1 -1
- package/dist-esm/test/integration.spec.js +128 -0
- package/dist-esm/test/integration.spec.js.map +1 -0
- package/dist-esm/test/testEnv.js +6 -2
- package/dist-esm/test/testEnv.js.map +1 -1
- package/package.json +32 -32
- package/types/web-pubsub.d.ts +165 -109
- package/dist-esm/src/normalizeOptions.js +0 -8
- package/dist-esm/src/normalizeOptions.js.map +0 -1
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"parseConnectionString.js","sourceRoot":"","sources":["../../src/parseConnectionString.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAOjC,MAAM,UAAU,qBAAqB,CAAC,IAAY;IAChD,
|
1
|
+
{"version":3,"file":"parseConnectionString.js","sourceRoot":"","sources":["../../src/parseConnectionString.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAOjC,MAAM,UAAU,qBAAqB,CAAC,IAAY;IAChD,MAAM,MAAM,GAA6B,EAAE,CAAC;IAE5C,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;QAC5B,MAAM,aAAa,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACrC,IAAI,aAAa,KAAK,CAAC,CAAC;YAAE,OAAO;QACjC,MAAM,GAAG,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,WAAW,EAAE,CAAC;QACxD,MAAM,KAAK,GAAG,CAAC,CAAC,SAAS,CAAC,aAAa,GAAG,CAAC,CAAC,CAAC;QAC7C,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IACtB,CAAC,CAAC,CAAC;IAEH,IAAI,YAAY,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;IACtC,IAAI,CAAC,YAAY;QAAE,MAAM,IAAI,SAAS,CAAC,oCAAoC,CAAC,CAAC;IAC7E,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE;QACpC,YAAY,GAAG,WAAW,YAAY,EAAE,CAAC;KAC1C;IACD,MAAM,GAAG,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;IAChC,IAAI,CAAC,GAAG;QAAE,MAAM,IAAI,SAAS,CAAC,sCAAsC,CAAC,CAAC;IACtE,MAAM,UAAU,GAAG,IAAI,kBAAkB,CAAC,GAAG,CAAC,CAAC;IAC/C,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;IAC5B,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,YAAY,CAAC,CAAC;IAClC,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC;IAChB,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC;IAChC,GAAG,CAAC,IAAI,GAAG,EAAE,CAAC;IAEd,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC;AAClC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AzureKeyCredential } from \"@azure/core-auth\";\nimport { URL } from \"./util/url\";\n\ninterface ParsedConnectionString {\n credential: AzureKeyCredential;\n endpoint: string;\n}\n\nexport function parseConnectionString(conn: string): ParsedConnectionString {\n const parsed: { [id: string]: string } = {};\n\n conn.split(\";\").forEach((i) => {\n const assignmentPos = i.indexOf(\"=\");\n if (assignmentPos === -1) return;\n const key = i.substring(0, assignmentPos).toLowerCase();\n const value = i.substring(assignmentPos + 1);\n parsed[key] = value;\n });\n\n let endpointPart = parsed[\"endpoint\"];\n if (!endpointPart) throw new TypeError(\"connection string missing endpoint\");\n if (!endpointPart.startsWith(\"http\")) {\n endpointPart = `https://${endpointPart}`;\n }\n const key = parsed[\"accesskey\"];\n if (!key) throw new TypeError(\"connection string missing access key\");\n const credential = new AzureKeyCredential(key);\n const port = parsed[\"port\"];\n const url = new URL(endpointPart);\n url.port = port;\n const endpoint = url.toString();\n url.port = \"\";\n\n return { credential, endpoint };\n}\n"]}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
2
|
+
// Licensed under the MIT license.
|
3
|
+
export const webPubSubReverseProxyPolicyName = "webPubSubReverseProxyPolicy";
|
4
|
+
/**
|
5
|
+
* Create an HTTP pipeline policy to use a reverse proxy.
|
6
|
+
* This is generally going to be an Azure APIM endpoint.
|
7
|
+
* @internal
|
8
|
+
*/
|
9
|
+
export function webPubSubReverseProxyPolicy(endpoint) {
|
10
|
+
const rpEndpointUrl = new URL(endpoint);
|
11
|
+
return {
|
12
|
+
name: webPubSubReverseProxyPolicyName,
|
13
|
+
sendRequest(request, next) {
|
14
|
+
const parsedUrl = new URL(request.url);
|
15
|
+
parsedUrl.host = rpEndpointUrl.host;
|
16
|
+
request.url = parsedUrl.toString();
|
17
|
+
return next(request);
|
18
|
+
},
|
19
|
+
};
|
20
|
+
}
|
21
|
+
//# sourceMappingURL=reverseProxyPolicy.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"reverseProxyPolicy.js","sourceRoot":"","sources":["../../src/reverseProxyPolicy.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AASlC,MAAM,CAAC,MAAM,+BAA+B,GAAG,6BAA6B,CAAC;AAE7E;;;;GAIG;AACH,MAAM,UAAU,2BAA2B,CAAC,QAAgB;IAC1D,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC;IACxC,OAAO;QACL,IAAI,EAAE,+BAA+B;QACrC,WAAW,CAAC,OAAwB,EAAE,IAAiB;YACrD,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YACvC,SAAS,CAAC,IAAI,GAAG,aAAa,CAAC,IAAI,CAAC;YACpC,OAAO,CAAC,GAAG,GAAG,SAAS,CAAC,QAAQ,EAAE,CAAC;YACnC,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n PipelineResponse,\n PipelineRequest,\n SendRequest,\n PipelinePolicy,\n} from \"@azure/core-rest-pipeline\";\n\nexport const webPubSubReverseProxyPolicyName = \"webPubSubReverseProxyPolicy\";\n\n/**\n * Create an HTTP pipeline policy to use a reverse proxy.\n * This is generally going to be an Azure APIM endpoint.\n * @internal\n */\nexport function webPubSubReverseProxyPolicy(endpoint: string): PipelinePolicy {\n const rpEndpointUrl = new URL(endpoint);\n return {\n name: webPubSubReverseProxyPolicyName,\n sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {\n const parsedUrl = new URL(request.url);\n parsedUrl.host = rpEndpointUrl.host;\n request.url = parsedUrl.toString();\n return next(request);\n },\n };\n}\n"]}
|
package/dist-esm/src/tracing.js
CHANGED
@@ -4,6 +4,6 @@ import { createSpanFunction } from "@azure/core-tracing";
|
|
4
4
|
/** @internal */
|
5
5
|
export const createSpan = createSpanFunction({
|
6
6
|
namespace: "Microsoft.WebPubSub",
|
7
|
-
packagePrefix: "Azure.Messaging.WebPubSub"
|
7
|
+
packagePrefix: "Azure.Messaging.WebPubSub",
|
8
8
|
});
|
9
9
|
//# sourceMappingURL=tracing.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"tracing.js","sourceRoot":"","sources":["../../src/tracing.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzD,gBAAgB;AAChB,MAAM,CAAC,MAAM,UAAU,GAAG,kBAAkB,CAAC;IAC3C,SAAS,EAAE,qBAAqB;IAChC,aAAa,EAAE,2BAA2B;CAC3C,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { createSpanFunction } from \"@azure/core-tracing\";\n\n/** @internal */\nexport const createSpan = createSpanFunction({\n namespace: \"Microsoft.WebPubSub\",\n packagePrefix: \"Azure.Messaging.WebPubSub\"
|
1
|
+
{"version":3,"file":"tracing.js","sourceRoot":"","sources":["../../src/tracing.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzD,gBAAgB;AAChB,MAAM,CAAC,MAAM,UAAU,GAAG,kBAAkB,CAAC;IAC3C,SAAS,EAAE,qBAAqB;IAChC,aAAa,EAAE,2BAA2B;CAC3C,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { createSpanFunction } from \"@azure/core-tracing\";\n\n/** @internal */\nexport const createSpan = createSpanFunction({\n namespace: \"Microsoft.WebPubSub\",\n packagePrefix: \"Azure.Messaging.WebPubSub\",\n});\n"]}
|
package/dist-esm/src/utils.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,SAAS,aAAa,CAAC,GAAY;IACjC,OAAO,CACL,OAAO,GAAG,KAAK,UAAU;QACzB,CAAC,OAAO,GAAG,KAAK,QAAQ;YACtB,GAAG,IAAI,IAAI;YACX,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,KAAK,aAAa;gBACrC,GAAG,CAAC,WAAW,CAAC,IAAI,KAAK,MAAM;gBAC/B,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAC9B,CAAC;AACJ,CAAC;AAmBD,MAAM,UAAU,oBAAoB,CAAC,OAAgB,EAAE,OAA4B;IACjF,IAAI,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,MAAK,YAAY,EAAE;QACzC,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;YAC/B,MAAM,IAAI,SAAS,CAAC,2BAA2B,CAAC,CAAC;SAClD;QACD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;KACxD;SAAM,IAAI,aAAa,CAAC,OAAO,CAAC,EAAE;QACjC,OAAO,EAAE,WAAW,EAAE,0BAA0B,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;KACtE;SAAM;QACL,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;KAC9E;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { RequestBodyType } from \"@azure/core-rest-pipeline\";\n\nfunction isRequestBody(obj: unknown): obj is RequestBodyType {\n return (\n typeof obj === \"function\" ||\n (typeof obj === \"object\" &&\n obj != null &&\n (obj.constructor.name === \"ArrayBuffer\" ||\n obj.constructor.name === \"Blob\" ||\n ArrayBuffer.isView(obj)))\n );\n}\n\nexport interface TextPlainPayload {\n contentType: \"text/plain\";\n payload: string;\n}\n\nexport interface JsonPayload {\n contentType: \"application/json\";\n payload: string;\n}\n\nexport interface BinaryPayload {\n contentType: \"application/octet-stream\";\n payload: RequestBodyType;\n}\n\nexport type Payload = TextPlainPayload | JsonPayload | BinaryPayload;\n\nexport function getPayloadForMessage(message: unknown, options: Record<string, any>): Payload {\n if (options?.contentType === \"text/plain\") {\n if (typeof message !== \"string\") {\n throw new TypeError(\"Message must be a string.\");\n }\n return { contentType: \"text/plain\", payload: message };\n } else if (isRequestBody(message)) {\n return { contentType: \"application/octet-stream\", payload: message };\n } else {\n return { contentType: \"application/json\", payload: JSON.stringify(message) };\n }\n}\n"]}
|
@@ -17,11 +17,11 @@ export function webPubSubKeyCredentialPolicy(credential) {
|
|
17
17
|
const bearerToken = jwt.sign({}, credential.key, {
|
18
18
|
audience: request.url,
|
19
19
|
expiresIn: "1h",
|
20
|
-
algorithm: "HS256"
|
20
|
+
algorithm: "HS256",
|
21
21
|
});
|
22
22
|
request.headers.set("Authorization", `Bearer ${bearerToken}`);
|
23
23
|
return next(request);
|
24
|
-
}
|
24
|
+
},
|
25
25
|
};
|
26
26
|
}
|
27
27
|
//# sourceMappingURL=webPubSubCredentialPolicy.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"webPubSubCredentialPolicy.js","sourceRoot":"","sources":["../../src/webPubSubCredentialPolicy.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAUlC,OAAO,GAAG,MAAM,cAAc,CAAC;AAE/B;;GAEG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,8BAA8B,CAAC;AAE/E;;;;GAIG;AACH,MAAM,UAAU,4BAA4B,CAAC,UAAyB;IACpE,OAAO;QACL,IAAI,EAAE,gCAAgC;QACtC,WAAW,CAAC,OAAwB,EAAE,IAAiB;YACrD,MAAM,WAAW,GAAG,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,UAAU,CAAC,GAAG,EAAE;gBAC/C,QAAQ,EAAE,OAAO,CAAC,GAAG;gBACrB,SAAS,EAAE,IAAI;gBACf,SAAS,EAAE,OAAO;aACnB,CAAC,CAAC;YACH,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,UAAU,WAAW,EAAE,CAAC,CAAC;YAC9D,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { KeyCredential } from \"@azure/core-auth\";\nimport {\n PipelineResponse,\n PipelineRequest,\n SendRequest,\n PipelinePolicy
|
1
|
+
{"version":3,"file":"webPubSubCredentialPolicy.js","sourceRoot":"","sources":["../../src/webPubSubCredentialPolicy.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAUlC,OAAO,GAAG,MAAM,cAAc,CAAC;AAE/B;;GAEG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,8BAA8B,CAAC;AAE/E;;;;GAIG;AACH,MAAM,UAAU,4BAA4B,CAAC,UAAyB;IACpE,OAAO;QACL,IAAI,EAAE,gCAAgC;QACtC,WAAW,CAAC,OAAwB,EAAE,IAAiB;YACrD,MAAM,WAAW,GAAG,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,UAAU,CAAC,GAAG,EAAE;gBAC/C,QAAQ,EAAE,OAAO,CAAC,GAAG;gBACrB,SAAS,EAAE,IAAI;gBACf,SAAS,EAAE,OAAO;aACnB,CAAC,CAAC;YACH,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,UAAU,WAAW,EAAE,CAAC,CAAC;YAC9D,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { KeyCredential } from \"@azure/core-auth\";\nimport {\n PipelineResponse,\n PipelineRequest,\n SendRequest,\n PipelinePolicy,\n} from \"@azure/core-rest-pipeline\";\n\nimport jwt from \"jsonwebtoken\";\n\n/**\n * The programmatic identifier of the webPubSubKeyCredentialPolicy.\n */\nexport const webPubSubKeyCredentialPolicyName = \"webPubSubKeyCredentialPolicy\";\n\n/**\n * Create an HTTP pipeline policy to authenticate a request\n * using an `AzureKeyCredential` for Text Analytics\n * @internal\n */\nexport function webPubSubKeyCredentialPolicy(credential: KeyCredential): PipelinePolicy {\n return {\n name: webPubSubKeyCredentialPolicyName,\n sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {\n const bearerToken = jwt.sign({}, credential.key, {\n audience: request.url,\n expiresIn: \"1h\",\n algorithm: \"HS256\",\n });\n request.headers.set(\"Authorization\", `Bearer ${bearerToken}`);\n return next(request);\n },\n };\n}\n"]}
|
@@ -5,8 +5,8 @@ import { parseConnectionString } from "../src/parseConnectionString";
|
|
5
5
|
import { assert } from "chai";
|
6
6
|
describe("Can parse connection string", function () {
|
7
7
|
it("can parse valid connection string", async () => {
|
8
|
-
|
9
|
-
|
8
|
+
let conn = "Endpoint=http://localhost;AccessKey=ABC;Port=8080;Version=1.0;";
|
9
|
+
let parsed = parseConnectionString(conn);
|
10
10
|
assert.equal(parsed.credential.key, "ABC");
|
11
11
|
assert.equal(parsed.endpoint, "http://localhost:8080/");
|
12
12
|
conn = "Endpoint=http://localhost;AccessKey=ABC;";
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"conn.spec.js","sourceRoot":"","sources":["../../test/conn.spec.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,oCAAoC;AACpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAE9B,QAAQ,CAAC,6BAA6B,EAAE;IACtC,EAAE,CAAC,mCAAmC,EAAE,KAAK,IAAI,EAAE;QACjD,IAAI,IAAI,GAAG,gEAAgE,CAAC;QAC5E,IAAI,MAAM,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAC;QACzC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC3C,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,EAAE,wBAAwB,CAAC,CAAC;QACxD,IAAI,GAAG,0CAA0C,CAAC;QAClD,MAAM,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAC;QACrC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC3C,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,EAAE,mBAAmB,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,0CAA0C,EAAE,KAAK,IAAI,EAAE;QACxD,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,qBAAqB,CAAC,4BAA4B,CAAC,CAAC,CAAC;QACzE,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,qBAAqB,CAAC,mBAAmB,CAAC,CAAC,CAAC;QAChE,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,qBAAqB,CAAC,YAAY,CAAC,CAAC,CAAC;IAC3D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n/* eslint-disable no-invalid-this */\nimport { parseConnectionString } from \"../src/parseConnectionString\";\nimport { assert } from \"chai\";\n\ndescribe(\"Can parse connection string\", function() {\n it(\"can parse valid connection string\", async () => {\n
|
1
|
+
{"version":3,"file":"conn.spec.js","sourceRoot":"","sources":["../../test/conn.spec.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,oCAAoC;AACpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAE9B,QAAQ,CAAC,6BAA6B,EAAE;IACtC,EAAE,CAAC,mCAAmC,EAAE,KAAK,IAAI,EAAE;QACjD,IAAI,IAAI,GAAG,gEAAgE,CAAC;QAC5E,IAAI,MAAM,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAC;QACzC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC3C,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,EAAE,wBAAwB,CAAC,CAAC;QACxD,IAAI,GAAG,0CAA0C,CAAC;QAClD,MAAM,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAC;QACrC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC3C,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,EAAE,mBAAmB,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,0CAA0C,EAAE,KAAK,IAAI,EAAE;QACxD,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,qBAAqB,CAAC,4BAA4B,CAAC,CAAC,CAAC;QACzE,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,qBAAqB,CAAC,mBAAmB,CAAC,CAAC,CAAC;QAChE,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,qBAAqB,CAAC,YAAY,CAAC,CAAC,CAAC;IAC3D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n/* eslint-disable no-invalid-this */\nimport { parseConnectionString } from \"../src/parseConnectionString\";\nimport { assert } from \"chai\";\n\ndescribe(\"Can parse connection string\", function () {\n it(\"can parse valid connection string\", async () => {\n let conn = \"Endpoint=http://localhost;AccessKey=ABC;Port=8080;Version=1.0;\";\n let parsed = parseConnectionString(conn);\n assert.equal(parsed.credential.key, \"ABC\");\n assert.equal(parsed.endpoint, \"http://localhost:8080/\");\n conn = \"Endpoint=http://localhost;AccessKey=ABC;\";\n parsed = parseConnectionString(conn);\n assert.equal(parsed.credential.key, \"ABC\");\n assert.equal(parsed.endpoint, \"http://localhost/\");\n });\n it(\"can throw with invalid connection string\", async () => {\n assert.throws(() => parseConnectionString(\"Endpoint=http://localhost;\"));\n assert.throws(() => parseConnectionString(\"http://localhost;\"));\n assert.throws(() => parseConnectionString(\"localhost;\"));\n });\n});\n"]}
|
@@ -1,12 +1,12 @@
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
2
2
|
// Licensed under the MIT license.
|
3
3
|
/* eslint-disable no-invalid-this */
|
4
|
-
import { env, record } from "@azure/test-
|
4
|
+
import { env, record } from "@azure-tools/test-recorder";
|
5
5
|
import { WebPubSubServiceClient } from "../src";
|
6
6
|
import { assert } from "chai";
|
7
7
|
import environmentSetup from "./testEnv";
|
8
|
+
/* eslint-disable @typescript-eslint/no-invalid-this */
|
8
9
|
describe("Group client working with a group", function () {
|
9
|
-
this.timeout(30000);
|
10
10
|
let recorder;
|
11
11
|
let client;
|
12
12
|
let lastResponse;
|
@@ -38,12 +38,20 @@ describe("Group client working with a group", function () {
|
|
38
38
|
}
|
39
39
|
assert.exists(error);
|
40
40
|
assert.strictEqual(error === null || error === void 0 ? void 0 : error.name, "RestError");
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
try {
|
42
|
+
await client.removeConnection("xxxx", { onResponse });
|
43
|
+
}
|
44
|
+
catch (e) {
|
45
|
+
assert.exists(error);
|
46
|
+
assert.strictEqual(error === null || error === void 0 ? void 0 : error.name, "RestError");
|
47
|
+
}
|
44
48
|
});
|
45
|
-
|
49
|
+
// skipping until we can record better tests with an actual user active.
|
50
|
+
it.skip("can manage users", async () => {
|
51
|
+
// service returns 404, this should likely be raised as an error but isn't
|
52
|
+
// due to the swagger design
|
46
53
|
await client.addUser("brian");
|
54
|
+
// service returns 404 and this throws.
|
47
55
|
await client.removeUser("brian");
|
48
56
|
});
|
49
57
|
afterEach(async function () {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"groups.spec.js","sourceRoot":"","sources":["../../test/groups.spec.ts"],"names":[],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AAwE;IACxE,EAAE,CAAC,IAAI,CAAC,kBAAkB,EAAE,KAAK,IAAI,EAAE;QACrC,0EAA0E;QAC1E,4BAA4B;QAC5B,MAAM,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAE9B,uCAAuC;QACvC,MAAM,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,KAAK;QACb,IAAI,QAAQ,EAAE;YACZ,QAAQ,CAAC,IAAI,EAAE,CAAC;SACjB;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n/* eslint-disable no-invalid-this */\nimport { env, Recorder, record } from \"@azure-tools/test-recorder\";\nimport { WebPubSubServiceClient, WebPubSubGroup } from \"../src\";\nimport { assert } from \"chai\";\nimport environmentSetup from \"./testEnv\";\nimport { FullOperationResponse } from \"@azure/core-client\";\nimport { RestError } from \"@azure/core-rest-pipeline\";\n/* eslint-disable @typescript-eslint/no-invalid-this */\n\ndescribe(\"Group client working with a group\", function () {\n let recorder: Recorder;\n let client: WebPubSubGroup;\n let lastResponse: FullOperationResponse | undefined;\n function onResponse(response: FullOperationResponse) {\n lastResponse = response;\n }\n beforeEach(function () {\n recorder = record(this, environmentSetup);\n const hubClient = new WebPubSubServiceClient(env.WPS_CONNECTION_STRING, \"simplechat\");\n client = hubClient.group(\"group\");\n });\n\n it(\"can broadcast to groups\", async () => {\n await client.sendToAll(\"hello\", { contentType: \"text/plain\", onResponse });\n assert.equal(lastResponse?.status, 202);\n\n await client.sendToAll({ x: 1, y: 2 }, { onResponse });\n assert.equal(lastResponse?.status, 202);\n\n const binaryMessage = new Uint8Array(10);\n await client.sendToAll(binaryMessage.buffer, { onResponse });\n assert.equal(lastResponse?.status, 202);\n });\n\n it(\"can manage connections\", async () => {\n // this endpoint returns 404 for connections not on the hub\n let error: RestError | undefined;\n try {\n await client.addConnection(\"xxxx\");\n } catch (e) {\n error = e;\n }\n\n assert.exists(error);\n assert.strictEqual(error?.name, \"RestError\");\n\n try {\n await client.removeConnection(\"xxxx\", { onResponse });\n } catch (e) {\n assert.exists(error);\n assert.strictEqual(error?.name, \"RestError\");\n }\n });\n\n // skipping until we can record better tests with an actual user active.\n it.skip(\"can manage users\", async () => {\n // service returns 404, this should likely be raised as an error but isn't\n // due to the swagger design\n await client.addUser(\"brian\");\n\n // service returns 404 and this throws.\n await client.removeUser(\"brian\");\n });\n\n afterEach(async function () {\n if (recorder) {\n recorder.stop();\n }\n });\n});\n"]}
|
@@ -1,32 +1,41 @@
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
2
2
|
// Licensed under the MIT license.
|
3
3
|
/* eslint-disable no-invalid-this */
|
4
|
-
import { env, record } from "@azure/test-
|
4
|
+
import { env, record, isLiveMode } from "@azure-tools/test-recorder";
|
5
5
|
import { WebPubSubServiceClient, AzureKeyCredential } from "../src";
|
6
6
|
import { assert } from "chai";
|
7
7
|
import environmentSetup from "./testEnv";
|
8
|
+
import { DefaultAzureCredential } from "@azure/identity";
|
9
|
+
/* eslint-disable @typescript-eslint/no-invalid-this */
|
8
10
|
describe("HubClient", function () {
|
9
11
|
let recorder;
|
10
12
|
beforeEach(function () {
|
11
13
|
recorder = record(this, environmentSetup);
|
12
14
|
});
|
13
|
-
afterEach(function () {
|
15
|
+
afterEach(async function () {
|
14
16
|
if (recorder) {
|
15
|
-
recorder.stop();
|
17
|
+
await recorder.stop();
|
16
18
|
}
|
17
19
|
});
|
18
20
|
describe("Constructing a HubClient", () => {
|
19
21
|
it("takes a connection string, hub name, and options", () => {
|
20
22
|
assert.doesNotThrow(() => {
|
21
23
|
new WebPubSubServiceClient(env.WPS_CONNECTION_STRING, "test-hub", {
|
22
|
-
retryOptions: { maxRetries: 2 }
|
24
|
+
retryOptions: { maxRetries: 2 },
|
23
25
|
});
|
24
26
|
});
|
25
27
|
});
|
26
28
|
it("takes an endpoint, an API key, a hub name, and options", () => {
|
27
29
|
assert.doesNotThrow(() => {
|
28
30
|
new WebPubSubServiceClient(env.ENDPOINT, new AzureKeyCredential(env.WPS_API_KEY), "test-hub", {
|
29
|
-
retryOptions: { maxRetries: 2 }
|
31
|
+
retryOptions: { maxRetries: 2 },
|
32
|
+
});
|
33
|
+
});
|
34
|
+
});
|
35
|
+
it("takes an endpoint, DefaultAzureCredential, a hub name, and options", () => {
|
36
|
+
assert.doesNotThrow(() => {
|
37
|
+
new WebPubSubServiceClient(env.ENDPOINT, new DefaultAzureCredential(), "test-hub", {
|
38
|
+
retryOptions: { maxRetries: 2 },
|
30
39
|
});
|
31
40
|
});
|
32
41
|
});
|
@@ -49,10 +58,32 @@ describe("HubClient", function () {
|
|
49
58
|
await client.sendToAll(binaryMessage.buffer, { onResponse });
|
50
59
|
assert.equal(lastResponse === null || lastResponse === void 0 ? void 0 : lastResponse.status, 202);
|
51
60
|
});
|
61
|
+
it("can broadcast using the DAC", async () => {
|
62
|
+
const dacClient = new WebPubSubServiceClient(env.ENDPOINT, new DefaultAzureCredential(), "simplechat");
|
63
|
+
await dacClient.sendToAll("hello", { contentType: "text/plain", onResponse });
|
64
|
+
assert.equal(lastResponse === null || lastResponse === void 0 ? void 0 : lastResponse.status, 202);
|
65
|
+
await dacClient.sendToAll({ x: 1, y: 2 }, { onResponse });
|
66
|
+
assert.equal(lastResponse === null || lastResponse === void 0 ? void 0 : lastResponse.status, 202);
|
67
|
+
const binaryMessage = new Uint8Array(10);
|
68
|
+
await dacClient.sendToAll(binaryMessage.buffer, { onResponse });
|
69
|
+
assert.equal(lastResponse === null || lastResponse === void 0 ? void 0 : lastResponse.status, 202);
|
70
|
+
});
|
71
|
+
it("can broadcast using APIM", async () => {
|
72
|
+
const apimClient = new WebPubSubServiceClient(env.WPS_CONNECTION_STRING, "simplechat", {
|
73
|
+
reverseProxyEndpoint: env.REVERSE_PROXY_ENDPOINT,
|
74
|
+
});
|
75
|
+
await apimClient.sendToAll("hello", { contentType: "text/plain", onResponse });
|
76
|
+
assert.equal(lastResponse === null || lastResponse === void 0 ? void 0 : lastResponse.status, 202);
|
77
|
+
await apimClient.sendToAll({ x: 1, y: 2 }, { onResponse });
|
78
|
+
assert.equal(lastResponse === null || lastResponse === void 0 ? void 0 : lastResponse.status, 202);
|
79
|
+
const binaryMessage = new Uint8Array(10);
|
80
|
+
await apimClient.sendToAll(binaryMessage.buffer, { onResponse });
|
81
|
+
assert.equal(lastResponse === null || lastResponse === void 0 ? void 0 : lastResponse.status, 202);
|
82
|
+
});
|
52
83
|
it("can send messages to a user", async () => {
|
53
84
|
await client.sendToUser("brian", "hello", {
|
54
85
|
contentType: "text/plain",
|
55
|
-
onResponse
|
86
|
+
onResponse,
|
56
87
|
});
|
57
88
|
assert.equal(lastResponse === null || lastResponse === void 0 ? void 0 : lastResponse.status, 202);
|
58
89
|
await client.sendToUser("brian", { x: 1, y: 2 }, { onResponse });
|
@@ -73,13 +104,16 @@ describe("HubClient", function () {
|
|
73
104
|
// `removeUserFromAllGroups` always times out.
|
74
105
|
it.skip("can manage users", async () => {
|
75
106
|
this.timeout(Infinity);
|
76
|
-
const res = await client.
|
107
|
+
const res = await client.userExists("foo");
|
77
108
|
assert.ok(!res);
|
78
109
|
await client.removeUserFromAllGroups("brian", { onResponse });
|
79
110
|
assert.equal(lastResponse === null || lastResponse === void 0 ? void 0 : lastResponse.status, 200);
|
80
111
|
});
|
81
|
-
it("can check if a connection exists", async ()
|
82
|
-
|
112
|
+
it("can check if a connection exists", async function () {
|
113
|
+
// likely bug in recorder for this test - recording not generating properly
|
114
|
+
if (!isLiveMode())
|
115
|
+
this.skip();
|
116
|
+
const res = await client.connectionExists("xxx");
|
83
117
|
assert.ok(!res);
|
84
118
|
});
|
85
119
|
it("can grant permissions to connections", async () => {
|
@@ -93,7 +127,10 @@ describe("HubClient", function () {
|
|
93
127
|
// grantPermission validates connection ids, so we expect an error here.
|
94
128
|
assert.equal(error.statusCode, 404);
|
95
129
|
});
|
96
|
-
it("can revoke permissions from connections", async ()
|
130
|
+
it("can revoke permissions from connections", async function () {
|
131
|
+
// likely bug in recorder for this test - recording not generating properly
|
132
|
+
if (!isLiveMode())
|
133
|
+
this.skip();
|
97
134
|
let error;
|
98
135
|
try {
|
99
136
|
await client.revokePermission("xxx", "joinLeaveGroup", { targetName: "x" });
|
@@ -104,6 +141,12 @@ describe("HubClient", function () {
|
|
104
141
|
// grantPermission validates connection ids, so we expect an error here.
|
105
142
|
assert.equal(error.statusCode, 404);
|
106
143
|
});
|
144
|
+
// service API doesn't work yet.
|
145
|
+
it.skip("can generate client tokens", async () => {
|
146
|
+
await client.getClientAccessToken({
|
147
|
+
userId: "brian",
|
148
|
+
});
|
149
|
+
});
|
107
150
|
});
|
108
151
|
});
|
109
152
|
//# sourceMappingURL=hubs.spec.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"hubs.spec.js","sourceRoot":"","sources":["../../test/hubs.spec.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,oCAAoC;AACpC,OAAO,EAAE,GAAG,EAAY,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAC;AACpE,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,gBAAgB,MAAM,WAAW,CAAC;AAGzC,QAAQ,CAAC,WAAW,EAAE;IACpB,IAAI,QAAkB,CAAC;IACvB,UAAU,CAAC;QACT,QAAQ,GAAG,MAAM,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC;IAC5C,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC;QACR,IAAI,QAAQ,EAAE;YACZ,QAAQ,CAAC,IAAI,EAAE,CAAC;SACjB;IACH,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,0BAA0B,EAAE,GAAG,EAAE;QACxC,EAAE,CAAC,kDAAkD,EAAE,GAAG,EA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,IAAI,EAAE;YAChD,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;YAC9C,MAAM,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,sCAAsC,EAAE,KAAK,IAAI,EAAE;YACpD,IAAI,KAAK,CAAC;YACV,IAAI;gBACF,MAAM,MAAM,CAAC,eAAe,CAAC,KAAK,EAAE,gBAAgB,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC;aAC5E;YAAC,OAAO,CAAC,EAAE;gBACV,KAAK,GAAG,CAAC,CAAC;aACX;YACD,wEAAwE;YACxE,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;QACtC,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,yCAAyC,EAAE,KAAK,IAAI,EAAE;YACvD,IAAI,KAAK,CAAC;YACV,IAAI;gBACF,MAAM,MAAM,CAAC,gBAAgB,CAAC,KAAK,EAAE,gBAAgB,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC;aAC7E;YAAC,OAAO,CAAC,EAAE;gBACV,KAAK,GAAG,CAAC,CAAC;aACX;YACD,wEAAwE;YACxE,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;QACtC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n/* eslint-disable no-invalid-this */\nimport { env, Recorder, record } from \"@azure/test-utils-recorder\";\nimport { WebPubSubServiceClient, AzureKeyCredential } from \"../src\";\nimport { assert } from \"chai\";\nimport environmentSetup from \"./testEnv\";\nimport { FullOperationResponse } from \"@azure/core-client\";\n\ndescribe(\"HubClient\", function() {\n let recorder: Recorder;\n beforeEach(function() {\n recorder = record(this, environmentSetup);\n });\n\n afterEach(function() {\n if (recorder) {\n recorder.stop();\n }\n });\n\n describe(\"Constructing a HubClient\", () => {\n it(\"takes a connection string, hub name, and options\", () => {\n assert.doesNotThrow(() => {\n new WebPubSubServiceClient(env.WPS_CONNECTION_STRING, \"test-hub\", {\n retryOptions: { maxRetries: 2 }\n });\n });\n });\n\n it(\"takes an endpoint, an API key, a hub name, and options\", () => {\n assert.doesNotThrow(() => {\n new WebPubSubServiceClient(\n env.ENDPOINT,\n new AzureKeyCredential(env.WPS_API_KEY),\n \"test-hub\",\n {\n retryOptions: { maxRetries: 2 }\n }\n );\n });\n });\n });\n\n describe(\"Working with a hub\", function() {\n let client: WebPubSubServiceClient;\n let lastResponse: FullOperationResponse | undefined;\n function onResponse(response: FullOperationResponse) {\n lastResponse = response;\n }\n beforeEach(function() {\n client = new WebPubSubServiceClient(env.WPS_CONNECTION_STRING, \"simplechat\");\n });\n\n it(\"can broadcast\", async () => {\n await client.sendToAll(\"hello\", { contentType: \"text/plain\", onResponse });\n assert.equal(lastResponse?.status, 202);\n\n await client.sendToAll({ x: 1, y: 2 }, { onResponse });\n assert.equal(lastResponse?.status, 202);\n\n const binaryMessage = new Uint8Array(10);\n await client.sendToAll(binaryMessage.buffer, { onResponse });\n assert.equal(lastResponse?.status, 202);\n });\n\n it(\"can send messages to a user\", async () => {\n await client.sendToUser(\"brian\", \"hello\", {\n contentType: \"text/plain\",\n onResponse\n });\n assert.equal(lastResponse?.status, 202);\n\n await client.sendToUser(\"brian\", { x: 1, y: 2 }, { onResponse });\n assert.equal(lastResponse?.status, 202);\n\n const binaryMessage = new Uint8Array(10);\n await client.sendToUser(\"brian\", binaryMessage.buffer, { onResponse });\n assert.equal(lastResponse?.status, 202);\n });\n\n it(\"can send messages to a connection\", async () => {\n await client.sendToConnection(\"xxxx\", \"hello\", { contentType: \"text/plain\", onResponse });\n assert.equal(lastResponse?.status, 202);\n\n await client.sendToConnection(\"xxxx\", { x: 1, y: 2 }, { onResponse });\n assert.equal(lastResponse?.status, 202);\n const binaryMessage = new Uint8Array(10);\n\n await client.sendToConnection(\"xxxx\", binaryMessage.buffer, { onResponse });\n assert.equal(lastResponse?.status, 202);\n });\n\n // `removeUserFromAllGroups` always times out.\n it.skip(\"can manage users\", async () => {\n this.timeout(Infinity);\n const res = await client.hasUser(\"foo\");\n assert.ok(!res);\n await client.removeUserFromAllGroups(\"brian\", { onResponse });\n assert.equal(lastResponse?.status, 200);\n });\n\n it(\"can check if a connection exists\", async () => {\n const res = await client.hasConnection(\"xxx\");\n assert.ok(!res);\n });\n\n it(\"can grant permissions to connections\", async () => {\n let error;\n try {\n await client.grantPermission(\"xxx\", \"joinLeaveGroup\", { targetName: \"x\" });\n } catch (e) {\n error = e;\n }\n // grantPermission validates connection ids, so we expect an error here.\n assert.equal(error.statusCode, 404);\n });\n\n it(\"can revoke permissions from connections\", async () => {\n let error;\n try {\n await client.revokePermission(\"xxx\", \"joinLeaveGroup\", { targetName: \"x\" });\n } catch (e) {\n error = e;\n }\n // grantPermission validates connection ids, so we expect an error here.\n assert.equal(error.statusCode, 404);\n });\n });\n});\n"]}
|
1
|
+
{"version":3,"file":"hubs.spec.js","sourceRoot":"","sources":["../../test/hubs.spec.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,oCAAoC;AACpC,OAAO,EAAE,GAAG,EAAY,MAAM,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAC/E,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAC;AACpE,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,gBAAgB,MAAM,WAAW,CAAC;AAEzC,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzD,uDAAuD;AAEvD,QAAQ,CAAC,WAAW,EAAE;IACpB,IAAI,QAAkB,CAAC;IACvB,UAAU,CAAC;QACT,QAAQ,GAAG,MAAM,CAAC,IAAI,EAA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C,KAAK,CAAC,CAAC;YACjD,MAAM,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,sCAAsC,EAAE,KAAK,IAAI,EAAE;YACpD,IAAI,KAAK,CAAC;YACV,IAAI;gBACF,MAAM,MAAM,CAAC,eAAe,CAAC,KAAK,EAAE,gBAAgB,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC;aAC5E;YAAC,OAAO,CAAC,EAAE;gBACV,KAAK,GAAG,CAAC,CAAC;aACX;YACD,wEAAwE;YACxE,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;QACtC,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,yCAAyC,EAAE,KAAK;YACjD,2EAA2E;YAC3E,IAAI,CAAC,UAAU,EAAE;gBAAE,IAAI,CAAC,IAAI,EAAE,CAAC;YAC/B,IAAI,KAAK,CAAC;YACV,IAAI;gBACF,MAAM,MAAM,CAAC,gBAAgB,CAAC,KAAK,EAAE,gBAAgB,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC;aAC7E;YAAC,OAAO,CAAC,EAAE;gBACV,KAAK,GAAG,CAAC,CAAC;aACX;YACD,wEAAwE;YACxE,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;QACtC,CAAC,CAAC,CAAC;QAEH,gCAAgC;QAChC,EAAE,CAAC,IAAI,CAAC,4BAA4B,EAAE,KAAK,IAAI,EAAE;YAC/C,MAAM,MAAM,CAAC,oBAAoB,CAAC;gBAChC,MAAM,EAAE,OAAO;aAChB,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n/* eslint-disable no-invalid-this */\nimport { env, Recorder, record, isLiveMode } from \"@azure-tools/test-recorder\";\nimport { WebPubSubServiceClient, AzureKeyCredential } from \"../src\";\nimport { assert } from \"chai\";\nimport environmentSetup from \"./testEnv\";\nimport { FullOperationResponse } from \"@azure/core-client\";\nimport { DefaultAzureCredential } from \"@azure/identity\";\n/* eslint-disable @typescript-eslint/no-invalid-this */\n\ndescribe(\"HubClient\", function () {\n let recorder: Recorder;\n beforeEach(function () {\n recorder = record(this, environmentSetup);\n });\n\n afterEach(async function () {\n if (recorder) {\n await recorder.stop();\n }\n });\n\n describe(\"Constructing a HubClient\", () => {\n it(\"takes a connection string, hub name, and options\", () => {\n assert.doesNotThrow(() => {\n new WebPubSubServiceClient(env.WPS_CONNECTION_STRING, \"test-hub\", {\n retryOptions: { maxRetries: 2 },\n });\n });\n });\n\n it(\"takes an endpoint, an API key, a hub name, and options\", () => {\n assert.doesNotThrow(() => {\n new WebPubSubServiceClient(\n env.ENDPOINT,\n new AzureKeyCredential(env.WPS_API_KEY),\n \"test-hub\",\n {\n retryOptions: { maxRetries: 2 },\n }\n );\n });\n });\n\n it(\"takes an endpoint, DefaultAzureCredential, a hub name, and options\", () => {\n assert.doesNotThrow(() => {\n new WebPubSubServiceClient(env.ENDPOINT, new DefaultAzureCredential(), \"test-hub\", {\n retryOptions: { maxRetries: 2 },\n });\n });\n });\n });\n\n describe(\"Working with a hub\", function () {\n let client: WebPubSubServiceClient;\n let lastResponse: FullOperationResponse | undefined;\n function onResponse(response: FullOperationResponse) {\n lastResponse = response;\n }\n beforeEach(function () {\n client = new WebPubSubServiceClient(env.WPS_CONNECTION_STRING, \"simplechat\");\n });\n\n it(\"can broadcast\", async () => {\n await client.sendToAll(\"hello\", { contentType: \"text/plain\", onResponse });\n assert.equal(lastResponse?.status, 202);\n\n await client.sendToAll({ x: 1, y: 2 }, { onResponse });\n assert.equal(lastResponse?.status, 202);\n\n const binaryMessage = new Uint8Array(10);\n await client.sendToAll(binaryMessage.buffer, { onResponse });\n assert.equal(lastResponse?.status, 202);\n });\n\n it(\"can broadcast using the DAC\", async () => {\n const dacClient = new WebPubSubServiceClient(\n env.ENDPOINT,\n new DefaultAzureCredential(),\n \"simplechat\"\n );\n\n await dacClient.sendToAll(\"hello\", { contentType: \"text/plain\", onResponse });\n assert.equal(lastResponse?.status, 202);\n\n await dacClient.sendToAll({ x: 1, y: 2 }, { onResponse });\n assert.equal(lastResponse?.status, 202);\n\n const binaryMessage = new Uint8Array(10);\n await dacClient.sendToAll(binaryMessage.buffer, { onResponse });\n assert.equal(lastResponse?.status, 202);\n });\n\n it(\"can broadcast using APIM\", async () => {\n const apimClient = new WebPubSubServiceClient(env.WPS_CONNECTION_STRING, \"simplechat\", {\n reverseProxyEndpoint: env.REVERSE_PROXY_ENDPOINT,\n });\n\n await apimClient.sendToAll(\"hello\", { contentType: \"text/plain\", onResponse });\n assert.equal(lastResponse?.status, 202);\n\n await apimClient.sendToAll({ x: 1, y: 2 }, { onResponse });\n assert.equal(lastResponse?.status, 202);\n\n const binaryMessage = new Uint8Array(10);\n await apimClient.sendToAll(binaryMessage.buffer, { onResponse });\n assert.equal(lastResponse?.status, 202);\n });\n\n it(\"can send messages to a user\", async () => {\n await client.sendToUser(\"brian\", \"hello\", {\n contentType: \"text/plain\",\n onResponse,\n });\n assert.equal(lastResponse?.status, 202);\n\n await client.sendToUser(\"brian\", { x: 1, y: 2 }, { onResponse });\n assert.equal(lastResponse?.status, 202);\n\n const binaryMessage = new Uint8Array(10);\n await client.sendToUser(\"brian\", binaryMessage.buffer, { onResponse });\n assert.equal(lastResponse?.status, 202);\n });\n\n it(\"can send messages to a connection\", async () => {\n await client.sendToConnection(\"xxxx\", \"hello\", { contentType: \"text/plain\", onResponse });\n assert.equal(lastResponse?.status, 202);\n\n await client.sendToConnection(\"xxxx\", { x: 1, y: 2 }, { onResponse });\n assert.equal(lastResponse?.status, 202);\n const binaryMessage = new Uint8Array(10);\n\n await client.sendToConnection(\"xxxx\", binaryMessage.buffer, { onResponse });\n assert.equal(lastResponse?.status, 202);\n });\n\n // `removeUserFromAllGroups` always times out.\n it.skip(\"can manage users\", async () => {\n this.timeout(Infinity);\n const res = await client.userExists(\"foo\");\n assert.ok(!res);\n await client.removeUserFromAllGroups(\"brian\", { onResponse });\n assert.equal(lastResponse?.status, 200);\n });\n\n it(\"can check if a connection exists\", async function () {\n // likely bug in recorder for this test - recording not generating properly\n if (!isLiveMode()) this.skip();\n const res = await client.connectionExists(\"xxx\");\n assert.ok(!res);\n });\n\n it(\"can grant permissions to connections\", async () => {\n let error;\n try {\n await client.grantPermission(\"xxx\", \"joinLeaveGroup\", { targetName: \"x\" });\n } catch (e) {\n error = e;\n }\n // grantPermission validates connection ids, so we expect an error here.\n assert.equal(error.statusCode, 404);\n });\n\n it(\"can revoke permissions from connections\", async function () {\n // likely bug in recorder for this test - recording not generating properly\n if (!isLiveMode()) this.skip();\n let error;\n try {\n await client.revokePermission(\"xxx\", \"joinLeaveGroup\", { targetName: \"x\" });\n } catch (e) {\n error = e;\n }\n // grantPermission validates connection ids, so we expect an error here.\n assert.equal(error.statusCode, 404);\n });\n\n // service API doesn't work yet.\n it.skip(\"can generate client tokens\", async () => {\n await client.getClientAccessToken({\n userId: \"brian\",\n });\n });\n });\n});\n"]}
|
@@ -0,0 +1,128 @@
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
2
|
+
// Licensed under the MIT license.
|
3
|
+
/* eslint-disable no-invalid-this */
|
4
|
+
import { WebPubSubServiceClient } from "../src/index";
|
5
|
+
import { env, isLiveMode } from "@azure-tools/test-recorder";
|
6
|
+
import { assert } from "chai";
|
7
|
+
import ws from "ws";
|
8
|
+
function defer() {
|
9
|
+
let actualResolve;
|
10
|
+
let actualReject;
|
11
|
+
const promise = new Promise((resolve, reject) => {
|
12
|
+
actualResolve = resolve;
|
13
|
+
actualReject = reject;
|
14
|
+
});
|
15
|
+
return {
|
16
|
+
promise,
|
17
|
+
resolve: actualResolve,
|
18
|
+
reject: actualReject,
|
19
|
+
};
|
20
|
+
}
|
21
|
+
class SimpleWebSocketFrame {
|
22
|
+
constructor(data, isBinary) {
|
23
|
+
this.data = data;
|
24
|
+
this.isBinary = isBinary;
|
25
|
+
if (!isBinary) {
|
26
|
+
this.dataAsString = data.toString();
|
27
|
+
}
|
28
|
+
}
|
29
|
+
isEndSignal() {
|
30
|
+
return (this.isBinary &&
|
31
|
+
this.data instanceof Buffer &&
|
32
|
+
this.data[0] === 5 &&
|
33
|
+
this.data[1] === 1 &&
|
34
|
+
this.data[2] === 1);
|
35
|
+
}
|
36
|
+
}
|
37
|
+
class PubSubWebSocketFrame {
|
38
|
+
constructor(data, isBinary) {
|
39
|
+
assert.isFalse(isBinary);
|
40
|
+
this.dataAsString = data.toString();
|
41
|
+
this.message = JSON.parse(this.dataAsString);
|
42
|
+
}
|
43
|
+
isEndSignal() {
|
44
|
+
return this.message.dataType === "binary" && this.message.data === "BQEB";
|
45
|
+
}
|
46
|
+
}
|
47
|
+
function getEndSignal() {
|
48
|
+
// magic number 511
|
49
|
+
const payload = new Uint8Array(3);
|
50
|
+
payload[0] = 5;
|
51
|
+
payload[1] = 1;
|
52
|
+
payload[2] = 1;
|
53
|
+
return payload;
|
54
|
+
}
|
55
|
+
describe("ServiceClient to manage the connected WebSocket connections", function () {
|
56
|
+
it("Simple clients can receive expected messages with different content types", async function () {
|
57
|
+
if (!isLiveMode())
|
58
|
+
this.skip();
|
59
|
+
const hub = "SimpleClientCanReceiveMessage";
|
60
|
+
const messages = [];
|
61
|
+
// Get token
|
62
|
+
const serviceClient = new WebPubSubServiceClient(env.WPS_CONNECTION_STRING, hub);
|
63
|
+
const token = await serviceClient.getClientAccessToken();
|
64
|
+
const endSignal = defer();
|
65
|
+
// Start simple WebSocket connections
|
66
|
+
const client = new ws.WebSocket(token.url);
|
67
|
+
client.on("message", (data, isBinary) => {
|
68
|
+
const frame = new SimpleWebSocketFrame(data, isBinary);
|
69
|
+
if (frame.isEndSignal()) {
|
70
|
+
endSignal.resolve();
|
71
|
+
client.close();
|
72
|
+
}
|
73
|
+
else {
|
74
|
+
messages.push(frame);
|
75
|
+
}
|
76
|
+
});
|
77
|
+
client.on("open", async () => {
|
78
|
+
// send to all
|
79
|
+
// Send a JSON message
|
80
|
+
await serviceClient.sendToAll({ message: "Hello world!" });
|
81
|
+
// Send a plain text message
|
82
|
+
await serviceClient.sendToAll("Hi there!", { contentType: "text/plain" });
|
83
|
+
// Send the binary end signal message
|
84
|
+
await serviceClient.sendToAll(getEndSignal());
|
85
|
+
});
|
86
|
+
await endSignal.promise;
|
87
|
+
assert.equal(messages.length, 2);
|
88
|
+
assert.equal(messages[0].dataAsString, '{"message":"Hello world!"}');
|
89
|
+
assert.equal(messages[1].dataAsString, "Hi there!");
|
90
|
+
});
|
91
|
+
it("Subprotocol clients can receive expected messages with different content types", async function () {
|
92
|
+
if (!isLiveMode())
|
93
|
+
this.skip();
|
94
|
+
const hub = "PubSubClientCanReceiveMessage";
|
95
|
+
const messages = [];
|
96
|
+
// Get token
|
97
|
+
const serviceClient = new WebPubSubServiceClient(env.WPS_CONNECTION_STRING, hub);
|
98
|
+
const token = await serviceClient.getClientAccessToken();
|
99
|
+
const endSignal = defer();
|
100
|
+
// Start simple WebSocket connections
|
101
|
+
const client = new ws.WebSocket(token.url, "json.webpubsub.azure.v1");
|
102
|
+
client.on("message", (data, isBinary) => {
|
103
|
+
const frame = new PubSubWebSocketFrame(data, isBinary);
|
104
|
+
if (frame.isEndSignal()) {
|
105
|
+
endSignal.resolve();
|
106
|
+
client.close();
|
107
|
+
}
|
108
|
+
else {
|
109
|
+
messages.push(frame);
|
110
|
+
}
|
111
|
+
});
|
112
|
+
client.on("open", async () => {
|
113
|
+
// send to all
|
114
|
+
// Send a JSON message
|
115
|
+
await serviceClient.sendToAll({ message: "Hello world!" });
|
116
|
+
// Send a plain text message
|
117
|
+
await serviceClient.sendToAll("Hi there!", { contentType: "text/plain" });
|
118
|
+
// Send the binary end signal message
|
119
|
+
await serviceClient.sendToAll(getEndSignal());
|
120
|
+
});
|
121
|
+
await endSignal.promise;
|
122
|
+
assert.equal(messages.length, 3);
|
123
|
+
assert.equal(messages[0].message.event, "connected");
|
124
|
+
assert.equal(messages[1].dataAsString, '{"type":"message","from":"server","dataType":"json","data":{"message":"Hello world!"}}');
|
125
|
+
assert.equal(messages[2].dataAsString, '{"type":"message","from":"server","dataType":"text","data":"Hi there!"}');
|
126
|
+
});
|
127
|
+
});
|
128
|
+
//# sourceMappingURL=integration.spec.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"integration.spec.js","sourceRoot":"","sources":["../../test/integration.spec.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,oCAAoC;AACpC,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAE7D,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,SAAS,KAAK;IAKZ,IAAI,aAA6B,CAAC;IAClC,IAAI,YAAkC,CAAC;IAEvC,MAAM,OAAO,GAAG,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACjD,aAAa,GAAG,OAAO,CAAC;QACxB,YAAY,GAAG,MAAM,CAAC;IACxB,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,OAAO;QACP,OAAO,EAAE,aAAc;QACvB,MAAM,EAAE,YAAa;KACtB,CAAC;AACJ,CAAC;AAED,MAAM,oBAAoB;IAExB,YAAmB,IAAqC,EAAS,QAAiB;QAA/D,SAAI,GAAJ,IAAI,CAAiC;QAAS,aAAQ,GAAR,QAAQ,CAAS;QAChF,IAAI,CAAC,QAAQ,EAAE;YACb,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;SACrC;IACH,CAAC;IAED,WAAW;QACT,OAAO,CACL,IAAI,CAAC,QAAQ;YACb,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AC,CAAC;QAEH,MAAM,SAAS,CAAC,OAAO,CAAC;QAExB,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QACjC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;QACrD,MAAM,CAAC,KAAK,CACV,QAAQ,CAAC,CAAC,CAAC,CAAC,YAAY,EACxB,wFAAwF,CACzF,CAAC;QACF,MAAM,CAAC,KAAK,CACV,QAAQ,CAAC,CAAC,CAAC,CAAC,YAAY,EACxB,yEAAyE,CAC1E,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n/* eslint-disable no-invalid-this */\nimport { WebPubSubServiceClient } from \"../src/index\";\nimport { env, isLiveMode } from \"@azure-tools/test-recorder\";\nimport { Context } from \"mocha\";\nimport { assert } from \"chai\";\nimport ws from \"ws\";\n\nfunction defer<T>(): {\n promise: Promise<T>;\n resolve: (t: T) => void;\n reject: (err: Error) => void;\n} {\n let actualResolve: (t: T) => void;\n let actualReject: (err: Error) => void;\n\n const promise = new Promise<T>((resolve, reject) => {\n actualResolve = resolve;\n actualReject = reject;\n });\n\n return {\n promise,\n resolve: actualResolve!,\n reject: actualReject!,\n };\n}\n\nclass SimpleWebSocketFrame {\n public dataAsString: string | undefined;\n constructor(public data: Buffer | ArrayBuffer | Buffer[], public isBinary: boolean) {\n if (!isBinary) {\n this.dataAsString = data.toString();\n }\n }\n\n isEndSignal(): boolean {\n return (\n this.isBinary &&\n this.data instanceof Buffer &&\n this.data[0] === 5 &&\n this.data[1] === 1 &&\n this.data[2] === 1\n );\n }\n}\n\nclass PubSubWebSocketFrame {\n public message: any;\n public dataAsString: string;\n constructor(data: Buffer | ArrayBuffer | Buffer[], isBinary: boolean) {\n assert.isFalse(isBinary);\n this.dataAsString = data.toString();\n this.message = JSON.parse(this.dataAsString);\n }\n\n isEndSignal(): boolean {\n return this.message.dataType === \"binary\" && this.message.data === \"BQEB\";\n }\n}\n\nfunction getEndSignal(): Uint8Array {\n // magic number 511\n const payload = new Uint8Array(3);\n payload[0] = 5;\n payload[1] = 1;\n payload[2] = 1;\n return payload;\n}\n\ndescribe(\"ServiceClient to manage the connected WebSocket connections\", function () {\n it(\"Simple clients can receive expected messages with different content types\", async function (this: Context) {\n if (!isLiveMode()) this.skip();\n const hub = \"SimpleClientCanReceiveMessage\";\n\n const messages: SimpleWebSocketFrame[] = [];\n\n // Get token\n const serviceClient = new WebPubSubServiceClient(env.WPS_CONNECTION_STRING, hub);\n const token = await serviceClient.getClientAccessToken();\n const endSignal = defer<void>();\n // Start simple WebSocket connections\n const client = new ws.WebSocket(token.url);\n client.on(\"message\", (data, isBinary) => {\n const frame = new SimpleWebSocketFrame(data, isBinary);\n if (frame.isEndSignal()) {\n endSignal.resolve();\n client.close();\n } else {\n messages.push(frame);\n }\n });\n client.on(\"open\", async () => {\n // send to all\n // Send a JSON message\n await serviceClient.sendToAll({ message: \"Hello world!\" });\n\n // Send a plain text message\n await serviceClient.sendToAll(\"Hi there!\", { contentType: \"text/plain\" });\n\n // Send the binary end signal message\n await serviceClient.sendToAll(getEndSignal());\n });\n await endSignal.promise;\n\n assert.equal(messages.length, 2);\n assert.equal(messages[0].dataAsString, '{\"message\":\"Hello world!\"}');\n assert.equal(messages[1].dataAsString, \"Hi there!\");\n });\n\n it(\"Subprotocol clients can receive expected messages with different content types\", async function (this: Context) {\n if (!isLiveMode()) this.skip();\n const hub = \"PubSubClientCanReceiveMessage\";\n const messages: PubSubWebSocketFrame[] = [];\n\n // Get token\n const serviceClient = new WebPubSubServiceClient(env.WPS_CONNECTION_STRING, hub);\n const token = await serviceClient.getClientAccessToken();\n const endSignal = defer<void>();\n // Start simple WebSocket connections\n const client = new ws.WebSocket(token.url, \"json.webpubsub.azure.v1\");\n client.on(\"message\", (data, isBinary) => {\n const frame = new PubSubWebSocketFrame(data, isBinary);\n if (frame.isEndSignal()) {\n endSignal.resolve();\n client.close();\n } else {\n messages.push(frame);\n }\n });\n client.on(\"open\", async () => {\n // send to all\n // Send a JSON message\n await serviceClient.sendToAll({ message: \"Hello world!\" });\n\n // Send a plain text message\n await serviceClient.sendToAll(\"Hi there!\", { contentType: \"text/plain\" });\n\n // Send the binary end signal message\n await serviceClient.sendToAll(getEndSignal());\n });\n\n await endSignal.promise;\n\n assert.equal(messages.length, 3);\n assert.equal(messages[0].message.event, \"connected\");\n assert.equal(\n messages[1].dataAsString,\n '{\"type\":\"message\",\"from\":\"server\",\"dataType\":\"json\",\"data\":{\"message\":\"Hello world!\"}}'\n );\n assert.equal(\n messages[2].dataAsString,\n '{\"type\":\"message\",\"from\":\"server\",\"dataType\":\"text\",\"data\":\"Hi there!\"}'\n );\n });\n});\n"]}
|
package/dist-esm/test/testEnv.js
CHANGED
@@ -2,10 +2,14 @@ const environmentSetup = {
|
|
2
2
|
replaceableVariables: {
|
3
3
|
WPS_CONNECTION_STRING: "Endpoint=endpoint;AccessKey=api_key;Version=1.0;",
|
4
4
|
WPS_API_KEY: "api_key",
|
5
|
-
ENDPOINT: "endpoint"
|
5
|
+
ENDPOINT: "https://endpoint",
|
6
|
+
REVERSE_PROXY_ENDPOINT: "https://rp-endpoint",
|
7
|
+
AZURE_CLIENT_ID: "azure_client_id",
|
8
|
+
AZURE_CLIENT_SECRET: "azure_client_secret",
|
9
|
+
AZURE_TENANT_ID: "azuretenantid",
|
6
10
|
},
|
7
11
|
customizationsOnRecordings: [],
|
8
|
-
queryParametersToSkip: []
|
12
|
+
queryParametersToSkip: [],
|
9
13
|
};
|
10
14
|
export default environmentSetup;
|
11
15
|
//# sourceMappingURL=testEnv.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"testEnv.js","sourceRoot":"","sources":["../../test/testEnv.ts"],"names":[],"mappings":"AAIA,MAAM,gBAAgB,GAA6B;IACjD,oBAAoB,EAAE;QACpB,qBAAqB,EAAE,kDAAkD;QACzE,WAAW,EAAE,SAAS;QACtB,QAAQ,EAAE,
|
1
|
+
{"version":3,"file":"testEnv.js","sourceRoot":"","sources":["../../test/testEnv.ts"],"names":[],"mappings":"AAIA,MAAM,gBAAgB,GAA6B;IACjD,oBAAoB,EAAE;QACpB,qBAAqB,EAAE,kDAAkD;QACzE,WAAW,EAAE,SAAS;QACtB,QAAQ,EAAE,kBAAkB;QAC5B,sBAAsB,EAAE,qBAAqB;QAC7C,eAAe,EAAE,iBAAiB;QAClC,mBAAmB,EAAE,qBAAqB;QAC1C,eAAe,EAAE,eAAe;KACjC;IACD,0BAA0B,EAAE,EAAE;IAC9B,qBAAqB,EAAE,EAAE;CAC1B,CAAC;AAEF,eAAe,gBAAgB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\nimport { RecorderEnvironmentSetup } from \"@azure-tools/test-recorder\";\n\nconst environmentSetup: RecorderEnvironmentSetup = {\n replaceableVariables: {\n WPS_CONNECTION_STRING: \"Endpoint=endpoint;AccessKey=api_key;Version=1.0;\",\n WPS_API_KEY: \"api_key\",\n ENDPOINT: \"https://endpoint\",\n REVERSE_PROXY_ENDPOINT: \"https://rp-endpoint\",\n AZURE_CLIENT_ID: \"azure_client_id\",\n AZURE_CLIENT_SECRET: \"azure_client_secret\",\n AZURE_TENANT_ID: \"azuretenantid\",\n },\n customizationsOnRecordings: [],\n queryParametersToSkip: [],\n};\n\nexport default environmentSetup;\n"]}
|