-
Notifications
You must be signed in to change notification settings - Fork 182
mayuran/DPROD-2759/ws_improvements #7070
Changes from all commits
fc54798
ca92e71
307c975
43e572c
60c1716
eacfe41
d62e8ff
102e343
664d1ca
59ab09f
be6dc8f
e33debc
be43c32
d10f917
ff92483
97078da
0f003c9
5b1e994
07f3451
51fa7f0
abb84c3
906f176
c8370ef
8a3bf6f
f4baf09
4fe3497
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import { useCallback, useState } from 'react' | ||
import { TSocketEndpointNames, TSocketResponseData } from 'common/websocket/types' | ||
import apiManager from 'common/websocket' | ||
import apiManager, { ApiManager } from 'common/websocket' | ||
import { getLanguage, isBrowser } from 'common/utility' | ||
|
||
const useWS = <T extends TSocketEndpointNames>(name: T) => { | ||
const [is_loading, setIsLoading] = useState(false) | ||
|
@@ -15,6 +16,23 @@ const useWS = <T extends TSocketEndpointNames>(name: T) => { | |
const send = useCallback( | ||
async (data?: Parameters<typeof apiManager.augmentedSend<T>>[1]) => { | ||
setIsLoading(true) | ||
const readyState = parseInt(ApiManager.readyState) | ||
if (readyState !== 1 && readyState !== 0) { | ||
if (isBrowser()) { | ||
const currentLanguage = getLanguage() ?? 'en' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. its old method which we are using to get language so i didn't change the method There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can improve it. Why not. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thats where the high test coverage helps :) to increase confidence and thus enable refactors like that ;) |
||
try { | ||
// Connect to WebSocket if not connected | ||
await apiManager.reconnectIfNotConnected(currentLanguage) | ||
} catch (e) { | ||
setError(e) | ||
setIsLoading(false) | ||
return | ||
} | ||
} else { | ||
setIsLoading(false) | ||
return | ||
} | ||
} | ||
try { | ||
const response = await apiManager.augmentedSend(name, data) | ||
setData(response[name] as TSocketResponseData<T>) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kept console logs for QA purpose, later will remove console logs.