Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions core/src/internal_mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ export { isIPV4OrHostname, Servers } from "./servers.ts";

export { wsconnect, wsUrlParseFn } from "./ws_transport.ts";

export type { WsConnectionOptions, WsSocketFactory } from "./ws_transport.ts";

export {
AuthorizationError,
ClosedConnectionError,
Expand Down
2 changes: 2 additions & 0 deletions core/src/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,6 @@ export type {
TlsOptions,
TokenAuth,
UserPass,
WsConnectionOptions,
WsSocketFactory,
} from "./internal_mod.ts";
19 changes: 17 additions & 2 deletions core/src/ws_transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,26 @@ import { errors, InvalidArgumentError } from "./errors.ts";
const VERSION = version;
const LANG = "nats.ws";

/**
* WsSocketFactory is a factory that returns a WebSocket and a boolean
* indicating if the connection is encrypted. Client code is responsible
* for creating a W3C WebSocket compliant transport.
*
* @param u the url to connect to
* @param opts the connection options
* @returns a promise that resolves to a WebSocket and a boolean indicating if
* the connection is encrypted
*/
export type WsSocketFactory = (u: string, opts: ConnectionOptions) => Promise<{
socket: WebSocket;
encrypted: boolean;
}>;
interface WsConnectionOptions extends ConnectionOptions {

/**
* WsConnectionOptions exposes wsconnect specific options not applicable to
* other transports.
*/
export interface WsConnectionOptions extends ConnectionOptions {
wsFactory?: WsSocketFactory;
}

Expand Down Expand Up @@ -334,7 +349,7 @@ export function wsUrlParseFn(u: string, encrypted?: boolean): string {
}

export function wsconnect(
opts: ConnectionOptions = {},
opts: ConnectionOptions | WsConnectionOptions = {},
): Promise<NatsConnection> {
setTransportFactory({
defaultPort: 443,
Expand Down
2 changes: 1 addition & 1 deletion docs/core/assets/hierarchy.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/core/assets/navigation.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading