npm.io
1.0.12 • Published 4 years ago

service-commons

Licence
MIT
Version
1.0.12
Deps
4
Size
206 kB
Vulns
23
Weekly
0
Stars
10.1K

Service Commons

Provides common building blocks for creating service infrastructure, including in servers and client APIs.

This contains

Injection: the implementation of Injection from the @angular/core project to help with service extensibility patterns. WebSockets: WebSocketClientService wraps a WebSocket with an rxjs Observer.

WebSocketClientService

const wsService = new WebSocketClientService(WebSocketEnvironment.Node);
const handleMessage = (data) => {
  console.debug("data: " + data);
};
const subMessages = <Subject<MessageEvent>>wsService
  .create(URL)
  .pipe(
    map((response: MessageEvent): any => {
      // We have to parse because message data is always text
      const data = JSON.parse(response.data);
      handleMessage(data);
      return data;
    }));

Notes

https://www.npmjs.com/package/ws

Keywords