UNPKG

@azure/web-pubsub

Version:
97 lines 3.95 kB
// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. import { RestError } from "@azure/core-rest-pipeline"; import { tracingClient } from "./tracing.js"; import { getPayloadForMessage } from "./utils.js"; /** * @hidden */ export class WebPubSubGroupImpl { /** * @internal */ constructor(client, hubName, groupName) { /** * The Web PubSub API version being used by this client */ this.apiVersion = "2020-10-01"; this.client = client; this.groupName = groupName; this.hubName = hubName; } /** * Add a specific connection to this group * * @param connectionId - The connection id to add to this group * @param options - Additional options */ async addConnection(connectionId, options = {}) { let response; function onResponse(rawResponse, flatResponse) { response = rawResponse; if (options.onResponse) { options.onResponse(rawResponse, flatResponse); } } return tracingClient.withSpan("WebPubSubGroupClient.addConnection", options, async (updatedOptions) => { await this.client.webPubSub.addConnectionToGroup(this.hubName, this.groupName, connectionId, Object.assign(Object.assign({}, updatedOptions), { onResponse })); if (response.status === 404) { throw new RestError(`Connection id '${connectionId}' doesn't exist`, { statusCode: response === null || response === void 0 ? void 0 : response.status, request: response === null || response === void 0 ? void 0 : response.request, response: response, }); } }); } /** * Remove a specific connection from this group * * @param connectionId - The connection id to remove from this group * @param options - Additional options */ async removeConnection(connectionId, options = {}) { return tracingClient.withSpan("WebPubSubGroupClient.removeConnection", options, (updatedOptions) => { return this.client.webPubSub.removeConnectionFromGroup(this.hubName, this.groupName, connectionId, updatedOptions); }); } /** * Close all connections to this group * * @param options - Additional options */ async closeAllConnections(options = {}) { return tracingClient.withSpan("WebPubSubGroupClient.closeAllConnections", options, (updatedOptions) => { return this.client.webPubSub.closeGroupConnections(this.hubName, this.groupName, updatedOptions); }); } /** * Add a user to this group * * @param username - The user name to add * @param options - Additional options */ async addUser(username, options = {}) { return tracingClient.withSpan("WebPubSubGroupClient.addUser", options, (updatedOptions) => { return this.client.webPubSub.addUserToGroup(this.hubName, this.groupName, username, updatedOptions); }); } /** * Remove a user from this group * * @param username - The user name to remove * @param options - Additional options */ async removeUser(username, options = {}) { return tracingClient.withSpan("WebPubSubGroupClient.removeUser", options, (updatedOptions) => { return this.client.webPubSub.removeUserFromGroup(this.hubName, this.groupName, username, updatedOptions); }); } async sendToAll(message, options = {}) { return tracingClient.withSpan("WebPubSubGroupClient.sendToAll", options, (updatedOptions) => { const { contentType, payload } = getPayloadForMessage(message, updatedOptions); return this.client.webPubSub.sendToGroup(this.hubName, this.groupName, contentType, payload, updatedOptions); }); } } //# sourceMappingURL=groupClient.js.map