Javascript sending message to Livecode

Bringing the internet highway into your project? Building FTP, HTTP, email, chat or other client solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
dhurtt
Posts: 42
Joined: Sat Nov 09, 2013 7:37 pm

Javascript sending message to Livecode

Post by dhurtt » Thu Jan 16, 2014 6:06 am

I found the example of Livecode calling a Javascript function with "do", but I was wondering if there is some way for Javascript to send a message to Livecode, where I could then write a handler to process it.

Here is the background: Firebase has a REST API, which I have successfully accessed from Livecode on both a Mac and iOS, but it has some limitations. The primary issue is that the REST API does not (cannot?) support callbacks so that when data updates on Firebase the new data – and only the new data - is sent to the client. Their Javascript library, however, does this quite easily. I wrote a small HTML app that uses the JavaScript client and it essentially does exactly what I need. If I use the REST API I can do something similar, but I typically get back more data than I want and have to parse through the chaff. This is not sustainable for several reason, the least of which is that you pay for bandwidth, so if you are shipping back data that you don't use, you will be throwing away money.

So the idea is to create a simple HTML file with embedded Javascript and include those files with the standalone app (iOS is my primary concern). I would then open a browser window (probably off-screen, invisible, or with a 1-pixel size, not sure yet) and using the ability for Livecode to trigger Javascript functions using the "do" command. The basic issue is that Javascript registers an event listener with Firebase so that when new data comes in, just that data is sent to the Javascript callback function. I would like Javascript to then "pass" the event to Livecode so that it can be handled. This would save me from having Livecode "poll" the browser by calling a Javascript function periodically.

Does anyone know of any way to do this?

If I am not clear, please let me know. This is sort of hard to describe with visuals. Thanks in advance.,

Dale

dhurtt
Posts: 42
Joined: Sat Nov 09, 2013 7:37 pm

Re: Javascript sending message to Livecode

Post by dhurtt » Fri Jan 17, 2014 5:47 pm

I found the answer over in this post. The basic answer is that Javascript cannot speak to Livecode because it appears to be out of its context, but it can speak to the browser. The browser in turn can communicate with Livecode through the event messages it passes to Livecode to handle. I had thought I would end up using hashcodes in the URL and once I started honing in on that as a possible solution, my searches in the Livecode forum came up with better info. As always, someone has already asked it, it is just a matter of finding the right question!

Post Reply