/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/nguyentien0620-zkteco-js@1.0.2/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
const ZTCP=require("./src/ztcp"),ZUDP=require("./src/zudp"),{ZkError:ZkError,ERROR_TYPES:ERROR_TYPES}=require("./src/exceptions/handler");class ZktecoJsCustom{constructor(t,e,i,r){this.connectionType=null,this.ztcp=new ZTCP(t,e,i),this.zudp=new ZUDP(t,e,i,r),this.interval=null,this.timer=null,this.isBusy=!1,this.ip=t}async functionWrapper(t,e,i){try{switch(this.connectionType){case"tcp":if(this.ztcp&&this.ztcp.socket)return await t();throw new ZkError(new Error("TCP socket isn't connected!"),`[TCP] ${i}`,this.ip);case"udp":if(this.zudp&&this.zudp.socket)return await e();throw new ZkError(new Error("UDP socket isn't connected!"),`[UDP] ${i}`,this.ip);default:throw new ZkError(new Error("Unsupported connection type or socket isn't connected!"),"",this.ip)}}catch(t){throw new ZkError(t,`[${this.connectionType?.toUpperCase()}] ${i}`,this.ip)}}async createSocket(t,e){try{if(this.ztcp.socket)try{return await this.ztcp.connect(),console.log("TCP reconnection successful"),this.connectionType="tcp",!0}catch(t){throw new ZkError(t,"TCP CONNECT ERROR CUSTOM",this.ip)}else try{return await this.ztcp.createSocket(t,e),await this.ztcp.connect(),console.log("TCP connection successful"),this.connectionType="tcp",!0}catch(t){throw new ZkError(t,"TCP CONNECT ERROR CUSTOM",this.ip)}}catch(i){try{this.ztcp.socket&&await this.ztcp.disconnect()}catch(t){}if(i.code!==ERROR_TYPES.ECONNREFUSED)return Promise.reject(new ZkError(i,"TCP CONNECT",this.ip));try{return this.zudp.socket||await this.zudp.createSocket(t,e),await this.zudp.connect(),console.log("UDP connection successful"),this.connectionType="udp",!0}catch(t){if("EADDRINUSE"!==t.code){this.connectionType=null;try{await this.zudp.disconnect()}catch(t){}return Promise.reject(new ZkError(t,"UDP CONNECT",this.ip))}return this.connectionType="udp",!0}}}async getUsers(){return await this.functionWrapper((()=>this.ztcp.getUsers()),(()=>this.zudp.getUsers()))}async getTime(){return await this.functionWrapper((()=>this.ztcp.getTime()),(()=>this.zudp.getTime()))}async setTime(t){return await this.functionWrapper((()=>this.ztcp.setTime(t)),(()=>this.zudp.setTime(t)))}async voiceTest(){return await this.functionWrapper((()=>this.ztcp.voiceTest()))}async getProductTime(){return await this.functionWrapper((()=>this.ztcp.getProductTime()))}async getVendor(){return await this.functionWrapper((()=>this.ztcp.getVendor()))}async getMacAddress(){return await this.functionWrapper((()=>this.ztcp.getMacAddress()))}async getSerialNumber(){return await this.functionWrapper((()=>this.ztcp.getSerialNumber()))}async getDeviceVersion(){return await this.functionWrapper((()=>this.ztcp.getDeviceVersion()))}async getDeviceName(){return await this.functionWrapper((()=>this.ztcp.getDeviceName()))}async getPlatform(){return await this.functionWrapper((()=>this.ztcp.getPlatform()))}async getOS(){return await this.functionWrapper((()=>this.ztcp.getOS()))}async getWorkCode(){return await this.functionWrapper((()=>this.ztcp.getWorkCode()))}async getPIN(){return await this.functionWrapper((()=>this.ztcp.getPIN()))}async getFaceOn(){return await this.functionWrapper((()=>this.ztcp.getFaceOn()))}async getSSR(){return await this.functionWrapper((()=>this.ztcp.getSSR()))}async getFirmware(){return await this.functionWrapper((()=>this.ztcp.getFirmware()))}async setUser(t,e,i,r,n=0,c=0){return await this.functionWrapper((()=>this.ztcp.setUser(t,e,i,r,n,c)))}async deleteUser(t){return await this.functionWrapper((()=>this.ztcp.deleteUser(t)))}async getAttendanceSize(){return await this.functionWrapper((()=>this.ztcp.getAttendanceSize()))}async getAttendances(t){return await this.functionWrapper((()=>this.ztcp.getAttendances(t)),(()=>this.zudp.getAttendances(t)))}async getRealTimeLogs(t){return await this.functionWrapper((()=>this.ztcp.getRealTimeLogs(t)),(()=>this.zudp.getRealTimeLogs(t)))}async disconnect(){return await this.functionWrapper((()=>this.ztcp.disconnect()),(()=>this.zudp.disconnect()))}async connect(){return await this.functionWrapper((()=>this.ztcp.connect()),(()=>this.zudp.connect()))}async freeData(){return await this.functionWrapper((()=>this.ztcp.freeData()),(()=>this.zudp.freeData()))}async disableDevice(){return await this.functionWrapper((()=>this.ztcp.disableDevice()),(()=>this.zudp.disableDevice()))}async enableDevice(){return await this.functionWrapper((()=>this.ztcp.enableDevice()),(()=>this.zudp.enableDevice()))}async getInfo(){return await this.functionWrapper((()=>this.ztcp.getInfo()),(()=>this.zudp.getInfo()))}async getSocketStatus(){return await this.functionWrapper((()=>this.ztcp.getSocketStatus()),(()=>this.zudp.getSocketStatus()))}async clearAttendanceLog(){return await this.functionWrapper((()=>this.ztcp.clearAttendanceLog()),(()=>this.zudp.clearAttendanceLog()))}async clearData(){return await this.functionWrapper((()=>this.ztcp.clearData()),(()=>this.zudp.clearData()))}async executeCmd(t,e=""){return await this.functionWrapper((()=>this.ztcp.executeCmd(t,e)),(()=>this.zudp.executeCmd(t,e)))}setIntervalSchedule(t,e){this.interval=setInterval(t,e)}setTimerSchedule(t,e){this.timer=setTimeout(t,e)}}module.exports=ZktecoJsCustom;
//# sourceMappingURL=/sm/7d473a5f880960b2231f565e12d0453ce74f3f542fa056e592ba284b4db5b913.map