UNPKG

8.5 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7var _events = require("events");
8var util = _interopRequireWildcard(require("util"));
9function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
10function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
11class Debug extends _events.EventEmitter {
12 /*
13 @options Which debug details should be sent.
14 data - dump of packet data
15 payload - details of decoded payload
16 */
17 constructor({
18 data = false,
19 payload = false,
20 packet = false,
21 token = false
22 } = {}) {
23 super();
24 this.options = {
25 data,
26 payload,
27 packet,
28 token
29 };
30 this.indent = ' ';
31 }
32 packet(direction, packet) {
33 if (this.haveListeners() && this.options.packet) {
34 this.log('');
35 this.log(direction);
36 this.log(packet.headerToString(this.indent));
37 }
38 }
39 data(packet) {
40 if (this.haveListeners() && this.options.data) {
41 this.log(packet.dataToString(this.indent));
42 }
43 }
44 payload(generatePayloadText) {
45 if (this.haveListeners() && this.options.payload) {
46 this.log(generatePayloadText());
47 }
48 }
49 token(token) {
50 if (this.haveListeners() && this.options.token) {
51 this.log(util.inspect(token, {
52 showHidden: false,
53 depth: 5,
54 colors: true
55 }));
56 }
57 }
58 haveListeners() {
59 return this.listeners('debug').length > 0;
60 }
61 log(text) {
62 this.emit('debug', text);
63 }
64}
65var _default = exports.default = Debug;
66module.exports = Debug;
67//# sourceMappingURL=data:application/json;charset=utf-8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