2

I hope questions from beginners are acceptable. I don't mind studying, but based on research so far, I'm not sure where to even begin........

I'm in need of a script that can fit into a small URI space (around 1,000 characters or less) that will rapidly update itself with information parsed by a server script (lsl/mono served by a meta-verse object over http).

The target browser is the built in media viewer of the Second Life viewer (Mozilla based). The parsed html will come from an LSL/mono script. I am attempting to display the resulting html on a primitive inside the Second Life meta-verse (which basically just turns the prim face into a kind of UV projected browser window) at an update resolution from 0.2 to 0.5 seconds.

I gather that I need something like ajax to constantly ping a serving object for the refreshed dynamic information and update a section in the initial URI? I'm at a loss as to how to set this up.

Already Tried: I've tried simply putting my small bit of html in the URI itself and having the meta-verse's mono/lsl script force a browser update, and this works to some degree, but forcing a media refresh via such a script is throttled to a reliable refresh resolution of around 2 seconds. I really need the refresh to be fully client side instead...at a resolution of more like 0.2 seconds, as the information is used to update a moving vehicle's digital dash instruments.

Already Tried: Just using a meta based refresh in the URI. Either I did it wrong, or it just doesn't work. Would such a method support a resolution of less than a second anyway?

Also attempted using script examples about ajax from this web site, and while they give good example code, they don't show how to set up the headers and such in the browser to use whatever libraries they're speaking of (it's assumed at the level of those threads the reader knows what libraries they're talking about and how to set them up)...so none of that works for me at this point.

The server script parses a simple bit of dynamically refreshed html formatted text. It could all be dumped into a single div area on each refresh pass.

Example of html that requires rapid parsing:

<body bgcolor="black">
<font size="7" color="cyan"><center>
Throttle: 50%<br>
Speed: 40<br>
Bearing: 100, 100, 1000<hr="red">
HP: 200 - Kills: 3<br>
Damage Dealt: 1000
</center></body>

Or if it's more efficient, it could be dumped as simple variable updates for a more advanced script that only change 'the numbers' in a table? But I have no idea how to do that either.

I think I have a pretty good understanding on how to get the server side scripts to parse the required html I wish to display. I'm just at a total loss on how to set up a URI that will ask for it every 0.2 seconds from the client-side...and avoid pulling that information from a 'cache' rather than the actual target url.

Credo
  • 21
  • 3
  • Use web sockets: http://socket.io – royhowie May 17 '15 at 00:45
  • What is _"a small URI space (around 1,000 characters or less)"_ ? Total `js` that updates `div` 1,000 characters or less ? – guest271314 May 17 '15 at 01:04
  • The meta verse can take a URI (as opposed to a url) of limited space, which can contain a small script, or a small web page. – Credo May 17 '15 at 01:11
  • If the script is larger than that, I could probably still use it, but I'd have to serve the entire script at least once from a server somewhere. No big deal if that is necessary. I'm just hoping to keep it simple as I 'learn' the basics :) – Credo May 17 '15 at 01:13
  • Here is a bit of an overview: http://wiki.secondlife.com/wiki/Shared_Media_and_data_URIs – Credo May 17 '15 at 01:15
  • Is requirement to embed script within a `data URI` that updates _"Example of html that requires rapid parsing"_ ? Or both script and `html` to update ? Would jQuery already be defined at page ? – guest271314 May 17 '15 at 01:46
  • In short, I think I just need a really small script that stays resident in the browser, and pings my server-side url every 0.2 seconds to get its 'body' html and display it. If it's less than 1,000 characters, I can load up the script right into the address bar of the viewer (using a metaverse script) and start the whole ball rolling. If it's longer than 32k, then I'll need to get the script from a url instead of a URI. – Credo May 17 '15 at 01:49
  • 1. Secondlife servers ask my client side viewer to load up a uri or url. I use a mono script to get this far. 2. Once the viewer starts running the script, I want that to stay resident and just keep pinging the server-object to refresh the html body every 0.2 seconds. Eventually I'd like to learn to get fancy with this and do more complex displays, but for now I'm happy to try to understand how to refresh one simple div, or the entire page display that rapidly. – Credo May 17 '15 at 02:00

1 Answers1

0

If interpret Question correctly , try utilizing XMLHttpRequest

var js = 'data:text/html;charset=utf-8,<html><script>(function r(){var x=new XMLHttpRequest();x.open("GET","https://gist.githubusercontent.com/anonymous/27e432abdb3c506aaa04/raw/109eb3da644a4bbc4aaa4d10ed286471a31b9655/update.html",true);x.onload=function(){document.write(x.responseText);setTimeout(function(){console.log(r)},200)};x.send()}())</script></html>';

431 characters

// note, `console.log(r)` called at `x.onload` instead of `r()` , 
// at stacksnippets ; to prevent recursive call to `r` , multiple requests , here
var js = 'data:text/html;charset=utf-8,%3Chtml%3E%3Cscript%3E(function%20r()%7Bvar%20x%3Dnew%20XMLHttpRequest()%3Bx.open(%22GET%22%2C%22https%3A%2F%2Fgist.githubusercontent.com%2Fanonymous%2F27e432abdb3c506aaa04%2Fraw%2F109eb3da644a4bbc4aaa4d10ed286471a31b9655%2Fupdate.html%22%2Ctrue)%3Bx.onload%3Dfunction()%7Bdocument.write(x.responseText)%3BsetTimeout(function()%7Bconsole.log(r)%7D%2C200)%7D%3Bx.send()%7D())%3C%2Fscript%3E%3C%2Fhtml%3E';

location.href = js;
guest271314
  • 1
  • 15
  • 104
  • 177