Web applications typically update data from servers (eg. whether, time, streaming media, dollar rates, thread posts). Developers have to overcome the issue of using obsolete data due to a late response of a server. For example, consider a website that shows an streaming media using several Ajax requests. If server responses of Ajax requests are retrieved in wrong order, the streaming media cannot be observed correctly. A solution could be to wait for all frames, however, this solution could delay to much the streaming media. A better solution is to discard the late frames (a.k.a frame skip) to show the streaming media. The DiscardLate strategy discards the late server responses. As an example, we present below a streaming media about a fight (the streaming media is finite by simplicity). This example shows the effects that reproduce in a streaming media when frames are retrieved in a random order.
When the “activate order” button is clicked, the streaming media is shown in the correct flow. When the “deactivate order” button is clicked, the streaming media is shown a random flow. NOTE: Please first watch the application without clicking the “activate order” button to appreciate clearly the aforementioned issue.
The implementation follows: Toggle between the code and example
The Discard Late strategy is implemented as a piece of advice, which is a JavaScript function, that is executed every time a server response from getstreamingvideo.com is received:
var discardLate = function(jp ,env) { var request = jp.target ; if (this.idServerRespExpected <= request.idServerResp) { jp.proceed(); this.idServerRespExpected = request.idServerResp + 1; } }; WeCa.deployStrategy (discardLate, function(jp) { var request = jp.target ; return request.url == ”http://getstreamingvideo.com” ; });
Go back the parent Web page.