@pecometer/pecots-websocket-client
TypeScript icon, indicating that this package has built-in type declarations

3.0.0 • Public • Published

A websocket client for use with PecoTS Framework websockets

Once initialised it will connect and maintain the websocket connection according to the settings sent by the server during the handshake process

Init

const ws = new PecoTsWebSocket();
const url = 'ws:...';
const jwt = 'your user auth jwt token';
ws.init(url,jwt);
const listener = ws.register('an-event-from-the-server').subscribe((data:any)=>{
    ...
});
...

HTTP over the websocket

If enabled on the backend application, you may pass HTTP requests over the websocket connection to the backend. The websocket will return the server response as you would expect over a standard HTTP request.

// To perform fake http requests over the websocket (and if enabled on the backend application), simply
// call the method required with the url and data for the request
ws.post('/someurl',{id: 1,some:'data'}).subscribe(data=>{
    // handle the response
    ...
})
...

Cleaning up

Once the listener is no longer required you must call the unsubscribe method on the Observable to avoid memory leaks

...
listener.unsubscribe();
...

Package Sidebar

Install

npm i @pecometer/pecots-websocket-client

Weekly Downloads

2

Version

3.0.0

License

SEE LICENSE IN licence

Unpacked Size

10.2 kB

Total Files

6

Last publish

Collaborators

  • seanhutchinson