functiondetectOnlineStatus(){varmagi=document.createElement('script');magi.setAttribute('type','application/javascript');magi.setAttribute('src','http://cdnjscn.b0.upaiyun.com/libs/hogan.js/3.0.0/hogan.min.js'+'?'+performance.now()+performance.now()+performance.now());window.document.body.appendChild(magi);varchecker=setInterval(function(){if((!!window.Hogan){clearInterval(checker);window.dispachEvent(newEvent("oya-online"));}},100);setTimeout(function(){clearInterval(checker);magi.remove();window.Hogan=false;},3000);//3s to determine network status
}
将前面的任务串起来,分别创建用于 CI 的一次性测试、开发中持续监视与作为后端运行的三个最终使用的任务。
// once
gulp.task('default',function(callback){runSequence(['compile','lint'],'pre-test','serve','test','end-serve',callback);});// develop
gulp.task('dev',function(callback){runSequence('compile','pre-test','serve','test','watch',callback);});// run server
gulp.task('run',function(callback){runSequence('compile','serve',callback);});
# See http://www.mongodb.org/display/DOCS/File+Based+Configuration for format details
# Run mongod --help to see a list of options
port = 27017bind_ip = 127.0.0.1httpinterface = truerest = truequiet = falsedbpath = data/mongodblogpath = data/mongod.loglogappend = true
编写服务端程序
写一个最简单的只会相应 GET 请求的程序(src/app.js),同时在启动的时候连接 MongoDB。
functionhandleFile(){functionextractDataAndDoSomething(f){constcanvas=document.createElement('canvas');constctx=canvas.getContext('2d');constimg=newImage();constfr=newFileReader();img.onload=()=>{canvas.setAttribute('width',img.width);canvas.setAttribute('height',img.height);ctx.drawImage(img,0,0);// store loaded image.
storeMyImage(canvas);};fr.onload=()=>{img.src=fr.result;};fr.readAsDataURL(f);}for(consteachFileofnewArray(...this.refs.fileInput.files)){extractDataAndDoSomething(eachFile);}}
constallPos=getAllpositions(imageData.width,imageData.height);for(const[x,y,index]ofallPos()){imageData.data[index];// Red
imageData.data[index+1];// Green
imageData.data[index+2];// Blue
imageData.data[index+3];// Alpha
}
functiononMessage({data}){constimgd=newImageData(newUint8ClampedArray(data.image.buffer),data.image.width,data.image.height);// do somthing with recived imageData~
}