Tuesday, June 30, 2009

Reading .sol (SharedObjects) created by Browser Flex App in a new AIR Application - Seamless integration? Web & Desktop?

    One of the requirements was to provide seamless integration between the browser flex application serving the client needs when the network is on vs an AIR Application as an offline system when the network turns off. But the requirement isnt straight as you think. What it says is, When network is connected the end user will be using flex browser application by navigating to the URL which downloads a lot of data on to the client machine from the server which periodically gets updated based on the data-change on the server. This is stored as client side SharedObjects through the browser ran flex app. Now when the network turns off, the end user would launch the offline system that should read through earlier created sharedobjects while network was on and work through it. AIR App should also be able to write a shared object containing data required to be parsed through the browser flex app when launched (when network is back)...

    This kind of sounds so wierd to me. After hearing the requirement, i was like WHAT?? But then i started to see through different ways of achieving it. With Browser Sandbox Security, browser flex app always can get hold of SO (Shared objects) created through SharedObject.getLocal(). Even if we were to understand and agree to one common location that AIR Could understandably read, keeping the location parameter excluded for a whole lot of argument... The Important thing is to consider serialize and de-serialize a FileStream read ByteArray into AS Objects that can be natively used in the code. Well, more to that is the SharedObjects written through the browser flex app could also carry complex data structures which could carry more information rather than a simple data->name/value

   While doing the research, i went through a lot of google search - .minerva was exactly doing what i was looking for but its not open to go through the bits of it and tweak to get it working !!

Here is a sample code demoing the problem:

 


Browser Flex App creates a shared object (typed ClazzTest.as containing two public variables value1 and value2 of type string)

AIR App code that tries to read the shared object created by the browser flex app above.. (for now assume that the object location is hardcoded)

The above AIR App code doesnt work. Its just the way i wish it would. But i believe we need to go through the entire signature of SharedObject and read the bytestream in the way SharedObject is defined as an entirety like header, body etc. I just looked at the Serializer and Deserializer in AMF-PHP and that just gives me some idea. Trying to do this entirely might take a long time than to get it just working quickly... I am still on a hunt !! ------------------------------------------ If someone is looking out for a quick solution where in you wont have enough time to write an AMF object parser, you can follow my quick solution. We lowered the IE settings to allow scripting, there by i invoke a javascript function which writes the data to the flat xml file in the client machine from the flex application through ActiveXObject(), and these flat .xml files are read by the AIR app later on. Atleast this seems to work fine for me until i converge on a right solution !!

0 comments: