Skip to content

Allow passthrough of ws options to websocket factory #218

@prescience-data

Description

@prescience-data

Happy to do this as a PR given it seems trivial to add, but prefer to ask before sending unsolicited PRs.

This should allow passing of the parent ws library options to allow setting headers and other environment-specific options that might be required.

A practical example I just ran into was a Chromium fork that requires authentication headers to be sent with the websocket request.

The implementation I'd suggest to avoid breaking any existing API is something like:

import type { ClientOptions } from "ws"
// ... other imports

export default async function openWebSocket(
  url: string,
  raceCancellation?: RaceCancellation,
  clientOptions?: ClientOptions
): Promise<[AttachMessageTransport, CloseWebSocket]> {
  const ws = new NodeWebSocket(url, clientOptions);
  // ... remaining code
}

This allows appending the options as an optional trailing arg which avoids any breaking change or API surface modification.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions