8.1.0 • Published 4 years ago

lightstreamer-client-node-gs v8.1.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
4 years ago

Lightstreamer Client SDK (Custom)

:warning: This library is not official! This package has some fixes related to graceful shutdown. In particular this package has additional public module ExecutorCtrl, that has two public methods initialize and destroy. So, to allow you application make graceful shutdown you need to manually call initialize method before start the work and then before exit, call destroy to stop inner timers.

Lightstreamer Client SDK enables any JavaScript application running in a web browser or in a Node.js container to communicate bidirectionally with a Lightstreamer Server. The API allows to subscribe to real-time data pushed by the server, to display such data, and to send any message to the server.

The library offers automatic recovery from connection failures, automatic selection of the best available transport, and full decoupling of subscription and connection operations. It is responsible of forwarding the subscriptions to the Server and re-forwarding all the subscriptions whenever the connection is broken and then reopened.

The library also offers support for Web Push Notifications on Apple platforms via Apple Push Notification Service (APNs) and Google platforms via Firebase Cloud Messaging (FCM). With Web Push, subscriptions deliver their updates via push notifications even when the application is offline.

Quickstart

To connect to a Lightstreamer Server, a LightstreamerClient object has to be created, configured, and instructed to connect to the Lightstreamer Server. A minimal version of the code that creates a LightstreamerClient and connects to the Lightstreamer Server on https://push.lightstreamer.com will look like this:

var client = new LightstreamerClient("https://push.lightstreamer.com/","DEMO");
client.connect();

For each subscription to be subscribed to a Lightstreamer Server a Subscription instance is needed. A simple Subscription containing three items and two fields to be subscribed in MERGE mode is easily created (see Lightstreamer General Concepts):

var sub = new Ls.Subscription("MERGE",["item1","item2","item3"],["stock_name","last_price"]);
sub.setDataAdapter("QUOTE_ADAPTER");
sub.setRequestedSnapshot("yes");
client.subscribe(sub);

Before sending the subscription to the server, usually at least one SubscriptionListener is attached to the Subscription instance in order to consume the real-time updates. The following code shows the values of the fields stock_name and last_price each time a new update is received for the subscription:

sub.addListener({
    onItemUpdate: function(obj) {
      console.log(obj.getValue("stock_name") + ": " + obj.getValue("last_price"));
    }
});

Below is the complete JavaScript code embedded in an HTML page:

<html>
<head>
    <script src="https://unpkg.com/lightstreamer-client-web/lightstreamer.min.js"></script>
    <script>
    var client = new Ls.LightstreamerClient("https://push.lightstreamer.com","DEMO");  
    client.connect();
    
    var sub = new Ls.Subscription("MERGE",["item1","item2","item3"],["stock_name","last_price"]);
    sub.setDataAdapter("QUOTE_ADAPTER");
    sub.setRequestedSnapshot("yes");
    sub.addListener({
        onItemUpdate: function(obj) {
          console.log(obj.getValue("stock_name") + ": " + obj.getValue("last_price"));
        }
    });
    client.subscribe(sub);
    </script>
</head>
<body>
</body>
</html>

npm Packages

Building

To build the library, enter the directory tools and run the command node build.js.

The scripts generates the following builds for the Web platform (saved in tools/dist):

UMDCommonJSES Module
Buildlightstreamer.js lightstreamer.min.jslightstreamer.common.jslightstreamer.esm.js

and the following ones for the Node.js platform (saved in tools/dist-node):

CommonJS
Buildlightstreamer-node.js lightstreamer-node.min.js

For the build options, see the configuration file tools/build.config.js.

Compatibility

The library requires Server 7.1 and breaks the compatibility with Server version 7.0. However, if Web Push Notifications are not used, compatibility with Server version 7.0 is still ensured.

Documentation

Support

For questions and support please use the Official Forum. The issue list of this page is exclusively for bug reports and feature requests.

License

Apache 2.0