-
November 27th, 2017, 04:49 AM
#1
I have issue on connecting LS server in multiple page
(App developed my using Ionic Cordova platform.)
I have an application like trading platform. In my first page, I need to display all of the live rates(List of stocks and their rates). If they click on trade button I need to display only what every tradable stock. And If click on the stock from this I need to display responding stock details and Bid and Ask price and from this screen, users will submit their required quantity and submit the page. For every page currently, i'm opening the new connection.
var protocolToUse = document.location.protocol != "file:" ? document.location.protocol : "http:";
var portToUse = document.location.protocol == "https:" ? "443" : "8080";
var lsClient = new Lightstreamer.LightstreamerClient(protocolToUse+"//domain.com:"+portToUse,"STOCKLIST_REMOTE");
lsClient.connect();
As like that connecting in all of my three pages. But If I navigate the pages means connection getting close automatically. Showing the error like session terminated. Could you please help me anyone to fix this issue. Or else id there any other way to share the connection(connectionSharing) from one page to another page. I have tried like below code but issue happens. It says have to add connection sharing library.
lsClient.connectionSharing.enableSharing("CommonCo nnection", "ATTACH", "CREATE");
And also I need if we use connectionsharring means how to use that shared connection in another page.
I have below code in all of my three page controller(I'm using ionic framework for my android application )
var protocolToUse = document.location.protocol != "file:" ? document.location.protocol : "http:";
var portToUse = document.location.protocol == "https:" ? "443" : "8080";
var lsClient = new Lightstreamer.LightstreamerClient(protocolToUse+"//domain.com:"+portToUse,"STOCKLIST_REMOTE");
lsClient.connectionOptions.setHttpExtraHeaders({"u sername" : "bullion"});
lsClient.addListener({
onStatusChange: function(newStatus) {
console.log(newStatus);
}
});
lsClient.connect();
Last edited by rvkvino; November 27th, 2017 at 07:52 AM.
-
November 27th, 2017, 09:32 AM
#2
Hi rvkvino,
ConnectionSharing is the object of our client API that allow to specify if and how the connection is shared between different LightstreamerClient instances.
If you are using a versiont 7.0.x of Lightstreamer Web Client this is the correct syntax to leverage the engine sharing:
lsClient.enableSharing(new ConnectionSharing("my_sharing_name", "ATTACH", "CREATE"));
If you've built your library with the provided generator,please make sure you've included the ConnectionSharing class.
I confirm that the code should be the same in all your pages and the Lightstramer client will manage out of the box the sharing of a single connection to the server across all LightstreamerClient instances.
Please, take also a look at this demo that shows a quite similar scenario.
Regards,
Giuseppe
-
November 27th, 2017, 01:22 PM
#3
Hi,
I have used the code as like below in my all the 3 pages.
var protocolToUse = document.location.protocol != "file:" ? document.location.protocol : "http:";
var portToUse = document.location.protocol == "https:" ? "443" : "8080";
var lsClient = new Lightstreamer.LightstreamerClient(protocolToUse+"//domain.com:"+portToUse,"STOCKLIST_REMOTE");
lsClient.connectionOptions.setHttpExtraHeaders({"u sername" : "bullion"});
lsClient.enableSharing(new Lightstreamer.ConnectionSharing("CommonConnection" , "ATTACH", "CREATE"));
lsClient.addListener({
onStatusChange: function(newStatus) {
console.log(newStatus);
}
});
lsClient.connect();
This idn't work for me, If I navigate from first page to second page stock table didn't display. Connection status showing like connected. AS like this demo I dind't create single lsClient.js file and define into my controller.
-
November 28th, 2017, 06:58 AM
#4
I have changed the functionality as like below,
First created global file and in it created lsclient variable and created a connection on that. And for slave pages I have connected and subscribe the LS Server.
Global Declarationlsconnection.js)
var protocolToUse = document.location.protocol != "file:" ? document.location.protocol : "http:";
var portToUse = document.location.protocol == "https:" ? "443" : "8080";
var lsClient = new Lightstreamer.LightstreamerClient(protocolToUse+"//mydomain.com:"+portToUse,"SLNSTOCKLISTDEMO_REMOTE" );
lsClient.connectionOptions.setHttpExtraHeaders({"u sername" : "bullion"});
lsClient.enableSharing(new Lightstreamer.ConnectionSharing("CommonConnection" , "ATTACH", "CREATE"));
And my all the 3 pages used as like below(slave page)
lsClient.connect();
var liverateSubscription = new Lightstreamer.Subscription("COMMAND", liverateId, fieldList);
//my subscription
var liverateId = "Item";
var fieldList = ["key", "command", "desc", "bid", "ask", "high" , "low", "order"];
var bidaskfieldsList = ["desc", "bid", "ask", "low" , "high", "ratedisplay", "updatetime", "msg"];
var bidaskitemList = ["Gold", "Silver", "INR", "MGold", "MSilver", "Marketstatus"];
var liverateSubscription = new Lightstreamer.Subscription("COMMAND", liverateId, fieldList);
var liverateGrid = new Lightstreamer.DynaGrid("liverates",true);
liverateGrid.setAutoCleanBehavior(true,false);
liverateGrid.addListener({
onVisualUpdate: function(key,info) {
if (info == null) {
return;
}
info.forEachChangedField(function(fieldName,val) {
var lastPrice = info.getChangedFieldValue(fieldName);
if (lastPrice !== null) {
var prevPrice = liverateGrid.getValue(key,fieldName);
if(prevPrice != null){
if (!prevPrice || lastPrice > prevPrice) {
info.setAttribute("#2636f2",null,"backgroundColor" );
info.setAttribute("#FFFFFF",null,"color");
} else {
info.setAttribute("#FF0000",null,"backgroundColor" );
info.setAttribute("#FFFFFF",null,"color");
}
}
} else {
info.setAttribute("",null,"backgroundColor");
info.setAttribute("",null,"color");
}
});
}
});
liverateGrid.setSort("order", false);
liverateSubscription.setDataAdapter("QUOTE_ADAPTER ");
liverateSubscription.setRequestedSnapshot("yes");
liverateSubscription.addListener(liverateGrid);
lsClient.subscribe(liverateSubscription);
It is working without terminate the session. But showing unchanged text everywhere mostly. Whenever the rates getting change at that time only showing the rates, after that showing only UNCHANGED text. Attached the screenshot for your reference.
-
November 28th, 2017, 09:19 AM
#5
Hi rvkvino,
Please could you confirm that every slave pages declare its own instance of lsClient?
Thank you,
Giuseppe
-
November 28th, 2017, 10:39 AM
#6
Could you please give me the code sample that creating an instance from lsClient. I have tried but showing lsClinet not having constructor method.
Last edited by rvkvino; November 28th, 2017 at 10:51 AM.
-
November 28th, 2017, 12:02 PM
#7
Hi rvkvino,
Basically, in every page you should have something like this
var lsClientPageX = new LightstreamerClient(protocolToUse+"//mydomain.com:"+portToUse,"SLNSTOCKLISTDEMO_REMOTE" );
lsClientPageX.enableSharing(new Lightstreamer.ConnectionSharing("CommonConnection" , "ATTACH", "CREATE"));
Regards,
Giuseppe
-
November 28th, 2017, 01:08 PM
#8
Hi,
I have tried this already, But what happens means if I give this connection to open all the page means It terminating the session and continuously trying to reconnect the session. While I navigate the tabs more than 3 times means it disconnect the session.
-
November 28th, 2017, 02:54 PM
#9
Hi rvkvino,
Any chance to collect the client log of one of the page?
You should add to your code something like this:
the log will appear in the browser console.
Regards,
Giuseppe
-
November 29th, 2017, 07:40 AM
#10
Hi,
I have tried this like below, It is working on my browser but not working on the device.
This file written in lsconnection.js and globally included in my application.
var protocolToUse = document.location.protocol != "file:" ? document.location.protocol : "http:";
var portToUse = document.location.protocol == "https:" ? "443" : "8080";
var lsClient = new Lightstreamer.LightstreamerClient(protocolToUse+"//mydomain.com:"+portToUse,"STOCKLIST_REMOTE");
lsClient.connectionOptions.setHttpExtraHeaders({"u sername" : "bullion"});
lsClient.enableSharing(new Lightstreamer.ConnectionSharing("CommonConnection" , "ATTACH", "CREATE"));
lsClient.connect();
And all of my three controllers written the code like bellow and subscribed in this controller only.
var protocolToUse = document.location.protocol != "file:" ? document.location.protocol : "http:";
var portToUse = document.location.protocol == "https:" ? "443" : "8080";
var lsClient = new Lightstreamer.LightstreamerClient(protocolToUse+"//mydomain.com:"+portToUse,"STOCKLIST_REMOTE");
lsClient.connectionOptions.setHttpExtraHeaders({"u sername" : "bullion"});
lsClient.enableSharing(new Lightstreamer.ConnectionSharing("CommonConnection" , "ATTACH", "CREATE"));
var liverateSubscription = new Lightstreamer.Subscription("COMMAND", liverateId, fieldList);
This working well without terminate the session on browser (ionic serve --lab). But not working after build the app and check in real device.
Similar Threads
-
By dimitarn in forum Client SDKs
Replies: 5
Last Post: December 10th, 2009, 10:52 AM
-
By cbrogliato in forum Client SDKs
Replies: 1
Last Post: October 2nd, 2009, 02:13 PM
-
By codingvn in forum Client SDKs
Replies: 5
Last Post: July 17th, 2008, 10:01 AM
-
By camerone in forum Client SDKs
Replies: 1
Last Post: August 20th, 2007, 02:37 PM
-
Replies: 1
Last Post: March 15th, 2007, 02:44 PM
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
All times are GMT +1. The time now is 05:20 PM.
Bookmarks