Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1

    node.js authetication

    Hi,

    I'm using LightStreamer to connect with IG Index (https://labs.ig.com/streaming-api-guide). I have succeeded using javascript in Chrome and now I am trying with node.js with very similar code. I can connect over http to "http://push.lightstreamer.com" without any authentication but I can't connection to https with a password. What am I missing? I am sure the endpoint, clientId and password are correct in that they are the same as the Chrome version which works. I keep getting:

    Lightstreamer connection status:CONNECTING
    Lightstreamer connection statusISCONNECTED:WILL-RETRY
    Lightstreamer connection status:CONNECTING
    Lightstreamer connection statusISCONNECTED:WILL-RETRY
    Lightstreamer connection status:CONNECTING

    Thanks for your help!
    Tim

    Node.js Code
    Code:
        ls = require("lightstreamer-client");
    
    
        IGInterface.prototype.connectToLightstreamer = function(loginCallback) {
          console.log("Connecting to lightstreamer");
          this.lsClient = new ls.LightstreamerClient(this.lsEndpoint);
          this.lsClient.connectionDetails.setUser(this.clientId);
          this.password = "";
          if (this.clientToken) {
            this.password = "CST-" + this.clientToken;
          }
          if (this.clientToken && this.accountToken) {
            this.password = this.password + "|";
          }
          if (this.accountToken) {
            this.password = this.password + "XST-" + this.accountToken;
          }
          this.lsClient.connectionDetails.setPassword(this.password);
          console.log(this.lsClient.connectionDetails);
          this.lsClient.addListener({
            onListenStart: (function(_this) {
              return function() {
                return _this.showMessage("Lightstreamer client - start listening");
              };
            })(this),
            onStatusChange: (function(_this) {
              return function(status) {
                _this.showMessage("Lightstreamer connection status:" + status);
                if (status === "CONNECTED:WS-STREAMING") {
                  return loginCallback();
                }
              };
            })(this)
          });
          return this.lsClient.connect();
        };

  2. #2
    Administrator
    Join Date
    Feb 2012
    Location
    Milano
    Posts
    538
    Hi Tim,

    Please could you confirm if your node app is able to connect to "https://push.lightstreamer.com"?
    Furthermore, please enable the detailed log of the Lightstreamer JavaScript client library so that we can get some more precise information about what is happening.
    You should add something like this to your code:



    Regards,
    Giuseppe

  3. #3
    I am able to connect to https://push.lightstreamer.com as well as http://push.lightstreamer.com. I've attached the LoggerProvider and the error looks to be 'License not valid for this Client version'. Is there anything I can do about that without access to the server?

    Full log: LSLog.txt

  4. #4
    Administrator
    Join Date
    Feb 2012
    Location
    Milano
    Posts
    538
    Hi Tim,

    To fix your issue should be enough change the version of the JavaScript client library in use. The correct one to use with IG servers is those downloadable from here(sdk_client_javascript.zip\sdk_client_javascript\a lternative_libs\lightstreamer_node.js).

    Regards,
    Giuseppe

  5. #5
    Thanks! I'll give that a go.

  6. #6
    Thank you Giuseppe! This is probably a bit of a noob question but how do I use that library in node.js? I am requiring it like so:

    Code:
    ls = require "../thirdparty/lightstreamer_node.js"
    but ls appears to be an empty object when I log it. I have tried putting module.exports at the beginning of the lightstreamer_node.js file (which is minified):

    Code:
    module.exports = (function(){function u(){return function(g){return g}}function D().....
    but ls is then undefined for some reason. Also, unless I require "amdefine" at the beginning of the minified lightstreamer_node.js file I get the error "define is not defined".

    Code:
    var define = require("amdefine");
    This all just worked when I npm installed lightstreamer-client. I have even tried replacing the lightstreamer.js file with the contents of the lightstreamer_node.js file in the node_modules folder but no luck. Any help would be much appreciated.

    Cheers,
    Tim

    Edit:
    I have also npm installed faye-websocket and xmlhttprequest as I think they are dependencies but still no dice.
    Last edited by TimL; September 23rd, 2015 at 08:14 AM.

  7. #7
    Administrator
    Join Date
    Feb 2012
    Location
    Milano
    Posts
    538
    Hi Tim,

    Unfortunately the versions prior to 6.2.3 of lightstreamer-client package can not be obtained through "npm istall".
    So you should use the lightstreamer_node.js file and rely on an AMD loader (i.e.: require.js).
    Please refer to section "2.3.5.2 Using the AMD loader" of "JavaScript Client Guide" documentation, but in your case something like this should work:


  8. #8
    Sorry to bother you again Giuseppe. Perhaps this is one for Stack Overflow: Why would define still be undefined after requiring lightstreamer_node.js in the way you described above? From what I have read here: http://requirejs.org/docs/node.html requirejs should define define for me.

    I have installed requirejs
    Code:
    npm install requirejs
    and my code looks like this
    Code:
        var ls = {};
    
        IGInterface.prototype.connectToLightstreamer = function(loginCallback) {
          var requirejs;
          requirejs = require('requirejs');
    
          requirejs.config({
            deps: ["../thirdparty/lightstreamer_node.js"],
            nodeRequire: require
          });
    
          return requirejs(["LightstreamerClient", "Subscription"], (function(_this) {
            return function(LightstreamerClient, Subscription) {
              ls.LightstreamerClient = LightstreamerClient;
              ls.Subscription = Subscription;
              _this.lsClient = new ls.LightstreamerClient(_this.endPoint);
              _this.lsClient.connectionDetails.setUser(_this.clientId);
              _this.lsClient.connectionDetails.setPassword(_this.getPassword());
              _this.lsClient.addListener({
                onStatusChange: function(status) {
                  _this.showMessage("LS connection status: " + status);
                  if (status === "CONNECTED:WS-STREAMING") {
                    return loginCallback();
                  }
                }
              });
              return _this.lsClient.connect();
            };
          })(this));
        };
    the error is
    Code:
    /home/ubuntu/workspace/node_modules/requirejs/bin/r.js:2585
                        throw err;
                              ^
    Error: Tried loading "../thirdparty/lightstreamer_node.js" at ../thirdparty/lightstreamer_node.js then tried node's require("../thirdparty/lightstreamer_node.js") and it failed with error: ReferenceError: define is not defined
        at /home/ubuntu/workspace/node_modules/requirejs/bin/r.js:2578:27
        at Object.context.execCb (/home/ubuntu/workspace/node_modules/requirejs/bin/r.js:1929:33)
        at Object.Module.check (/home/ubuntu/workspace/node_modules/requirejs/bin/r.js:1129:51)
        at Object.Module.enable (/home/ubuntu/workspace/node_modules/requirejs/bin/r.js:1416:22)
        at Object.Module.init (/home/ubuntu/workspace/node_modules/requirejs/bin/r.js:1034:26)
        at callGetModule (/home/ubuntu/workspace/node_modules/requirejs/bin/r.js:1443:63)
        at Object.context.completeLoad (/home/ubuntu/workspace/node_modules/requirejs/bin/r.js:1822:21)
        at Function.req.load (/home/ubuntu/workspace/node_modules/requirejs/bin/r.js:2591:17)
        at Object.context.load (/home/ubuntu/workspace/node_modules/requirejs/bin/r.js:1918:21)
        at Object.Module.load (/home/ubuntu/workspace/node_modules/requirejs/bin/r.js:1080:29)
    I have tried reinstalling requirejs several times, deleting it in node_modules first and I've also re downloaded lightstreamer_node.js to make sure it's not been corrupted by me. Any ideas?

    Cheers,
    Tim

  9. #9
    I eventually fixed this. lightstreamer_node.js had to be in the same directory as the file I was writing: https://github.com/jrburke/requirejs/issues/122

  10. #10
    Administrator
    Join Date
    Feb 2012
    Location
    Milano
    Posts
    538
    Hi Tim,

    Good news, thank you for the feedback.

 

 

Similar Threads

  1. Node.js client failing to connect in HTTP-STREAMING transport
    By david@theredx.com in forum Client APIs
    Replies: 1
    Last Post: July 25th, 2013, 05:13 PM
  2. Benchmarking Socket.IO vs. Lightstreamer with Node.js
    By Alessandro in forum Adapter APIs
    Replies: 0
    Last Post: June 3rd, 2013, 01:47 PM
  3. Replies: 0
    Last Post: May 9th, 2013, 03:33 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT +1. The time now is 02:41 PM.