From 6099a6c4f62aa49a9f8d21afbe13e3f3dfd5e60e Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sun, 9 Apr 2023 12:15:38 -0400 Subject: [PATCH] *Update dist --- dist/peer.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/dist/peer.js b/dist/peer.js index 74e1737..09b76b8 100644 --- a/dist/peer.js +++ b/dist/peer.js @@ -39,9 +39,10 @@ class Peer { async init() { const self = this; let pipe; + const raw = await maybeGetAsyncProperty(self._peer.rawStream); this._socket = new socket_js_1.default({ - remoteAddress: self._peer.rawStream.remoteHost, - remotePort: self._peer.rawStream.remotePort, + remoteAddress: raw.remoteHost, + remotePort: raw.remotePort, remotePublicKey: self._peer.remotePublicKey, async write(data, cb) { if (pipe) { @@ -90,3 +91,17 @@ class Peer { } } exports.default = Peer; +async function maybeGetAsyncProperty(object) { + if (typeof object === "function") { + object = object(); + } + if (isPromise(object)) { + object = await object; + } + return object; +} +function isPromise(obj) { + return (!!obj && + (typeof obj === "object" || typeof obj === "function") && + typeof obj.then === "function"); +}