Friday, April 23rd, 2010

Oni Rocket: Stratifying on the server side

Category: JavaScript, Server

<p>Alexander Fritze has been working on some very interesting developments. We have talked about his Stratified JavaScript library in the past, and he has brought his model to the server with with Oni Rocket. He tells us more:

Earlier this year I teamed up with my ex-Joost colleague Tom Germeau to found Oni Labs (http://www.onilabs.com/), where we are pursuing the ‘stratified’ idea to build a complete platform for developing web apps.

Our product, “Oni Rocket”, is an asynchronous web server similar to nodejs but programmable in the callback-less ‘stratified’ way enabled by SJS. Like nodejs, we use Google’s V8 under the hood.

On top of the server we run the “Rocket Framework”, which provides things like the CommonJS module system on both client and server and enables seamless bidirectional SJS calls between client and server. Among the modules is “Oni Surface”, a small UI toolkit for cross-platform box layout a la Flex or XUL, but of course everything is also fully compatible with existing JS libraries and UI frameworks.

The current plan is to make a first release of Rocket sometime this summer, and at the moment it looks like we’re pretty much on track.

There is a nice write up here with sample code:

javascript
< view plain text >
  1. // the server API
  2. var cluster = require("cluster");
  3.  
  4. var chat = cluster.createBroadcaster(api, {backlog: 10});
  5.  
  6. api.exports.connect = function () {
  7.   return chat.register(this);
  8. };
  9.  
  10. // the client API
  11. var s = require("surface");
  12. var b = require("bridge");
  13.  
  14. var main = s.VBox({w:"*", h:"*"},
  15.   s.VBox({w:"*", class: "surface-title"}, s.Label({w:"|"},"Chat")),
  16.   s.VBox({h:"*", w:"*", name: "messages"}),
  17.   s.HBox({w:"*", class: "surface-toolbar", name: "toolbar"},
  18.     s.TextInput({w:"*", style: "margin: 5px", name: "text"})
  19.   )
  20. );
  21.  
  22. s.surface.append(main);
  23. var chat = b.call("chat.connect");
  24.  
  25. waitfor {
  26.   while (true) {
  27.     var message = chat.waitForMessage();
  28.     main.messages.append(s.Label(message));
  29.   }
  30. } or {
  31.   while (true) {
  32.     main.toolbar.text.waitFor("keydown", function (ee) {
  33.       return ee.event.keyCode == 13;
  34.     });
  35.     chat.broadcast(main.toolbar.text.getValue());
  36.     main.toolbar.text.setValue("");
  37.   }
  38. }

Posted by Dion Almaer at 6:17 am
5 Comments

++++-
4 rating from 2 votes

5 Comments »

Comments feed TrackBack URI

wow, thanks guys. I’m flattered and somewhat interested :D

Comment by oni — April 23, 2010

This is interesting.. I like the idea of stradlling the client and server more seamlessly. I also like the blocking style of event binding.

Comment by AlexeiWhite — April 23, 2010

I get goosebumps thinking of the apps that could be built with these type of technologies! It seems like tighter serverside and client side integration is a really hot topic right now.

Comment by chuckles1313 — April 23, 2010

Definitely very interesting concept to have this unification happening, although I do wonder about more complex scenarios. Additionally it seems like the api callback stuff could be made nicer by having the bridge return a proxy object where you call methods on it as normal and those are really delegated to the service, rather than using call and passing strings.

Comment by meandmycode — April 24, 2010

@meandmycode:

I understand that it’s difficult to extrapolate from the simple example we present in the video, especially since we don’t use a lot of SJS’s “stratified” capabilities (at least not on the surface – the bridge and the Rocket framework itself make quite extensive use of SJS). We’ll hopefully have some examples that focus more in-depth on SJS soon.

About the api call interface: At the time of making the video we were lacking a crossbrowser SJS implementation of __noSuchMethod__, hence the akward indirect calls. We are working on sugaring the syntax, and it will pretty much look exactly like you suggest :-)

Comment by afri — April 24, 2010

Leave a comment

You must be logged in to post a comment.