Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add options for websocket #177

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

Zerounary
Copy link

add options for websocket

@craftycram
Copy link

I'd love this PR to be merged since I need the rejectUnauthorized option to support self-signed certificates

@barlock
Copy link

barlock commented May 22, 2023

For anyone waiting for this PR, here's a decent workaround:

import ReconnectingWebSocket from 'reconnecting-websocket';
import { type Options, type UrlProvider } from 'reconnecting-websocket';
import WebSocket, { type ClientOptions } from 'ws';

const wsFactory = (options: ClientOptions) =>
  class WsOptions extends WebSocket {
    constructor(url: string, protocols?: string | string[]) {
      super(url, protocols, options);
    }
  };

export class KeepAliveWs extends ReconnectingWebSocket {
  constructor(
    url: UrlProvider,
    protocols?: string | string[],
    options: Options = {},
  ) {
    const { connectionTimeout = 4000 } = options;
    const opts = {
      ...options,
      connectionTimeout: connectionTimeout + 1000, // give WS time to disconnect without throwing
      WebSocket: wsFactory({ handshakeTimeout: connectionTimeout }), // PASS CUSTOM ARGUMENTS HERE
    };

    super(url, protocols, opts);
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants