# HG changeset patch # User wycc # Date 1289259712 -28800 # Node ID bd9b0142fc7efbd9f499b86ffe31fd3bccabdfee # Parent 3a3734289523aa855f7edaf996df163c53aa9acb Update the sample application. We can use the ./test5 to test it now. It will download the image from the VOD server and render it in the screen. diff -r 3a3734289523 -r bd9b0142fc7e nodejs/examples/mce/background.png Binary file nodejs/examples/mce/background.png has changed diff -r 3a3734289523 -r bd9b0142fc7e nodejs/examples/mce/epg.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nodejs/examples/mce/epg.js Tue Nov 09 07:41:52 2010 +0800 @@ -0,0 +1,164 @@ +// -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*- +// vim: sw=4:ts=8:sts=4 +var http = require('http'); +var URL = require('url'); +var sys = require("sys"); +var fs = require("fs"); +var os = require("child_process"); +function EPG() +{ + var epgsrv = http.createClient(8080, '211.23.50.144'); + var cmd = '{"Protocol":"EPG-CSP","Command":"SearchRequest","ProgramCat":"MainCat"}'; + var headers={ + 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', + 'Host':'211.23.50.144:8080', + 'User-Agent':'MadButterfly', + 'Content-Type':'application/x-www-form-urlencoded' + }; + headers['Content-Length'] = cmd.length; + var request = epgsrv.request('POST', '/IPTV_EPG/EPGService.do?timestamp='+new Date().getTime(),headers); + var self = this; + sys.puts("aaaa"); + var js = ''; + request.write(cmd); + request.end(); + request.on('response', function(res) { + sys.puts("connected"); + res.on('data',function (data) { + js = js + data; + }); + res.on('end', function () { + res = JSON.parse(js); + sys.puts("parsed"); + self.onLoad(res); + + }); + }); +} + + +/** + * Check if the file has been cached. Create a symbolic to link if it is cached already. + * + */ +function isCached(cachepath,file,obj) { + var fields = cachepath.split('.'); + try { + var ext = fields.pop(); + var pngfile = cachepath; + sys.puts("ext="+ext); + if (ext != 'png') { + fields.push('png'); + pngfile = fields.join('.'); + } + var st = fs.statSync(pngfile); + try { + fs.unlinkSync(file); + } catch(e) { + } + fs.linkSync(pngfile, file); + obj.pend = obj.pend - 1; + if (obj.pend == 0) { + obj.onInitDone(); + } + return 1; + } catch(e) { + sys.puts(e); + } + return 0; +} + +/** + * Implement the mkdir -p to create the directory + */ +function CreateDirectory(cachepath) +{ + var fields = cachepath.split('/'); + var p=''; + for(i=0;i"+u[k]); + } + var c = http.createClient(8080,'211.23.50.144'); + var req = c.request('GET',u.pathname,headers); + req.end(); + req.on('response', function(res) { + res.on('data',function(data) { + fs.writeSync(f,data,0,data.length); + }); + res.on('end',function() { + fs.close(f); + var fields = cachepath.split('.'); + var ext = fields.pop(); + if (ext != "png") { + fields.push("png"); + newf = fields.join("."); + os.spawn("convert",[file,newf]); + } else { + newf = cachepath; + } + try { + fs.unlinkSync(file); + } catch(e) { + } + sys.puts("end of "+cachepath+" to "+file); + fs.symlinkSync(newf, file); + obj.pend = obj.pend - 1; + if (obj.pend == 0) { + obj.onInitDone(); + } + + }); + + }); +} + +EPG.prototype.onLoad = function(res) { + cats = res['ProgramCat']; + this.pend = cats.length; + for (i in cats) { + c = cats[i]; + httpGetFile(c['ProgramPIC'],'cat'+i+'.png',this); + } +} + + +EPG.prototype.onInitDone=function() { + if (this.loadCallback) + this.loadCallback(); +} + +EPG.prototype.registerInitDone=function(cb) { + this.loadCallback = cb; +} + +exports.EPG = EPG; diff -r 3a3734289523 -r bd9b0142fc7e nodejs/examples/mce/mainmenu.js --- a/nodejs/examples/mce/mainmenu.js Sun Nov 07 11:36:12 2010 +0800 +++ b/nodejs/examples/mce/mainmenu.js Tue Nov 09 07:41:52 2010 +0800 @@ -6,13 +6,17 @@ var animate=require("animate"); var fs = require("fs"); var EPG = require('./epg'); - +/** + * We will fetch the EPG file from the server and fetch all images required for the main category from it. + * If these files are cached, we will not fetch it again. Otherwise, we will fetch them. The EPG class is + * responsible for the cache management. + */ function MainMenu(app) { var self = this; - //var epg = new EPG.EPG(); - //epg.registerInitDone(function() { self.init();}); - self.init(); + var epg = new EPG.EPG(); + epg.registerInitDone(function() { self.init();}); + //self.init(); } MainMenu.prototype.init=function() { diff -r 3a3734289523 -r bd9b0142fc7e nodejs/examples/mce/test --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nodejs/examples/mce/test Tue Nov 09 07:41:52 2010 +0800 @@ -0,0 +1,4 @@ +#!/bin/sh + +export NODE_PATH=${PWD}/../../objs/default:${PWD}/../.. +node mbmce.js