PDA

View Full Version : How to access the LightstreamerEngine object from a Push-page


Alessandro
02-02-2007, 05:45 PM
The preferred way to access the LightstreamerEngine (http://www.lightstreamer.com/docs/client_web_jsdoc/LightstreamerEngine.html) object from a Push-page is through the onEngineReady() (http://www.lightstreamer.com/docs/client_web_jsdoc/PushPage.html#onEngineReady) event handler callback of the PushPage object. You will be passed a reference to the LightstreamerEngine object (that you can save for subsequent uses) as soon as it is ready. A typical implementation could be the following:

var e; //LightstreamerEngine object reference
var p = new PushPage();
p.onEngineReady = function(engine) { e = engine }
p.bind();
// one on the possible ways of setting the engine
p.loadEngine(“lsengine.html?config=lsengine_config.js”);
// first alternative way
// p.loadEngineMinimal(“lsengine.html”, “MyEngine”);
// second alternative way
// p.setEngineReference(parent.frames[“MY_ENGINE_FRAME”]);
// third alternative way
// p.setEngineReference(null, “MyEngine”);

The result is that the variable “e” of the Push-page will contain a reference to the LightstreamerEngine object only when the engine is actually ready.

Mone
03-02-2007, 12:57 PM
Sometimes the "link" between the LightstreamerEngine and a Push-page is lost (eg. if the Push-page is a pop-up and the opener page - that contains the LightstreamerEngine - gets closed)
Lightstreamer web client detects such cases and notifies the PushPage object.
You should just remember to delete the stored reference when you get an onEngineLost (http://www.lightstreamer.com/docs/client_web_jsdoc/PushPage.html#onEngineLost) call:
p.onEngineLost = function() { e = null; }