// API callback
processResults({
"version":"1.0",
"feed":{
"title":{
"$t":"Videosmatching:pragprog",
"type":"text"
},
"entry":[{
"title":{
"$t":"Usingtmuxfor productive mouse-freeprogramming",
},
"media$group":{
"media$content":[{
"url":"http://www.youtube.com/v/JXwS7z6Dqic,
"type": "application/x-shockwave-flash",
"medium": "video",
"isDefault": "true"
}],
"media$thumbnail": [{
"url": "http://i.ytimg.com/vi/JXwS7z6Dqic/0.jpg",
"height": 360,
"width":480,
"time":"00:02:01"
}]
}
}]
}
});
Look at the code for the response carefully—it’s calling processResults(), passing
it a bunch of data. When our worker receives this response from YouTube,
it’s going to execute it. We just have to parse the data and send it back to the
user interface. We’ll pull out just the thumbnail and the video link and put
them in a new object, which we send back using postMessage():
where_next/web_workers/javascripts/worker.js
varprocessResults=function(json){
vardata,result;
for(varindex= 0; index< json.feed.entry.length;index++){
result= json.feed.entry[index]["media$group"];
data= {
thumbnail:result["media$thumbnail"][0]["url"],
videolink:result["media$content"][0]["url"]
}
postMessage(data);
}
};
Chapter 11. Where to Go Next • 246
Download from Wow! eBook <www.wowebook.com> report erratum • discuss