@azure/web-pubsub 1.1.4-alpha.20241119.1 → 1.1.4-alpha.20241120.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (205) hide show
  1. package/dist/commonjs/generated/generatedClient.d.ts +19 -0
  2. package/dist/commonjs/generated/generatedClient.d.ts.map +1 -0
  3. package/dist/commonjs/generated/generatedClient.js +76 -0
  4. package/dist/commonjs/generated/generatedClient.js.map +1 -0
  5. package/dist/commonjs/generated/generatedClientContext.d.ts +14 -0
  6. package/dist/commonjs/generated/generatedClientContext.d.ts.map +1 -0
  7. package/dist/commonjs/generated/generatedClientContext.js +46 -0
  8. package/dist/commonjs/generated/generatedClientContext.js.map +1 -0
  9. package/dist/commonjs/generated/index.d.ts +4 -0
  10. package/dist/commonjs/generated/index.d.ts.map +1 -0
  11. package/dist/commonjs/generated/index.js +16 -0
  12. package/dist/commonjs/generated/index.js.map +1 -0
  13. package/dist/commonjs/generated/models/index.d.ts +323 -0
  14. package/dist/commonjs/generated/models/index.d.ts.map +1 -0
  15. package/dist/commonjs/generated/models/index.js +27 -0
  16. package/dist/commonjs/generated/models/index.js.map +1 -0
  17. package/dist/commonjs/generated/models/mappers.d.ts +30 -0
  18. package/dist/commonjs/generated/models/mappers.d.ts.map +1 -0
  19. package/dist/commonjs/generated/models/mappers.js +463 -0
  20. package/dist/commonjs/generated/models/mappers.js.map +1 -0
  21. package/dist/commonjs/generated/models/parameters.d.ts +31 -0
  22. package/dist/commonjs/generated/models/parameters.d.ts.map +1 -0
  23. package/dist/commonjs/generated/models/parameters.js +335 -0
  24. package/dist/commonjs/generated/models/parameters.js.map +1 -0
  25. package/dist/commonjs/generated/operations/healthApi.d.ts +18 -0
  26. package/dist/commonjs/generated/operations/healthApi.d.ts.map +1 -0
  27. package/dist/commonjs/generated/operations/healthApi.js +43 -0
  28. package/dist/commonjs/generated/operations/healthApi.js.map +1 -0
  29. package/dist/commonjs/generated/operations/index.d.ts +3 -0
  30. package/dist/commonjs/generated/operations/index.d.ts.map +1 -0
  31. package/dist/commonjs/generated/operations/index.js +13 -0
  32. package/dist/commonjs/generated/operations/index.js.map +1 -0
  33. package/dist/commonjs/generated/operations/webPubSub.d.ts +249 -0
  34. package/dist/commonjs/generated/operations/webPubSub.d.ts.map +1 -0
  35. package/dist/commonjs/generated/operations/webPubSub.js +874 -0
  36. package/dist/commonjs/generated/operations/webPubSub.js.map +1 -0
  37. package/dist/commonjs/generated/operationsInterfaces/healthApi.d.ts +10 -0
  38. package/dist/commonjs/generated/operationsInterfaces/healthApi.d.ts.map +1 -0
  39. package/dist/commonjs/generated/operationsInterfaces/healthApi.js +10 -0
  40. package/dist/commonjs/generated/operationsInterfaces/healthApi.js.map +1 -0
  41. package/dist/commonjs/generated/operationsInterfaces/index.d.ts +3 -0
  42. package/dist/commonjs/generated/operationsInterfaces/index.d.ts.map +1 -0
  43. package/dist/commonjs/generated/operationsInterfaces/index.js +13 -0
  44. package/dist/commonjs/generated/operationsInterfaces/index.js.map +1 -0
  45. package/dist/commonjs/generated/operationsInterfaces/webPubSub.d.ts +224 -0
  46. package/dist/commonjs/generated/operationsInterfaces/webPubSub.d.ts.map +1 -0
  47. package/dist/commonjs/generated/operationsInterfaces/webPubSub.js +10 -0
  48. package/dist/commonjs/generated/operationsInterfaces/webPubSub.js.map +1 -0
  49. package/dist/commonjs/groupClient.d.ts +232 -0
  50. package/dist/commonjs/groupClient.d.ts.map +1 -0
  51. package/dist/commonjs/groupClient.js +101 -0
  52. package/dist/commonjs/groupClient.js.map +1 -0
  53. package/dist/commonjs/hubClient.d.ts +478 -0
  54. package/dist/commonjs/hubClient.d.ts.map +1 -0
  55. package/dist/commonjs/hubClient.js +372 -0
  56. package/dist/commonjs/hubClient.js.map +1 -0
  57. package/dist/commonjs/index.d.ts +5 -0
  58. package/dist/commonjs/index.d.ts.map +1 -0
  59. package/dist/commonjs/index.js +12 -0
  60. package/dist/commonjs/index.js.map +1 -0
  61. package/dist/commonjs/logger.d.ts +5 -0
  62. package/dist/commonjs/logger.d.ts.map +1 -0
  63. package/dist/commonjs/logger.js +11 -0
  64. package/dist/commonjs/logger.js.map +1 -0
  65. package/dist/commonjs/package.json +3 -0
  66. package/dist/commonjs/parseConnectionString.d.ts +8 -0
  67. package/dist/commonjs/parseConnectionString.d.ts.map +1 -0
  68. package/dist/commonjs/parseConnectionString.js +34 -0
  69. package/dist/commonjs/parseConnectionString.js.map +1 -0
  70. package/dist/commonjs/reverseProxyPolicy.d.ts +9 -0
  71. package/dist/commonjs/reverseProxyPolicy.d.ts.map +1 -0
  72. package/dist/commonjs/reverseProxyPolicy.js +25 -0
  73. package/dist/commonjs/reverseProxyPolicy.js.map +1 -0
  74. package/dist/commonjs/tracing.d.ts +3 -0
  75. package/dist/commonjs/tracing.d.ts.map +1 -0
  76. package/dist/commonjs/tracing.js +12 -0
  77. package/dist/commonjs/tracing.js.map +1 -0
  78. package/dist/commonjs/tsdoc-metadata.json +11 -0
  79. package/dist/commonjs/utils.d.ts +29 -0
  80. package/dist/commonjs/utils.d.ts.map +1 -0
  81. package/dist/commonjs/utils.js +73 -0
  82. package/dist/commonjs/utils.js.map +1 -0
  83. package/dist/commonjs/webPubSubCredentialPolicy.d.ts +13 -0
  84. package/dist/commonjs/webPubSubCredentialPolicy.d.ts.map +1 -0
  85. package/dist/commonjs/webPubSubCredentialPolicy.js +32 -0
  86. package/dist/commonjs/webPubSubCredentialPolicy.js.map +1 -0
  87. package/dist/esm/generated/generatedClient.d.ts +19 -0
  88. package/dist/esm/generated/generatedClient.d.ts.map +1 -0
  89. package/{dist-esm/src → dist/esm}/generated/generatedClient.js +1 -1
  90. package/dist/esm/generated/generatedClient.js.map +1 -0
  91. package/dist/esm/generated/generatedClientContext.d.ts +14 -0
  92. package/dist/esm/generated/generatedClientContext.d.ts.map +1 -0
  93. package/dist/esm/generated/generatedClientContext.js.map +1 -0
  94. package/dist/esm/generated/index.d.ts +4 -0
  95. package/dist/esm/generated/index.d.ts.map +1 -0
  96. package/{dist-esm/src → dist/esm}/generated/index.js +3 -3
  97. package/dist/esm/generated/index.js.map +1 -0
  98. package/dist/esm/generated/models/index.d.ts +323 -0
  99. package/dist/esm/generated/models/index.d.ts.map +1 -0
  100. package/dist/esm/generated/models/mappers.d.ts +30 -0
  101. package/dist/esm/generated/models/mappers.d.ts.map +1 -0
  102. package/dist/esm/generated/models/parameters.d.ts +31 -0
  103. package/dist/esm/generated/models/parameters.d.ts.map +1 -0
  104. package/{dist-esm/src → dist/esm}/generated/models/parameters.js +1 -1
  105. package/dist/esm/generated/models/parameters.js.map +1 -0
  106. package/dist/esm/generated/operations/healthApi.d.ts +18 -0
  107. package/dist/esm/generated/operations/healthApi.d.ts.map +1 -0
  108. package/{dist-esm/src → dist/esm}/generated/operations/healthApi.js +2 -2
  109. package/dist/esm/generated/operations/healthApi.js.map +1 -0
  110. package/dist/esm/generated/operations/index.d.ts +3 -0
  111. package/dist/esm/generated/operations/index.d.ts.map +1 -0
  112. package/{dist-esm/src/generated/operationsInterfaces → dist/esm/generated/operations}/index.js +2 -2
  113. package/dist/esm/generated/operations/index.js.map +1 -0
  114. package/dist/esm/generated/operations/webPubSub.d.ts +249 -0
  115. package/dist/esm/generated/operations/webPubSub.d.ts.map +1 -0
  116. package/{dist-esm/src → dist/esm}/generated/operations/webPubSub.js +2 -2
  117. package/dist/esm/generated/operations/webPubSub.js.map +1 -0
  118. package/dist/esm/generated/operationsInterfaces/healthApi.d.ts +10 -0
  119. package/dist/esm/generated/operationsInterfaces/healthApi.d.ts.map +1 -0
  120. package/{dist-esm/src → dist/esm}/generated/operationsInterfaces/healthApi.js.map +1 -1
  121. package/dist/esm/generated/operationsInterfaces/index.d.ts +3 -0
  122. package/dist/esm/generated/operationsInterfaces/index.d.ts.map +1 -0
  123. package/{dist-esm/src/generated/operations → dist/esm/generated/operationsInterfaces}/index.js +2 -2
  124. package/dist/esm/generated/operationsInterfaces/index.js.map +1 -0
  125. package/dist/esm/generated/operationsInterfaces/webPubSub.d.ts +224 -0
  126. package/dist/esm/generated/operationsInterfaces/webPubSub.d.ts.map +1 -0
  127. package/dist/esm/generated/operationsInterfaces/webPubSub.js.map +1 -0
  128. package/dist/esm/groupClient.d.ts +232 -0
  129. package/dist/esm/groupClient.d.ts.map +1 -0
  130. package/{dist-esm/src → dist/esm}/groupClient.js +2 -2
  131. package/dist/esm/groupClient.js.map +1 -0
  132. package/dist/esm/hubClient.d.ts +478 -0
  133. package/dist/esm/hubClient.d.ts.map +1 -0
  134. package/{dist-esm/src → dist/esm}/hubClient.js +9 -9
  135. package/dist/esm/hubClient.js.map +1 -0
  136. package/dist/esm/index.d.ts +5 -0
  137. package/dist/esm/index.d.ts.map +1 -0
  138. package/{dist-esm/src → dist/esm}/index.js +2 -2
  139. package/dist/esm/index.js.map +1 -0
  140. package/dist/esm/logger.d.ts +5 -0
  141. package/dist/esm/logger.d.ts.map +1 -0
  142. package/dist/esm/package.json +3 -0
  143. package/dist/esm/parseConnectionString.d.ts +8 -0
  144. package/dist/esm/parseConnectionString.d.ts.map +1 -0
  145. package/dist/esm/reverseProxyPolicy.d.ts +9 -0
  146. package/dist/esm/reverseProxyPolicy.d.ts.map +1 -0
  147. package/dist/esm/tracing.d.ts +3 -0
  148. package/dist/esm/tracing.d.ts.map +1 -0
  149. package/dist/esm/utils.d.ts +29 -0
  150. package/dist/esm/utils.d.ts.map +1 -0
  151. package/dist/esm/webPubSubCredentialPolicy.d.ts +13 -0
  152. package/dist/esm/webPubSubCredentialPolicy.d.ts.map +1 -0
  153. package/package.json +56 -52
  154. package/dist/index.js +0 -2441
  155. package/dist/index.js.map +0 -1
  156. package/dist-esm/samples-dev/broadcasting.js +0 -27
  157. package/dist-esm/samples-dev/broadcasting.js.map +0 -1
  158. package/dist-esm/samples-dev/directMessage.js +0 -20
  159. package/dist-esm/samples-dev/directMessage.js.map +0 -1
  160. package/dist-esm/samples-dev/managingGroups.js +0 -23
  161. package/dist-esm/samples-dev/managingGroups.js.map +0 -1
  162. package/dist-esm/src/generated/generatedClient.js.map +0 -1
  163. package/dist-esm/src/generated/generatedClientContext.js.map +0 -1
  164. package/dist-esm/src/generated/index.js.map +0 -1
  165. package/dist-esm/src/generated/models/parameters.js.map +0 -1
  166. package/dist-esm/src/generated/operations/healthApi.js.map +0 -1
  167. package/dist-esm/src/generated/operations/index.js.map +0 -1
  168. package/dist-esm/src/generated/operations/webPubSub.js.map +0 -1
  169. package/dist-esm/src/generated/operationsInterfaces/index.js.map +0 -1
  170. package/dist-esm/src/generated/operationsInterfaces/webPubSub.js.map +0 -1
  171. package/dist-esm/src/groupClient.js.map +0 -1
  172. package/dist-esm/src/hubClient.js.map +0 -1
  173. package/dist-esm/src/index.js.map +0 -1
  174. package/dist-esm/test/conn.spec.js +0 -23
  175. package/dist-esm/test/conn.spec.js.map +0 -1
  176. package/dist-esm/test/groups.spec.js +0 -138
  177. package/dist-esm/test/groups.spec.js.map +0 -1
  178. package/dist-esm/test/hubs.spec.js +0 -270
  179. package/dist-esm/test/hubs.spec.js.map +0 -1
  180. package/dist-esm/test/integration.spec.js +0 -299
  181. package/dist-esm/test/integration.spec.js.map +0 -1
  182. package/dist-esm/test/odata.spec.js +0 -15
  183. package/dist-esm/test/odata.spec.js.map +0 -1
  184. package/dist-esm/test/testEnv.js +0 -23
  185. package/dist-esm/test/testEnv.js.map +0 -1
  186. /package/{dist-esm/src → dist/esm}/generated/generatedClientContext.js +0 -0
  187. /package/{dist-esm/src → dist/esm}/generated/models/index.js +0 -0
  188. /package/{dist-esm/src → dist/esm}/generated/models/index.js.map +0 -0
  189. /package/{dist-esm/src → dist/esm}/generated/models/mappers.js +0 -0
  190. /package/{dist-esm/src → dist/esm}/generated/models/mappers.js.map +0 -0
  191. /package/{dist-esm/src → dist/esm}/generated/operationsInterfaces/healthApi.js +0 -0
  192. /package/{dist-esm/src → dist/esm}/generated/operationsInterfaces/webPubSub.js +0 -0
  193. /package/{dist-esm/src → dist/esm}/logger.js +0 -0
  194. /package/{dist-esm/src → dist/esm}/logger.js.map +0 -0
  195. /package/{dist-esm/src → dist/esm}/parseConnectionString.js +0 -0
  196. /package/{dist-esm/src → dist/esm}/parseConnectionString.js.map +0 -0
  197. /package/{dist-esm/src → dist/esm}/reverseProxyPolicy.js +0 -0
  198. /package/{dist-esm/src → dist/esm}/reverseProxyPolicy.js.map +0 -0
  199. /package/{dist-esm/src → dist/esm}/tracing.js +0 -0
  200. /package/{dist-esm/src → dist/esm}/tracing.js.map +0 -0
  201. /package/{dist-esm/src → dist/esm}/utils.js +0 -0
  202. /package/{dist-esm/src → dist/esm}/utils.js.map +0 -0
  203. /package/{dist-esm/src → dist/esm}/webPubSubCredentialPolicy.js +0 -0
  204. /package/{dist-esm/src → dist/esm}/webPubSubCredentialPolicy.js.map +0 -0
  205. /package/{types → dist}/web-pubsub.d.ts +0 -0
@@ -1,270 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT License.
3
- /* eslint-disable no-invalid-this */
4
- import { Recorder, isLiveMode, assertEnvironmentVariable } from "@azure-tools/test-recorder";
5
- import { WebPubSubServiceClient, AzureKeyCredential } from "../src";
6
- import { assert } from "@azure-tools/test-utils";
7
- import recorderOptions from "./testEnv";
8
- import { createTestCredential } from "@azure-tools/test-credential";
9
- /* eslint-disable @typescript-eslint/no-invalid-this */
10
- describe("HubClient", function () {
11
- describe("Constructing a HubClient", () => {
12
- const credential = createTestCredential();
13
- it("takes a connection string, hub name, and options", () => {
14
- assert.doesNotThrow(() => {
15
- new WebPubSubServiceClient(assertEnvironmentVariable("WPS_CONNECTION_STRING"), "test-hub", {
16
- retryOptions: { maxRetries: 2 },
17
- });
18
- });
19
- });
20
- it("takes an endpoint, an API key, a hub name, and options", () => {
21
- assert.doesNotThrow(() => {
22
- new WebPubSubServiceClient(assertEnvironmentVariable("WPS_ENDPOINT"), new AzureKeyCredential(assertEnvironmentVariable("WPS_API_KEY")), "test-hub", {
23
- retryOptions: { maxRetries: 2 },
24
- });
25
- });
26
- });
27
- it("takes an endpoint, DefaultAzureCredential, a hub name, and options", () => {
28
- assert.doesNotThrow(() => {
29
- new WebPubSubServiceClient(assertEnvironmentVariable("WPS_ENDPOINT"), credential, "test-hub", {
30
- retryOptions: { maxRetries: 2 },
31
- });
32
- });
33
- });
34
- });
35
- describe("Working with a hub", function () {
36
- let recorder;
37
- let client;
38
- let lastResponse;
39
- const credential = createTestCredential();
40
- function onResponse(response) {
41
- lastResponse = response;
42
- }
43
- beforeEach(async function () {
44
- recorder = new Recorder(this.currentTest);
45
- await recorder.start(recorderOptions);
46
- client = new WebPubSubServiceClient(assertEnvironmentVariable("WPS_CONNECTION_STRING"), "simplechat", recorder.configureClientOptions({}));
47
- });
48
- afterEach(async function () {
49
- await recorder.stop();
50
- });
51
- it("can broadcast", async () => {
52
- await client.sendToAll("hello", { contentType: "text/plain", onResponse });
53
- assert.equal(lastResponse === null || lastResponse === void 0 ? void 0 : lastResponse.status, 202);
54
- await client.sendToAll({ x: 1, y: 2 }, { onResponse });
55
- assert.equal(lastResponse === null || lastResponse === void 0 ? void 0 : lastResponse.status, 202);
56
- const binaryMessage = new Uint8Array(10);
57
- await client.sendToAll(binaryMessage.buffer, { onResponse });
58
- assert.equal(lastResponse === null || lastResponse === void 0 ? void 0 : lastResponse.status, 202);
59
- });
60
- it("can broadcast with filter", async () => {
61
- await client.sendToAll("hello", {
62
- contentType: "text/plain",
63
- filter: "userId ne 'user1'",
64
- messageTtlSeconds: 60,
65
- onResponse,
66
- });
67
- assert.equal(lastResponse === null || lastResponse === void 0 ? void 0 : lastResponse.status, 202);
68
- let error;
69
- try {
70
- await client.sendToAll("hello", {
71
- contentType: "text/plain",
72
- filter: "invalid filter",
73
- });
74
- }
75
- catch (e) {
76
- if (e.name !== "RestError") {
77
- throw e;
78
- }
79
- error = e;
80
- }
81
- assert.equal(error.statusCode, 400);
82
- assert.equal(JSON.parse(error.message).message, "Invalid syntax for 'invalid filter': Syntax error at position 14 in 'invalid filter'. (Parameter 'filter')");
83
- });
84
- it("can broadcast using the DAC", async () => {
85
- const dacClient = new WebPubSubServiceClient(assertEnvironmentVariable("WPS_ENDPOINT"), credential, "simplechat", recorder.configureClientOptions({}));
86
- await dacClient.sendToAll("hello", { contentType: "text/plain", onResponse });
87
- assert.equal(lastResponse === null || lastResponse === void 0 ? void 0 : lastResponse.status, 202);
88
- await dacClient.sendToAll({ x: 1, y: 2 }, { onResponse });
89
- assert.equal(lastResponse === null || lastResponse === void 0 ? void 0 : lastResponse.status, 202);
90
- const binaryMessage = new Uint8Array(10);
91
- await dacClient.sendToAll(binaryMessage.buffer, { onResponse });
92
- assert.equal(lastResponse === null || lastResponse === void 0 ? void 0 : lastResponse.status, 202);
93
- });
94
- it("can broadcast using APIM", async () => {
95
- const apimClient = new WebPubSubServiceClient(assertEnvironmentVariable("WPS_CONNECTION_STRING"), "simplechat", recorder.configureClientOptions({
96
- reverseProxyEndpoint: assertEnvironmentVariable("WPS_REVERSE_PROXY_ENDPOINT"),
97
- }));
98
- await apimClient.sendToAll("hello", { contentType: "text/plain", onResponse });
99
- assert.equal(lastResponse === null || lastResponse === void 0 ? void 0 : lastResponse.status, 202);
100
- await apimClient.sendToAll({ x: 1, y: 2 }, { onResponse });
101
- assert.equal(lastResponse === null || lastResponse === void 0 ? void 0 : lastResponse.status, 202);
102
- const binaryMessage = new Uint8Array(10);
103
- await apimClient.sendToAll(binaryMessage.buffer, { onResponse });
104
- assert.equal(lastResponse === null || lastResponse === void 0 ? void 0 : lastResponse.status, 202);
105
- });
106
- it("can send messages to a user", async () => {
107
- await client.sendToUser("brian", "hello", {
108
- contentType: "text/plain",
109
- onResponse,
110
- });
111
- assert.equal(lastResponse === null || lastResponse === void 0 ? void 0 : lastResponse.status, 202);
112
- await client.sendToUser("brian", { x: 1, y: 2 }, { onResponse });
113
- assert.equal(lastResponse === null || lastResponse === void 0 ? void 0 : lastResponse.status, 202);
114
- const binaryMessage = new Uint8Array(10);
115
- await client.sendToUser("brian", binaryMessage.buffer, { onResponse });
116
- assert.equal(lastResponse === null || lastResponse === void 0 ? void 0 : lastResponse.status, 202);
117
- });
118
- it("can send to a user with filter", async () => {
119
- await client.sendToUser("vic", "hello", {
120
- contentType: "text/plain",
121
- filter: "userId ne 'user1'",
122
- onResponse,
123
- });
124
- assert.equal(lastResponse === null || lastResponse === void 0 ? void 0 : lastResponse.status, 202);
125
- let error;
126
- try {
127
- await client.sendToUser("brian", "hello", {
128
- contentType: "text/plain",
129
- filter: "invalid filter",
130
- });
131
- }
132
- catch (e) {
133
- if (e.name !== "RestError") {
134
- throw e;
135
- }
136
- error = e;
137
- }
138
- assert.equal(error.statusCode, 400);
139
- assert.equal(JSON.parse(error.message).message, "Invalid syntax for 'invalid filter': Syntax error at position 14 in 'invalid filter'. (Parameter 'filter')");
140
- });
141
- it("can send messages to a connection", async () => {
142
- await client.sendToConnection("xxxx", "hello", { contentType: "text/plain", onResponse });
143
- assert.equal(lastResponse === null || lastResponse === void 0 ? void 0 : lastResponse.status, 202);
144
- await client.sendToConnection("xxxx", { x: 1, y: 2 }, { onResponse });
145
- assert.equal(lastResponse === null || lastResponse === void 0 ? void 0 : lastResponse.status, 202);
146
- const binaryMessage = new Uint8Array(10);
147
- await client.sendToConnection("xxxx", binaryMessage.buffer, { onResponse });
148
- assert.equal(lastResponse === null || lastResponse === void 0 ? void 0 : lastResponse.status, 202);
149
- });
150
- it("can manage users", async () => {
151
- const res = await client.userExists("foo");
152
- assert.ok(!res);
153
- await client.removeUserFromAllGroups("brian", { onResponse });
154
- assert.equal(lastResponse === null || lastResponse === void 0 ? void 0 : lastResponse.status, 204);
155
- });
156
- it("can manage connections", async () => {
157
- await client.removeConnectionFromAllGroups("xxx", { onResponse });
158
- assert.equal(lastResponse === null || lastResponse === void 0 ? void 0 : lastResponse.status, 204);
159
- });
160
- it("can check if a connection exists", async function () {
161
- // likely bug in recorder for this test - recording not generating properly
162
- if (!isLiveMode())
163
- this.skip();
164
- const res = await client.connectionExists("xxx");
165
- assert.ok(!res);
166
- });
167
- it("can grant permissions to connections", async () => {
168
- let error;
169
- try {
170
- await client.grantPermission("xxx", "joinLeaveGroup", { targetName: "x" });
171
- }
172
- catch (e) {
173
- if (e.name !== "RestError") {
174
- throw e;
175
- }
176
- error = e;
177
- }
178
- // grantPermission validates connection ids, so we expect an error here.
179
- assert.equal(error.statusCode, 404);
180
- });
181
- it("can revoke permissions from connections", async function () {
182
- // likely bug in recorder for this test - recording not generating properly
183
- if (!isLiveMode())
184
- this.skip();
185
- await client.revokePermission("invalid-id", "joinLeaveGroup", { targetName: "x" });
186
- // Service doesn't throw error for invalid connection-ids
187
- });
188
- it("can trace through the various options", async function () {
189
- await assert.supportsTracing(async (options) => {
190
- const promises = [
191
- client.sendToAll("hello", Object.assign({ contentType: "text/plain", onResponse }, options)),
192
- client.sendToUser("brian", "hello", Object.assign({ contentType: "text/plain", onResponse }, options)),
193
- client.sendToConnection("xxxx", "hello", Object.assign({ contentType: "text/plain", onResponse }, options)),
194
- client.connectionExists("xxxx", options),
195
- client.closeConnection("xxxx", options),
196
- client.closeAllConnections(options),
197
- client.closeUserConnections("xxxx", options),
198
- client.removeUserFromAllGroups("foo", options),
199
- client.groupExists("foo", options),
200
- client.userExists("foo", options),
201
- client.grantPermission("xxxx", "joinLeaveGroup", Object.assign({ targetName: "x" }, options)),
202
- client.hasPermission("xxxx", "joinLeaveGroup", Object.assign({ targetName: "x" }, options)),
203
- client.revokePermission("xxxx", "joinLeaveGroup", options),
204
- client.getClientAccessToken(options),
205
- ];
206
- // We don't care about errors, only that we created (and closed) the appropriate spans.
207
- await Promise.all(promises.map((p) => p.catch(() => undefined)));
208
- }, [
209
- "WebPubSubServiceClient.sendToAll",
210
- "WebPubSubServiceClient.sendToUser",
211
- "WebPubSubServiceClient.sendToConnection",
212
- "WebPubSubServiceClient.connectionExists",
213
- "WebPubSubServiceClient.closeConnection",
214
- "WebPubSubServiceClient.closeAllConnections",
215
- "WebPubSubServiceClient.closeUserConnections",
216
- "WebPubSubServiceClient.removeUserFromAllGroups",
217
- "WebPubSubServiceClient.groupExists",
218
- "WebPubSubServiceClient.userExists",
219
- "WebPubSubServiceClient.grantPermission",
220
- "WebPubSubServiceClient.hasPermission",
221
- "WebPubSubServiceClient.revokePermission",
222
- "WebPubSubServiceClient.getClientAccessToken",
223
- ]);
224
- });
225
- it("can generate client tokens", async () => {
226
- const res = await client.getClientAccessToken({
227
- userId: "brian",
228
- groups: ["group1"],
229
- });
230
- const url = new URL(res.url);
231
- assert.ok(url.searchParams.has("access_token"));
232
- assert.equal(url.host, new URL(client.endpoint).host);
233
- assert.equal(url.pathname, `/client/hubs/${client.hubName}`);
234
- });
235
- it("can generate default client tokens", async () => {
236
- const res = await client.getClientAccessToken({
237
- userId: "brian",
238
- groups: ["group1"],
239
- clientProtocol: "default",
240
- });
241
- const url = new URL(res.url);
242
- assert.ok(url.searchParams.has("access_token"));
243
- assert.equal(url.host, new URL(client.endpoint).host);
244
- assert.equal(url.pathname, `/client/hubs/${client.hubName}`);
245
- });
246
- it("can generate client MQTT tokens", async () => {
247
- const res = await client.getClientAccessToken({
248
- userId: "brian",
249
- groups: ["group1"],
250
- clientProtocol: "mqtt",
251
- });
252
- const url = new URL(res.url);
253
- assert.ok(url.searchParams.has("access_token"));
254
- assert.equal(url.host, new URL(client.endpoint).host);
255
- assert.equal(url.pathname, `/clients/mqtt/hubs/${client.hubName}`);
256
- });
257
- it("can generate socketIO client tokens", async () => {
258
- const res = await client.getClientAccessToken({
259
- userId: "brian",
260
- groups: ["group1"],
261
- clientProtocol: "socketio",
262
- });
263
- const url = new URL(res.url);
264
- assert.ok(url.searchParams.has("access_token"));
265
- assert.equal(url.host, new URL(client.endpoint).host);
266
- assert.equal(url.pathname, `/clients/socketio/hubs/${client.hubName}`);
267
- });
268
- });
269
- });
270
- //# sourceMappingURL=hubs.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hubs.spec.js","sourceRoot":"","sources":["../../test/hubs.spec.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,oC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C,GAAG,CAAC,QAAQ,EAAE,0BAA0B,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;QACzE,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 { Recorder, isLiveMode, assertEnvironmentVariable } from \"@azure-tools/test-recorder\";\nimport { WebPubSubServiceClient, AzureKeyCredential } from \"../src\";\nimport { assert } from \"@azure-tools/test-utils\";\nimport recorderOptions from \"./testEnv\";\nimport type { FullOperationResponse } from \"@azure/core-client\";\nimport { createTestCredential } from \"@azure-tools/test-credential\";\n/* eslint-disable @typescript-eslint/no-invalid-this */\n\ndescribe(\"HubClient\", function () {\n describe(\"Constructing a HubClient\", () => {\n const credential = createTestCredential();\n it(\"takes a connection string, hub name, and options\", () => {\n assert.doesNotThrow(() => {\n new WebPubSubServiceClient(assertEnvironmentVariable(\"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 assertEnvironmentVariable(\"WPS_ENDPOINT\"),\n new AzureKeyCredential(assertEnvironmentVariable(\"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(\n assertEnvironmentVariable(\"WPS_ENDPOINT\"),\n credential,\n \"test-hub\",\n {\n retryOptions: { maxRetries: 2 },\n },\n );\n });\n });\n });\n\n describe(\"Working with a hub\", function () {\n let recorder: Recorder;\n let client: WebPubSubServiceClient;\n let lastResponse: FullOperationResponse | undefined;\n const credential = createTestCredential();\n function onResponse(response: FullOperationResponse): void {\n lastResponse = response;\n }\n beforeEach(async function () {\n recorder = new Recorder(this.currentTest);\n await recorder.start(recorderOptions);\n\n client = new WebPubSubServiceClient(\n assertEnvironmentVariable(\"WPS_CONNECTION_STRING\"),\n \"simplechat\",\n recorder.configureClientOptions({}),\n );\n });\n\n afterEach(async function () {\n await recorder.stop();\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 with filter\", async () => {\n await client.sendToAll(\"hello\", {\n contentType: \"text/plain\",\n filter: \"userId ne 'user1'\",\n messageTtlSeconds: 60,\n onResponse,\n });\n assert.equal(lastResponse?.status, 202);\n\n let error;\n try {\n await client.sendToAll(\"hello\", {\n contentType: \"text/plain\",\n filter: \"invalid filter\",\n });\n } catch (e: any) {\n if (e.name !== \"RestError\") {\n throw e;\n }\n\n error = e;\n }\n assert.equal(error.statusCode, 400);\n assert.equal(\n JSON.parse(error.message).message,\n \"Invalid syntax for 'invalid filter': Syntax error at position 14 in 'invalid filter'. (Parameter 'filter')\",\n );\n });\n\n it(\"can broadcast using the DAC\", async () => {\n const dacClient = new WebPubSubServiceClient(\n assertEnvironmentVariable(\"WPS_ENDPOINT\"),\n credential,\n \"simplechat\",\n recorder.configureClientOptions({}),\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(\n assertEnvironmentVariable(\"WPS_CONNECTION_STRING\"),\n \"simplechat\",\n recorder.configureClientOptions({\n reverseProxyEndpoint: assertEnvironmentVariable(\"WPS_REVERSE_PROXY_ENDPOINT\"),\n }),\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 to a user with filter\", async () => {\n await client.sendToUser(\"vic\", \"hello\", {\n contentType: \"text/plain\",\n filter: \"userId ne 'user1'\",\n onResponse,\n });\n assert.equal(lastResponse?.status, 202);\n\n let error;\n try {\n await client.sendToUser(\"brian\", \"hello\", {\n contentType: \"text/plain\",\n filter: \"invalid filter\",\n });\n } catch (e: any) {\n if (e.name !== \"RestError\") {\n throw e;\n }\n\n error = e;\n }\n assert.equal(error.statusCode, 400);\n assert.equal(\n JSON.parse(error.message).message,\n \"Invalid syntax for 'invalid filter': Syntax error at position 14 in 'invalid filter'. (Parameter 'filter')\",\n );\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 it(\"can manage users\", async () => {\n const res = await client.userExists(\"foo\");\n assert.ok(!res);\n await client.removeUserFromAllGroups(\"brian\", { onResponse });\n assert.equal(lastResponse?.status, 204);\n });\n\n it(\"can manage connections\", async () => {\n await client.removeConnectionFromAllGroups(\"xxx\", { onResponse });\n assert.equal(lastResponse?.status, 204);\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: any) {\n if (e.name !== \"RestError\") {\n throw e;\n }\n\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 await client.revokePermission(\"invalid-id\", \"joinLeaveGroup\", { targetName: \"x\" });\n // Service doesn't throw error for invalid connection-ids\n });\n\n it(\"can trace through the various options\", async function () {\n await assert.supportsTracing(\n async (options) => {\n const promises: Promise<any>[] = [\n client.sendToAll(\"hello\", { contentType: \"text/plain\", onResponse, ...options }),\n client.sendToUser(\"brian\", \"hello\", {\n contentType: \"text/plain\",\n onResponse,\n ...options,\n }),\n client.sendToConnection(\"xxxx\", \"hello\", {\n contentType: \"text/plain\",\n onResponse,\n ...options,\n }),\n client.connectionExists(\"xxxx\", options),\n client.closeConnection(\"xxxx\", options),\n client.closeAllConnections(options),\n client.closeUserConnections(\"xxxx\", options),\n client.removeUserFromAllGroups(\"foo\", options),\n client.groupExists(\"foo\", options),\n client.userExists(\"foo\", options),\n client.grantPermission(\"xxxx\", \"joinLeaveGroup\", { targetName: \"x\", ...options }),\n client.hasPermission(\"xxxx\", \"joinLeaveGroup\", { targetName: \"x\", ...options }),\n client.revokePermission(\"xxxx\", \"joinLeaveGroup\", options),\n client.getClientAccessToken(options),\n ];\n // We don't care about errors, only that we created (and closed) the appropriate spans.\n await Promise.all(promises.map((p) => p.catch(() => undefined)));\n },\n [\n \"WebPubSubServiceClient.sendToAll\",\n \"WebPubSubServiceClient.sendToUser\",\n \"WebPubSubServiceClient.sendToConnection\",\n \"WebPubSubServiceClient.connectionExists\",\n \"WebPubSubServiceClient.closeConnection\",\n \"WebPubSubServiceClient.closeAllConnections\",\n \"WebPubSubServiceClient.closeUserConnections\",\n \"WebPubSubServiceClient.removeUserFromAllGroups\",\n \"WebPubSubServiceClient.groupExists\",\n \"WebPubSubServiceClient.userExists\",\n \"WebPubSubServiceClient.grantPermission\",\n \"WebPubSubServiceClient.hasPermission\",\n \"WebPubSubServiceClient.revokePermission\",\n \"WebPubSubServiceClient.getClientAccessToken\",\n ],\n );\n });\n\n it(\"can generate client tokens\", async () => {\n const res = await client.getClientAccessToken({\n userId: \"brian\",\n groups: [\"group1\"],\n });\n const url = new URL(res.url);\n assert.ok(url.searchParams.has(\"access_token\"));\n assert.equal(url.host, new URL(client.endpoint).host);\n assert.equal(url.pathname, `/client/hubs/${client.hubName}`);\n });\n\n it(\"can generate default client tokens\", async () => {\n const res = await client.getClientAccessToken({\n userId: \"brian\",\n groups: [\"group1\"],\n clientProtocol: \"default\",\n });\n const url = new URL(res.url);\n assert.ok(url.searchParams.has(\"access_token\"));\n assert.equal(url.host, new URL(client.endpoint).host);\n assert.equal(url.pathname, `/client/hubs/${client.hubName}`);\n });\n\n it(\"can generate client MQTT tokens\", async () => {\n const res = await client.getClientAccessToken({\n userId: \"brian\",\n groups: [\"group1\"],\n clientProtocol: \"mqtt\",\n });\n const url = new URL(res.url);\n assert.ok(url.searchParams.has(\"access_token\"));\n assert.equal(url.host, new URL(client.endpoint).host);\n assert.equal(url.pathname, `/clients/mqtt/hubs/${client.hubName}`);\n });\n\n it(\"can generate socketIO client tokens\", async () => {\n const res = await client.getClientAccessToken({\n userId: \"brian\",\n groups: [\"group1\"],\n clientProtocol: \"socketio\",\n });\n const url = new URL(res.url);\n assert.ok(url.searchParams.has(\"access_token\"));\n assert.equal(url.host, new URL(client.endpoint).host);\n assert.equal(url.pathname, `/clients/socketio/hubs/${client.hubName}`);\n });\n });\n});\n"]}
@@ -1,299 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT License.
3
- /* eslint-disable no-invalid-this */
4
- import { WebPubSubServiceClient, odata } from "../src/index";
5
- import { isLiveMode, assertEnvironmentVariable } 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(id = undefined) {
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
- (id === undefined || this.data[3] === id));
36
- }
37
- toString() {
38
- if (this.isEndSignal()) {
39
- return "|EndSignal|";
40
- }
41
- if (!this.isBinary) {
42
- return this.dataAsString;
43
- }
44
- else {
45
- return this.data.toString();
46
- }
47
- }
48
- }
49
- class PubSubWebSocketFrame {
50
- constructor(data, isBinary) {
51
- assert.isFalse(isBinary);
52
- this.dataAsString = data.toString();
53
- this.message = JSON.parse(this.dataAsString);
54
- }
55
- isEndSignal() {
56
- return this.message.dataType === "binary" && this.message.data === "BQEB";
57
- }
58
- toString() {
59
- if (this.isEndSignal()) {
60
- return "|EndSignal|";
61
- }
62
- return this.dataAsString;
63
- }
64
- }
65
- function getEndSignal(id = undefined) {
66
- // magic number 511
67
- const payload = new Uint8Array(id === undefined ? 3 : 4);
68
- payload[0] = 5;
69
- payload[1] = 1;
70
- payload[2] = 1;
71
- if (id !== undefined) {
72
- payload[3] = id;
73
- }
74
- return payload;
75
- }
76
- describe("ServiceClient to manage the connected WebSocket connections", function () {
77
- it("Simple clients can receive expected messages with different content types", async function () {
78
- if (!isLiveMode())
79
- this.skip();
80
- const hub = "SimpleClientCanReceiveMessage";
81
- const messages = [];
82
- // Get token
83
- const serviceClient = new WebPubSubServiceClient(assertEnvironmentVariable("WPS_CONNECTION_STRING"), hub);
84
- const token = await serviceClient.getClientAccessToken();
85
- const endSignal = defer();
86
- // Start simple WebSocket connections
87
- const client = new ws.WebSocket(token.url);
88
- client.on("message", (data, isBinary) => {
89
- const frame = new SimpleWebSocketFrame(data, isBinary);
90
- console.log(frame.toString());
91
- if (frame.isEndSignal()) {
92
- endSignal.resolve();
93
- client.close();
94
- }
95
- else {
96
- messages.push(frame);
97
- }
98
- });
99
- client.on("open", async () => {
100
- // send to all
101
- // Send a JSON message
102
- await serviceClient.sendToAll({ message: "Hello world!" });
103
- // Send a plain text message
104
- await serviceClient.sendToAll("Hi there!", { contentType: "text/plain" });
105
- // Send the binary end signal message
106
- await serviceClient.sendToAll(getEndSignal());
107
- });
108
- await endSignal.promise;
109
- assert.equal(messages.length, 2);
110
- assert.equal(messages[0].dataAsString, '{"message":"Hello world!"}');
111
- assert.equal(messages[1].dataAsString, "Hi there!");
112
- });
113
- it("Simple clients can can join group and receive group messages", async function () {
114
- if (!isLiveMode())
115
- this.skip();
116
- const hub = "SimpleClientCanReceiveGroupMessage";
117
- const messages = [];
118
- // Get token
119
- const serviceClient = new WebPubSubServiceClient(assertEnvironmentVariable("WPS_CONNECTION_STRING"), hub);
120
- const token = await serviceClient.getClientAccessToken({
121
- groups: ["group1", "group2"],
122
- });
123
- const end1Signal = defer();
124
- const end2Signal = defer();
125
- // Start simple WebSocket connections
126
- const client = new ws.WebSocket(token.url);
127
- client.on("message", (data, isBinary) => {
128
- const frame = new SimpleWebSocketFrame(data, isBinary);
129
- console.log(frame.toString());
130
- if (frame.isEndSignal(1)) {
131
- end1Signal.resolve();
132
- }
133
- else if (frame.isEndSignal(2)) {
134
- end2Signal.resolve();
135
- }
136
- else {
137
- messages.push(frame);
138
- }
139
- });
140
- client.on("open", async () => {
141
- const group1Client = serviceClient.group("group1");
142
- const group2Client = serviceClient.group("group2");
143
- // send to all
144
- // Send a JSON message
145
- await group1Client.sendToAll({ message: "Hello world from group1!" });
146
- await group2Client.sendToAll(getEndSignal(1));
147
- // Send a plain text message
148
- await group2Client.sendToAll("Hi there from group2!", { contentType: "text/plain" });
149
- // Send the binary end signal message
150
- await group2Client.sendToAll(getEndSignal(2));
151
- });
152
- await end1Signal.promise;
153
- await end2Signal.promise;
154
- client.close();
155
- assert.equal(messages.length, 2);
156
- // order from different groups is not guaranteed
157
- assert.isTrue(messages.findIndex((s) => s.dataAsString === '{"message":"Hello world from group1!"}') > -1);
158
- assert.isTrue(messages.findIndex((s) => s.dataAsString === "Hi there from group2!") > -1);
159
- });
160
- it("Subprotocol clients can receive expected messages with different content types", async function () {
161
- if (!isLiveMode())
162
- this.skip();
163
- const hub = "PubSubClientCanReceiveMessage";
164
- const messages = [];
165
- // Get token
166
- const serviceClient = new WebPubSubServiceClient(assertEnvironmentVariable("WPS_CONNECTION_STRING"), hub);
167
- const token = await serviceClient.getClientAccessToken();
168
- const endSignal = defer();
169
- const connectedSignal = defer();
170
- // Start simple WebSocket connections
171
- const client = new ws.WebSocket(token.url, "json.webpubsub.azure.v1");
172
- client.on("message", (data, isBinary) => {
173
- const frame = new PubSubWebSocketFrame(data, isBinary);
174
- console.log(frame.toString());
175
- if (frame.message.event === "connected") {
176
- connectedSignal.resolve();
177
- }
178
- if (frame.isEndSignal()) {
179
- endSignal.resolve();
180
- client.close();
181
- }
182
- else {
183
- messages.push(frame);
184
- }
185
- });
186
- client.on("open", async () => {
187
- await connectedSignal.promise;
188
- // send to all
189
- // Send a JSON message
190
- await serviceClient.sendToAll({ message: "Hello world!" });
191
- // Send a plain text message
192
- await serviceClient.sendToAll("Hi there!", { contentType: "text/plain" });
193
- // Send the binary end signal message
194
- await serviceClient.sendToAll(getEndSignal());
195
- });
196
- await endSignal.promise;
197
- assert.equal(messages.length, 3);
198
- assert.equal(messages[0].message.event, "connected");
199
- assert.equal(messages[1].dataAsString, '{"type":"message","from":"server","dataType":"json","data":{"message":"Hello world!"}}');
200
- assert.equal(messages[2].dataAsString, '{"type":"message","from":"server","dataType":"text","data":"Hi there!"}');
201
- });
202
- it("Clients can receive messages with filters", async function () {
203
- if (!isLiveMode())
204
- this.skip();
205
- const hub = "ClientCanReceiveMessageWithFilters";
206
- const messages = [];
207
- // Get token
208
- const serviceClient = new WebPubSubServiceClient(assertEnvironmentVariable("WPS_CONNECTION_STRING"), hub);
209
- const token = await serviceClient.getClientAccessToken({ groups: ["groupA"] });
210
- const endSignal = defer();
211
- // Start simple WebSocket connections
212
- const client = new ws.WebSocket(token.url);
213
- client.on("message", (data, isBinary) => {
214
- const frame = new SimpleWebSocketFrame(data, isBinary);
215
- console.log(frame.toString());
216
- if (frame.isEndSignal()) {
217
- endSignal.resolve();
218
- client.close();
219
- }
220
- else {
221
- messages.push(frame);
222
- }
223
- });
224
- client.on("open", async () => {
225
- // Send a JSON message to anonymous connections
226
- await serviceClient.sendToAll({ message: "Hello world!" }, { filter: "userId eq null", messageTtlSeconds: 60 });
227
- // Send a text message to connections in groupA but not in groupB
228
- const groupA = "groupA";
229
- const groupB = "groupB";
230
- await serviceClient.sendToAll("Hello world!", {
231
- contentType: "text/plain",
232
- // use plain text "'groupA' in groups and not('groupB' in groups)"
233
- // or use the odata helper method
234
- filter: odata `${groupA} in groups and not(${groupB} in groups)`,
235
- messageTtlSeconds: 60,
236
- });
237
- // Send the binary end signal message
238
- await serviceClient.sendToAll(getEndSignal());
239
- });
240
- await endSignal.promise;
241
- assert.equal(messages.length, 2);
242
- assert.equal(messages[0].dataAsString, '{"message":"Hello world!"}');
243
- assert.equal(messages[1].dataAsString, "Hello world!");
244
- });
245
- it("Clients can join or leave multiple groups with filter", async function () {
246
- if (!isLiveMode())
247
- this.skip();
248
- const hub = "ClientsCanJoinOrLeaveMultipleGroupsWithFilter";
249
- const messages = [];
250
- // Get token
251
- const serviceClient = new WebPubSubServiceClient(assertEnvironmentVariable("WPS_CONNECTION_STRING"), hub);
252
- const token = await serviceClient.getClientAccessToken({ userId: "user 1" });
253
- const startSignal = defer();
254
- const endSignal = defer();
255
- // Start simple WebSocket connections
256
- const client1 = new ws.WebSocket(token.url);
257
- const client2 = new ws.WebSocket(token.url);
258
- let opened = 0;
259
- const onOpen = () => {
260
- opened++;
261
- if (opened === 2) {
262
- startSignal.resolve();
263
- }
264
- };
265
- const onMessage = (data, isBinary) => {
266
- const frame = new SimpleWebSocketFrame(data, isBinary);
267
- console.log(frame.toString());
268
- messages.push(frame);
269
- if (messages.length === 6) {
270
- endSignal.resolve();
271
- }
272
- };
273
- client1.on("open", onOpen);
274
- client2.on("open", onOpen);
275
- client1.on("message", onMessage);
276
- client2.on("message", onMessage);
277
- // Wait all clients opened
278
- await startSignal.promise;
279
- // Add filtered connections to group1 and group2
280
- await serviceClient.addConnectionsToGroups(["group1", "group2"], "userId eq 'user 1'");
281
- // send to connections in both group1 and group2
282
- await serviceClient.sendToAll({ message: "Hi json!" }, { filter: "'group1' in groups and 'group2' in groups" });
283
- // Send a plain text message
284
- await serviceClient.sendToAll("Hi text!", {
285
- contentType: "text/plain",
286
- filter: "'group1' in groups and 'group2' in groups",
287
- });
288
- // Send the binary end signal message
289
- await serviceClient.sendToAll(getEndSignal(2), {
290
- filter: "'group1' in groups and 'group2' in groups",
291
- });
292
- // Timeout 1000 ms
293
- await Promise.race([new Promise((resolve) => setTimeout(resolve, 1000)), endSignal.promise]);
294
- assert.equal(messages.length, 6);
295
- client1.close();
296
- client2.close();
297
- });
298
- });
299
- //# sourceMappingURL=integration.spec.js.map