1.7.0 • Published 11 months ago

@firebend/control-tower-web-socket-client v1.7.0

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

web-socket-client

This library was generated with Nx.

It allows clients to connected to Control Tower's Real Time Event platform.

Running unit tests

Run nx test web-socket-client to execute the unit tests via Jest.

Running lint

Run nx lint web-socket-client to execute the lint via ESLint.

Examples

Connecting and Listening to All Events for a Given Entity

This snippet will register an event handler for any load change.

realTimeEventFactory('insert url')
  .withAccessToken('insert token or token promise')
  .startAsync()
  .then(builder => {
    builder.onAll('loads', event => {
      console.log('A load event triggered!', event.trigger)
    });
  });

Connecting and Listening to a Specific Trigger for a Given Entity

This snippet registers a handler to only receive modification events for the load entity.

realTimeEventFactory('insert url')
  .withAccessToken('insert token or token promise')
  .startAsync()
  .then(builder => {
    builder.on('loads', triggers => {
      triggers
        .on('Modified')
        .withEventHandler(event => {
          console.log('A load was modified!', event.eventTime)
        })
    });
  });

Connecting and Listening to a Specific Trigger With a Filter for a Given Entity

This snippet registers a handler to receive Created triggers and Modified triggers. The modified trigger has a filter to only fire when the load status or any stop in the stop array has been altered.

realTimeEventFactory('insert url')
  .withAccessToken('insert token or token promise')
  .startAsync()
  .then(builder => {
    builder.on('loads', triggers => {
      triggers
        .onTrigger('Created')
        .onTrigger('Modified', filters => {
          filters.withFilter('/loadStatus')
            .withFilter('/stops/*')
        })
        .withEventHandler(event => {
          console.log('A load event was triggered!', event.trigger)
        })
    });
  });
1.17.0

11 months ago

1.7.0

11 months ago

1.6.0

1 year ago

1.5.0

2 years ago

1.4.0

2 years ago

1.3.0

2 years ago

1.2.0

2 years ago

1.1.3

2 years ago

1.1.1

2 years ago

1.0.1

2 years ago

0.5.1

2 years ago

0.6.0

2 years ago

0.5.0

2 years ago

0.4.0

2 years ago

0.3.0

2 years ago