/*! Epson ePOS SDK Version 2.12.0 Copyright(C) Seiko Epson Corporation 2016 - 2019. All rights reserved. */ (function(window,undefined){function callbackInfo(){this.callbackInfoList=new Object()}callbackInfo.prototype={addCallback:function(callback,sq){this.callbackInfoList[sq]=callback},removeCallback:function(sq){for(var i in this.callbackInfoList){if(i==sq){delete this.callbackInfoList[i];return}}},getCallback:function(sq){if(this.callbackInfoList[sq]!=null){return this.callbackInfoList[sq]}return null}};function CommBox(boxID,commBoxManager,callbackInfo){this.ERROR_OK="OK";this.ERROR_NOT_OPENED="NOT_OPENED";this.ERROR_MEMBER_NOT_FOUND="MEMBER_NOT_FOUND";this.ERROR_SYSTEM_ERROR="SYSTEM_ERROR";this.boxID=boxID;this.commBoxManager=commBoxManager;this.callbackInfo=callbackInfo;this.onreceive=null;this.connectionObj=this.commBoxManager.connectionObj}CommBox.prototype={getCommHistory:function(option,callback){var _option=(typeof(option)=="function")?null:option;var _callback=(typeof(option)=="function")?option:callback;var allHistory=((_option==null)||(_option.allHistory==null))?false:option.allHistory;var data={type:"getcommhistory",box_id:this.boxID,all_history:allHistory};var eposmsg=MessageFactory.getCommBoxDataMessage(data);if(!this.commBoxManager.isOpened(this.getBoxId())){if(_callback!=null){_callback(this.ERROR_NOT_OPENED,null,eposmsg.sequence)}return eposmsg.sequence}this.callbackInfo.addCallback(_callback,eposmsg.sequence);this.connectionObj.emit(eposmsg);return eposmsg.sequence},send:function(message,memberID,callback){var data={type:"send",box_id:this.boxID,message:message,member_id:memberID};var eposmsg=MessageFactory.getCommBoxDataMessage(data);if(!this.commBoxManager.isOpened(this.getBoxId())){if(callback!=null){callback(this.ERROR_NOT_OPENED,0,eposmsg.sequence)}return eposmsg.sequence}this.callbackInfo.addCallback(callback,eposmsg.sequence);this.connectionObj.emit(eposmsg);return eposmsg.sequence},client_getcommhistory:function(data,sq){var code=data.code;var historyList=data.history_list;var getCommHistoryCB=this.callbackInfo.getCallback(sq);this.callbackInfo.removeCallback(sq);if(getCommHistoryCB!=null){getCommHistoryCB(code,historyList,sq)}return},client_send:function(data,sq){var code=data.code;var count=data.count;var sendCB=this.callbackInfo.getCallback(sq);this.callbackInfo.removeCallback(sq);if(sendCB!=null){sendCB(code,count,sq)}return},client_onreceive:function(data,sq){var rcvData=new Object();rcvData.senderId=data.sender_id;rcvData.receiverId=data.receiver_id;rcvData.message=data.message;if(this.onreceive!=null){this.onreceive(rcvData)}return},getBoxId:function(){return this.boxID}};function CommBoxManager(){this.ERROR_OK="OK";this.ERROR_BOX_COUNT_OVER="BOX_COUNT_OVER";this.ERROR_BOX_CLIENT_OVER="BOX_CLIENT_OVER";this.ERROR_MEMBERID_ALREADY_USED="MEMBERID_ALREADY_USED";this.ERROR_ALREADY_OPENED="ALREADY_OPENED";this.ERROR_NOT_OPENED="NOT_OPENED";this.ERROR_PARAMETER_ERROR="PARAMETER_ERROR";this.ERROR_SYSTEM_ERROR="SYSTEM_ERROR";this.callbackInfo=new callbackInfo();this.commBoxList=new Array();this.connectionObj=null}CommBoxManager.prototype={setConnectionObject:function(connectionObj){this.connectionObj=connectionObj},openCommBox:function(boxID,option,callback){var memberID="";if(option!=null&&option.memberID!=null){memberID=option.memberID}var data={box_id:boxID,member_id:memberID};var eposmsg=MessageFactory.getOpenCommBoxMessage(data);if(!this.connectionObj.isUsableDeviceIF()){callback(null,this.ERROR_SYSTEM_ERROR,eposmsg.sequence);return eposmsg.sequence}this.connectionObj.emit(eposmsg);this.callbackInfo.addCallback(callback,eposmsg.sequence);return eposmsg.sequence},closeCommBox:function(boxObj,callback){var data={box_id:boxID};var eposmsg=MessageFactory.getCloseCommBoxMessage(data);try{var boxID=boxObj.getBoxId();data.box_id=boxID;eposmsg=MessageFactory.getCloseCommBoxMessage(data);if(!this.isOpened(boxID)){if(callback!=null){callback(this.ERROR_NOT_OPENED,eposmsg.sequence)}return eposmsg.sequence}this.connectionObj.emit(eposmsg)}catch(e){if(callback!=null){callback(this.ERROR_PARAMETER_ERROR,eposmsg.sequence)}}this.callbackInfo.addCallback(callback,eposmsg.sequence);return eposmsg.sequence},client_opencommbox:function(data,sq){var boxID=data.box_id;var code=data.code;var commBoxObj=null;if(code==this.ERROR_OK&&this.getCommBox(boxID)==null){commBoxObj=new CommBox(boxID,this,this.callbackInfo)}if(commBoxObj!=null){this.commBoxList.push(commBoxObj)}var openCommBoxCB=this.callbackInfo.getCallback(sq);this.callbackInfo.removeCallback(sq);if(openCommBoxCB!=null){openCommBoxCB(commBoxObj,code,sq)}return},client_closecommbox:function(data,sq){var boxID=data.box_id;var code=data.code;this.removeCommBox(boxID);var closeCommBoxCB=this.callbackInfo.getCallback(sq);this.callbackInfo.removeCallback(sq);if(closeCommBoxCB!=null){closeCommBoxCB(code,sq)}return},executeCommDataCallback:function(data,sq){var boxID=data.box_id;var commBoxObj=this.getCommBox(boxID);var method="client_"+data.type;try{eval("commBoxObj."+method+"(data, sq)")}catch(e){throw new Error("")}return},getCommBox:function(boxID){var commBoxObj=null;for(var i=0;i"}catch(e){throw e}return this};Display.prototype.createWindow=function(number,x,y,width,hight,scrollMode){try{var s="";s+=getIntAttr("number",number,1,4);s+=getIntAttr("x",x,1,20);s+=getIntAttr("y",y,1,2);s+=getIntAttr("width",width,1,(21-x));s+=getIntAttr("height",hight,1,(3-y));s+=getEnumAttr("scrollmode",scrollMode,regexScrollMode);this.message+=""}catch(e){throw e}return this};Display.prototype.destroyWindow=function(number){try{var s="";s+=getIntAttr("number",number,1,4);this.message+="'}catch(e){throw e}return this};Display.prototype.setCurrentWindow=function(number){try{var s="";s+=getIntAttr("number",number,1,4);this.message+=""}catch(e){throw e}return this};Display.prototype.setCursorPosition=function(){try{var s="";s+=getIntAttr("x",arguments[0],1,20);s+=getIntAttr("y",arguments[1],1,2);this.message+=""}catch(e){throw e}return this};Display.prototype.moveCursorPosition=function(){try{var s="";s+=getEnumAttr("moveto",arguments[0],regexMoveto);this.message+=""}catch(e){throw e}return this};Display.prototype.setCursorType=function(underline){try{var s="";s+=getEnumAttr("type",underline,regexUnderline);this.message+=""}catch(e){throw e}return this};Display.prototype.addText=function(){try{var s="";switch(arguments.length){case 1:break;case 2:s+=' lang="'+arguments[1]+'"';break;case 3:s+=getIntAttr("x",arguments[1],1,20);s+=getIntAttr("y",arguments[2],1,2);break;case 4:s+=getIntAttr("x",arguments[1],1,20);s+=getIntAttr("y",arguments[2],1,2);s+=' lang="'+arguments[3]+'"';break;default:throw new Error("Parameters are invalid");break}this.message+=""+escapeMarkup(arguments[0])+""}catch(e){throw e}return this};Display.prototype.addReverseText=function(){try{var s="";switch(arguments.length){case 1:s+=getBoolAttr("reverse",true);break;case 2:s+=' lang="'+arguments[1]+'"';s+=getBoolAttr("reverse",true);break;case 3:s+=getIntAttr("x",arguments[1],1,20);s+=getIntAttr("y",arguments[2],1,2);s+=getBoolAttr("reverse",true);break;case 4:s+=getIntAttr("x",arguments[1],1,20);s+=getIntAttr("y",arguments[2],1,2);s+=' lang="'+arguments[3]+'"';s+=getBoolAttr("reverse",true);break;default:throw new Error("Parameters are invalid");break}this.message+=""+escapeMarkup(arguments[0])+""}catch(e){throw e}return this};Display.prototype.clearWindow=function(){try{this.message+=""}catch(e){throw e}return this};Display.prototype.setBlink=function(interval){try{var s="";s+=getUShortAttr("interval",interval);this.message+=""}catch(e){throw e}return this};Display.prototype.setBrightness=function(value){try{var s="";s+=getEnumAttr("value",value,regexBrightness);this.message+=""}catch(e){throw e}return this};Display.prototype.addMarquee=function(text,format,uwait,rwait,repeat,lang){try{var s="";s+=getEnumAttr("format",format,regexMarquee);s+=getIntAttr("uwait",uwait,0,2000);s+=getIntAttr("rwait",rwait,100,2000);s+=getIntAttr("repeat",repeat,0,127);if((typeof lang)!=="undefined"){s+=' lang="'+lang+'"'}this.message+=""+escapeMarkup(text)+""}catch(e){throw e}return this};Display.prototype.showClock=function(){try{this.message+=""}catch(e){throw e}return this};Display.prototype.addCommand=function(text){try{this.message+=""+toHexBinary(text)+""}catch(e){throw e}return this};Display.prototype.send=function(){var sq=-1;if((!this.ePosDev.eposprint)&&(this.connectionObj.isUsableDeviceIF())){try{var xml=this.toString();var data={type:"display",timeout:this.timeout,displaydata:xml};var eposmsg=MessageFactory.getDeviceDataMessage(this.deviceID,data,this.isCrypto);this.connectionObj.emit(eposmsg);sq=eposmsg.sequence;this.message=""}catch(e){sq=-1}}else{var self=this,address=this.connectionObj.getAddressWithProtocol()+"/cgi-bin/eposDisp/service.cgi?devid="+this.deviceID+"&timeout="+this.timeout,soap,xhr,tid,res,success,code,status;res={};soap='';soap+=""+this.toString()+"";if(window.XMLHttpRequest){xhr=new XMLHttpRequest();if(!("withCredentials" in xhr)&&window.XDomainRequest){xhr=new XDomainRequest();xhr.open("POST",address,true);xhr.onload=function(){res=xhr.responseText;if(/response/.test(res)){success=/success\s*=\s*"\s*(1|true)\s*"/.test(res);code=res.match(/code\s*=\s*"\s*(\S*)\s*"/)?RegExp.$1:"";status=res.match(/status\s*=\s*"\s*(\d+)\s*"/)?parseInt(RegExp.$1):0;self.fireReceiveEvent(success,code,status,0)}else{self.fireErrorEvent(0,xhr.responseText,0)}};xhr.onerror=function(){self.fireErrorEvent(0,xhr.responseText,0)};xhr.onprogress=function(){};xhr.ontimeout=xhr.onerror;xhr.timeout=self.timeout;xhr.send(soap)}else{xhr.open("POST",address,true);xhr.setRequestHeader("Content-Type","text/xml; charset=utf-8");xhr.setRequestHeader("If-Modified-Since","Thu, 01 Jan 1970 00:00:00 GMT");xhr.setRequestHeader("SOAPAction",'""');xhr.onreadystatechange=function(){if(xhr.readyState==4){clearTimeout(tid);if(xhr.status==200&&xhr.responseXML){res=xhr.responseXML.getElementsByTagName("response");if(res.length>0){success=/^(1|true)$/.test(res[0].getAttribute("success"));code=res[0].hasAttribute("code")?res[0].getAttribute("code"):"";status=res[0].hasAttribute("status")?parseInt(res[0].getAttribute("status")):0;self.fireReceiveEvent(success,code,status,0)}else{self.fireErrorEvent(xhr.status,xhr.responseText,0)}}else{self.fireErrorEvent(xhr.status,xhr.responseText,0)}}};tid=setTimeout(function(){xhr.abort()},this.timeout);xhr.send(soap)}this.message=""}else{throw new Error("XMLHttpRequest is not supported")}sq=0}return sq};Display.prototype.fireReceiveEvent=function(success,code,status,sq){if(code=="EX_ENPC_TIMEOUT"){code="ERROR_DEVICE_BUSY"}if(this.onreceive){this.onreceive({success:success,code:code,status:status},sq)}};Display.prototype.fireErrorEvent=function(status,responseText,sq){if(this.onerror){this.onerror({status:0,responseText:this.ASB_NO_RESPONSE},sq)}this.ePosDev.cleanup()};Display.prototype.client_onxmlresult=function(res,sq){if(res){var xml=res.resultdata;var success=/success\s*=\s*"\s*(1|true)\s*"/.test(xml);xml.match(/code\s*=\s*"\s*(\S*)\s*"/);var code=RegExp.$1;xml.match(/status\s*=\s*"\s*(\d+)\s*"/);var status=parseInt(RegExp.$1);if(this.onreceive){this.onreceive({success:success,code:code,status:status},sq)}}else{if(this.onerror){this.onerror({status:0,responseText:this.ASB_NO_RESPONSE},sq)}this.ePosDev.cleanup()}};Display.prototype.toString=function(){var epos=''+this.message+"";return epos};Display.prototype.setXmlString=function(xml){this.message=xml};Display.prototype.getXmlString=function(){return this.message};Display.prototype.callEvent=function(eventName,data){var eventReq={type:eventName,data:data};var eposmsg=MessageFactory.getDeviceDataMessage(this.deviceID,data,this.isCrypto);var sequence=-1;try{this.connectionObj.emit(eposmsg);sequence=eposmsg.sequence}catch(e){}return sequence};var regexBrightness=/^(20|40|60|100)$/;var regexScrollMode=/^(overwrite|v_scroll|h_scroll)$/;var regexMoveto=/^(top_left|top_right|bottom_left|bottom_right)$/;var regexUnderline=/^(none|underline)$/;var regexMarquee=/^(walk|place)$/;function OtherPeripheral(deviceID,isCrypto){this.deviceID=deviceID;this.isCrypto=isCrypto;this.connectionObj=null}OtherPeripheral.prototype={setConnectionObject:function(connectionObj){this.connectionObj=connectionObj},send:function(methodName,data){var _data={};for(var key in data){_data[key]=data[key]}_data.type=methodName;var eposmsg=MessageFactory.getDeviceDataMessage(this.deviceID,_data,this.isCrypto);var sequence=-1;try{this.connectionObj.emit(eposmsg);sequence=eposmsg.sequence}catch(e){}return sequence},client_onreceive:function(data){try{var eventData=data;delete eventData.type;this.onreceive(data.type,eventData)}catch(e){}return},callEvent:function(eventName,data){var eventReq={type:eventName,data:data};var eposmsg=MessageFactory.getDeviceDataMessage(this.deviceID,data,this.isCrypto);var sequence=-1;try{this.connectionObj.emit(eposmsg);sequence=eposmsg.sequence}catch(e){}return sequence}};function Keyboard(deviceID,isCrypto){this.VK_CANCEL=3;this.VK_BACK=8;this.VK_TAB=9;this.VK_RETURN=13;this.VK_SHIFT=16;this.VK_CONTROL=17;this.VK_MENU=18;this.VK_PAUSE=19;this.VK_CAPITAL=20;this.VK_KANA=21;this.VK_ESCAPE=27;this.VK_CONVERT=28;this.VK_NONCONVERT=29;this.VK_SPACE=32;this.VK_PRIOR=33;this.VK_NEXT=34;this.VK_END=35;this.VK_HOME=36;this.VK_LEFT=37;this.VK_UP=38;this.VK_RIGHT=39;this.VK_DOWN=40;this.VK_INSERT=45;this.VK_DELETE=46;this.VK_0=48;this.VK_1=49;this.VK_2=50;this.VK_3=51;this.VK_4=52;this.VK_5=53;this.VK_6=54;this.VK_7=55;this.VK_8=56;this.VK_9=57;this.VK_A=65;this.VK_B=66;this.VK_C=67;this.VK_D=68;this.VK_E=69;this.VK_F=70;this.VK_G=71;this.VK_H=72;this.VK_I=73;this.VK_J=74;this.VK_K=75;this.VK_L=76;this.VK_M=77;this.VK_N=78;this.VK_O=79;this.VK_P=80;this.VK_Q=81;this.VK_R=82;this.VK_S=83;this.VK_T=84;this.VK_U=85;this.VK_V=86;this.VK_W=87;this.VK_X=88;this.VK_Y=89;this.VK_Z=90;this.VK_LWIN=91;this.VK_RWIN=92;this.VK_APPS=93;this.VK_NUMPAD0=96;this.VK_NUMPAD1=97;this.VK_NUMPAD2=98;this.VK_NUMPAD3=99;this.VK_NUMPAD4=100;this.VK_NUMPAD5=101;this.VK_NUMPAD6=102;this.VK_NUMPAD7=103;this.VK_NUMPAD8=104;this.VK_NUMPAD9=105;this.VK_MULTIPLY=106;this.VK_ADD=107;this.VK_SEPARATOR=108;this.VK_SUBTRACT=109;this.VK_DECIMAL=110;this.VK_DIVIDE=111;this.VK_F1=112;this.VK_F2=113;this.VK_F3=114;this.VK_F4=115;this.VK_F5=116;this.VK_F6=117;this.VK_F7=118;this.VK_F8=119;this.VK_F9=120;this.VK_F10=121;this.VK_F11=122;this.VK_F12=123;this.VK_NUMLOCK=144;this.VK_SCROLL=145;this.VK_LSHIFT=160;this.VK_RSHIFT=161;this.VK_LCONTROL=162;this.VK_RCONTROL=163;this.VK_LMENU=164;this.VK_RMENU=165;this.VK_OEM_1=186;this.VK_OEM_PLUS=187;this.VK_OEM_COMMA=188;this.VK_OEM_MINUS=189;this.VK_OEM_PERIOD=190;this.VK_OEM_2=191;this.VK_OEM_3=192;this.VK_OEM_4=219;this.VK_OEM_5=220;this.VK_OEM_6=221;this.VK_OEM_7=222;this.VK_OEM_102=226;this.VK_OEM_ATTN=240;this.deviceID=deviceID;this.isCrypto=isCrypto;this.connectionObj=null}Keyboard.prototype={setConnectionObject:function(connectionObj){this.connectionObj=connectionObj},client_onkeypress:function(data){try{if(this.onkeypress==null){return}this.onkeypress(data)}catch(e){}return},client_onstring:function(data){try{if(this.onstring==null){return}this.onstring(data)}catch(e){}return},setPrefix:function(keycodes){var data={type:"setprefix"};if(typeof keycodes=="object"){if((keycodes.length==0)){return -1}data.keycodes=keycodes}else{if((keycodes==null)||(keycodes=="")){return -1}data.keycodes=[keycodes]}var eposmsg=MessageFactory.getDeviceDataMessage(this.deviceID,data,this.isCrypto);var sequence=-1;try{this.connectionObj.emit(eposmsg);sequence=eposmsg.sequence}catch(e){}return sequence},callEvent:function(eventName,data){var eventReq=data;eventReq.type=eventName;var eposmsg=MessageFactory.getDeviceDataMessage(this.deviceID,eventReq,this.isCrypto);var sequence=-1;try{this.connectionObj.emit(eposmsg);sequence=eposmsg.sequence}catch(e){}return sequence}};function MSR(deviceID,isCrypto){this.deviceID=deviceID;this.isCrypto=isCrypto;this.connectionObj=null}MSR.prototype={setConnectionObject:function(connectionObj){this.connectionObj=connectionObj},client_ondata:function(data){try{if(this.ondata==null){return}this.ondata(data)}catch(e){}return},callEvent:function(eventName,data){var eventReq=data;eventReq.type=eventName;var eposmsg=MessageFactory.getDeviceDataMessage(this.deviceID,eventReq,this.isCrypto);var sequence=-1;try{this.connectionObj.emit(eposmsg);sequence=eposmsg.sequence}catch(e){}return sequence}}; /*! Based JavaScript is ePOS-Print API Version 5.0.0 */ function ePOSBuilder(){this.message="";this.halftone=0;this.brightness=1;this.force=false;this.FONT_A="font_a";this.FONT_B="font_b";this.FONT_C="font_c";this.FONT_D="font_d";this.FONT_E="font_e";this.FONT_SPECIAL_A="special_a";this.FONT_SPECIAL_B="special_b";this.ALIGN_LEFT="left";this.ALIGN_CENTER="center";this.ALIGN_RIGHT="right";this.COLOR_NONE="none";this.COLOR_1="color_1";this.COLOR_2="color_2";this.COLOR_3="color_3";this.COLOR_4="color_4";this.FEED_PEELING="peeling";this.FEED_CUTTING="cutting";this.FEED_CURRENT_TOF="current_tof";this.FEED_NEXT_TOF="next_tof";this.MODE_MONO="mono";this.MODE_GRAY16="gray16";this.BARCODE_UPC_A="upc_a";this.BARCODE_UPC_E="upc_e";this.BARCODE_EAN13="ean13";this.BARCODE_JAN13="jan13";this.BARCODE_EAN8="ean8";this.BARCODE_JAN8="jan8";this.BARCODE_CODE39="code39";this.BARCODE_ITF="itf";this.BARCODE_CODABAR="codabar";this.BARCODE_CODE93="code93";this.BARCODE_CODE128="code128";this.BARCODE_GS1_128="gs1_128";this.BARCODE_GS1_DATABAR_OMNIDIRECTIONAL="gs1_databar_omnidirectional";this.BARCODE_GS1_DATABAR_TRUNCATED="gs1_databar_truncated";this.BARCODE_GS1_DATABAR_LIMITED="gs1_databar_limited";this.BARCODE_GS1_DATABAR_EXPANDED="gs1_databar_expanded";this.HRI_NONE="none";this.HRI_ABOVE="above";this.HRI_BELOW="below";this.HRI_BOTH="both";this.SYMBOL_PDF417_STANDARD="pdf417_standard";this.SYMBOL_PDF417_TRUNCATED="pdf417_truncated";this.SYMBOL_QRCODE_MODEL_1="qrcode_model_1";this.SYMBOL_QRCODE_MODEL_2="qrcode_model_2";this.SYMBOL_QRCODE_MICRO="qrcode_micro";this.SYMBOL_MAXICODE_MODE_2="maxicode_mode_2";this.SYMBOL_MAXICODE_MODE_3="maxicode_mode_3";this.SYMBOL_MAXICODE_MODE_4="maxicode_mode_4";this.SYMBOL_MAXICODE_MODE_5="maxicode_mode_5";this.SYMBOL_MAXICODE_MODE_6="maxicode_mode_6";this.SYMBOL_GS1_DATABAR_STACKED="gs1_databar_stacked";this.SYMBOL_GS1_DATABAR_STACKED_OMNIDIRECTIONAL="gs1_databar_stacked_omnidirectional";this.SYMBOL_GS1_DATABAR_EXPANDED_STACKED="gs1_databar_expanded_stacked";this.SYMBOL_AZTECCODE_FULLRANGE="azteccode_fullrange";this.SYMBOL_AZTECCODE_COMPACT="azteccode_compact";this.SYMBOL_DATAMATRIX_SQUARE="datamatrix_square";this.SYMBOL_DATAMATRIX_RECTANGLE_8="datamatrix_rectangle_8";this.SYMBOL_DATAMATRIX_RECTANGLE_12="datamatrix_rectangle_12";this.SYMBOL_DATAMATRIX_RECTANGLE_16="datamatrix_rectangle_16";this.LEVEL_0="level_0";this.LEVEL_1="level_1";this.LEVEL_2="level_2";this.LEVEL_3="level_3";this.LEVEL_4="level_4";this.LEVEL_5="level_5";this.LEVEL_6="level_6";this.LEVEL_7="level_7";this.LEVEL_8="level_8";this.LEVEL_L="level_l";this.LEVEL_M="level_m";this.LEVEL_Q="level_q";this.LEVEL_H="level_h";this.LEVEL_DEFAULT="default";this.LINE_THIN="thin";this.LINE_MEDIUM="medium";this.LINE_THICK="thick";this.LINE_THIN_DOUBLE="thin_double";this.LINE_MEDIUM_DOUBLE="medium_double";this.LINE_THICK_DOUBLE="thick_double";this.DIRECTION_LEFT_TO_RIGHT="left_to_right";this.DIRECTION_BOTTOM_TO_TOP="bottom_to_top";this.DIRECTION_RIGHT_TO_LEFT="right_to_left";this.DIRECTION_TOP_TO_BOTTOM="top_to_bottom";this.CUT_NO_FEED="no_feed";this.CUT_FEED="feed";this.CUT_RESERVE="reserve";this.DRAWER_1="drawer_1";this.DRAWER_2="drawer_2";this.PULSE_100="pulse_100";this.PULSE_200="pulse_200";this.PULSE_300="pulse_300";this.PULSE_400="pulse_400";this.PULSE_500="pulse_500";this.PATTERN_NONE="none";this.PATTERN_0="pattern_0";this.PATTERN_1="pattern_1";this.PATTERN_2="pattern_2";this.PATTERN_3="pattern_3";this.PATTERN_4="pattern_4";this.PATTERN_5="pattern_5";this.PATTERN_6="pattern_6";this.PATTERN_7="pattern_7";this.PATTERN_8="pattern_8";this.PATTERN_9="pattern_9";this.PATTERN_10="pattern_10";this.PATTERN_A="pattern_a";this.PATTERN_B="pattern_b";this.PATTERN_C="pattern_c";this.PATTERN_D="pattern_d";this.PATTERN_E="pattern_e";this.PATTERN_ERROR="error";this.PATTERN_PAPER_END="paper_end";this.LAYOUT_RECEIPT="receipt";this.LAYOUT_RECEIPT_BM="receipt_bm";this.LAYOUT_LABEL="label";this.LAYOUT_LABEL_BM="label_bm";this.HALFTONE_DITHER=0;this.HALFTONE_ERROR_DIFFUSION=1;this.HALFTONE_THRESHOLD=2}ePOSBuilder.prototype.addText=function(data){this.message+=""+escapeMarkup(data)+"";return this};ePOSBuilder.prototype.addTextLang=function(lang){this.message+='';return this};ePOSBuilder.prototype.addTextAlign=function(align){var s="";s+=getEnumAttr("align",align,regexAlign);this.message+="";return this};ePOSBuilder.prototype.addTextRotate=function(rotate){var s="";s+=getBoolAttr("rotate",rotate);this.message+="";return this};ePOSBuilder.prototype.addTextLineSpace=function(linespc){var s="";s+=getUByteAttr("linespc",linespc);this.message+="";return this};ePOSBuilder.prototype.addTextFont=function(font){var s="";s+=getEnumAttr("font",font,regexFont);this.message+="";return this};ePOSBuilder.prototype.addTextSmooth=function(smooth){var s="";s+=getBoolAttr("smooth",smooth);this.message+="";return this};ePOSBuilder.prototype.addTextDouble=function(dw,dh){var s="";if(dw!==undefined){s+=getBoolAttr("dw",dw)}if(dh!==undefined){s+=getBoolAttr("dh",dh)}this.message+="";return this};ePOSBuilder.prototype.addTextSize=function(width,height){var s="";if(width!==undefined){s+=getIntAttr("width",width,1,8)}if(height!==undefined){s+=getIntAttr("height",height,1,8)}this.message+="";return this};ePOSBuilder.prototype.addTextStyle=function(reverse,ul,em,color){var s="";if(reverse!==undefined){s+=getBoolAttr("reverse",reverse)}if(ul!==undefined){s+=getBoolAttr("ul",ul)}if(em!==undefined){s+=getBoolAttr("em",em)}if(color!==undefined){s+=getEnumAttr("color",color,regexColor)}this.message+="";return this};ePOSBuilder.prototype.addTextPosition=function(x){var s="";s+=getUShortAttr("x",x);this.message+="";return this};ePOSBuilder.prototype.addTextVPosition=function(y){var s="";s+=getUShortAttr("y",y);this.message+="";return this};ePOSBuilder.prototype.addFeedUnit=function(unit){var s="";s+=getUByteAttr("unit",unit);this.message+="";return this};ePOSBuilder.prototype.addFeedLine=function(line){var s="";s+=getUByteAttr("line",line);this.message+="";return this};ePOSBuilder.prototype.addFeed=function(){this.message+="";return this};ePOSBuilder.prototype.addFeedPosition=function(pos){var s="";s+=getEnumAttr("pos",pos,regexFeed);this.message+="";return this};ePOSBuilder.prototype.addImage=function(context,x,y,width,height,color,mode){var s="",ht=this.halftone,br=this.brightness,imgdata,raster;getUShortAttr("x",x);getUShortAttr("y",y);s+=getUShortAttr("width",width);s+=getUShortAttr("height",height);if(color!==undefined){s+=getEnumAttr("color",color,regexColor)}if(mode!==undefined){s+=getEnumAttr("mode",mode,regexMode)}if(isNaN(ht)||ht<0||ht>2){throw new Error('Property "halftone" is invalid')}if(isNaN(br)||br<0.1||br>10){throw new Error('Property "brightness" is invalid')}imgdata=context.getImageData(x,y,width,height);raster=(mode==this.MODE_GRAY16)?toGrayImage(imgdata,br):toMonoImage(imgdata,ht,br);this.message+=""+toBase64Binary(raster)+"";return this};ePOSBuilder.prototype.addLogo=function(key1,key2){var s="";s+=getUByteAttr("key1",key1);s+=getUByteAttr("key2",key2);this.message+="";return this};ePOSBuilder.prototype.addBarcode=function(data,type,hri,font,width,height){var s="";s+=getEnumAttr("type",type,regexBarcode);if(hri!==undefined){s+=getEnumAttr("hri",hri,regexHri)}if(font!==undefined){s+=getEnumAttr("font",font,regexFont)}if(width!==undefined){s+=getUByteAttr("width",width)}if(height!==undefined){s+=getUByteAttr("height",height)}this.message+=""+escapeControl(escapeMarkup(data))+"";return this};ePOSBuilder.prototype.addSymbol=function(data,type,level,width,height,size){var s="";s+=getEnumAttr("type",type,regexSymbol);if(level!==undefined){s+=getEnumIntAttr("level",level,regexLevel,0,255)}if(width!==undefined){s+=getUByteAttr("width",width)}if(height!==undefined){s+=getUByteAttr("height",height)}if(size!==undefined){s+=getUShortAttr("size",size)}this.message+=""+escapeControl(escapeMarkup(data))+"";return this};ePOSBuilder.prototype.addHLine=function(x1,x2,style){var s="";s+=getUShortAttr("x1",x1);s+=getUShortAttr("x2",x2);if(style!==undefined){s+=getEnumAttr("style",style,regexLine)}this.message+="";return this};ePOSBuilder.prototype.addVLineBegin=function(x,style){var s="";s+=getUShortAttr("x",x);if(style!==undefined){s+=getEnumAttr("style",style,regexLine)}this.message+="";return this};ePOSBuilder.prototype.addVLineEnd=function(x,style){var s="";s+=getUShortAttr("x",x);if(style!==undefined){s+=getEnumAttr("style",style,regexLine)}this.message+="";return this};ePOSBuilder.prototype.addPageBegin=function(){this.message+="";return this};ePOSBuilder.prototype.addPageEnd=function(){this.message+="";return this};ePOSBuilder.prototype.addPageArea=function(x,y,width,height){var s="";s+=getUShortAttr("x",x);s+=getUShortAttr("y",y);s+=getUShortAttr("width",width);s+=getUShortAttr("height",height);this.message+="";return this};ePOSBuilder.prototype.addPageDirection=function(dir){var s="";s+=getEnumAttr("dir",dir,regexDirection);this.message+="";return this};ePOSBuilder.prototype.addPagePosition=function(x,y){var s="";s+=getUShortAttr("x",x);s+=getUShortAttr("y",y);this.message+="";return this};ePOSBuilder.prototype.addPageLine=function(x1,y1,x2,y2,style){var s="";s+=getUShortAttr("x1",x1);s+=getUShortAttr("y1",y1);s+=getUShortAttr("x2",x2);s+=getUShortAttr("y2",y2);if(style!==undefined){s+=getEnumAttr("style",style,regexLine)}this.message+="";return this};ePOSBuilder.prototype.addPageRectangle=function(x1,y1,x2,y2,style){var s="";s+=getUShortAttr("x1",x1);s+=getUShortAttr("y1",y1);s+=getUShortAttr("x2",x2);s+=getUShortAttr("y2",y2);if(style!==undefined){s+=getEnumAttr("style",style,regexLine)}this.message+="";return this};ePOSBuilder.prototype.addCut=function(type){var s="";if(type!==undefined){s+=getEnumAttr("type",type,regexCut)}this.message+="";return this};ePOSBuilder.prototype.addPulse=function(drawer,time){var s="";if(drawer!==undefined){s+=getEnumAttr("drawer",drawer,regexDrawer)}if(time!==undefined){s+=getEnumAttr("time",time,regexPulse)}this.message+="";return this};ePOSBuilder.prototype.addSound=function(pattern,repeat,cycle){var s="";if(pattern!==undefined){s+=getEnumAttr("pattern",pattern,regexPattern)}if(repeat!==undefined){s+=getUByteAttr("repeat",repeat)}if(cycle!==undefined){s+=getUShortAttr("cycle",cycle)}this.message+="";return this};ePOSBuilder.prototype.addLayout=function(type,width,height,margin_top,margin_bottom,offset_cut,offset_label){var s="";s+=getEnumAttr("type",type,regexLayout);if(width!==undefined){s+=getUShortAttr("width",width)}if(height!==undefined){s+=getUShortAttr("height",height)}if(margin_top!==undefined){s+=getShortAttr("margin-top",margin_top)}if(margin_bottom!==undefined){s+=getShortAttr("margin-bottom",margin_bottom)}if(offset_cut!==undefined){s+=getShortAttr("offset-cut",offset_cut)}if(offset_label!==undefined){s+=getShortAttr("offset-label",offset_label)}this.message+="";return this};ePOSBuilder.prototype.addRecovery=function(){this.message+="";return this};ePOSBuilder.prototype.addReset=function(){this.message+="";return this};ePOSBuilder.prototype.addCommand=function(data){this.message+=""+toHexBinary(data)+"";return this};ePOSBuilder.prototype.toString=function(){var s="";if(this.force){s+=getBoolAttr("force",true)}return'"+this.message+""};function toHexBinary(s){var l=s.length,r=new Array(l),i;for(i=0;i>18&63);r[j++]=t.charAt(n>>12&63);r[j++]=t.charAt(n>>6&63);r[j++]=t.charAt(n&63)}while(p--){r[--j]="="}return r.join("")}function toMonoImage(imgdata,s,g){var x=String.fromCharCode,m8=[[2,130,34,162,10,138,42,170],[194,66,226,98,202,74,234,106],[50,178,18,146,58,186,26,154],[242,114,210,82,250,122,218,90],[14,142,46,174,6,134,38,166],[206,78,238,110,198,70,230,102],[62,190,30,158,54,182,22,150],[254,126,222,94,246,118,214,86]],d=imgdata.data,w=imgdata.width,h=imgdata.height,r=new Array((w+7>>3)*h),n=0,p=0,q=0,t=128,e=new Array(),e1,e2,b,v,f,i,j;if(s==1){i=w;while(i--){e.push(0)}}for(j=0;j>4;f=v-(v0){e[i-1]+=f}e[i]=f*7+e2;e1=f*5;e2=f*3}if(v>b}i++;if(b==7||i==w){r[q++]=x(n==16?32:n);n=0}}}return r.join("")}function toGrayImage(imgdata,g){var x=String.fromCharCode,m4=[[0,9,2,11],[13,4,15,6],[3,12,1,10],[16,7,14,5]],thermal=[0,7,13,19,23,27,31,35,40,44,49,52,54,55,57,59,61,62,64,66,67,69,70,70,71,72,73,74,75,76,77,78,79,80,81,82,83,83,84,85,86,86,87,88,88,89,90,90,91,91,92,93,93,94,94,95,96,96,97,98,98,99,99,100,101,101,102,102,103,103,104,104,105,105,106,106,107,107,108,108,109,109,110,110,111,111,112,112,112,113,113,114,114,115,115,116,116,117,117,118,118,119,119,120,120,120,121,121,122,122,123,123,123,124,124,125,125,125,126,126,127,127,127,128,128,129,129,130,130,130,131,131,132,132,132,133,133,134,134,135,135,135,136,136,137,137,137,138,138,139,139,139,140,140,141,141,141,142,142,143,143,143,144,144,145,145,146,146,146,147,147,148,148,148,149,149,150,150,150,151,151,152,152,152,153,153,154,154,155,155,155,156,156,157,157,158,158,159,159,160,160,161,161,161,162,162,163,163,164,164,165,165,166,166,166,167,167,168,168,169,169,170,170,171,171,172,173,173,174,175,175,176,177,178,178,179,180,180,181,182,182,183,184,184,185,186,186,187,189,191,193,195,198,200,202,255],d=imgdata.data,w=imgdata.width,h=imgdata.height,r=new Array((w+1>>1)*h),n=0,p=0,q=0,b,v,v1,i,j;for(j=0;j&'"\t\n\r]/g;if(markup.test(s)){s=s.replace(markup,function(c){var r="";switch(c){case"<":r="<";break;case">":r=">";break;case"&":r="&";break;case"'":r="'";break;case'"':r=""";break;case"\t":r=" ";break;case"\n":r=" ";break;case"\r":r=" ";break;default:break}return r})}return s}function escapeControl(s){var control=/[\\\x00-\x1f\x7f-\xff]/g;if(control.test(s)){s=s.replace(control,function(c){return(c=="\\")?"\\\\":"\\x"+("0"+c.charCodeAt(0).toString(16)).slice(-2)})}return s}var regexFont=/^(font_[a-e]|special_[ab])$/,regexAlign=/^(left|center|right)$/,regexColor=/^(none|color_[1-4])$/,regexFeed=/^(peeling|cutting|current_tof|next_tof)$/,regexMode=/^(mono|gray16)$/,regexBarcode=/^(upc_[ae]|[ej]an13|[ej]an8|code(39|93|128)|itf|codabar|gs1_128|gs1_databar_(omnidirectional|truncated|limited|expanded))$/,regexHri=/^(none|above|below|both)$/,regexSymbol=/^(pdf417_(standard|truncated)|qrcode_(model_[12]|micro)|maxicode_mode_[2-6]|gs1_databar_(stacked(_omnidirectional)?|expanded_stacked)|azteccode_(fullrange|compact)|datamatrix_(square|rectangle_(8|12|16)))$/,regexLevel=/^(level_[0-8lmqh]|default)$/,regexLine=/^(thin|medium|thick)(_double)?$/,regexDirection=/^(left_to_right|bottom_to_top|right_to_left|top_to_bottom)$/,regexCut=/^(no_feed|feed|reserve)$/,regexDrawer=/^drawer_[12]$/,regexPulse=/^pulse_[1-5]00$/,regexPattern=/^(none|pattern_(10|[0-9a-e])|error|paper_end)$/,regexLayout=/^(receipt|label)(_bm)?$/;function getEnumAttr(name,value,regex){if(!regex.test(value)){throw new Error('Parameter "'+name+'" is invalid')}return" "+name+'="'+value+'"'}function getBoolAttr(name,value){return" "+name+'="'+!!value+'"'}function getIntAttr(name,value,min,max){if(isNaN(value)||valuemax){throw new Error('Parameter "'+name+'" is invalid')}return" "+name+'="'+value+'"'}function getUByteAttr(name,value){return getIntAttr(name,value,0,255)}function getUShortAttr(name,value){return getIntAttr(name,value,0,65535)}function getShortAttr(name,value){return getIntAttr(name,value,-32768,32767)}function getEnumIntAttr(name,value,regex,min,max){if(!regex.test(value)){if(isNaN(value)||valuemax){throw new Error('Parameter "'+name+'" is invalid')}}return" "+name+'="'+value+'"'}function ePOSPrint(address){this.address=address;this.enabled=false;this.interval=3000;this.timeout=300000;this.status=0;this.battery=0;this.drawerOpenLevel=0;this.onreceive=null;this.onerror=null;this.onstatuschange=null;this.ononline=null;this.onoffline=null;this.onpoweroff=null;this.oncoverok=null;this.oncoveropen=null;this.onpaperok=null;this.onpaperend=null;this.onpapernearend=null;this.ondrawerclosed=null;this.ondraweropen=null;this.onbatterylow=null;this.onbatteryok=null;this.onbatterystatuschange=null;this.ASB_NO_RESPONSE=1;this.ASB_PRINT_SUCCESS=2;this.ASB_DRAWER_KICK=4;this.ASB_BATTERY_OFFLINE=4;this.ASB_OFF_LINE=8;this.ASB_COVER_OPEN=32;this.ASB_PAPER_FEED=64;this.ASB_WAIT_ON_LINE=256;this.ASB_PANEL_SWITCH=512;this.ASB_MECHANICAL_ERR=1024;this.ASB_AUTOCUTTER_ERR=2048;this.ASB_UNRECOVER_ERR=8192;this.ASB_AUTORECOVER_ERR=16384;this.ASB_RECEIPT_NEAR_END=131072;this.ASB_RECEIPT_END=524288;this.ASB_BUZZER=16777216;this.ASB_WAIT_REMOVE_LABEL=16777216;this.ASB_NO_LABEL=67108864;this.ASB_SPOOLER_IS_STOPPED=2147483648;this.DRAWER_OPEN_LEVEL_LOW=0;this.DRAWER_OPEN_LEVEL_HIGH=1}ePOSPrint.prototype=new ePOSBuilder();ePOSPrint.prototype.constructor=ePOSPrint;ePOSPrint.prototype.open=function(){if(!this.enabled){this.enabled=true;this.status=0;this.battery=0;this.send()}};ePOSPrint.prototype.close=function(){this.enabled=false;if(this.intervalid){clearTimeout(this.intervalid);delete this.intervalid}if(this.intervalxhr){this.intervalxhr.abort();delete this.intervalxhr}};ePOSPrint.prototype.getPrintJobStatus=function(printjobid){this.send(printjobid)};ePOSPrint.prototype.send=function(request,printjobid){var args=arguments.length,epos=this,address=epos.address,soap,xhr,tid,res,success,code,status,battery;if(!/^';if(printjobid){soap+=''+printjobid+""}soap+=""+request+"";if(window.XMLHttpRequest){xhr=new XMLHttpRequest();if(!("withCredentials" in xhr)&&window.XDomainRequest){xhr=new XDomainRequest();xhr.open("POST",address,true);xhr.onload=function(){res=xhr.responseText;if(/response/.test(res)){success=/success\s*=\s*"\s*(1|true)\s*"/.test(res);code=res.match(/code\s*=\s*"\s*(\S*)\s*"/)?RegExp.$1:"";status=res.match(/status\s*=\s*"\s*(\d+)\s*"/)?parseInt(RegExp.$1):0;battery=res.match(/battery\s*=\s*"\s*(\d+)\s*"/)?parseInt(RegExp.$1):0;printjobid=res.match(/\s*(\S*)\s*<\/printjobid>/)?RegExp.$1:"";if(args>0){fireReceiveEvent(epos,success,code,status,battery,printjobid)}else{fireStatusEvent(epos,status,battery)}}else{if(args>0){fireErrorEvent(epos,0,xhr.responseText)}else{fireStatusEvent(epos,epos.ASB_NO_RESPONSE,0)}}if(args<1){updateStatus(epos)}};xhr.onerror=function(){if(args>0){fireErrorEvent(epos,0,xhr.responseText)}else{fireStatusEvent(epos,epos.ASB_NO_RESPONSE,0);updateStatus(epos)}};xhr.onprogress=function(){};xhr.ontimeout=xhr.onerror;xhr.timeout=epos.timeout;xhr.send(soap)}else{xhr.open("POST",address,true);xhr.setRequestHeader("Content-Type","text/xml; charset=utf-8");xhr.setRequestHeader("If-Modified-Since","Thu, 01 Jan 1970 00:00:00 GMT");xhr.setRequestHeader("SOAPAction",'""');xhr.onreadystatechange=function(){if(xhr.readyState==4){clearTimeout(tid);if(xhr.status==200&&xhr.responseXML){res=xhr.responseXML.getElementsByTagName("response");if(res.length>0){success=/^(1|true)$/.test(res[0].getAttribute("success"));code=res[0].hasAttribute("code")?res[0].getAttribute("code"):"";status=res[0].hasAttribute("status")?parseInt(res[0].getAttribute("status")):0;battery=res[0].hasAttribute("battery")?parseInt(res[0].getAttribute("battery")):0;res=xhr.responseXML.getElementsByTagName("printjobid");printjobid=res.length>0?res[0].textContent:"";if(args>0){fireReceiveEvent(epos,success,code,status,battery,printjobid)}else{fireStatusEvent(epos,status,battery)}}else{if(args>0){fireErrorEvent(epos,xhr.status,xhr.responseText)}else{fireStatusEvent(epos,epos.ASB_NO_RESPONSE,0)}}}else{if(args>0){fireErrorEvent(epos,xhr.status,xhr.responseText)}else{fireStatusEvent(epos,epos.ASB_NO_RESPONSE,0)}}if(args<1){updateStatus(epos)}}};tid=setTimeout(function(){xhr.abort()},epos.timeout);xhr.send(soap)}if(args<1){epos.intervalxhr=xhr}}else{throw new Error("XMLHttpRequest is not supported")}};function fireReceiveEvent(epos,success,code,status,battery,printjobid){if(code=="EX_ENPC_TIMEOUT"){code="ERROR_DEVICE_BUSY"}if(epos.onreceive){epos.onreceive({success:success,code:code,status:status,battery:battery,printjobid:printjobid})}}function fireStatusEvent(epos,status,battery){var diff,difb;if(status==0||status==epos.ASB_NO_RESPONSE){status=epos.status|epos.ASB_NO_RESPONSE}diff=epos.status==0?~0:epos.status^status;difb=epos.status==0?~0:epos.battery^battery;epos.status=status;epos.battery=battery;if(diff&&epos.onstatuschange){epos.onstatuschange(status)}if(difb&&epos.onbatterystatuschange){epos.onbatterystatuschange(battery)}if(diff&(epos.ASB_NO_RESPONSE|epos.ASB_OFF_LINE)){if(status&epos.ASB_NO_RESPONSE){if(epos.onpoweroff){epos.onpoweroff()}}else{if(status&epos.ASB_OFF_LINE){if(epos.onoffline){epos.onoffline()}}else{if(epos.ononline){epos.ononline()}}}}if(diff&epos.ASB_COVER_OPEN){if(status&epos.ASB_NO_RESPONSE){}else{if(status&epos.ASB_COVER_OPEN){if(epos.oncoveropen){epos.oncoveropen()}}else{if(epos.oncoverok){epos.oncoverok()}}}}if(diff&(epos.ASB_RECEIPT_END|epos.ASB_RECEIPT_NEAR_END)){if(status&epos.ASB_NO_RESPONSE){}else{if(status&epos.ASB_RECEIPT_END){if(epos.onpaperend){epos.onpaperend()}}else{if(status&epos.ASB_RECEIPT_NEAR_END){if(epos.onpapernearend){epos.onpapernearend()}}else{if(epos.onpaperok){epos.onpaperok()}}}}}if(diff&epos.ASB_DRAWER_KICK){if(status&epos.ASB_NO_RESPONSE){}else{if(status&epos.ASB_DRAWER_KICK){if(epos.drawerOpenLevel==epos.DRAWER_OPEN_LEVEL_HIGH){if(epos.ondraweropen){epos.ondraweropen()}}else{if(epos.ondrawerclosed){epos.ondrawerclosed()}}if(epos.onbatterylow){epos.onbatterylow()}}else{if(epos.drawerOpenLevel==epos.DRAWER_OPEN_LEVEL_HIGH){if(epos.ondrawerclosed){epos.ondrawerclosed()}}else{if(epos.ondraweropen){epos.ondraweropen()}}if(epos.onbatteryok){epos.onbatteryok()}}}}}function fireErrorEvent(epos,status,responseText){if(epos.onerror){epos.onerror({status:status,responseText:responseText})}}function updateStatus(epos){var delay=epos.interval;if(epos.enabled){if(isNaN(delay)||delay<1000){delay=3000}epos.intervalid=setTimeout(function(){delete epos.intervalid;if(epos.enabled){epos.send()}},delay)}delete epos.intervalxhr}function CanvasPrint(address){this.address=address;this.mode="mono";this.halftone=0;this.brightness=1;this.align="left";this.color="color_1";this.paper="receipt";this.feed="current_tof";this.cut=false;this.layout=null;this.ALIGN_LEFT="left";this.ALIGN_CENTER="center";this.ALIGN_RIGHT="right";this.COLOR_NONE="none";this.COLOR_1="color_1";this.COLOR_2="color_2";this.COLOR_3="color_3";this.COLOR_4="color_4";this.FEED_PEELING="peeling";this.FEED_CUTTING="cutting";this.FEED_CURRENT_TOF="current_tof";this.FEED_NEXT_TOF="next_tof";this.HALFTONE_DITHER=0;this.HALFTONE_ERROR_DIFFUSION=1;this.HALFTONE_THRESHOLD=2;this.MODE_MONO="mono";this.MODE_GRAY16="gray16";this.PAPER_RECEIPT="receipt";this.PAPER_RECEIPT_BM="receipt_bm";this.PAPER_LABEL="label";this.PAPER_LABEL_BM="label_bm";this.connectionObj=null}CanvasPrint.prototype=new ePOSPrint();CanvasPrint.prototype.constructor=CanvasPrint;CanvasPrint.prototype.setConnectionObject=function(connectionObj){this.connectionObj=connectionObj};CanvasPrint.prototype.print=function(){var args=arguments.length;var address=this.address,layout=this.layout,paper=this.paper;var canvas=arguments[0],cut=this.cut,mode=this.mode,printjobid=undefined;switch(args){case 2:printjobid=arguments[1];break;case 4:printjobid=arguments[3];case 3:cut=arguments[1];mode=arguments[2];break}if((typeof(canvas)=="undefined")||(canvas==null)){throw new Error("Canvas is not supported")}if(!canvas.getContext){throw new Error("Canvas is not supported")}if(layout){this.addLayout(paper,layout.width,layout.height,layout.margin_top,layout.margin_bottom,layout.offset_cut,layout.offset_label)}if(paper!=this.PAPER_RECEIPT){this.addFeedPosition(this.FEED_CURRENT_TOF);if(layout){this.addFeedPosition(this.FEED_NEXT_TOF)}}this.addTextAlign(this.align);this.addImage(canvas.getContext("2d"),0,0,canvas.width,canvas.height,this.color,mode);if(paper!=this.PAPER_RECEIPT){this.addFeedPosition(this.feed);if(cut){this.addCut(this.CUT_NO_FEED)}}else{if(cut){this.addCut(this.CUT_FEED)}}this.send(address,this.toString(),printjobid)};CanvasPrint.prototype.recover=function(){this.force=true;this.addRecovery();this.send(this.address,this.toString())};CanvasPrint.prototype.reset=function(){this.addReset();this.send(this.address,this.toString())};if(!window.epson){window.epson={}}window.epson.ePOSBuilder=ePOSBuilder;window.epson.ePOSPrint=ePOSPrint;window.epson.CanvasPrint=CanvasPrint;function POSKeyboard(deviceID,isCrypto){this.deviceID=deviceID;this.isCrypto=isCrypto;this.connectionObj=null}POSKeyboard.prototype={setConnectionObject:function(connectionObj){this.connectionObj=connectionObj},client_onkeypress:function(data){try{if(this.onkeypress==null){return}this.onkeypress(data)}catch(e){}return},callEvent:function(eventName,data){var eventReq=data;eventReq.type=eventName;var eposmsg=MessageFactory.getDeviceDataMessage(this.deviceID,eventReq,this.isCrypto);var sequence=-1;try{this.connectionObj.emit(eposmsg);sequence=eposmsg.sequence}catch(e){}return sequence}};function Printer(deviceID,isCrypto,ePOSDeviceContext){this.deviceID=deviceID;this.isCrypto=isCrypto;this.ePosDev=ePOSDeviceContext;this.timeout=10000}Printer.prototype=new CanvasPrint();Printer.prototype.finalize=function(){this.stopMonitor()};Printer.prototype.toString=function(){var str=ePOSBuilder.prototype.toString.apply(this);return str};Printer.prototype.addFeedUnit=function(unit){try{ePOSBuilder.prototype.addFeedUnit.apply(this,arguments)}catch(e){throw e}return this};Printer.prototype.addFeedLine=function(line){try{ePOSBuilder.prototype.addFeedLine.apply(this,arguments)}catch(e){throw e}return this};Printer.prototype.addFeed=function(unit){try{ePOSBuilder.prototype.addFeed.apply(this,arguments)}catch(e){throw e}return this};Printer.prototype.addFeedPosition=function(line){try{ePOSBuilder.prototype.addFeedPosition.apply(this,arguments)}catch(e){throw e}return this};Printer.prototype.addText=function(text){try{ePOSBuilder.prototype.addText.apply(this,arguments)}catch(e){throw e}return this};Printer.prototype.addTextLang=function(lang){try{ePOSBuilder.prototype.addTextLang.apply(this,arguments)}catch(e){throw e}return this};Printer.prototype.addTextAlign=function(align){try{ePOSBuilder.prototype.addTextAlign.apply(this,arguments)}catch(e){throw e}return this};Printer.prototype.addTextRotate=function(rotate){try{ePOSBuilder.prototype.addTextRotate.apply(this,arguments)}catch(e){throw e}return this};Printer.prototype.addTextLineSpace=function(linespc){try{ePOSBuilder.prototype.addTextLineSpace.apply(this,arguments)}catch(e){throw e}return this};Printer.prototype.addTextFont=function(font){try{ePOSBuilder.prototype.addTextFont.apply(this,arguments)}catch(e){throw e}return this};Printer.prototype.addTextSmooth=function(smooth){try{ePOSBuilder.prototype.addTextSmooth.apply(this,arguments)}catch(e){throw e}return this};Printer.prototype.addTextDouble=function(dw,dh){try{ePOSBuilder.prototype.addTextDouble.apply(this,arguments)}catch(e){throw e}return this};Printer.prototype.addTextSize=function(width,height){try{ePOSBuilder.prototype.addTextSize.apply(this,arguments)}catch(e){throw e}return this};Printer.prototype.addTextStyle=function(reverse,ul,em,color){try{ePOSBuilder.prototype.addTextStyle.apply(this,arguments)}catch(e){throw e}return this};Printer.prototype.addTextPosition=function(x){try{ePOSBuilder.prototype.addTextPosition.apply(this,arguments)}catch(e){throw e}return this};Printer.prototype.addTextVPosition=function(y){try{ePOSBuilder.prototype.addTextVPosition.apply(this,arguments)}catch(e){throw e}return this};Printer.prototype.addImage=function(context,x,y,width,height,color,mode){try{ePOSBuilder.prototype.addImage.apply(this,arguments)}catch(e){throw e}return this};Printer.prototype.addLogo=function(key1,key2){try{ePOSBuilder.prototype.addLogo.apply(this,arguments)}catch(e){throw e}return this};Printer.prototype.addBarcode=function(barCodeData,type,hri,font,width,height){try{ePOSBuilder.prototype.addBarcode.apply(this,arguments)}catch(e){throw e}return this};Printer.prototype.addSymbol=function(symbolData,type,level,width,height,size){try{ePOSBuilder.prototype.addSymbol.apply(this,arguments)}catch(e){throw e}return this};Printer.prototype.addCommand=function(data){try{ePOSBuilder.prototype.addCommand.apply(this,arguments)}catch(e){throw e}return this};Printer.prototype.addHLine=function(x1,x2,style){try{ePOSBuilder.prototype.addHLine.apply(this,arguments)}catch(e){throw e}return this};Printer.prototype.addVLineBegin=function(x,style){try{ePOSBuilder.prototype.addVLineBegin.apply(this,arguments)}catch(e){throw e}return this};Printer.prototype.addVLineEnd=function(x,style){try{ePOSBuilder.prototype.addVLineEnd.apply(this,arguments)}catch(e){throw e}return this};Printer.prototype.addPageBegin=function(){try{ePOSBuilder.prototype.addPageBegin.apply(this)}catch(e){throw e}return this};Printer.prototype.addPageEnd=function(){try{ePOSBuilder.prototype.addPageEnd.apply(this)}catch(e){throw e}return this};Printer.prototype.addPageArea=function(x,y,width,height){try{ePOSBuilder.prototype.addPageArea.apply(this,arguments)}catch(e){throw e}return this};Printer.prototype.addPageDirection=function(dir){try{ePOSBuilder.prototype.addPageDirection.apply(this,arguments)}catch(e){throw e}return this};Printer.prototype.addPagePosition=function(x,y){try{ePOSBuilder.prototype.addPagePosition.apply(this,arguments)}catch(e){throw e}return this};Printer.prototype.addPageLine=function(x1,y1,x2,y2,style){try{ePOSBuilder.prototype.addPageLine.apply(this,arguments)}catch(e){throw e}return this};Printer.prototype.addPageRectangle=function(x1,y1,x2,y2,style){try{ePOSBuilder.prototype.addPageRectangle.apply(this,arguments)}catch(e){throw e}return this};Printer.prototype.addCut=function(type){try{ePOSBuilder.prototype.addCut.apply(this,arguments)}catch(e){throw e}return this};Printer.prototype.addPulse=function(drawer,time){try{ePOSBuilder.prototype.addPulse.apply(this,arguments)}catch(e){throw e}return this};Printer.prototype.addSound=function(pattern,repeat,cycle){try{ePOSBuilder.prototype.addSound.apply(this,arguments)}catch(e){throw e}return this};Printer.prototype.addLayout=function(type,width,height,margin_top,margin_bottom,offset_cut,offset_label){try{ePOSBuilder.prototype.addLayout.apply(this,arguments)}catch(e){throw e}return this};Printer.prototype.setXmlString=function(xml){this.message=xml};Printer.prototype.getXmlString=function(){return this.message};Printer.prototype.getPrintJobStatus=function(printjobid){this.setXmlString("");this.send(printjobid)};Printer.prototype.send=function(printjobid){var sq=-1;if((!this.ePosDev.eposprint)&&(this.connectionObj.isUsableDeviceIF())){try{var data={type:"print",timeout:this.timeout,printdata:this.toString()};switch(arguments.length){case 0:data.printdata=this.toString();break;case 1:data.printdata=this.toString();data.printjobid=printjobid;break;case 2:case 3:data.printdata=arguments[1];data.printjobid=arguments[2]}var eposmsg=MessageFactory.getDeviceDataMessage(this.deviceID,data,this.isCrypto);var sequence=-1;try{this.connectionObj.emit(eposmsg);sequence=eposmsg.sequence}catch(e){}this.force=false;this.setXmlString("")}catch(e){sq=-1}}else{var self=this,address=this.connectionObj.getAddressWithProtocol()+"/cgi-bin/epos/service.cgi?devid="+this.deviceID+"&timeout="+this.timeout,soap,xhr,tid,res,success,code,status,battery;soap='';if(printjobid){soap+=''+printjobid+""}soap+=""+this.toString()+"";if(window.XMLHttpRequest){xhr=new XMLHttpRequest();if(!("withCredentials" in xhr)&&window.XDomainRequest){xhr=new XDomainRequest();xhr.open("POST",address,true);xhr.onload=function(){res=xhr.responseText;if(/response/.test(res)){success=/success\s*=\s*"\s*(1|true)\s*"/.test(res);code=res.match(/code\s*=\s*"\s*(\S*)\s*"/)?RegExp.$1:"";status=res.match(/status\s*=\s*"\s*(\d+)\s*"/)?parseInt(RegExp.$1):0;battery=res.match(/battery\s*=\s*"\s*(\d+)\s*"/)?parseInt(RegExp.$1):0;printjobid=res.match(/\s*(\S*)\s*<\/printjobid>/)?RegExp.$1:"";self.fireReceiveEvent(success,code,status,battery,printjobid,0)}else{self.fireErrorEvent(0,xhr.responseText,0)}};xhr.onerror=function(){self.fireErrorEvent(0,xhr.responseText,0)};xhr.onprogress=function(){};xhr.ontimeout=xhr.onerror;xhr.timeout=self.timeout;xhr.send(soap)}else{xhr.open("POST",address,true);xhr.setRequestHeader("Content-Type","text/xml; charset=utf-8");xhr.setRequestHeader("If-Modified-Since","Thu, 01 Jan 1970 00:00:00 GMT");xhr.setRequestHeader("SOAPAction",'""');xhr.onreadystatechange=function(){if(xhr.readyState==4){clearTimeout(tid);if(xhr.status==200&&xhr.responseXML){res=xhr.responseXML.getElementsByTagName("response");if(res.length>0){success=/^(1|true)$/.test(res[0].getAttribute("success"));code=res[0].hasAttribute("code")?res[0].getAttribute("code"):"";status=res[0].hasAttribute("status")?parseInt(res[0].getAttribute("status")):0;battery=res[0].hasAttribute("battery")?parseInt(res[0].getAttribute("battery")):0;res=xhr.responseXML.getElementsByTagName("printjobid");printjobid=res.length>0?res[0].textContent:"";self.fireReceiveEvent(success,code,status,battery,printjobid,0)}else{self.fireErrorEvent(xhr.status,xhr.responseText,0)}}else{self.fireErrorEvent(xhr.status,xhr.responseText,0)}}};tid=setTimeout(function(){xhr.abort()},this.timeout);xhr.send(soap)}this.setXmlString("")}else{throw new Error("XMLHttpRequest is not supported")}sq=0}return sq};Printer.prototype.client_onxmlresult=function(res,sq){if(res){var xml=res.resultdata;var success=/success\s*=\s*"\s*(1|true)\s*"/.test(xml);xml.match(/code\s*=\s*"\s*(\S*)\s*"/);var code=RegExp.$1;xml.match(/status\s*=\s*"\s*(\d+)\s*"/);var status=parseInt(RegExp.$1);xml.match(/battery\s*=\s*"\s*(\d+)\s*"/);var battery=parseInt(RegExp.$1);this.fireReceiveEvent(success,code,status,battery,res.printjobid,sq)}else{this.fireErrorEvent(0,this.ASB_NO_RESPONSE,sq)}};Printer.prototype.startMonitor=function(){var result=false;var address=this.connectionObj.getAddressWithProtocol()+"/cgi-bin/epos/service.cgi?devid="+this.deviceID+"&timeout=10000";try{if(!this.enabled){this.address=address;this.enabled=true;this.status=this.ASB_DRAWER_KICK;this.sendStartMonitorCommand()}result=true}catch(e){throw e}return result};Printer.prototype.sendStartMonitorCommand=function(){var self=this;var address=this.address;var request=new ePOSBuilder().toString();var soap=''+request+"";var epos=this;if(window.XDomainRequest){var xdr=new XDomainRequest();xdr.open("POST",address,true);xdr.onload=function(){var res=xdr.responseText;if(/response/.test(res)){var success=/success\s*=\s*"\s*(1|true)\s*"/.test(res);res.match(/code\s*=\s*"\s*(\S*)\s*"/);var code=RegExp.$1;res.match(/status\s*=\s*"\s*(\d+)\s*"/);var status=parseInt(RegExp.$1);res.match(/battery\s*=\s*"\s*(\d+)\s*"/);var battery=parseInt(RegExp.$1);self.fireStatusEvent(epos,status,battery)}else{self.fireStatusEvent(epos,epos.ASB_NO_RESPONSE,0)}self.updateStatus(epos)};xdr.onerror=function(){self.fireStatusEvent(epos,epos.ASB_NO_RESPONSE);self.updateStatus(epos)};xdr.onprogress=function(){};xdr.ontimeout=xdr.onerror;xdr.send(soap)}else{if(window.XMLHttpRequest){var xhr=new XMLHttpRequest();xhr.open("POST",address,true);xhr.setRequestHeader("Content-Type","text/xml; charset=utf-8");xhr.setRequestHeader("If-Modified-Since","Thu, 01 Jan 1970 00:00:00 GMT");xhr.setRequestHeader("SOAPAction",'""');xhr.onreadystatechange=function(){if(xhr.readyState==4){if(xhr.status==200&&xhr.responseXML){var res=xhr.responseXML.getElementsByTagName("response");if(res.length>0){var success=/^(1|true)$/.test(res[0].getAttribute("success"));var code=res[0].getAttribute("code");var status=parseInt(res[0].getAttribute("status"));var battery=res[0].hasAttribute("battery")?parseInt(res[0].getAttribute("battery")):0;self.fireStatusEvent(epos,status,battery)}else{self.fireStatusEvent(epos,epos.ASB_NO_RESPONSE,0)}}else{self.fireStatusEvent(epos,epos.ASB_NO_RESPONSE,0)}self.updateStatus(epos)}};xhr.send(soap)}else{throw new Error("XMLHttpRequest is not supported")}}};Printer.prototype.stopMonitor=function(){var result=false;try{this.enabled=false;if(this.timeoutid){clearTimeout(this.timeoutid);delete this.timeoutid}result=true}catch(e){throw e}return result};Printer.prototype.fireReceiveEvent=function(success,code,status,battery,printjobid,sq){delete this.isPrint;if(code=="EX_ENPC_TIMEOUT"){code="ERROR_DEVICE_BUSY"}if(this.onreceive){this.onreceive({success:success,code:code,status:status,battery:battery,printjobid:printjobid},sq)}};Printer.prototype.fireErrorEvent=function(status,responseText,sq){if(this.onerror){this.onerror({status:status,responseText:responseText},sq)}this.ePosDev.cleanup()};Printer.prototype.fireStatusEvent=function(epos,status,battery){if(status==0||status==this.ASB_NO_RESPONSE){status=this.status|this.ASB_NO_RESPONSE}var diff=this.status==this.ASB_DRAWER_KICK?~0:this.status^status;var difb=this.status==0?~0:this.battery^battery;this.status=status;this.battery=battery;if(diff&&this.onstatuschange){this.onstatuschange(status)}if(difb&&this.onbatterystatuschange){this.onbatterystatuschange(battery)}if(diff&(this.ASB_NO_RESPONSE|this.ASB_OFF_LINE)){if(status&this.ASB_NO_RESPONSE){if(this.onpoweroff){this.onpoweroff()}}else{if(status&this.ASB_OFF_LINE){if(this.onoffline){this.onoffline()}}else{if(this.ononline){this.ononline()}}}}if(diff&this.ASB_COVER_OPEN){if(status&this.ASB_NO_RESPONSE){}else{if(status&this.ASB_COVER_OPEN){if(this.oncoveropen){this.oncoveropen()}}else{if(this.oncoverok){this.oncoverok()}}}}if(diff&(this.ASB_RECEIPT_END|this.ASB_RECEIPT_NEAR_END)){if(status&this.ASB_NO_RESPONSE){}else{if(status&this.ASB_RECEIPT_END){if(this.onpaperend){this.onpaperend()}}else{if(status&this.ASB_RECEIPT_NEAR_END){if(this.onpapernearend){this.onpapernearend()}}else{if(this.onpaperok){this.onpaperok()}}}}}if(diff&this.ASB_DRAWER_KICK){if(status&this.ASB_NO_RESPONSE){}else{if(status&this.ASB_DRAWER_KICK){if(this.drawerOpenLevel==this.DRAWER_OPEN_LEVEL_HIGH){if(this.ondraweropen){this.ondraweropen()}}else{if(this.ondrawerclosed){this.ondrawerclosed()}}if(this.onbatterylow){this.onbatterylow()}}else{if(this.drawerOpenLevel==this.DRAWER_OPEN_LEVEL_HIGH){if(this.ondrawerclosed){this.ondrawerclosed()}}else{if(this.ondraweropen){this.ondraweropen()}}if(this.onbatteryok){this.onbatteryok()}}}}};Printer.prototype.updateStatus=function(){var self=this;if(this.enabled){var delay=this.interval;if(isNaN(delay)||delay<1000){delay=3000}this.timeoutid=setTimeout(function(){delete self.timeoutid;if(self.enabled){self.sendStartMonitorCommand()}},delay)}};Printer.prototype.print=function(canvas,cut,mode,printjobid){try{CanvasPrint.prototype.print.apply(this,arguments)}catch(e){throw e}};Printer.prototype.reset=function(){try{CanvasPrint.prototype.reset.apply(this,arguments)}catch(e){throw e}};Printer.prototype.recover=function(){try{CanvasPrint.prototype.recover.apply(this,arguments)}catch(e){throw e}};function HybridPrinter(deviceID,isCrypto,ePOSDeviceContext){this.deviceID=deviceID;this.isCrypto=isCrypto;this.ePosDev=ePOSDeviceContext;this.connectionObj=null;this.ReceiptPrinter;this.SlipPrinter;this.EndorsePrinter;this.MICRReader;this.force=false;this.onstatuschange;this.ononline;this.onoffline;this.onpoweroff;this.oncoveropen;this.onpaperok;this.onpapernearend;this.onpaperend;this.ondrawerclosed;this.ondraweropen;this.ASB_NO_RESPONSE=1;this.ASB_PRINT_SUCCESS=2;this.ASB_DRAWER_KICK=4;this.ASB_OFF_LINE=8;this.ASB_COVER_OPEN=32;this.ASB_PAPER_FEED=64;this.ASB_WAIT_ON_LINE=256;this.ASB_PANEL_SWITCH=512;this.ASB_MECHANICAL_ERR=1024;this.ASB_AUTOCUTTER_ERR=2048;this.ASB_UNRECOVER_ERR=8192;this.ASB_AUTORECOVER_ERR=16384;this.ASB_RECEIPT_NEAR_END=131072;this.ASB_RECEIPT_END=524288;this.ASB_TOF_NOPAPER=2097152;this.ASB_BOF_NOPAPER=4194304;this.ASB_SLIP_NO_SELECT=16777216;this.ASB_SLIP_IMPOSSIBLE_PRINT=33554432;this.ASB_SPOOLER_IS_STOPPED=2147483648;this.SUCCESS="SUCCESS";this.CANCEL="CANCEL";this.ERROR_PARAMMETER="ERROR_PARAMMETER";this.ERROR_COMMAND="ERROR_COMMAND";this.ERROR_DEVICE_NOT_FOUND="ERROR_DEVICE_NOT_FOUND";this.ERROR_DEVICE_BUSY="ERROR_DEVICE_BUSY";this.ERROR_NOT_SUPPORTED="ERROR_NOT_SUPPORTED";this.ERROR_COVER_OPEN="ERROR_COVER_OPEN";this.ERROR_TIMEOUT="ERROR_TIMEOUT";this.ERROR_AUTOMATICAL="ERROR_AUTOMATICAL";this.ERROR_UNRECOVERABLE="ERROR_UNRECOVERABLE";this.ERROR_BADPORT="ERROR_BADPORT";this.SYSTEM_ERROR="SYSTEM_ERROR";this.init(deviceID)}HybridPrinter.prototype={init:function(deviceID){var obj=this;obj.deviceID=deviceID;obj.ReceiptPrinter=new ReceiptPrinter(this);obj.SlipPrinter=new SlipPrinter(this);obj.EndorsePrinter=new EndorsePrinter(this);obj.MICRReader=new MICRReader(this);obj.ReceiptPrinter.onstatuschange=function(status){if(obj.onstatuschange!=null){obj.onstatuschange(status)}};obj.ReceiptPrinter.ononline=function(){if(obj.ononline!=null){obj.ononline()}};obj.ReceiptPrinter.onoffline=function(){if(obj.onoffline!=null){obj.onoffline()}};obj.ReceiptPrinter.onpoweroff=function(){if(obj.onpoweroff!=null){obj.onpoweroff()}};obj.ReceiptPrinter.oncoveropen=function(){if(obj.oncoveropen!=null){obj.oncoveropen()}};obj.ReceiptPrinter.onpaperok=function(){if(obj.onpaperok!=null){obj.onpaperok()}};obj.ReceiptPrinter.onpapernearend=function(){if(obj.onpapernearend!=null){obj.onpapernearend()}};obj.ReceiptPrinter.onpaperend=function(){if(obj.onpaperend!=null){obj.onpaperend()}};obj.ReceiptPrinter.ondrawerclosed=function(){if(obj.ondrawerclosed!=null){obj.ondrawerclosed()}};obj.ReceiptPrinter.ondraweropen=function(){if(obj.ondraweropen!=null){obj.ondraweropen()}}},setConnectionObject:function(connectionObj){this.connectionObj=connectionObj;this.ReceiptPrinter.setConnectionObject(this.connectionObj)},lock:function(){var data={type:"lock"};return this.send(data)},unlock:function(){var data={type:"unlock"};return this.send(data)},eject:function(){var data={type:"eject"};return this.send(data)},recover:function(){return this.ReceiptPrinter.recover()},reset:function(){this.ReceiptPrinter.force=this.force;var ret=this.ReceiptPrinter.reset();this.force=false;return ret},startMonitor:function(){return this.ReceiptPrinter.startMonitor()},stopMonitor:function(){return this.ReceiptPrinter.stopMonitor()},client_onreceive:function(res,sq){switch(res.eventtype){case"slipprint":case"slipcancel":this.SlipPrinter.fireOnReceive(res,sq);break;case"endorseprint":case"endorsecancel":this.EndorsePrinter.fireOnReceive(res,sq);break;case"micrread":case"micrcleaning":case"micrcancel":this.MICRReader.fireOnReceive(res,sq);break;case"print":var tmp=res;tmp.eventtype=this.ReceiptPrinter.methodName;this.fireOnReceive(tmp,sq);break;default:this.fireOnReceive(res,sq);break}},client_onxmlresult:function(res,sq){this.ReceiptPrinter.fireOnReceive(res,sq)},fireOnReceive:function(res,sq){if(this.onreceive==null){return}if(res==null){return}this.onreceive({eventtype:res.eventtype,success:res.success,code:res.code,status:res.status},sq)},callEvent:function(eventName,data){var eventReq=data;eventReq.type=eventName;return this.send(eventReq)},send:function(data){var eposmsg=MessageFactory.getDeviceDataMessage(this.deviceID,data,this.isCrypto);var sequence=-1;try{this.connectionObj.emit(eposmsg);sequence=eposmsg.sequence}catch(e){}return sequence}};function ReceiptPrinter(parent){this.parent=parent;this.methodName="";this.deviceID=this.parent.deviceID;this.ePosDev=this.parent.ePosDev;this.connectionObj=null;this.SUCCESS="SUCCESS";this.CANCEL="CANCEL";this.ERROR_PARAMMETER="ERROR_PARAMMETER";this.ERROR_COMMAND="ERROR_COMMAND";this.ERROR_DEVICE_NOT_FOUND="DeviceNotFound";this.ERROR_DEVICE_BUSY="ERROR_DEVICE_BUSY";this.ERROR_NOT_SUPPORTED="ERROR_NOT_SUPPORTED";this.ERROR_COVER_OPEN="EPTR_COVER_OPEN";this.ERROR_TIMEOUT="EX_TIMEOUT";this.ERROR_AUTOMATICAL="EPTR_AUTOMATICAL";this.ERROR_UNRECOVERABLE="EPTR_UNRECOVERABLE";this.ERROR_BADPORT="EX_BADPORT";this.SYSTEM_ERROR="SYSTEM_ERROR";this.EPTR_CUTTER="EPTR_CUTTER";this.EPTR_MECHANICAL="EPTR_MECHANICAL";this.EPTR_REC_EMPTY="EPTR_REC_EMPTY";this.EPTR_SCHEMAERROR="SchemaError";this.EPTR_PRINT_SYSTEM_ERROR="PrintSystemError"}ReceiptPrinter.prototype.setConnectionObject=function(connectionObj){this.connectionObj=connectionObj};ReceiptPrinter.prototype=new Printer();ReceiptPrinter.prototype.send=function(){if(this.methodName==""){this.methodName="send"}return Printer.prototype.send.apply(this,arguments)};ReceiptPrinter.prototype.print=function(canvas,cut,mode){this.methodName="print";return Printer.prototype.print.apply(this,arguments)};ReceiptPrinter.prototype.recover=function(){this.methodName="recover";return Printer.prototype.recover.apply(this,arguments)};ReceiptPrinter.prototype.reset=function(){this.methodName="reset";return Printer.prototype.reset.apply(this,arguments)};ReceiptPrinter.prototype.fireOnReceive=function(res,sq){if(this.onreceive==null){return}var eventtype=this.methodName;var success="false";var code="";var status=this.ASB_NO_RESPONSE;if(res){var xml=res.resultdata;success=/success\s*=\s*"\s*(1|true)\s*"/.test(xml);xml.match(/code\s*=\s*"\s*(\S*)\s*"/);code=RegExp.$1;if(code==""){code=(success)?"SUCCESS":"ERROR_DEVICE_NOT_FOUND"}xml.match(/status\s*=\s*"\s*(\d+)\s*"/);status=parseInt(RegExp.$1)}if(code=="EX_ENPC_TIMEOUT"){code="ERROR_DEVICE_BUSY"}this.onreceive({eventtype:eventtype,success:success,code:code,status:status},sq);this.methodName=""};function SlipPrinter(parent){this.parent=parent;this.SUCCESS="SUCCESS";this.CANCEL="CANCEL";this.ERROR_PARAMMETER="ERROR_PARAMMETER";this.ERROR_COMMAND="ERROR_COMMAND";this.ERROR_DEVICE_NOT_FOUND="ERROR_DEVICE_NOT_FOUND";this.ERROR_DEVICE_BUSY="ERROR_DEVICE_BUSY";this.ERROR_NOT_SUPPORTED="ERROR_NOT_SUPPORTED";this.ERROR_COVER_OPEN="ERROR_COVER_OPEN";this.ERROR_TIMEOUT="ERROR_TIMEOUT";this.ERROR_AUTOMATICAL="ERROR_AUTOMATICAL";this.ERROR_UNRECOVERABLE="ERROR_UNRECOVERABLE";this.ERROR_BADPORT="ERROR_BADPORT";this.SYSTEM_ERROR="SYSTEM_ERROR";this.EPTR_CUTTER="EPTR_CUTTER";this.EPTR_MECHANICAL="EPTR_MECHANICAL";this.EPTR_REC_EMPTY="EPTR_REC_EMPTY";this.EPTR_SCHEMAERROR="EPTR_SCHEMAERROR";this.EPTR_PRINT_SYSTEM_ERROR="EPTR_PRINT_SYSTEM_ERROR"}SlipPrinter.prototype=new ePOSBuilder();SlipPrinter.prototype.timeout=60000;SlipPrinter.prototype.send=function(){var xml=(arguments.length<1)?this.toString():arguments[1];var data={type:"slipprint",timeout:this.timeout,printdata:xml};var sequence=this.parent.send(data);this.setXmlString("");return sequence};SlipPrinter.prototype.setXmlString=function(xml){this.message=xml};SlipPrinter.prototype.getXmlString=function(){return this.message};SlipPrinter.prototype.cancel=function(){var data={type:"slipcancel"};return this.parent.send(data)};SlipPrinter.prototype.fireOnReceive=function(res,sq){if(this.onreceive==null){return}if(res==null){return}var eventtype="";switch(res.eventtype){case"slipprint":eventtype="send";break;case"slipcancel":eventtype="cancel";break;default:break}var code=res.code;if(code=="EX_ENPC_TIMEOUT"){code="ERROR_DEVICE_BUSY"}this.onreceive({eventtype:eventtype,success:res.success,code:code,status:res.status},sq)};function EndorsePrinter(parent){this.parent=parent;this.mode40cpl=false;this.SUCCESS="SUCCESS";this.CANCEL="CANCEL";this.ERROR_PARAMMETER="ERROR_PARAMMETER";this.ERROR_COMMAND="ERROR_COMMAND";this.ERROR_DEVICE_NOT_FOUND="ERROR_DEVICE_NOT_FOUND";this.ERROR_DEVICE_BUSY="ERROR_DEVICE_BUSY";this.ERROR_NOT_SUPPORTED="ERROR_NOT_SUPPORTED";this.ERROR_COVER_OPEN="ERROR_COVER_OPEN";this.ERROR_TIMEOUT="ERROR_TIMEOUT";this.ERROR_AUTOMATICAL="ERROR_AUTOMATICAL";this.ERROR_UNRECOVERABLE="ERROR_UNRECOVERABLE";this.ERROR_BADPORT="ERROR_BADPORT";this.SYSTEM_ERROR="SYSTEM_ERROR";this.EPTR_CUTTER="EPTR_CUTTER";this.EPTR_MECHANICAL="EPTR_MECHANICAL";this.EPTR_REC_EMPTY="EPTR_REC_EMPTY";this.EPTR_SCHEMAERROR="EPTR_SCHEMAERROR";this.EPTR_PRINT_SYSTEM_ERROR="EPTR_PRINT_SYSTEM_ERROR"}EndorsePrinter.prototype=new ePOSBuilder();EndorsePrinter.prototype.timeout=60000;EndorsePrinter.prototype.send=function(){var xml=(arguments.length<1)?this.toString():arguments[1];var data={type:"endorseprint",is40cplmode:this.mode40cpl,timeout:this.timeout,printdata:xml};var sequence=this.parent.send(data);this.setXmlString("");return sequence};EndorsePrinter.prototype.setXmlString=function(xml){this.message=xml};EndorsePrinter.prototype.getXmlString=function(){return this.message};EndorsePrinter.prototype.cancel=function(){var data={type:"endorsecancel"};return this.parent.send(data)};EndorsePrinter.prototype.enable40cplmode=function(flag){this.mode40cpl=flag};EndorsePrinter.prototype.fireOnReceive=function(res,sq){if(this.onreceive==null){return}if(res==null){return}var eventtype="";switch(res.eventtype){case"endorseprint":eventtype="send";break;case"endorsecancel":eventtype="cancel";break;default:break}var code=res.code;if(code=="EX_ENPC_TIMEOUT"){code="ERROR_DEVICE_BUSY"}this.onreceive({eventtype:eventtype,success:res.success,code:code,status:res.status},sq)};function MICRReader(parent){this.parent=parent;this.timeout=60000;this.FONT_E13B="MICR_E13B";this.FONT_CMC7="MICR_CMC7";this.SUCCESS="SUCCESS";this.CANCEL="CANCEL";this.ERROR_PARAMMETER="ERROR_PARAMMETER";this.ERROR_COMMAND="ERROR_COMMAND";this.ERROR_DEVICE_NOT_FOUND="ERROR_DEVICE_NOT_FOUND";this.ERROR_DEVICE_BUSY="ERROR_DEVICE_BUSY";this.ERROR_NOT_SUPPORTED="ERROR_NOT_SUPPORTED";this.ERROR_COVER_OPEN="ERROR_COVER_OPEN";this.ERROR_TIMEOUT="ERROR_TIMEOUT";this.ERROR_AUTOMATICAL="ERROR_AUTOMATICAL";this.ERROR_UNRECOVERABLE="ERROR_UNRECOVERABLE";this.ERROR_BADPORT="ERROR_BADPORT";this.SYSTEM_ERROR="SYSTEM_ERROR";this.EMICR_ILLEGAL_LENGTH="EMICR_ILLEGAL_LENGTH";this.EMICR_NO_MICR="EMICR_NO_MICR";this.EMICR_RECOGNITION="EMICR_RECOGNITION";this.EMICR_READ="EMICR_READ";this.EMICR_NOISE_DETECTED="EMICR_NOISE_DETECTED";this.EMICR_COVER_OPENED="EMICR_COVER_OPENED";this.EMICR_PAPER_JAM="EMICR_PAPER_JAM"}MICRReader.prototype.read=function(ignoreerror,font){var data={type:"micrread",ignoreerror:ignoreerror,font:font,timeout:this.timeout};return this.parent.send(data)};MICRReader.prototype.cleaning=function(){var data={type:"micrcleaning",timeout:this.timeout};return this.parent.send(data)};MICRReader.prototype.cancel=function(){var data={type:"micrcancel"};return this.parent.send(data)};MICRReader.prototype.fireOnReceive=function(res,sq){if(this.onreceive==null){return}if(res==null){return}var eventtype="";switch(res.eventtype){case"micrread":eventtype="read";break;case"micrcleaning":eventtype="cleaning";break;case"micrcancel":eventtype="cancel";break;default:break}var code=res.code;if(code=="EX_ENPC_TIMEOUT"){code="ERROR_DEVICE_BUSY"}this.onreceive({eventtype:eventtype,success:res.success,code:code,status:res.status,data:res.data},sq)};function HybridPrinter2(deviceID,isCrypto,ePOSDeviceContext){this.deviceID=deviceID;this.isCrypto=isCrypto;this.ePosDev=ePOSDeviceContext;this.connectionObj=null;this.ReceiptPrinter=null;this.SlipPrinter2=null;this.ValidationPrinter=null;this.EndorsePrinter2=null;this.MICRReader2=null;this.currentPrinter=null;this.isMicrMode=false;this.FONT_A="font_a";this.FONT_B="font_b";this.FONT_C="font_c";this.FONT_D="font_d";this.FONT_E="font_e";this.FONT_SPECIAL_A="special_a";this.FONT_SPECIAL_B="special_b";this.ALIGN_LEFT="left";this.ALIGN_CENTER="center";this.ALIGN_RIGHT="right";this.COLOR_NONE="none";this.COLOR_1="color_1";this.COLOR_2="color_2";this.COLOR_3="color_3";this.COLOR_4="color_4";this.FEED_PEELING="peeling";this.FEED_CUTTING="cutting";this.FEED_CURRENT_TOF="current_tof";this.FEED_NEXT_TOF="next_tof";this.MODE_MONO="mono";this.MODE_GRAY16="gray16";this.BARCODE_UPC_A="upc_a";this.BARCODE_UPC_E="upc_e";this.BARCODE_EAN13="ean13";this.BARCODE_JAN13="jan13";this.BARCODE_EAN8="ean8";this.BARCODE_JAN8="jan8";this.BARCODE_CODE39="code39";this.BARCODE_ITF="itf";this.BARCODE_CODABAR="codabar";this.BARCODE_CODE93="code93";this.BARCODE_CODE128="code128";this.BARCODE_GS1_128="gs1_128";this.BARCODE_GS1_DATABAR_OMNIDIRECTIONAL="gs1_databar_omnidirectional";this.BARCODE_GS1_DATABAR_TRUNCATED="gs1_databar_truncated";this.BARCODE_GS1_DATABAR_LIMITED="gs1_databar_limited";this.BARCODE_GS1_DATABAR_EXPANDED="gs1_databar_expanded";this.HRI_NONE="none";this.HRI_ABOVE="above";this.HRI_BELOW="below";this.HRI_BOTH="both";this.SYMBOL_PDF417_STANDARD="pdf417_standard";this.SYMBOL_PDF417_TRUNCATED="pdf417_truncated";this.SYMBOL_QRCODE_MODEL_1="qrcode_model_1";this.SYMBOL_QRCODE_MODEL_2="qrcode_model_2";this.SYMBOL_QRCODE_MICRO="qrcode_micro";this.SYMBOL_MAXICODE_MODE_2="maxicode_mode_2";this.SYMBOL_MAXICODE_MODE_3="maxicode_mode_3";this.SYMBOL_MAXICODE_MODE_4="maxicode_mode_4";this.SYMBOL_MAXICODE_MODE_5="maxicode_mode_5";this.SYMBOL_MAXICODE_MODE_6="maxicode_mode_6";this.SYMBOL_GS1_DATABAR_STACKED="gs1_databar_stacked";this.SYMBOL_GS1_DATABAR_STACKED_OMNIDIRECTIONAL="gs1_databar_stacked_omnidirectional";this.SYMBOL_GS1_DATABAR_EXPANDED_STACKED="gs1_databar_expanded_stacked";this.SYMBOL_AZTECCODE_FULLRANGE="azteccode_fullrange";this.SYMBOL_AZTECCODE_COMPACT="azteccode_compact";this.SYMBOL_DATAMATRIX_SQUARE="datamatrix_square";this.SYMBOL_DATAMATRIX_RECTANGLE_8="datamatrix_rectangle_8";this.SYMBOL_DATAMATRIX_RECTANGLE_12="datamatrix_rectangle_12";this.SYMBOL_DATAMATRIX_RECTANGLE_16="datamatrix_rectangle_16";this.LEVEL_0="level_0";this.LEVEL_1="level_1";this.LEVEL_2="level_2";this.LEVEL_3="level_3";this.LEVEL_4="level_4";this.LEVEL_5="level_5";this.LEVEL_6="level_6";this.LEVEL_7="level_7";this.LEVEL_8="level_8";this.LEVEL_L="level_l";this.LEVEL_M="level_m";this.LEVEL_Q="level_q";this.LEVEL_H="level_h";this.LEVEL_DEFAULT="default";this.LINE_THIN="thin";this.LINE_MEDIUM="medium";this.LINE_THICK="thick";this.LINE_THIN_DOUBLE="thin_double";this.LINE_MEDIUM_DOUBLE="medium_double";this.LINE_THICK_DOUBLE="thick_double";this.DIRECTION_LEFT_TO_RIGHT="left_to_right";this.DIRECTION_BOTTOM_TO_TOP="bottom_to_top";this.DIRECTION_RIGHT_TO_LEFT="right_to_left";this.DIRECTION_TOP_TO_BOTTOM="top_to_bottom";this.CUT_NO_FEED="no_feed";this.CUT_FEED="feed";this.CUT_RESERVE="reserve";this.DRAWER_1="drawer_1";this.DRAWER_2="drawer_2";this.PULSE_100="pulse_100";this.PULSE_200="pulse_200";this.PULSE_300="pulse_300";this.PULSE_400="pulse_400";this.PULSE_500="pulse_500";this.PATTERN_NONE="none";this.PATTERN_0="pattern_0";this.PATTERN_1="pattern_1";this.PATTERN_2="pattern_2";this.PATTERN_3="pattern_3";this.PATTERN_4="pattern_4";this.PATTERN_5="pattern_5";this.PATTERN_6="pattern_6";this.PATTERN_7="pattern_7";this.PATTERN_8="pattern_8";this.PATTERN_9="pattern_9";this.PATTERN_10="pattern_10";this.PATTERN_A="pattern_a";this.PATTERN_B="pattern_b";this.PATTERN_C="pattern_c";this.PATTERN_D="pattern_d";this.PATTERN_E="pattern_e";this.PATTERN_ERROR="error";this.PATTERN_PAPER_END="paper_end";this.LAYOUT_RECEIPT="receipt";this.LAYOUT_RECEIPT_BM="receipt_bm";this.LAYOUT_LABEL="label";this.LAYOUT_LABEL_BM="label_bm";this.HALFTONE_DITHER=0;this.HALFTONE_ERROR_DIFFUSION=1;this.HALFTONE_THRESHOLD=2;this.ASB_NO_RESPONSE=1;this.ASB_PRINT_SUCCESS=2;this.ASB_DRAWER_KICK=4;this.ASB_OFF_LINE=8;this.ASB_COVER_OPEN=32;this.ASB_PAPER_FEED=64;this.ASB_WAIT_ON_LINE=256;this.ASB_PANEL_SWITCH=512;this.ASB_MECHANICAL_ERR=1024;this.ASB_AUTOCUTTER_ERR=2048;this.ASB_UNRECOVER_ERR=8192;this.ASB_AUTORECOVER_ERR=16384;this.ASB_INSERTION_WAIT_PAPER=65536;this.ASB_RECEIPT_NEAR_END=131072;this.ASB_REMOVAL_WAIT_PAPER=262144;this.ASB_RECEIPT_END=524288;this.ASB_TOF_NOPAPER=2097152;this.ASB_BOF_NOPAPER=4194304;this.ASB_SLIP_NO_SELECT=16777216;this.ASB_SLIP_IMPOSSIBLE_PRINT=33554432;this.ASB_EJD_NOPAPER=1073741824;this.ASB_VALIDATION_NO_SELECT=67108864;this.ASB_VALIDATION_IMPOSSIBLE_PRINT=134217728;this.ASB_SPOOLER_IS_STOPPED=2147483648;this.DRAWER_OPEN_LEVEL_LOW=0;this.DRAWER_OPEN_LEVEL_HIGH=1;this.SUCCESS="SUCCESS";this.CANCEL="CANCEL";this.ERROR_CANCEL_FAILED="ERROR_CANCEL_FAILED";this.ERROR_PARAMMETER="ERROR_PARAMMETER";this.ERROR_COMMAND="ERROR_COMMAND";this.ERROR_DEVICE_NOT_FOUND="ERROR_DEVICE_NOT_FOUND";this.ERROR_DEVICE_BUSY="ERROR_DEVICE_BUSY";this.ERROR_NOT_SUPPORTED="ERROR_NOT_SUPPORTED";this.ERROR_COVER_OPEN="ERROR_COVER_OPEN";this.ERROR_TIMEOUT="ERROR_TIMEOUT";this.ERROR_AUTOMATICAL="ERROR_AUTOMATICAL";this.ERROR_UNRECOVERABLE="ERROR_UNRECOVERABLE";this.ERROR_BADPORT="ERROR_BADPORT";this.SYSTEM_ERROR="SYSTEM_ERROR";this.EPTR_AUTOMATICAL="EPTR_AUTOMATICAL";this.EPTR_COVER_OPEN="EPTR_COVER_OPEN";this.EPTR_CUTTER="EPTR_CUTTER";this.EPTR_MECHANICAL="EPTR_MECHANICAL";this.EPTR_REC_EMPTY="EPTR_REC_EMPTY";this.EPTR_UNRECOVERABLE="EPTR_UNRECOVERABLE";this.EPTR_SCHEMAERROR="EPTR_SCHEMAERROR";this.EPTR_PRINT_SYSTEM_ERROR="EPTR_PRINT_SYSTEM_ERROR";this.EPTR_PAPER_PULLED_OUT="EPTR_PAPER_PULLED_OUT";this.EMICR_ILLEGAL_LENGTH="EMICR_ILLEGAL_LENGTH";this.EMICR_NO_MICR="EMICR_NO_MICR";this.EMICR_RECOGNITION="EMICR_RECOGNITION";this.EMICR_READ="EMICR_READ";this.EMICR_NOISE_DETECTED="EMICR_NOISE_DETECTED";this.EMICR_COVER_OPENED="EMICR_COVER_OPENED";this.EMICR_PAPER_JAM="EMICR_PAPER_JAM";this.EMICR_PAPER_PULLED_OUT="EMICR_PAPER_PULLED_OUT";this.DeviceNotFound="DeviceNotFound";this.EX_TIMEOUT="EX_TIMEOUT";this.EX_BADPORT="EX_BADPORT";this.SchemaError="SchemaError";this.PrintSystemError="PrintSystemError";this.PAPERTYPE_RECEIPT=0;this.PAPERTYPE_SLIP=1;this.PAPERTYPE_ENDORSE=2;this.PAPERTYPE_VALIDATION=3;this.FONT_E13B="MICR_E13B";this.FONT_CMC7="MICR_CMC7";this.halftone=this.HALFTONE_DITHER;this.brightness=1;this.force=false;this.drawerOpenLevel=this.DRAWER_OPEN_LEVEL_LOW;this.paperType=this.PAPERTYPE_RECEIPT;this.interval=3000;this.waitTime=500;this.enable40cplMode=true;this.onstatuschange=null;this.ononline=null;this.onoffline=null;this.onpoweroff=null;this.oncoveropen=null;this.onpaperok=null;this.onpapernearend=null;this.onpaperend=null;this.ondrawerclosed=null;this.ondraweropen=null;this.init(deviceID)}HybridPrinter2.prototype.init=function(deviceID){this.deviceID=deviceID;this.ReceiptPrinter=new ReceiptPrinter(this);this.SlipPrinter2=new SlipPrinter2(this);this.ValidationPrinter=new ValidationPrinter(this);this.EndorsePrinter2=new EndorsePrinter2(this);this.MICRReader2=new MICRReader2(this);this.currentPrinter=this.ReceiptPrinter;this.ReceiptPrinter.onstatuschange=function(status){if(this.parent.onstatuschange!=null){this.parent.onstatuschange(status)}};this.ReceiptPrinter.ononline=function(){if(this.parent.ononline!=null){this.parent.ononline()}};this.ReceiptPrinter.onoffline=function(){if(this.parent.onoffline!=null){this.parent.onoffline()}};this.ReceiptPrinter.onpoweroff=function(){if(this.parent.onpoweroff!=null){this.parent.onpoweroff()}};this.ReceiptPrinter.oncoveropen=function(){if(this.parent.oncoveropen!=null){this.parent.oncoveropen()}};this.ReceiptPrinter.oncoverok=function(){if(this.parent.oncoverok!=null){this.parent.oncoverok()}};this.ReceiptPrinter.onpaperok=function(){if(this.parent.onpaperok!=null){this.parent.onpaperok()}};this.ReceiptPrinter.onpapernearend=function(){if(this.parent.onpapernearend!=null){this.parent.onpapernearend()}};this.ReceiptPrinter.onpaperend=function(){if(this.parent.onpaperend!=null){this.parent.onpaperend()}};this.ReceiptPrinter.ondrawerclosed=function(){if(this.parent.ondrawerclosed!=null){this.parent.ondrawerclosed()}};this.ReceiptPrinter.ondraweropen=function(){if(this.parent.ondraweropen!=undefined){this.parent.ondraweropen()}};this.ReceiptPrinter.onreceive=function(res,sq){this.parent.fireOnReceive(res,sq)};this.SlipPrinter2.onreceive=function(res,sq){this.parent.fireOnReceive(res,sq)};this.EndorsePrinter2.onreceive=function(res,sq){this.parent.fireOnReceive(res,sq)};this.ValidationPrinter.onreceive=function(res,sq){this.parent.fireOnReceive(res,sq)};this.MICRReader2.onreceive=function(res,sq){this.parent.fireOnReceive(res,sq)}};HybridPrinter2.prototype.setConnectionObject=function(connectionObj){this.connectionObj=connectionObj;this.ReceiptPrinter.setConnectionObject(this.connectionObj)};HybridPrinter2.prototype.isValidFunction=function(paperType,supportPaperTypes){var isValid=false;var index=0;if(supportPaperTypes.length!=0){for(index=0;index1000000)){this.currentPrinter.timeout=0}else{this.currentPrinter.timeout=timeout}this.EndorsePrinter2.enable40cplmode(this.enable40cplMode);this.currentPrinter.force=this.force;var ret=this.currentPrinter.send();this.force=false;return ret};HybridPrinter2.prototype.print=function(canvas,cut,mode,timeout){if((typeof(timeout)!="number")||(timeout<1)||(timeout>1000000)){this.ReceiptPrinter.timeout=0}else{this.ReceiptPrinter.timeout=timeout}this.ReceiptPrinter.print.apply(this.ReceiptPrinter,[canvas,cut,mode]);return this};HybridPrinter2.prototype.readMicrData=function(ignoreerror,micrFont,timeout){var ignoreerrorMicr=ignoreerror;var micrFontMicr=micrFont;if(typeof(ignoreerror)=="undefined"){ignoreerrorMicr=true}if(typeof(micrFont)=="undefined"){micrFontMicr=this.FONT_E13B}this.MICRReader2.timeout=timeout;this.MICRReader2.waitTime=this.waitTime;this.MICRReader2.read.apply(this.MICRReader2,[ignoreerrorMicr,micrFontMicr]);this.isMicrMode=true;return this};HybridPrinter2.prototype.cleanMicrReader=function(timeout){this.MICRReader2.timeout=timeout;this.MICRReader2.cleaning.apply(this.MICRReader2,[]);this.isMicrMode=true;return this};HybridPrinter2.prototype.client_onreceive=function(res,sq){switch(res.eventtype){case"slipprint2":case"slipcancel":case"slipwaitinsertion":this.SlipPrinter2.fireOnReceive(res,sq);break;case"endorseprint2":case"endorsecancel":case"endorsewaitinsertion":this.EndorsePrinter2.fireOnReceive(res,sq);break;case"validationprint2":case"validationcancel":case"validationwaitinsertion":this.ValidationPrinter.fireOnReceive(res,sq);break;case"micrread":case"micrcleaning":case"micrcancel":this.MICRReader2.fireOnReceive(res,sq);break;case"print":var tmp=res;tmp.eventtype=this.ReceiptPrinter.methodName;this.fireOnReceive(tmp,sq);break;default:this.fireOnReceive(res,sq);break}};HybridPrinter2.prototype.client_onxmlresult=function(res,sq){this.ReceiptPrinter.fireOnReceive(res,sq)};HybridPrinter2.prototype.fireOnReceive=function(res,sq){if(typeof(this.onreceive)==undefined){return}if(res==null){return}var eventtype=res.eventtype;var success=res.success;var code=res.code;var status=res.status;var data=res.data;switch(res.eventtype){case"send":eventtype="sendData";if(code==this.SUCCESS){this.isMicrMode=false}break;case"waitinsertion":eventtype="waitInsertion";if(code==this.SUCCESS){this.isMicrMode=false}break;case"read":eventtype="readMicrData";if(code==this.SUCCESS){this.isMicrMode=true}break;case"cleaning":eventtype="cleanMicrReader";if(code==this.SUCCESS){this.isMicrMode=true}break;case"cancel":eventtype="cancelInsertion";break;case"eject":eventtype="ejectPaper";if(code==this.SUCCESS){this.isMicrMode=false}break;default:break}switch(code){case"EX_ENPC_TIMEOUT":code="ERROR_DEVICE_BUSY";break;case"CANCEL":this.isMicrMode=false;break;default:break}this.onreceive({method:eventtype,success:success,code:code,status:status,data:data},sq)};HybridPrinter2.prototype.callEvent=function(eventName,data){var eventReq=data;eventReq.type=eventName;return this.send(eventReq)};HybridPrinter2.prototype.send=function(data){var eposmsg=MessageFactory.getDeviceDataMessage(this.deviceID,data,this.isCrypto);var sequence=-1;try{this.connectionObj.emit(eposmsg);sequence=eposmsg.sequence}catch(e){}return sequence};function SlipPrinter2(parent){this.parent=parent}SlipPrinter2.prototype=new SlipPrinter();SlipPrinter2.prototype.timeout=60000;SlipPrinter2.prototype.waitTime=500;SlipPrinter2.prototype.send=function(){var xml=null;if(arguments.length<1){xml=this.toString()}else{xml=arguments[1]}if((typeof(this.timeout)!="number")||(this.timeout<5000)||(this.timeout>1000000)){this.timeout=10000}var data={type:"slipprint2",timeout:this.timeout,printdata:xml};var sequence=this.parent.send(data);this.setXmlString("");return sequence};SlipPrinter2.prototype.setXmlString=function(xml){this.message=xml};SlipPrinter2.prototype.getXmlString=function(){return this.message};SlipPrinter2.prototype.waitInsertion=function(timeout){if((typeof(timeout)!="number")||(timeout<5000)||(timeout>900000)){this.timeout=60000}else{this.timeout=timeout}var slipWaitTime=this.waitTime;if((typeof(this.waitTime)!="number")||(this.waitTime<0)||(this.waitTime>6400)){slipWaitTime=500}var data={type:"slipwaitinsertion",timeout:this.timeout,waittime:slipWaitTime};return this.parent.send(data)};SlipPrinter2.prototype.cancel=function(){var data={type:"slipcancel"};return this.parent.send(data)};SlipPrinter2.prototype.fireOnReceive=function(res,sq){if(this.onreceive==null){return}if(res==null){return}var eventtype="";switch(res.eventtype){case"slipprint2":eventtype="send";break;case"slipcancel":eventtype="cancel";break;case"slipwaitinsertion":eventtype="waitinsertion";break;default:break}this.onreceive({eventtype:eventtype,success:res.success,code:res.code,status:res.status},sq)};function EndorsePrinter2(parent){this.parent=parent;this.mode40cpl=false}EndorsePrinter2.prototype=new EndorsePrinter();EndorsePrinter2.prototype.timeout=60000;EndorsePrinter2.prototype.waitTime=500;EndorsePrinter2.prototype.send=function(){var xml=null;if(arguments.length<1){xml=this.toString()}else{xml=arguments[1]}if((typeof(this.timeout)!="number")||(this.timeout<60000)||(this.timeout>900000)){this.timeout=60000}var data={type:"endorseprint2",is40cplmode:this.mode40cpl,timeout:this.timeout,printdata:xml};var sequence=this.parent.send(data);this.setXmlString("");return sequence};EndorsePrinter2.prototype.setXmlString=function(xml){this.message=xml};EndorsePrinter2.prototype.getXmlString=function(){return this.message};EndorsePrinter2.prototype.waitInsertion=function(timeout){if((typeof(timeout)!="number")||(timeout<5000)||(timeout>900000)){this.timeout=60000}else{this.timeout=timeout}var endorseWaitTime=this.waitTime;if((typeof(this.waitTime)!="number")||(this.waitTime<0)||(this.waitTime>6400)){endorseWaitTime=500}var data={type:"endorsewaitinsertion",timeout:this.timeout,waittime:endorseWaitTime};return this.parent.send(data)};EndorsePrinter2.prototype.cancel=function(){var data={type:"endorsecancel"};return this.parent.send(data)};EndorsePrinter2.prototype.enable40cplmode=function(flag){this.mode40cpl=flag};EndorsePrinter2.prototype.fireOnReceive=function(res,sq){if(this.onreceive==null){return}if(res==null){return}var eventtype="";switch(res.eventtype){case"endorseprint2":eventtype="send";break;case"endorsecancel":eventtype="cancel";break;case"endorsewaitinsertion":eventtype="waitinsertion";break;default:break}this.onreceive({eventtype:eventtype,success:res.success,code:res.code,status:res.status},sq)};function MICRReader2(parent){this.parent=parent}MICRReader2.prototype=new MICRReader();MICRReader2.prototype.waitTime=500;MICRReader2.prototype.read=function(ignoreerror,font){if((typeof(this.timeout)!="number")||(this.timeout<5000)||(this.timeout>900000)){this.timeout=60000}var micrWaitTime=this.waitTime;if((typeof(this.waitTime)!="number")||(this.waitTime<0)||(this.waitTime>6400)){micrWaitTime=500}var data={type:"micrread",ignoreerror:ignoreerror,font:font,timeout:this.timeout,waittime:micrWaitTime};return this.parent.send(data)};MICRReader2.prototype.cleaning=function(){var micrWaitTime=this.waitTime;this.timeout=60000;if((typeof(this.waitTime)!="number")||(this.waitTime<0)||(this.waitTime>6400)){micrWaitTime=500}var data={type:"micrcleaning",timeout:this.timeout,waittime:micrWaitTime};return this.parent.send(data)};function ValidationPrinter(parent){this.parent=parent}ValidationPrinter.prototype=new ePOSBuilder();ValidationPrinter.prototype.timeout=10000;ValidationPrinter.prototype.waitTime=500;ValidationPrinter.prototype.send=function(){var xml=null;if(arguments.length<1){xml=this.toString()}else{xml=arguments[1]}if((typeof(this.timeout)!="number")||(this.timeout<5000)||(this.timeout>1000000)){this.timeout=10000}var data={type:"validationprint2",timeout:this.timeout,printdata:xml};var sequence=this.parent.send(data);this.setXmlString("");return sequence};ValidationPrinter.prototype.setXmlString=function(xml){this.message=xml};ValidationPrinter.prototype.getXmlString=function(){return this.message};ValidationPrinter.prototype.waitInsertion=function(timeout){if((typeof(timeout)!="number")||(timeout<5000)||(timeout>900000)){this.timeout=60000}else{this.timeout=timeout}var validationWaitTime=this.waitTime;if((typeof(this.waitTime)!="number")||(this.waitTime<0)||(this.waitTime>6400)){validationWaitTime=500}var data={type:"validationwaitinsertion",timeout:this.timeout,waittime:validationWaitTime};return this.parent.send(data)};ValidationPrinter.prototype.cancel=function(){var data={type:"validationcancel"};return this.parent.send(data)};ValidationPrinter.prototype.fireOnReceive=function(res,sq){if(this.onreceive==null){return}if(res==null){return}var eventtype="";switch(res.eventtype){case"validationprint2":eventtype="send";break;case"validationcancel":eventtype="cancel";break;case"validationwaitinsertion":eventtype="waitinsertion";break;default:break}this.onreceive({eventtype:eventtype,success:res.success,code:res.code,status:res.status},sq)};function Scanner(deviceID,isCrypto){this.deviceID=deviceID;this.isCrypto=isCrypto;this.connectionObj=null}Scanner.prototype={setConnectionObject:function(connectionObj){this.connectionObj=connectionObj},client_ondata:function(data){try{if(this.ondata==null){return}this.ondata(data)}catch(e){}return},client_onbinarydata:function(data){try{if(this.onbinarydata==null){return}this.onbinarydata(data)}catch(e){}return},client_setbinarymode:function(data){try{if(this.onbinarymode==null){return}this.onbinarymode(data)}catch(e){}return},setBinaryMode:function(enable){var str="";if(enable==true){str="true"}else{str="false"}var data={type:"setbinarymode",binarymode:str};var eposmsg=MessageFactory.getDeviceDataMessage(this.deviceID,data,this.isCrypto);var sequence=-1;try{this.connectionObj.emit(eposmsg);sequence=eposmsg.sequence}catch(e){}return sequence},callEvent:function(eventName,data){var eventReq=data;eventReq.type=eventName;var eposmsg=MessageFactory.getDeviceDataMessage(this.deviceID,eventReq,this.isCrypto);var sequence=-1;try{this.connectionObj.emit(eposmsg);sequence=eposmsg.sequence}catch(e){}return sequence}};function SimpleSerial(deviceID,isCrypto){this.deviceID=deviceID;this.isCrypto=isCrypto;this.connectionObj=null}SimpleSerial.prototype={setConnectionObject:function(connectionObj){this.connectionObj=connectionObj},sendCommand:function(command){var data={type:"sendcommand",command:toHexBinary(command)};var eposmsg=MessageFactory.getDeviceDataMessage(this.deviceID,data,this.isCrypto);var sequence=-1;try{this.connectionObj.emit(eposmsg);sequence=eposmsg.sequence}catch(e){}return sequence},client_oncommandreply:function(data){try{if(this.oncommandreply==null){return}var hexData=data.data;hexData=hexData.replace(/[0-9a-fA-F]{2}/g,function(c){var hexNum=parseInt(c,16);return String.fromCharCode(hexNum)});data.data=hexData;this.oncommandreply(data)}catch(e){}return}};function Ofsc(){this.SERVICE_ID="OFSC";this.callback=null;this.connectionObj=null}Ofsc.prototype={setConnectionObject:function(connectionObj){this.connectionObj=connectionObj},send:function(xml,timeout,crypto,callback){this.callback=callback;try{if(this.connectionObj.isUsableDeviceIF()){var data={type:"print",timeout:timeout,printdata:xml};var eposmsg=MessageFactory.getServiceMessage(this.SERVICE_ID,crypto,data);this.connectionObj.emit(eposmsg)}}catch(e){return}},notify:function(eposmsg){var data=null;if(eposmsg.isCrypto=="1"){data=MessageFactory.decrypt(eposmsg.data)}else{data=eposmsg.data}if(this.callback!=null){this.callback(data.resultdata)}},onxmlresult:function(xml){if(this.callback!=null){this.callback(xml)}}};function CookieIO(){this.KEY="EPSON_EPOSDEVICE_CLIENTID";this.EXPIRES_MINUTES=5}CookieIO.prototype={writeId:function(value){var path=location.pathname;if(path.slice(-1)=="/"){path=path+"index.html"}var hostname=location.hostname;var expired=this.getExpiredDate();document.cookie=this.KEY+"_"+hostname+path+"="+escape(value)+"; expires="+expired},readId:function(){var id="";var strCookie=document.cookie+";";var path=location.pathname;if(path.slice(-1)=="/"){path=path+"index.html"}var hostname=location.hostname;var searchKey=this.KEY+"_"+hostname+path+"=";var keyValueFrom=strCookie.indexOf(searchKey);if(keyValueFrom!=-1){keyValueFrom+=searchKey.length;var keyValueTo=strCookie.indexOf(";",keyValueFrom);id=unescape(strCookie.substring(keyValueFrom,keyValueTo))}return id},getExpiredDate:function(){var expire=new Date();var nTime=expire.getTime();expire.setTime(nTime+(1000*60*this.EXPIRE_MINUTES));return expire.toUTCString()}};function DeviceObjElement(deviceId,isCrypto,deviceObject,callback){this.deviceId=deviceId;this.isCrypto=isCrypto;this.deviceObject=deviceObject;this.callback=callback}function DeviceObjElementMap(){this.elementList=new Array()}DeviceObjElementMap.prototype={add:function(element){this.elementList.push(element)},get:function(deviceId){var element=null;for(var i=0;i=4){this.eposprint=options.eposprint}else{this.eposprint=false}var self=this;if(this.eposprint){var selfofProb=this.conectionObj;this.conectionObj.probeWebServiceIF(function(accessTime){var result=self.ERROR_PARAMETER;if(selfofProb.isUsablePrintIF()){result=self.RESULT_OK}callback(result)})}else{this.connectBySocketIo(this.CONNECT_TIMEOUT,protocol)}},isConnected:function(){var devIsConnect=false;var wsIsConnect=false;switch(this.conectionObj.status(this.conectionObj.IF_EPOSDEVICE)){case this.conectionObj.CONNECT:case this.conectionObj.RECONNECTING:devIsConnect=true;break;case this.conectionObj.DISCONNECT:break}if(this.conectionObj.status(this.conectionObj.IF_EPOSPRINT)==this.conectionObj.CONNECT){wsIsConnect=true}return devIsConnect|wsIsConnect},disconnect:function(){var eposmsg=MessageFactory.getDisconnectMessage(this.connectionId);this.conectionObj.emit(eposmsg);this.cleanup()},createDevice:function(deviceId,deviceType,options,callback){try{if(!this.isConnected()){throw new Error(this.ERROR_SYSTEM)}if(this.devObjElmMap.get(deviceId)!=null){throw new Error(this.ERROR_DEVICE_IN_USE)}if(!this.devObjSelector.isSelectable(deviceType)){throw new Error(this.ERROR_DEVICE_NOT_FOUND)}var isCrypto=false;var isBufferEnable=false;if(typeof(options)=="boolean"){isCrypto=options}else{if(typeof(options.crypto)=="boolean"){isCrypto=options.crypto}if(typeof(options.buffer)=="boolean"){isBufferEnable=options.buffer}}if(deviceType==this.DEVICE_TYPE_DT){isCrypto=true;deviceId="local_dt"}var deviceObject=this.devObjSelector.select(deviceId,deviceType,options.driver,isCrypto,this);deviceObject.setConnectionObject(this.conectionObj);var element=new DeviceObjElement(deviceId,isCrypto,deviceObject,callback);this.devObjElmMap.add(element);if(this.conectionObj.isUsableDeviceIF()){var eposmsg=MessageFactory.getOpenDeviceMessage(deviceId,deviceType,isCrypto,isBufferEnable);this.conectionObj.emit(eposmsg)}else{var self=this;this.checkEposPrintService(deviceId,deviceType,function(result){if(result==self.RESULT_OK){callback(deviceObject,self.RESULT_OK)}else{callback(null,self.ERROR_DEVICE_NOT_FOUND)}})}}catch(e){var message=e.message;if((message==null)||(message=="")){message=this.ERROR_DEVICE_OPEN}if(callback!=null){callback(null,message)}}},deleteDevice:function(deviceObject,callback){try{var element=this.devObjElmMap.getByObj(deviceObject);if(element==null){throw new Error(this.ERROR_DEVICE_NOT_OPEN)}if(this.conectionObj.isUsableDeviceIF()){element.callback=callback;var eposmsg=MessageFactory.getCloseDeviceMessage(element.deviceId);this.conectionObj.emit(eposmsg)}else{try{deviceObject.finalize()}catch(e){}this.devObjElmMap.remove(element.deviceId);callback(this.RESULT_OK)}}catch(e){var message=e.message;if((message==null)||(message=="")){message=this.ERROR_DEVICE_CLOSE}if(callback!=null){callback(message)}}},getAdmin:function(){return this.admin},getLocation:function(){return this.location},sendOfscXml:function(xml,timeout,crypto,callback){this.ofsc.send(xml,timeout,crypto,callback)},getCommBoxManager:function(){if(this.conectionObj.status(this.conectionObj.IF_EPOSDEVICE)!=this.conectionObj.CONNECT){return null}return this.commBoxManager},cleanup:function(){if(this.waitRetryConnectId!=0){clearTimeout(this.waitRetryConnectId);this.waitRetryConnectId=0}this.connectStartTime=0;this.gbox.stock(this.socket);this.gbox.dispose();var devObjList=this.devObjElmMap.getElementList();devObjList.forEach(function(obj){try{obj.deviceObject.finalize()}catch(e){}});devObjList=null;this.devObjElmMap.removeAll();if((this.ondisconnect!=null)&&(this.conectionObj.status(this.conectionObj.IF_EPOSDEVICE)!=this.conectionObj.DISCONNECT||this.conectionObj.status(this.conectionObj.IF_EPOSPRINT)!=this.conectionObj.DISCONNECT)){this.ondisconnect()}this.cookieIo.writeId("");this.conectionObj.changeStatus(this.conectionObj.IF_ALL,this.conectionObj.DISCONNECT);this.socket=null;this.conectionObj.setSocket(null);this.connectionId=null;this.conectionObj.setAddress("","","");if(this.reconnectTimerId!=null){clearInterval(this.reconnectTimerId)}this.reconnectTimerId=null;this.reconnectTryCount=0;this.admin="";this.location="";this.recievedDataId=0;this.eposprint=false},connectBySocketIo:function(timeout){var selfofProb=this.conectionObj;var url=selfofProb.getSocketIoURL();this.socket=io.connect(url,{reconnect:false,"connect timeout":timeout,"force new connection":true});this.conectionObj.setSocket(this.socket);var self=this;this.socket.on("connect",function(data){try{self.gbox.dispose()}catch(e){}});this.socket.on("close",function(){selfofProb.changeStatus(selfofProb.IF_EPOSDEVICE,tselfofProb.DISCONNECT)});this.socket.on("disconnect",function(data){try{if(selfofProb.status(selfofProb.IF_EPOSDEVICE)==selfofProb.RECONNECTING){return}else{if(self.cookieIo.readId()==""&&self.connectionId==null){self.cleanup()}else{self.startReconnectAction()}}}catch(e){}});this.socket.on("error",function(){try{selfofProb.probeWebServiceIF(function(accessTime){if(selfofProb.isUsablePrintIF()){self.eposprint=true;selfofProb.registIFAccessResult(selfofProb.IF_EPOSDEVICE,selfofProb.ACCESS_NONE)}else{selfofProb.changeStatus(selfofProb.IF_EPOSDEVICE,selfofProb.DISCONNECT);selfofProb.registIFAccessResult(selfofProb.IF_EPOSDEVICE,selfofProb.ACCESS_TIMEOUT)}})}catch(e){}});this.socket.on("connect_failed",function(){try{var selfofProb=this.conectionObj;this.conectionObj.probeWebServiceIF(function(accessTime){if(selfofProb.isUsablePrintIF()){self.eposprint=true;selfofProb.registIFAccessResult(selfofProb.IF_EPOSDEVICE,selfofProb.ACCESS_NONE)}else{selfofProb.changeStatus(selfofProb.IF_EPOSDEVICE,selfofProb.DISCONNECT);selfofProb.registIFAccessResult(selfofProb.IF_EPOSDEVICE,selfofProb.ACCESS_TIMEOUT)}})}catch(e){}});this.socket.on("message",function(data){try{var eposmsg=MessageFactory.parseRequestMessage(data);if(eposmsg.data_id!=""){self.recievedDataId=eposmsg.data_id}switch(eposmsg.request){case eposmsg.REQUEST.CONNECT:self.procConnect(eposmsg);break;case eposmsg.REQUEST.PUBKEY:self.procPubkey(eposmsg);break;case eposmsg.REQUEST.ADMININFO:self.procAdminInfo(eposmsg);break;case eposmsg.REQUEST.RECONNECT:self.procReconnect(eposmsg);break;case eposmsg.REQUEST.DISCONNECT:self.procDisconnect(eposmsg);break;case eposmsg.REQUEST.OPENDEVICE:self.procOpenDevice(eposmsg);break;case eposmsg.REQUEST.CLOSEDEVICE:self.procCloseDevice(eposmsg);break;case eposmsg.REQUEST.DEVICEDATA:self.procDeviceData(eposmsg);break;case eposmsg.REQUEST.SERVICEDATA:self.procServiceData(eposmsg);break;case eposmsg.REQUEST.OPENCOMMBOX:self.procOpenCommBox(eposmsg);break;case eposmsg.REQUEST.CLOSECOMMBOX:self.procCloseCommBox(eposmsg);break;case eposmsg.REQUEST.COMMDATA:self.procCommBoxData(eposmsg);break;case eposmsg.REQUEST.ERROR:self.procError(eposmsg);break;default:return}}catch(e){}})},procConnect:function(eposmsg){try{if(this.reconnectTimerId!=null){clearInterval(this.reconnectTimerId);this.reconnectTimerId=null}var response=null;var prevConnectionId=this.cookieIo.readId();if(eposmsg.data.protocol_version<2){response=MessageFactory.getPubkeyMessage(eposmsg.data.prime,eposmsg.data.key);this.conectionObj.emit(response)}else{if(this.connectionId!=null){response=MessageFactory.getReconnectMessage(this.connectionId,eposmsg.data.client_id,this.recievedDataId);this.conectionObj.emit(response)}else{if(prevConnectionId!=""){response=MessageFactory.getDisconnectMessage(prevConnectionId);this.conectionObj.emit(response);response=MessageFactory.getPubkeyMessage(eposmsg.data.prime,eposmsg.data.key);this.conectionObj.emit(response)}else{response=MessageFactory.getPubkeyMessage(eposmsg.data.prime,eposmsg.data.key);this.conectionObj.emit(response)}}}this.cookieIo.writeId(eposmsg.data.client_id);this.connectionId=eposmsg.data.client_id}catch(e){this.conectionObj.registIFAccessResult(this.conectionObj.IF_EPOSDEVICE,this.conectionObj.ACCESS_ERROR);this.cleanup()}},procPubkey:function(eposmsg){try{if(eposmsg.code=="SHARED_KEY_MISMATCH_ERROR"){var mismatchErrTime=new Date().getTime();var mismatchTimeout=0;if(this.connectStartTime!=0){mismatchTimeout=mismatchErrTime-this.connectStartTime;if(mismatchTimeout MIT Licensed */ (function(exports,global){var io=exports;io.version="0.8.7";io.protocol=1;io.transports=[];io.j=[];io.sockets={};io.connect=function(host,details){var uri=io.util.parseUri(host),uuri,socket;if(global&&global.location){uri.protocol=uri.protocol||global.location.protocol.slice(0,-1);uri.host=uri.host||(global.document?global.document.domain:global.location.hostname);uri.port=uri.port||global.location.port}uuri=io.util.uniqueUri(uri);var options={host:uri.host,secure:"https"==uri.protocol,port:uri.port||("https"==uri.protocol?443:80),query:uri.query||""};io.util.merge(options,details);if(options["force new connection"]||!io.sockets[uuri]){socket=new io.Socket(options)}if(!options["force new connection"]&&socket){io.sockets[uuri]=socket}socket=socket||io.sockets[uuri];return socket.of(uri.path.length>1?uri.path:"")}})("object"===typeof module?module.exports:(this.io={}),this);(function(exports,global){var util=exports.util={};var re=/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/;var parts=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];util.parseUri=function(str){var m=re.exec(str||""),uri={},i=14;while(i--){uri[parts[i]]=m[i]||""}return uri};util.uniqueUri=function(uri){var protocol=uri.protocol,host=uri.host,port=uri.port;if("document" in global){host=host||document.domain;port=port||(protocol=="https"&&document.location.protocol!=="https:"?443:document.location.port)}else{host=host||"localhost";if(!port&&protocol=="https"){port=443}}return(protocol||"http")+"://"+host+":"+(port||80)};util.query=function(base,addition){var query=util.chunkQuery(base||""),components=[];util.merge(query,util.chunkQuery(addition||""));for(var part in query){if(query.hasOwnProperty(part)){components.push(part+"="+query[part])}}return components.length?"?"+components.join("&"):""};util.chunkQuery=function(qs){var query={},params=qs.split("&"),i=0,l=params.length,kv;for(;iarr2.length?arr:arr2,shortest=arr.length>arr2.length?arr2:arr;for(var i=0,l=shortest.length;i0&&remaining.splice(0,1)[0]!=self.transport.name){}if(remaining.length){connect(remaining)}else{self.publish("connect_failed")}}}},self.options["connect timeout"])}})}connect();self.once("connect",function(){clearTimeout(self.connectTimeoutTimer);fn&&typeof fn=="function"&&fn()})});return this};Socket.prototype.packet=function(data){if(this.connected&&!this.doBuffer){this.transport.packet(data)}else{this.buffer.push(data)}return this};Socket.prototype.setBuffer=function(v){this.doBuffer=v;if(!v&&this.connected&&this.buffer.length){this.transport.payload(this.buffer);this.buffer=[]}};Socket.prototype.disconnect=function(){if(this.connected){if(this.open){this.of("").packet({type:"disconnect"})}this.onDisconnect("booted")}return this};Socket.prototype.disconnectSync=function(){var xhr=io.util.request(),uri=this.resource+"/"+io.protocol+"/"+this.sessionid;xhr.open("GET",uri,true);this.onDisconnect("booted")};Socket.prototype.isXDomain=function(){var port=global.location.port||("https:"==global.location.protocol?443:80);return this.options.host!==global.location.hostname||this.options.port!=port};Socket.prototype.onConnect=function(){if(!this.connected){this.connected=true;this.connecting=false;if(!this.doBuffer){this.setBuffer(false)}this.emit("connect")}};Socket.prototype.onOpen=function(){this.open=true};Socket.prototype.onClose=function(){this.open=false};Socket.prototype.onPacket=function(packet){this.of(packet.endpoint).onPacket(packet)};Socket.prototype.onError=function(err){if(err&&err.advice){if(err.advice==="reconnect"&&this.connected){this.disconnect();this.reconnect()}}this.publish("error",err&&err.reason?err.reason:err)};Socket.prototype.onDisconnect=function(reason){var wasConnected=this.connected;this.connected=false;this.connecting=false;this.open=false;if(wasConnected){this.transport.close();this.transport.clearTimeouts();this.publish("disconnect",reason);if("booted"!=reason&&this.options.reconnect&&!this.reconnecting){this.reconnect()}}};Socket.prototype.reconnect=function(){this.reconnecting=true;this.reconnectionAttempts=0;this.reconnectionDelay=this.options["reconnection delay"];var self=this,maxAttempts=this.options["max reconnection attempts"],tryMultiple=this.options["try multiple transports"],limit=this.options["reconnection limit"];function reset(){if(self.connected){for(var i in self.namespaces){if(self.namespaces.hasOwnProperty(i)&&""!==i){self.namespaces[i].packet({type:"connect"})}}self.publish("reconnect",self.transport.name,self.reconnectionAttempts)}self.removeListener("connect_failed",maybeReconnect);self.removeListener("connect",maybeReconnect);self.reconnecting=false;delete self.reconnectionAttempts;delete self.reconnectionDelay;delete self.reconnectionTimer;delete self.redoTransports;self.options["try multiple transports"]=tryMultiple}function maybeReconnect(){if(!self.reconnecting){return}if(self.connected){return reset()}if(self.connecting&&self.reconnecting){return self.reconnectionTimer=setTimeout(maybeReconnect,1000)}if(self.reconnectionAttempts++>=maxAttempts){if(!self.redoTransports){self.on("connect_failed",maybeReconnect);self.options["try multiple transports"]=true;self.transport=self.getTransport();self.redoTransports=true;self.connect()}else{self.publish("reconnect_failed");reset()}}else{if(self.reconnectionDelay=10};Flashsocket.xdomainCheck=function(){return true};if(typeof window!="undefined"){WEB_SOCKET_DISABLE_AUTO_INITIALIZATION=true}io.transports.push("flashsocket")})("undefined"!=typeof io?io.Transport:module.exports,"undefined"!=typeof io?io:module.parent.exports);if("undefined"!=typeof window){var swfobject=function(){var D="undefined",r="object",S="Shockwave Flash",W="ShockwaveFlash.ShockwaveFlash",q="application/x-shockwave-flash",R="SWFObjectExprInst",x="onreadystatechange",O=window,j=document,t=navigator,T=false,U=[h],o=[],N=[],I=[],l,Q,E,B,J=false,a=false,n,G,m=true,M=function(){var aa=typeof j.getElementById!=D&&typeof j.getElementsByTagName!=D&&typeof j.createElement!=D,ah=t.userAgent.toLowerCase(),Y=t.platform.toLowerCase(),ae=Y?/win/.test(Y):/win/.test(ah),ac=Y?/mac/.test(Y):/mac/.test(ah),af=/webkit/.test(ah)?parseFloat(ah.replace(/^.*webkit\/(\d+(\.\d+)?).*$/,"$1")):false,X=!+"\v1",ag=[0,0,0],ab=null;if(typeof t.plugins!=D&&typeof t.plugins[S]==r){ab=t.plugins[S].description;if(ab&&!(typeof t.mimeTypes!=D&&t.mimeTypes[q]&&!t.mimeTypes[q].enabledPlugin)){T=true;X=false;ab=ab.replace(/^.*\s+(\S+\s+\S+$)/,"$1");ag[0]=parseInt(ab.replace(/^(.*)\..*$/,"$1"),10);ag[1]=parseInt(ab.replace(/^.*\.(.*)\s.*$/,"$1"),10);ag[2]=/[a-zA-Z]/.test(ab)?parseInt(ab.replace(/^.*[a-zA-Z]+(.*)$/,"$1"),10):0}}else{if(typeof O.ActiveXObject!=D){try{var ad=new ActiveXObject(W);if(ad){ab=ad.GetVariable("$version");if(ab){X=true;ab=ab.split(" ")[1].split(",");ag=[parseInt(ab[0],10),parseInt(ab[1],10),parseInt(ab[2],10)]}}}catch(Z){}}}return{w3:aa,pv:ag,wk:af,ie:X,win:ae,mac:ac}}(),k=function(){if(!M.w3){return}if((typeof j.readyState!=D&&j.readyState=="complete")||(typeof j.readyState==D&&(j.getElementsByTagName("body")[0]||j.body))){f()}if(!J){if(typeof j.addEventListener!=D){j.addEventListener("DOMContentLoaded",f,false)}if(M.ie&&M.win){j.attachEvent(x,function(){if(j.readyState=="complete"){j.detachEvent(x,arguments.callee);f()}});if(O==top){(function(){if(J){return}try{j.documentElement.doScroll("left")}catch(X){setTimeout(arguments.callee,0);return}f()})()}}if(M.wk){(function(){if(J){return}if(!/loaded|complete/.test(j.readyState)){setTimeout(arguments.callee,0);return}f()})()}s(f)}}();function f(){if(J){return}try{var Z=j.getElementsByTagName("body")[0].appendChild(C("span"));Z.parentNode.removeChild(Z)}catch(aa){return}J=true;var X=U.length;for(var Y=0;Y0){for(var af=0;af0){var ae=c(Y);if(ae){if(F(o[af].swfVersion)&&!(M.wk&&M.wk<312)){w(Y,true);if(ab){aa.success=true;aa.ref=z(Y);ab(aa)}}else{if(o[af].expressInstall&&A()){var ai={};ai.data=o[af].expressInstall;ai.width=ae.getAttribute("width")||"0";ai.height=ae.getAttribute("height")||"0";if(ae.getAttribute("class")){ai.styleclass=ae.getAttribute("class")}if(ae.getAttribute("align")){ai.align=ae.getAttribute("align")}var ah={};var X=ae.getElementsByTagName("param");var ac=X.length;for(var ad=0;ad'}}aa.outerHTML='"+af+"";N[N.length]=ai.id;X=c(ai.id)}else{var Z=C(r);Z.setAttribute("type",q);for(var ac in ai){if(ai[ac]!=Object.prototype[ac]){if(ac.toLowerCase()=="styleclass"){Z.setAttribute("class",ai[ac])}else{if(ac.toLowerCase()!="classid"){Z.setAttribute(ac,ai[ac])}}}}for(var ab in ag){if(ag[ab]!=Object.prototype[ab]&&ab.toLowerCase()!="movie"){e(Z,ab,ag[ab])}}aa.parentNode.replaceChild(Z,aa);X=Z}}return X}function e(Z,X,Y){var aa=C("param");aa.setAttribute("name",X);aa.setAttribute("value",Y);Z.appendChild(aa)}function y(Y){var X=c(Y);if(X&&X.nodeName=="OBJECT"){if(M.ie&&M.win){X.style.display="none";(function(){if(X.readyState==4){b(Y)}else{setTimeout(arguments.callee,10)}})()}else{X.parentNode.removeChild(X)}}}function b(Z){var Y=c(Z);if(Y){for(var X in Y){if(typeof Y[X]=="function"){Y[X]=null}}Y.parentNode.removeChild(Y)}}function c(Z){var X=null;try{X=j.getElementById(Z)}catch(Y){}return X}function C(X){return j.createElement(X)}function i(Z,X,Y){Z.attachEvent(X,Y);I[I.length]=[Z,X,Y]}function F(Z){var Y=M.pv,X=Z.split(".");X[0]=parseInt(X[0],10);X[1]=parseInt(X[1],10)||0;X[2]=parseInt(X[2],10)||0;return(Y[0]>X[0]||(Y[0]==X[0]&&Y[1]>X[1])||(Y[0]==X[0]&&Y[1]==X[1]&&Y[2]>=X[2]))?true:false}function v(ac,Y,ad,ab){if(M.ie&&M.mac){return}var aa=j.getElementsByTagName("head")[0];if(!aa){return}var X=(ad&&typeof ad=="string")?ad:"screen";if(ab){n=null;G=null}if(!n||G!=X){var Z=C("style");Z.setAttribute("type","text/css");Z.setAttribute("media",X);n=aa.appendChild(Z);if(M.ie&&M.win&&typeof j.styleSheets!=D&&j.styleSheets.length>0){n=j.styleSheets[j.styleSheets.length-1]}G=X}if(M.ie&&M.win){if(n&&typeof n.addRule==r){n.addRule(ac,Y)}}else{if(n&&typeof j.createTextNode!=D){n.appendChild(j.createTextNode(ac+" {"+Y+"}"))}}}function w(Z,X){if(!m){return}var Y=X?"visible":"hidden";if(J&&c(Z)){c(Z).style.visibility=Y}else{v("#"+Z,"visibility:"+Y)}}function L(Y){var Z=/[\\\"<>\.;]/;var X=Z.exec(Y)!=null;return X&&typeof encodeURIComponent!=D?encodeURIComponent(Y):Y}var d=function(){if(M.ie&&M.win){window.attachEvent("onunload",function(){var ac=I.length;for(var ab=0;ab= 10.0.0 is required.");return}if(location.protocol=="file:"){console.error("WARNING: web-socket-js doesn't work in file:///... URL unless you set Flash Security Settings properly. Open the page via Web server i.e. http://...")}WebSocket=function(url,protocols,proxyHost,proxyPort,headers){var self=this;self.__id=WebSocket.__nextId++;WebSocket.__instances[self.__id]=self;self.readyState=WebSocket.CONNECTING;self.bufferedAmount=0;self.__events={};if(!protocols){protocols=[]}else{if(typeof protocols=="string"){protocols=[protocols]}}setTimeout(function(){WebSocket.__addTask(function(){WebSocket.__flash.create(self.__id,url,protocols,proxyHost||null,proxyPort||0,headers||null)})},0)};WebSocket.prototype.send=function(data){if(this.readyState==WebSocket.CONNECTING){throw"INVALID_STATE_ERR: Web Socket connection has not been established"}var result=WebSocket.__flash.send(this.__id,encodeURIComponent(data));if(result<0){return true}else{this.bufferedAmount+=result;return false}};WebSocket.prototype.close=function(){if(this.readyState==WebSocket.CLOSED||this.readyState==WebSocket.CLOSING){return}this.readyState=WebSocket.CLOSING;WebSocket.__flash.close(this.__id)};WebSocket.prototype.addEventListener=function(type,listener,useCapture){if(!(type in this.__events)){this.__events[type]=[]}this.__events[type].push(listener)};WebSocket.prototype.removeEventListener=function(type,listener,useCapture){if(!(type in this.__events)){return}var events=this.__events[type];for(var i=events.length-1;i>=0;--i){if(events[i]===listener){events.splice(i,1);break}}};WebSocket.prototype.dispatchEvent=function(event){var events=this.__events[event.type]||[];for(var i=0;i");this.doc.close();this.doc.parentWindow.s=this;var iframeC=this.doc.createElement("div");iframeC.className="socketio";this.doc.body.appendChild(iframeC);this.iframe=this.doc.createElement("iframe");iframeC.appendChild(this.iframe);var self=this,query=io.util.query(this.socket.options.query,"t="+ +new Date);this.iframe.src=this.prepareUrl()+query;io.util.on(window,"unload",function(){self.destroy()})};HTMLFile.prototype._=function(data,doc){this.onData(data);try{var script=doc.getElementsByTagName("script")[0];script.parentNode.removeChild(script)}catch(e){}};HTMLFile.prototype.destroy=function(){if(this.iframe){try{this.iframe.src="about:blank"}catch(e){}this.doc=null;this.iframe.parentNode.removeChild(this.iframe);this.iframe=null;CollectGarbage()}};HTMLFile.prototype.close=function(){this.destroy();return io.Transport.XHR.prototype.close.call(this)};HTMLFile.check=function(){if("ActiveXObject" in window){try{var a=new ActiveXObject("htmlfile");return a&&io.Transport.XHR.check()}catch(e){}}return false};HTMLFile.xdomainCheck=function(){return false};io.transports.push("htmlfile")})("undefined"!=typeof io?io.Transport:module.exports,"undefined"!=typeof io?io:module.parent.exports);(function(exports,io,global){exports["xhr-polling"]=XHRPolling;function XHRPolling(){io.Transport.XHR.apply(this,arguments)}io.util.inherit(XHRPolling,io.Transport.XHR);io.util.merge(XHRPolling,io.Transport.XHR);XHRPolling.prototype.name="xhr-polling";XHRPolling.prototype.open=function(){var self=this;io.Transport.XHR.prototype.open.call(self);return false};function empty(){}XHRPolling.prototype.get=function(){if(!this.open){return}var self=this;function stateChange(){if(this.readyState==4){this.onreadystatechange=empty;if(this.status==200){self.onData(this.responseText);self.get()}else{self.onClose()}}}function onload(){this.onload=empty;self.onData(this.responseText);self.get()}this.xhr=this.request();if(global.XDomainRequest&&this.xhr instanceof XDomainRequest){this.xhr.onload=this.xhr.onerror=onload}else{this.xhr.onreadystatechange=stateChange}this.xhr.send(null)};XHRPolling.prototype.onClose=function(){io.Transport.XHR.prototype.onClose.call(this);if(this.xhr){this.xhr.onreadystatechange=this.xhr.onload=empty;try{this.xhr.abort()}catch(e){}this.xhr=null}};XHRPolling.prototype.ready=function(socket,fn){var self=this;io.util.defer(function(){fn.call(self)})};io.transports.push("xhr-polling")})("undefined"!=typeof io?io.Transport:module.exports,"undefined"!=typeof io?io:module.parent.exports,this);(function(exports,io,global){var indicator=global.document&&"MozAppearance" in global.document.documentElement.style;exports["jsonp-polling"]=JSONPPolling;function JSONPPolling(socket){io.Transport["xhr-polling"].apply(this,arguments);this.index=io.j.length;var self=this;io.j.push(function(msg){self._(msg)})}io.util.inherit(JSONPPolling,io.Transport["xhr-polling"]);JSONPPolling.prototype.name="jsonp-polling";JSONPPolling.prototype.post=function(data){var self=this,query=io.util.query(this.socket.options.query,"t="+(+new Date)+"&i="+this.index);if(!this.form){var form=document.createElement("form"),area=document.createElement("textarea"),id=this.iframeId="socketio_iframe_"+this.index,iframe;form.className="socketio";form.style.position="absolute";form.style.top="-1000px";form.style.left="-1000px";form.target=id;form.method="POST";form.setAttribute("accept-charset","utf-8");area.name="d";form.appendChild(area);document.body.appendChild(form);this.form=form;this.area=area}this.form.action=this.prepareUrl()+query;function complete(){initIframe();self.socket.setBuffer(false)}function initIframe(){if(self.iframe){self.form.removeChild(self.iframe)}try{iframe=document.createElement('