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GAEL,cAAa,KACJ,KAAK,UACN,KAAK,KAAK,QAAS,EAAE,GAEjC,IAGZ,EAGJ,SAAS,cAEL,OADA,cACO,QAAQ,QAAQ,MAAM,IAAI,UACrC,CAEA,SAAS,oBAAoB,GAEzB,OADA,cACO,QAAQ,gBAAgB,EACnC,CAIA,QAAQ,IAAM,IACd,QAAQ,SAAW,SACnB,QAAQ,QAAU,YAClB,QAAQ,aAAe,iBACvB,QAAQ,cAAgB","file":"/npm/node-hid@3.2.0/nodehid.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/node-hid@3.2.0/nodehid.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\nconst EventEmitter = require(\"events\").EventEmitter;\nconst util = require(\"util\");\n\nlet driverType = null;\nfunction setDriverType(type) {\n    driverType = type;\n}\n\n// lazy load the C++ binding\nlet binding = null;\nfunction loadBinding() {\n    if (!binding) {\n        const options = require('./binding-options');\n        if (process.platform === \"linux\" && (!driverType || driverType === \"hidraw\")) {\n            options.name = 'HID_hidraw';\n        }\n        binding = require(\"pkg-prebuilds/bindings\")(__dirname, options);\n    }\n}\n\n//This class is a wrapper for `binding.HID` class\nfunction HID() {\n\n    // see issue #150 (enhancement, solves issue #149)\n    // throw an error for those who forget to instantiate, i.e. by \"*new* HID.HID()\"\n    // and who would otherwise be left trying to figure out why \"self.on is not a function\"\n    if (!new.target) {\n        throw new Error('HID() must be called with \\'new\\' operator');\n    }\n\n    //Inherit from EventEmitter\n    EventEmitter.call(this);\n\n    loadBinding();\n\n    /* We also want to inherit from `binding.HID`, but unfortunately,\n        it's not so easy for native Objects. For example, the\n        following won't work since `new` keyword isn't used:\n        `binding.HID.apply(this, arguments);`\n        So... we do this craziness instead...\n    */\n    var thisPlusArgs = new Array(arguments.length + 1);\n    thisPlusArgs[0] = null;\n    for(var i = 0; i < arguments.length; i++)\n        thisPlusArgs[i + 1] = arguments[i];\n    this._raw = new (Function.prototype.bind.apply(binding.HID,\n        thisPlusArgs) )();\n\n    /* Now we have `this._raw` Object from which we need to\n        inherit.  So, one solution is to simply copy all\n        prototype methods over to `this` and binding them to\n        `this._raw`\n    */\n    for(var i in binding.HID.prototype)\n        this[i] = binding.HID.prototype[i].bind(this._raw);\n\n    /* We are now done inheriting from `binding.HID` and EventEmitter.\n        Now upon adding a new listener for \"data\" events, we start\n        polling the HID device using `read(...)`\n        See `resume()` for more details. */\n    this._paused = true;\n    var self = this;\n    self.on(\"newListener\", function(eventName, listener) {\n        if(eventName == \"data\")\n            process.nextTick(self.resume.bind(self) );\n    });\n}\n//Inherit prototype methods\nutil.inherits(HID, EventEmitter);\n//Don't inherit from `binding.HID`; that's done above already!\n\nHID.prototype.close = function close() {\n    this._closing = true;\n    this.removeAllListeners();\n    if (this._paused) {\n        // Don't exit if a read is currently running\n        this._raw.close();\n        this._closed = true;\n    } else {\n        // Make sure the read is stopped ASAP\n        this._raw.readInterrupt();\n    }\n};\n//Pauses the reader, which stops \"data\" events from being emitted\nHID.prototype.pause = function pause() {\n    this._paused = true;\n    this._raw.readInterrupt();\n};\n\nHID.prototype.read = function read(callback) {\n    if (this._closed) {\n    throw new Error('Unable to read from a closed HID device');\n  } else {\n    return this._raw.read(callback);\n  }\n};\n\nHID.prototype.resume = function resume() {\n    var self = this;\n    if(self._paused && self.listeners(\"data\").length > 0)\n    {\n        //Start polling & reading loop\n        self._paused = false;\n        self.read(function readFunc(err, data) {\n            try {\n                if (self._closing) {\n                    // Discard any data if we're closing\n\n                    self._paused = true;\n                    self._raw.close();\n                    self._closed = true;\n\n                    return\n                }\n\n                if(err)\n                {\n                    //Emit error and pause reading\n                    self._paused = true;\n                    if(!self._closing)\n                        self.emit(\"error\", err);\n                    //else ignore any errors if I'm closing the device\n                }\n                else\n                {\n                    //If there are no \"data\" listeners, we pause\n                    if(self.listeners(\"data\").length <= 0)\n                        self._paused = true;\n                    //Keep reading if we aren't paused\n                    if(!self._paused)\n                        self.read(readFunc);\n                    //Now emit the event\n                    self.emit(\"data\", data);\n                }\n            } catch (e) {\n                // Emit an error on the device instead of propagating to a c++ exception\n                setImmediate(() => {\n                    if (!self._closing)\n                        self.emit(\"error\", e);\n                });\n            }\n        });\n    }\n};\n\nclass HIDAsync extends EventEmitter {\n    constructor(raw) {\n        super()\n\n        if (!(raw instanceof binding.HIDAsync)) {\n            throw new Error(`HIDAsync cannot be constructed directly. Use HIDAsync.open() instead`)\n        }\n\n        this._raw = raw\n\n        /* Now we have `this._raw` Object from which we need to\n            inherit.  So, one solution is to simply copy all\n            prototype methods over to `this` and binding them to\n            `this._raw`.\n            We explicitly wrap them in an async method, to ensure \n            that any thrown errors are promise rejections\n        */\n        for (let i in this._raw) {\n            this[i] = async (...args) => this._raw[i](...args);\n        }\n\n        /* Now upon adding a new listener for \"data\" events, we start\n            the read thread executing. See `resume()` for more details.\n        */\n        this.on(\"newListener\", (eventName, listener) =>{\n            if(eventName == \"data\")\n                process.nextTick(this.resume.bind(this) );\n        });\n        this.on(\"removeListener\", (eventName, listener) => {\n            if(eventName == \"data\" && this.listenerCount(\"data\") == 0)\n                process.nextTick(this.pause.bind(this) );\n        })\n    }\n\n    static async open(...args) {\n        loadBinding();\n        const native = await binding.openAsyncHIDDevice(...args);\n        return new HIDAsync(native)\n    }\n\n    async close() {\n        this._closing = true;\n        this.removeAllListeners();\n        await this._raw.close();\n        this._closed = true;\n    }\n    \n    //Pauses the reader, which stops \"data\" events from being emitted\n    pause() {\n        this._raw.readStop();\n    }\n\n    resume() {\n        if(this.listenerCount(\"data\") > 0)\n        {\n            //Start polling & reading loop\n            this._raw.readStart((err, data) => {\n                try {\n                    if (err) {\n                        if(!this._closing)\n                            this.emit(\"error\", err);\n                        //else ignore any errors if I'm closing the device\n                    } else {\n                        this.emit(\"data\", data);\n                    }\n                } catch (e) {\n                    // Emit an error on the device instead of propagating to a c++ exception\n                    setImmediate(() => {\n                        if (!this._closing)\n                            this.emit(\"error\", e);\n                    });\n                }\n            })\n        }\n    }\n}\n\nfunction showdevices() {\n    loadBinding();\n    return binding.devices.apply(HID,arguments);\n}\n\nfunction showdevicesAsync(...args) {\n    loadBinding();\n    return binding.devicesAsync(...args);\n}\n\n\n//Expose API\nexports.HID = HID;\nexports.HIDAsync = HIDAsync;\nexports.devices = showdevices;\nexports.devicesAsync = showdevicesAsync;\nexports.setDriverType = setDriverType;\n"]}