diff --git a/sdk/core/core-amqp/CHANGELOG.md b/sdk/core/core-amqp/CHANGELOG.md index 126f91585c16..c6371d85c701 100644 --- a/sdk/core/core-amqp/CHANGELOG.md +++ b/sdk/core/core-amqp/CHANGELOG.md @@ -2,6 +2,7 @@ ## 1.0.2 (Unreleased) +- Exports `WebSocketOptions` interface to configure the channelling of the AMQP connection over Web Sockets. [PR 7368](https://github.com/Azure/azure-sdk-for-js/pull/7368) ## 1.0.1 (2020-02-06) @@ -24,8 +25,6 @@ - Treat ETIMEOUT error from dns.resolve as network disconnected. -- Treat ETIMEOUT error from dns.resolve as network disconnected. - ## 1.0.0-preview.5 (2019-10-29) - Updated to use the latest version of the `@azure/abort-controller` and `@azure/core-auth` packages. diff --git a/sdk/core/core-amqp/src/index.ts b/sdk/core/core-amqp/src/index.ts index a6e4d7b79f57..ee78ed76678d 100644 --- a/sdk/core/core-amqp/src/index.ts +++ b/sdk/core/core-amqp/src/index.ts @@ -59,6 +59,7 @@ export { isIotHubConnectionString, randomNumberFromInterval, AsyncLock, - isNode + isNode, + WebSocketOptions } from "./util/utils"; export { logger } from "./log"; diff --git a/sdk/core/core-amqp/src/util/utils.ts b/sdk/core/core-amqp/src/util/utils.ts index 4fbddf39655b..44a7ee734f6c 100644 --- a/sdk/core/core-amqp/src/util/utils.ts +++ b/sdk/core/core-amqp/src/util/utils.ts @@ -3,6 +3,7 @@ import AsyncLock from "async-lock"; import { AbortSignalLike, AbortError } from "@azure/abort-controller"; +import { WebSocketImpl } from "rhea-promise"; export { AsyncLock }; /** @@ -28,6 +29,29 @@ export interface AsyncLockOptions { */ Promise?: any; } + +/** + * Options to configure the channelling of the AMQP connection over Web Sockets. + */ +export interface WebSocketOptions { + /** + * @property + * The WebSocket constructor used to create an AMQP connection over a WebSocket. + * This option should be provided in the below scenarios: + * - The TCP port 5671 which is that is used by the AMQP connection to Event Hubs is blocked in your environment. + * - Your application needs to be run behind a proxy server. + * - Your application needs to run in the browser and you want to provide your own choice of Websocket implementation + * instead of the built-in WebSocket in the browser. + */ + webSocket?: WebSocketImpl; + /** + * @property + * Options to be passed to the WebSocket constructor when the underlying `rhea` library instantiates + * the WebSocket. + */ + webSocketConstructorOptions?: any; +} + /** * A constant that indicates whether the environment is node.js or browser based. */ diff --git a/sdk/eventhub/event-hubs/package.json b/sdk/eventhub/event-hubs/package.json index 03c3fc5cf86f..1d1fe9f2c972 100644 --- a/sdk/eventhub/event-hubs/package.json +++ b/sdk/eventhub/event-hubs/package.json @@ -71,7 +71,7 @@ }, "dependencies": { "@azure/abort-controller": "^1.0.0", - "@azure/core-amqp": "^1.0.1", + "@azure/core-amqp": "^1.0.2", "@azure/core-asynciterator-polyfill": "^1.0.0", "@azure/core-tracing": "1.0.0-preview.7", "@azure/identity": "^1.0.0", diff --git a/sdk/eventhub/event-hubs/review/event-hubs.api.md b/sdk/eventhub/event-hubs/review/event-hubs.api.md index d068c9af9015..a510e6c158ea 100644 --- a/sdk/eventhub/event-hubs/review/event-hubs.api.md +++ b/sdk/eventhub/event-hubs/review/event-hubs.api.md @@ -12,6 +12,7 @@ import { SpanContext } from '@opentelemetry/types'; import { SpanOptions } from '@opentelemetry/types'; import { TokenCredential } from '@azure/core-amqp'; import { WebSocketImpl } from 'rhea-promise'; +import { WebSocketOptions } from '@azure/core-amqp'; // @public export interface Checkpoint { @@ -266,11 +267,7 @@ export interface TryAddOptions { export { WebSocketImpl } -// @public -export interface WebSocketOptions { - webSocket?: WebSocketImpl; - webSocketConstructorOptions?: any; -} +export { WebSocketOptions } // (No @packageDocumentation comment for this package) diff --git a/sdk/eventhub/event-hubs/src/index.ts b/sdk/eventhub/event-hubs/src/index.ts index 2b31685ddf15..45b809adee24 100644 --- a/sdk/eventhub/event-hubs/src/index.ts +++ b/sdk/eventhub/event-hubs/src/index.ts @@ -13,8 +13,7 @@ export { CreateBatchOptions, GetPartitionIdsOptions, GetPartitionPropertiesOptions, - GetEventHubPropertiesOptions, - WebSocketOptions + GetEventHubPropertiesOptions } from "./models/public"; export { EventHubConsumerClient } from "./eventHubConsumerClient"; export { EventHubProducerClient } from "./eventHubProducerClient"; @@ -34,5 +33,5 @@ export { EventDataBatch, TryAddOptions } from "./eventDataBatch"; export { Checkpoint } from "./partitionProcessor"; export { CheckpointStore, PartitionOwnership } from "./eventProcessor"; export { CloseReason } from "./models/public"; -export { MessagingError, RetryOptions, TokenCredential } from "@azure/core-amqp"; +export { MessagingError, RetryOptions, TokenCredential, WebSocketOptions } from "@azure/core-amqp"; export { logger } from "./log"; diff --git a/sdk/eventhub/event-hubs/src/models/public.ts b/sdk/eventhub/event-hubs/src/models/public.ts index e5b5d37c0b09..a68f8e2a2513 100644 --- a/sdk/eventhub/event-hubs/src/models/public.ts +++ b/sdk/eventhub/event-hubs/src/models/public.ts @@ -2,8 +2,7 @@ // Licensed under the MIT License. import { OperationOptions } from "../util/operationOptions"; -import { RetryOptions } from "@azure/core-amqp"; -import { WebSocketImpl } from "rhea-promise"; +import { RetryOptions, WebSocketOptions } from "@azure/core-amqp"; /** * The set of options to configure the behavior of `getEventHubProperties`. @@ -114,28 +113,6 @@ export interface EventHubClientOptions { userAgent?: string; } -/** - * Options to configure the channelling of the AMQP connection over Web Sockets. - */ -export interface WebSocketOptions { - /** - * @property - * The WebSocket constructor used to create an AMQP connection over a WebSocket. - * This option should be provided in the below scenarios: - * - The TCP port 5671 which is that is used by the AMQP connection to Event Hubs is blocked in your environment. - * - Your application needs to be run behind a proxy server - * - Your application needs to run in the browser and you want to provide your own choice of Websocket implementation - * instead of the built-in WebSocket in the browser. - */ - webSocket?: WebSocketImpl; - /** - * @property - * Options to be passed to the WebSocket constructor when the underlying `rhea` library instantiates - * the WebSocket. - */ - webSocketConstructorOptions?: any; -} - /** * Options to configure the `createBatch` method on the `EventHubProducerClient`. * - `partitionKey` : A value that is hashed to produce a partition assignment. diff --git a/sdk/servicebus/service-bus/package.json b/sdk/servicebus/service-bus/package.json index fa2e339f193e..18252031531d 100644 --- a/sdk/servicebus/service-bus/package.json +++ b/sdk/servicebus/service-bus/package.json @@ -77,7 +77,7 @@ ] }, "dependencies": { - "@azure/core-amqp": "^1.0.1", + "@azure/core-amqp": "^1.0.2", "@azure/core-http": "^1.0.0", "@opentelemetry/types": "^0.2.0", "@types/is-buffer": "^2.0.0", diff --git a/sdk/servicebus/service-bus/review/service-bus.api.md b/sdk/servicebus/service-bus/review/service-bus.api.md index b8ced41b2b83..93e553e451ec 100644 --- a/sdk/servicebus/service-bus/review/service-bus.api.md +++ b/sdk/servicebus/service-bus/review/service-bus.api.md @@ -16,6 +16,7 @@ import { RetryOptions } from '@azure/core-amqp'; import { TokenCredential } from '@azure/core-amqp'; import { TokenType } from '@azure/core-amqp'; import { WebSocketImpl } from 'rhea-promise'; +import { WebSocketOptions } from '@azure/core-amqp'; // @public export type AuthorizationRule = { @@ -259,8 +260,7 @@ export class ServiceBusClient { // @public export interface ServiceBusClientOptions { dataTransformer?: DataTransformer; - webSocket?: WebSocketImpl; - webSocketConstructorOptions?: any; + webSocketOptions?: WebSocketOptions; } // Warning: (ae-forgotten-export) The symbol "ReceivedMessage" needs to be exported by the entry point index.d.ts @@ -476,6 +476,8 @@ export interface TopicOptions { export { WebSocketImpl } +export { WebSocketOptions } + // (No @packageDocumentation comment for this package) diff --git a/sdk/servicebus/service-bus/src/index.ts b/sdk/servicebus/service-bus/src/index.ts index 623de70f31e4..3bd22ba3a8b8 100644 --- a/sdk/servicebus/service-bus/src/index.ts +++ b/sdk/servicebus/service-bus/src/index.ts @@ -12,7 +12,8 @@ export { DataTransformer, delay, MessagingError, - RetryOptions + RetryOptions, + WebSocketOptions } from "@azure/core-amqp"; export { QueueClient } from "./queueClient"; diff --git a/sdk/servicebus/service-bus/src/serviceBusClient.ts b/sdk/servicebus/service-bus/src/serviceBusClient.ts index cb43d24ea26d..9b32c0e46562 100644 --- a/sdk/servicebus/service-bus/src/serviceBusClient.ts +++ b/sdk/servicebus/service-bus/src/serviceBusClient.ts @@ -2,8 +2,6 @@ // Licensed under the MIT License. import * as log from "./log"; - -import { WebSocketImpl } from "rhea-promise"; import { ConnectionContext } from "./connectionContext"; import { QueueClient } from "./queueClient"; import { TopicClient } from "./topicClient"; @@ -15,6 +13,7 @@ import { isTokenCredential } from "@azure/core-amqp"; import { SubscriptionClient } from "./subscriptionClient"; +import { WebSocketOptions } from "@azure/core-amqp"; /** * Describes the options that can be provided while creating the ServiceBusClient. @@ -29,15 +28,10 @@ export interface ServiceBusClientOptions { */ dataTransformer?: DataTransformer; /** - * @property The WebSocket constructor used to create an AMQP connection - * over a WebSocket. In browsers, the built-in WebSocket will be used by default. In Node, a - * TCP socket will be used if a WebSocket constructor is not provided. - */ - webSocket?: WebSocketImpl; - /** - * @property Options to be passed to the WebSocket constructor + * @property + * Options to configure the channelling of the AMQP connection over Web Sockets. */ - webSocketConstructorOptions?: any; + webSocketOptions?: WebSocketOptions; } /** @@ -93,9 +87,9 @@ export class ServiceBusClient { config = ConnectionConfig.create(hostOrConnectionString); options = credentialOrServiceBusClientOptions as ServiceBusClientOptions; - config.webSocket = options && options.webSocket; + config.webSocket = options?.webSocketOptions?.webSocket; config.webSocketEndpointPath = "$servicebus/websocket"; - config.webSocketConstructorOptions = options && options.webSocketConstructorOptions; + config.webSocketConstructorOptions = options?.webSocketOptions?.webSocketConstructorOptions; // Since connectionstring was passed, create a SharedKeyCredential credential = new SharedKeyCredential(config.sharedAccessKeyName, config.sharedAccessKey);