Wednesday, May 16, 2007

REST-ful Rails reflections, SlIcer, and the 3D Web

So I've been quite busy throwing together a web/Second Life mash-up, implementing ideas outlined in a previous post. The basic premise is to build a framework, (I apply the term loosely, perhaps 'hack' is the more appropriate term), that could start bridging the gap between Second Life and the web.

I called the framework SlIcer for the hell of it, and began implementing it using Rails. The basic functions I'm working on include:

  • A set of sensors, deployed into Second Life, to detect people, and to detect scripted objects within range. These sensors are installed in various areas, and tuned for sensor range and angle to provide localized service. The sensors repeatedly sweep for named objects and people, and report up to SlIcer via HttpRequest with the object name, second life key, and the location vector. It would certainly be possible to add state properties to the report for real-life storage as well.
  • Co-located with certain sensor types are 'hubs', which act as the bridge between Second Life and real life. This may be a dumb idea, but I thought it useful to create a database to store and forward incoming data in SlIcer. The hub would poll SlIcer, and get messages as bundles. The bundles are pulled into Second Life, marked as distributed in the database, and then distributed to the target objects in range. The main benefits are:
    • A real time view of the objects in range, and the current position. Again, state properties are also possible. External applications could use this data in ways I quite haven't come up with yet...
    • An ability for real life apps to address objects within Second Life by a 'plain english' handle. This obviates the need to know the current key of a rezzed object in the sim.
  • A plain http call can be put into any application to post message bound for a Second Life object. Any application can push data into Second Life without any SL cruft, as long as the name of the target object is known.
  • The (future) ability to add reliable delivery (sequencing of messages, and delivery confirmation) semantics if this seems useful.
A later development might be to have some sort of event pub/sub mechanism. For example, anytime an object within a location is touched, it could report that event, and listeners outside of Second Life could tie in. We're looking at ambient orbs, as an example. It would be possible, given these mechanisms, to watch for certain thresholds of people occupying a certain room in a sim, and change the orb status...really, any number of interesting things would be possible.

So I've got the basics working using Rails. I have not tried NetBeans and Rails yet, sticking with RadRails for now, that seems to be all I need at this point. My original impulse was to use a REST-ful approach, given the new facilities in Rails for scaffold_resource. The particulars are described in this great tutorial. This was particularly attractive as the llHttpRequest LSL function supported GET, POST, PUT, and DELETE>. At any rate, I had some initial success, but rapidly ran into strange problems with Second Life. There are likely some strange ACCEPT headers sent out from an HttpRequest, because I began running into strange 406 Not Acceptable errors. Lazy developer I am, I just decided to punt REST for now, and just use GET and POST within normal Rails controllers. Now it works fine. I'll go back and dig when I have time...but I just don't.

It's an odd thing if you think about it. I was going through all sorts of gyrations to implement REST-ful interfaces, which was supposed to make things 'simple'. Really, the gyrations were there so I could code to a particular programming philosophy, and while attaining a philosophically pure implementation still has it's attraction, I was wasting time. Ironic!

I want to add props for a pretty interesting blog on the 3D web, there's more out there than I thought, and I thought I was pretty tiresome hyping this technology around my shop! Look through some of the reported developments, and see if you agree...hype or not?

Well, the sim is down for mx, hence attention to the blog. I'll put up some screen shots of how we're using SlIcer when I can get back in! Cheers...


Anonymous said...

mike: I too am tying to Ruby on RAILS via REST to POST datainto a db from SL using HttpRequest, and yes I'm getting the 406 error as well.

I'm hoping that you may have moved on with this and can shed sme light on the solution? Failing that I'd appreciate more detail on hw you solved the problem in the more traditional way. All this is new to me so if tradition works then I'd be happy.

Can you help? Thanks.

slant said...

I also received a 406 when I attempted this. I discovered that it is due to the XML not being formed in a way that SL likes. Not sure what about it is malformed, but it is nonetheless refusing the feed as a valid response.

Have either of you had any luck since then?