Orderly network net.WS
Orderly SDKs / Modules / @orderly.network/net / WS
Class: WS
Table of contents
Constructors
Properties
- _eventContainer
- _eventHandlers
- _eventPrivateHandlers
- _pendingPrivateSubscribe
- _pendingPublicSubscribe
- _privateHeartbeatTime
- _privateRetryCount
- _publicHeartbeatTime
- _publicRetryCount
- _publicSocket
- authenticated
- options
- privateIsReconnecting
- privateSocket
- publicIsReconnecting
- reconnectInterval
Accessors
Methods
- authenticate
- bindEvents
- checkSocketStatus
- close
- closePrivate
- createPrivateSC
- createPublicSC
- emit
- errorBoardscast
- generateMessage
- getTopicKeyFromMessage
- getTopicKeyFromParams
- handlePendingPrivateTopic
- off
- on
- onMessage
- onNetworkStatusChange
- onOpen
- onPrivateClose
- onPrivateError
- onPrivateMessage
- onPrivateOpen
- onPublicClose
- onPublicError
- onPublicMessage
- onVisibilityChange
- onceSubscribe
- openPrivate
- privateSubscribe
- reconnectPrivate
- reconnectPublic
- send
- subscribe
- unsubscribe
- unsubscribePrivate
- unsubscribePublic
Constructors
constructor
• new WS(options
)
Parameters
Name | Type |
---|---|
options | WSOptions |
Defined in
Properties
_eventContainer
• Private
_eventContainer: Map
<string
, Set
<Function
>>
Defined in
_eventHandlers
• Private
_eventHandlers: Map
<string
, Topics
>
Defined in
_eventPrivateHandlers
• Private
_eventPrivateHandlers: Map
<string
, Topics
>
Defined in
_pendingPrivateSubscribe
• Private
_pendingPrivateSubscribe: any
[][] = []
Defined in
_pendingPublicSubscribe
• Private
_pendingPublicSubscribe: any
[][] = []
Defined in
_privateHeartbeatTime
• Private
Optional
_privateHeartbeatTime: number
Defined in
_privateRetryCount
• Private
_privateRetryCount: number
= 0
Defined in
_publicHeartbeatTime
• Private
Optional
_publicHeartbeatTime: number
Defined in
_publicRetryCount
• Private
_publicRetryCount: number
= 0
Defined in
_publicSocket
• Private
_publicSocket: WebSocket
Defined in
authenticated
• Private
authenticated: boolean
= false
Defined in
options
• Private
options: WSOptions
Defined in
privateIsReconnecting
• Private
privateIsReconnecting: boolean
= false
Defined in
privateSocket
• Private
Optional
privateSocket: WebSocket
Defined in
publicIsReconnecting
• Private
publicIsReconnecting: boolean
= false
Defined in
reconnectInterval
• Private
reconnectInterval: number
= 1000
Defined in
Accessors
accountId
• set
accountId(accountId
): void
Parameters
Name | Type |
---|---|
accountId | string |
Returns
void
Defined in
client
• get
client(): Object
Returns
Object
Name | Type |
---|---|
private? | WebSocket |
public | WebSocket |
Defined in
Methods
authenticate
▸ Private
authenticate(accountId
): Promise
<void
>
Parameters
Name | Type |
---|---|
accountId | string |
Returns
Promise
<void
>
Defined in
bindEvents
▸ Private
bindEvents(): void
Returns
void
Defined in
checkSocketStatus
▸ Private
checkSocketStatus(): void
Determine the current connection status,
- If it is disconnected, reconnect
- If no message is received for too long, disconnect and reconnect actively
- When returning from the background and the network status changes, the following process is followed
Returns
void
Defined in
close
▸ close(): void
Returns
void
Defined in
closePrivate
▸ closePrivate(code?
, reason?
): void
Parameters
Name | Type |
---|---|
code? | number |
reason? | string |
Returns
void
Defined in
createPrivateSC
▸ Private
createPrivateSC(options
): void
Parameters
Name | Type |
---|---|
options | WSOptions |
Returns
void
Defined in
createPublicSC
▸ Private
createPublicSC(options
): void
Parameters
Name | Type |
---|---|
options | WSOptions |
Returns
void
Defined in
emit
▸ emit(eventName
, message
): void
Parameters
Name | Type |
---|---|
eventName | string |
message | any |
Returns
void
Defined in
errorBoardscast
▸ Private
errorBoardscast(error
, eventHandlers
): void
Parameters
Name | Type |
---|---|
error | any |
eventHandlers | Map <string , Topics > |
Returns
void
Defined in
generateMessage
▸ Private
generateMessage(params
, onUnsubscribe?
, onMessage?
): [MessageParams
, (event
: string
) => any
]
Parameters
Name | Type |
---|---|
params | any |
onUnsubscribe? | (event : string ) => any |
onMessage? | (message : any ) => any |
Returns
[MessageParams
, (event
: string
) => any
]
Defined in
getTopicKeyFromMessage
▸ Private
getTopicKeyFromMessage(message
): string
Parameters
Name | Type |
---|---|
message | any |
Returns
string
Defined in
getTopicKeyFromParams
▸ Private
getTopicKeyFromParams(params
): string
Parameters
Name | Type |
---|---|
params | any |
Returns
string
Defined in
handlePendingPrivateTopic
▸ Private
handlePendingPrivateTopic(): void
Returns
void
Defined in
off
▸ off(eventName
, callback
): void
Parameters
Name | Type |
---|---|
eventName | string |
callback | (message : any ) => any |
Returns
void
Defined in
on
▸ on(eventName
, callback
): void
Parameters
Name | Type |
---|---|
eventName | string |
callback | (message : any ) => any |
Returns
void
Defined in
onMessage
▸ Private
onMessage(event
, socket
, handlerMap
): void
Parameters
Name | Type |
---|---|
event | MessageEvent <any > |
socket | WebSocket |
handlerMap | Map <string , Topics > |
Returns
void
Defined in
onNetworkStatusChange
▸ Private
onNetworkStatusChange(): void
Returns
void
Defined in
onOpen
▸ Private
onOpen(event
): void
Parameters
Name | Type |
---|---|
event | Event |
Returns
void
Defined in
onPrivateClose
▸ Private
onPrivateClose(event
): void
Parameters
Name | Type |
---|---|
event | CloseEvent |
Returns
void
Defined in
onPrivateError
▸ Private
onPrivateError(event
): void
Parameters
Name | Type |
---|---|
event | Event |
Returns
void
Defined in
onPrivateMessage
▸ Private
onPrivateMessage(event
): void
Parameters
Name | Type |
---|---|
event | MessageEvent <any > |
Returns
void
Defined in
onPrivateOpen
▸ Private
onPrivateOpen(event
): void
Parameters
Name | Type |
---|---|
event | Event |
Returns
void
Defined in
onPublicClose
▸ Private
onPublicClose(event
): void
Parameters
Name | Type |
---|---|
event | CloseEvent |
Returns
void
Defined in
onPublicError
▸ Private
onPublicError(event
): void
Parameters
Name | Type |
---|---|
event | Event |
Returns
void
Defined in
onPublicMessage
▸ Private
onPublicMessage(event
): void
Parameters
Name | Type |
---|---|
event | MessageEvent <any > |
Returns
void
Defined in
onVisibilityChange
▸ Private
onVisibilityChange(): void
Returns
void
Defined in
onceSubscribe
▸ onceSubscribe(params
, callback
): void
Parameters
Name | Type |
---|---|
params | any |
callback | Omit <WSMessageHandler , "onUnsubscribe" > |
Returns
void
Defined in
openPrivate
▸ openPrivate(accountId
): void
Parameters
Name | Type |
---|---|
accountId | string |
Returns
void
Defined in
privateSubscribe
▸ privateSubscribe(params
, callback
): () => void
Parameters
Name | Type |
---|---|
params | any |
callback | WSMessageHandler | Omit <WSMessageHandler , "onUnsubscribe" > |
Returns
fn
▸ (): void
Returns
void
Defined in
reconnectPrivate
▸ Private
reconnectPrivate(): void
Returns
void
Defined in
reconnectPublic
▸ Private
reconnectPublic(): void
Returns
void
Defined in
send
▸ send(message
): void
Parameters
Name | Type |
---|---|
message | any |
Returns
void
Defined in
subscribe
▸ subscribe(params
, callback
, once?
, id?
): undefined
| unsubscribe
Parameters
Name | Type |
---|---|
params | any |
callback | WSMessageHandler | Omit <WSMessageHandler , "onUnsubscribe" > |
once? | boolean |
id? | string |
Returns
undefined
| unsubscribe
Defined in
unsubscribe
▸ Private
unsubscribe(parmas
, webSocket
, handlerMap
): void
Parameters
Name | Type |
---|---|
parmas | MessageParams |
webSocket | WebSocket |
handlerMap | Map <string , Topics > |
Returns
void
Defined in
unsubscribePrivate
▸ Private
unsubscribePrivate(parmas
): void
Parameters
Name | Type |
---|---|
parmas | MessageParams |
Returns
void
Defined in
unsubscribePublic
▸ Private
unsubscribePublic(parmas
): void
Parameters
Name | Type |
---|---|
parmas | MessageParams |
Returns
void