Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Commit

Permalink
add option to pass extra websocket client arguments (#561)
Browse files Browse the repository at this point in the history
  • Loading branch information
GingerBear authored Aug 12, 2020
1 parent a7e24c9 commit 624662e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

- Add `minTimeout` option for client. <br/>
[@jedwards1211](https://github.com/jedwards1211) in [#675](https://github.com/apollographql/subscriptions-transport-ws/pull/675)
- Accept extra WebSocket client arguments. <br/>
[@GingerBear](https://github.com/GingerBear) in [#561](https://github.com/apollographql/subscriptions-transport-ws/pull/561)

## v0.9.17

Expand Down
6 changes: 5 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export interface ClientOptions {
connectionCallback?: (error: Error[], result?: any) => void;
lazy?: boolean;
inactivityTimeout?: number;
wsOptionArguments?: any[];
}

export class SubscriptionClient {
Expand Down Expand Up @@ -96,6 +97,7 @@ export class SubscriptionClient {
private maxConnectTimeoutId: any;
private middlewares: Middleware[];
private maxConnectTimeGenerator: any;
private wsOptionArguments: any[];

constructor(
url: string,
Expand All @@ -112,6 +114,7 @@ export class SubscriptionClient {
reconnectionAttempts = Infinity,
lazy = false,
inactivityTimeout = 0,
wsOptionArguments = [],
} = (options || {});

this.wsImpl = webSocketImpl || NativeWebSocket;
Expand Down Expand Up @@ -139,6 +142,7 @@ export class SubscriptionClient {
this.client = null;
this.maxConnectTimeGenerator = this.createMaxConnectTimeGenerator();
this.connectionParams = this.getConnectionParams(connectionParams);
this.wsOptionArguments = wsOptionArguments;

if (!this.lazy) {
this.connect();
Expand Down Expand Up @@ -550,7 +554,7 @@ export class SubscriptionClient {
}

private connect() {
this.client = new this.wsImpl(this.url, this.wsProtocols);
this.client = new this.wsImpl(this.url, this.wsProtocols, ...this.wsOptionArguments);

this.checkMaxConnectTimeout();

Expand Down

0 comments on commit 624662e

Please sign in to comment.