{"version":3,"sources":["jsdelivr-header.js","/npm/unicast-definition@3.0.1/lib/unicast.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,ACNA,aAEA,MAAM,MAAS,QAAQ,QAAT,CAAmB,sBAC3B,aAAe,QAAQ,UACvB,MAAQ,QAAQ,gBAEhB,SAAW,QAAQ,0BASzB,MAAM,gBAAgB,aASpB,WAAA,CAAa,EAAK,EAAU,CAAC,GAC3B,QAEA,KAAK,QAAU,MAAM,CAAC,MAAO,EAAG,IAAK,mBAAoB,GAEzD,KAAK,IAAM,EAEX,IAAI,EAAY,EAAI,SACpB,EAAI,SAAW,CAAC,EAAQ,KACtB,IACE,EAAU,KAAK,EAAK,EAAQ,EAC9B,CAAE,MAAO,GACP,IAAI,EAAQ,MAAyB,aAAjB,EAAQ,MAChB,EAAQ,MAAQ,KAAK,QAAQ,IAGvC,MAAM,EAFN,KAAK,MAAM,EAAQ,MAAO,KAAY,EAAY,KAItD,CAAC,EAIH,KAAK,MAAQ,KAAK,KAUlB,KAAK,KAAO,CAAC,EAAO,KAAW,IACtB,EAAI,KAAK,EAAQ,IAAI,SAAS,KAAK,QAAQ,IAAK,EAAO,GAC5D,KAAK,QAAQ,OAGjB,MAAM,oCAAqC,KAAK,IAAI,IAAK,KAAK,IAAI,KACpE,CAKA,OAAA,GACE,KAAK,oBACL,KAAK,KAAO,KAAK,KACnB,EAGF,OAAO,QAAU","file":"/npm/unicast-definition@3.0.1/lib/unicast.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/unicast-definition@3.0.1/lib/unicast.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","'use strict'\n\nconst debug = (require('debug'))('unicast-definition')\nconst EventEmitter = require('events')\nconst merge = require('lodash.merge')\n\nconst MUnicast = require('./messages/municast.js')\n\n/**\n * Unicast component that simply sends messages to a neighbor.  It provides\n * easy-to-use event-like functions on top of a peer-sampling\n * protocol. Protocols can send messages using unicast.emit('eventName',\n * neighborId, args) and the neighbor can catch them using\n * unicast.on('eventName', args).\n */\nclass Unicast extends EventEmitter {\n  /**\n     * @param {IPSP} psp The peer-sampling protocol.\n     * @param {object} [options] The options of this unicast.\n     * @param {string} [options.pid = 'default-unicast'] The name of this\n     * unicast.\n     * @param {number} [option.retry = 0] The number of attempt to send a\n     * message.\n     */\n  constructor (psp, options = {}) {\n    super()\n    // #0 default options\n    this.options = merge({retry: 0, pid: 'default-unicast'}, options)\n    // #1 create the table of registered protocols\n    this.psp = psp\n    // #2 overload the receipt of messages from the peer-sampling protocol\n    let __receive = psp._receive\n    psp._receive = (peerId, message) => {\n      try {\n        __receive.call(psp, peerId, message)\n      } catch (e) {\n        if (message.type && message.type === 'MUnicast' &&\n                    message.pid === this.options.pid) {\n          this._emit(message.event, peerId, ...(message.args))\n        } else {\n          throw (e)\n        };\n      };\n    }\n\n    // #3 replace the basic behavior of eventemitter.emit\n    this._emit = this.emit\n    /**\n         * Send a message using the emit function.\n         * @param {string} event The event name.\n         * @param {string} peerId The identifier of the peer to send the event\n         * to.\n         * @param {object[]} [args] The arguments of the event.\n         * @returns {Promise} Resolved if the message seems to have been sent,\n         * rejected otherwise (e.g. timeout, unkown peers).\n         */\n    this.emit = (event, peerId, ...args) => {\n      return psp.send(peerId, new MUnicast(this.options.pid, event, args),\n        this.options.retry)\n    }\n\n    debug('just initialized on top of %s@%s.', this.psp.PID, this.psp.PEER)\n  };\n\n  /**\n     * Destroy all listeners and remove the send capabilities\n     */\n  destroy () {\n    this.removeAllListener()\n    this.emit = this._emit // retrieve basic behavior\n  };\n};\n\nmodule.exports = Unicast\n"]}