3.0.5 • Published 1 month ago

@jaraxa/nc-wsclient v3.0.5

Weekly downloads
-
License
ISC
Repository
github
Last release
1 month ago

ws-client

ws-client

Description

  • Netcomposer WebSocket wrapper using react-use-websocket and the Event Bus design pattern
  • Provides connection, communication and event subscription

WS Communication

WS communication

Dependencies

API

  • WSClientProvider: provider that allows the use of the useWSClient hook. Params: wsUrl (WS url to connect to), netcomposerAppPrefix (app identifier used as prefix), logMode ('verbose', 'minimalist', 'only-error' or 'off'), keepAliveTimeout (max time that the client can be idle to keep alive the connection with the server. Optional, defaults to 5 seconds), ackTimeout (max time to consider a WS ack message as slow. Optional, defaults to 5 seconds) & resultTimeout (max time to consider a WS result message as slow. Optional, defaults to 10 seconds). Client code must be wrapped by it.
  • useWSClient: hook that give access through destructuring to connectionStatus, sendCommand, connect & disconnect.
    • connectionStatus: variable that provides the state of the WS connection. One of Connecting, Open, Closing, Closed or Uninstantiated. Type can be imported as ConnectionStatus.
    • sendCommand: function that allows message sending to the WS. Accepts a param of type Message and returns a Promise. Message type can be imported.
  • useEventSubscription: hook that provides a subscribe on mount and unsubscribe on unmount mechanism. Params: eventKey (the event key this subscription is associated to) & eventHandler (the eventHandler to call in response to that event).

important: useEventSubscription eventHandler must be wrapped in React.useCallback to maintain referential stability

Log Modes

Verbose

  • Ack
  • Ping
  • Command
  • Result
  • Event
  • Error

Minimalist

  • Command
  • Result
  • Event
  • Error

Only Error

  • Result Error
  • Error

Off

  • Nothing

Examples

TODO

Resources

3.0.4

1 month ago

3.0.3

1 month ago

3.0.2

1 month ago

3.0.5

1 month ago

3.0.1

4 months ago

3.0.0

5 months ago

2.8.6

5 months ago

2.8.3

5 months ago

2.8.2

5 months ago

2.8.5

5 months ago

2.8.4

5 months ago

2.8.1

5 months ago

2.8.0

5 months ago

2.7.2

5 months ago

2.7.1

5 months ago

2.7.4

5 months ago

2.7.3

5 months ago

1.10.2

6 months ago

1.9.0

6 months ago

1.8.0

8 months ago

1.7.0

8 months ago

2.3.0

6 months ago

2.2.0

6 months ago

2.0.2

6 months ago

2.5.0

6 months ago

2.4.1

6 months ago

2.4.0

6 months ago

2.3.1

6 months ago

2.7.0

5 months ago

2.6.1

6 months ago

2.4.3

6 months ago

2.6.0

6 months ago

2.5.1

6 months ago

2.4.2

6 months ago

2.6.3

6 months ago

2.6.2

6 months ago

2.1.0

6 months ago

2.0.1

6 months ago

2.0.0

6 months ago

2.6.5

6 months ago

2.6.4

6 months ago

2.6.6

5 months ago

1.10.1

6 months ago

1.10.0

6 months ago

1.6.2

11 months ago

1.6.1

11 months ago

1.6.0

11 months ago

1.5.0

11 months ago

1.4.0

11 months ago

1.3.2

11 months ago

1.3.1

11 months ago

1.3.0

11 months ago

1.2.0

11 months ago

1.1.0

11 months ago

1.0.0

11 months ago