Archive for the 'Code' Category

JobScheduler, MkII

Saturday, October 27th, 2007

I’ve just re-written the JobScheduler, but can’t commit it from this hotel which blocks everything except web traffic. The new implementation has pluggable re-scheduling strategies, with three initial implementations for running once, running at fixed intervals with a random initial wait and for running on a boundary, such as on the hour or on the minute.
Read the rest of this entry »

Ekioh http redirect is now working

Wednesday, October 24th, 2007

Thanks to Piers at Ekioh and a few emails back and forth with debug builds and information, redirects now works like in dream.
So now you can use your regular url to access Zignal.
http://lt-fannar:8088/index.svg

log4es - Logging For EcmaScript

Tuesday, October 23rd, 2007

It turned out that the log4js library we’d started adopting does not support globally configured appenders, but rather expected us to configure appenders for each individual logger. Also, it’s rather big, unwieldy and has more levels of indirection than you really want in a tight loop in javascript.

We therefore went ahead and prettied up the logging library that Árni had worked on, re-naming it to log4es to distinguish it from the two existing log4js libraries.

Read the rest of this entry »

To load Zignal in Ekioh

Tuesday, October 23rd, 2007

To be able to load Zignal in Ekioh you need to go directly to /launch/client with correct parameters because it seams like Ekioh doesn’t support redirect in the http layer.

Example url:

http://lt-fannar:8088/launch/client?JSESSIONID=&Zignal-DmrSelector=Ekioh/db3073ab7ced&Zignal-DmrTypeSelector=Ekioh/Ekioh&Zignal-MacAddress=db3073ab7ced&renderingType=svg&Zignal-AccountSelector=1&Zignal-AccountPassword=1234&Zignal-DmrDriver=ekioh

Update : Redirect now works! :)

JobScheduler and channel-switch mockup

Friday, October 19th, 2007

The below code is a complete mockup of the channel-switching messaging and interactions, without actually switching channels or showing any svg graphics. It showcases the new JobScheduler and builds on the previous example.

We set up a job scheduler which delegates to a timer adapter using the browser’s window.setTimeout(...) and window.clearTimeout(...) methods (as opposed to what’s needed on SVG browsers without a window object or in unit tests).

We next set up a model for the current playback selection and a pair of listeners for channel changes to:

  1. Display the channel-switcher window, and set or reset the timer to hide it again for one second in the future.
  2. Do nothing, but set or reset the timer to switch the playing channel for 300ms in the future.

Finally, add a job to repeatedly select a random channel every 3 seconds to trigger everything. To manually trigger channel changes, add the following code to the testbed.html file: <a href="javascript:userInputJob()">random channel!</a>
Read the rest of this entry »

ObjectReferenceModel and synchronous DWR calls

Friday, October 19th, 2007

The following testbed sets up an ObjectReferenceModel representing the channelPlaybackModel and simulates some of the interaction for our 2.0-M02 milestone. It also sets up a couple of listeners to changes to the channel playback selection.

Finally, a loop will repeatedly wait for the user to click a button, then request a random channel from the server using a synchronous call and set the channel playback selection to that.

The two listeners will log to the firebug console what they would be doing in an actually developed system.

// import com.dustindiaz.publisher
// import tv.zignal.karateka.models.ObjectReferenceModel
// import dwr:interface/ScheduleClientApi

var channelPlaybackModel = new ObjectReferenceModel();

var channelPlaybackListener = function channelPlaybackListener(event) {
    var to = event.to ? event.to.url : "nothing";
    console.info("Ask PlaybackManager to start playing " + to);
}
channelPlaybackListener.subscribe(channelPlaybackModel.changed);

var channelSwitchListener = function channelSwitchListener(event) {
    var to = event.to ? event.to.title : "nothing";
    console.info("Display that we are watching " + to);
}
channelSwitchListener.subscribe(channelPlaybackModel.changed);

for( i=0; i<10; i++ ) {
    alert("Wait for user interaction");
    var channel;
    ScheduleClientApi.getRandomTvChannel({
        async:false,
        callback: function(result) {
            channel = result;
        }
    });
    channelPlaybackModel.set(channel);
}

Publisher

Friday, October 19th, 2007

This testbed shows how Dustin Diaz’ publisher framework can be imported and used. It is structured like a unit test and may be converted into one as the infrastructure for that is made more accessible.

 Read the rest of this entry »