ObjectReferenceModel and synchronous DWR calls

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);
}

Leave a Reply

You must be logged in to post a comment.