From 79391fe15739758a18b31d7f888eed3ba95c00df Mon Sep 17 00:00:00 2001 From: yashim-deriv Date: Fri, 19 Jul 2024 16:36:41 +0800 Subject: [PATCH] feat: reinit when websocket close --- src/client-library/deriv-api-client.ts | 4 ++-- src/context/api-context.tsx | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/client-library/deriv-api-client.ts b/src/client-library/deriv-api-client.ts index 6b575b3..663e5b0 100644 --- a/src/client-library/deriv-api-client.ts +++ b/src/client-library/deriv-api-client.ts @@ -9,8 +9,8 @@ import { } from '../types/api.types'; type DerivAPIClientOptions = { - onOpen: (e: Event) => void; - onClose: (e: CloseEvent) => void; + onOpen?: (e: Event) => void; + onClose?: (e: CloseEvent) => void; }; type DataHandler = (data: TSocketResponseData) => void; diff --git a/src/context/api-context.tsx b/src/context/api-context.tsx index 327288f..aab5b17 100644 --- a/src/context/api-context.tsx +++ b/src/context/api-context.tsx @@ -2,7 +2,9 @@ import { createContext, PropsWithChildren } from 'react'; import { URLUtils } from '@deriv-com/utils'; import { DerivAPIClient } from '../client-library/deriv-api-client'; -export const derivAPIClient = new DerivAPIClient(URLUtils.getWebsocketURL()); +export const derivAPIClient = new DerivAPIClient(URLUtils.getWebsocketURL(), { + onClose: () => window.location.reload(), +}); type APIData = { derivAPIClient: DerivAPIClient;