From affe9d13fc733419dd412c7223ac9b5ce4bf2a00 Mon Sep 17 00:00:00 2001 From: ybycode Date: Tue, 9 Jul 2019 04:06:54 +0200 Subject: [PATCH] [phoenix] Fix SocketConnectOptions for phoenix >= 1.4.3 (#36715) Adds/fixes types of SocketConnectOptions attributes: - Adds the missing attribute `binaryType`, - Adds the missing attribute `rejoinAfterMs`, - Fixes the type of `reconnectAfterMs`. --- types/phoenix/index.d.ts | 5 ++++- types/phoenix/phoenix-tests.ts | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/types/phoenix/index.d.ts b/types/phoenix/index.d.ts index 22a4d25f40..526b970e48 100644 --- a/types/phoenix/index.d.ts +++ b/types/phoenix/index.d.ts @@ -36,18 +36,21 @@ export class Channel { push(event: string, payload: object, timeout?: number): Push; } +export type BinaryType = 'arraybuffer' | 'blob'; export type ConnectionState = 'connecting' | 'open' | 'closing' | 'closed'; export interface SocketConnectOption { + binaryType: BinaryType; params: object | (() => object); transport: string; timeout: number; heartbeatIntervalMs: number; - reconnectAfterMs: number; longpollerTimeout: number; encode: (payload: object, callback: (encoded: any) => void) => void; decode: (payload: string, callback: (decoded: any) => void) => void; logger: (kind: string, message: string, data: any) => void; + reconnectAfterMs: (tries: number) => number; + rejoinAfterMs: (tries: number) => number; } export class Socket { diff --git a/types/phoenix/phoenix-tests.ts b/types/phoenix/phoenix-tests.ts index f0b0937851..86da971e05 100644 --- a/types/phoenix/phoenix-tests.ts +++ b/types/phoenix/phoenix-tests.ts @@ -1,7 +1,12 @@ import { Socket, Channel, Presence } from 'phoenix'; function test_socket() { - const socket = new Socket('/ws', {params: {userToken: '123'}}); + const socket = new Socket('/ws', { + binaryType: 'arraybuffer', + params: { userToken: '123' }, + reconnectAfterMs: tries => 1000, + rejoinAfterMs: tries => 1000, + }); socket.connect(); }