Compare commits
No commits in common. "6099a6c4f62aa49a9f8d21afbe13e3f3dfd5e60e" and "94e817f0450b9af819249f8ce91315c16fcb5f9e" have entirely different histories.
6099a6c4f6
...
94e817f045
|
@ -39,10 +39,9 @@ class Peer {
|
|||
async init() {
|
||||
const self = this;
|
||||
let pipe;
|
||||
const raw = await maybeGetAsyncProperty(self._peer.rawStream);
|
||||
this._socket = new socket_js_1.default({
|
||||
remoteAddress: raw.remoteHost,
|
||||
remotePort: raw.remotePort,
|
||||
remoteAddress: self._peer.rawStream.remoteHost,
|
||||
remotePort: self._peer.rawStream.remotePort,
|
||||
remotePublicKey: self._peer.remotePublicKey,
|
||||
async write(data, cb) {
|
||||
if (pipe) {
|
||||
|
@ -91,17 +90,3 @@ 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");
|
||||
}
|
||||
|
|
25
src/peer.ts
25
src/peer.ts
|
@ -101,10 +101,9 @@ export default class Peer {
|
|||
async init() {
|
||||
const self = this;
|
||||
let pipe;
|
||||
const raw = await maybeGetAsyncProperty(self._peer.rawStream);
|
||||
this._socket = new Socket({
|
||||
remoteAddress: raw.remoteHost,
|
||||
remotePort: raw.remotePort,
|
||||
remoteAddress: self._peer.rawStream.remoteHost,
|
||||
remotePort: self._peer.rawStream.remotePort,
|
||||
remotePublicKey: self._peer.remotePublicKey,
|
||||
async write(data: any, cb: Function) {
|
||||
if (pipe) {
|
||||
|
@ -158,23 +157,3 @@ export default class Peer {
|
|||
await this._channel.open();
|
||||
}
|
||||
}
|
||||
|
||||
async function maybeGetAsyncProperty(object: any) {
|
||||
if (typeof object === "function") {
|
||||
object = object();
|
||||
}
|
||||
|
||||
if (isPromise(object)) {
|
||||
object = await object;
|
||||
}
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
function isPromise(obj: Promise<any>) {
|
||||
return (
|
||||
!!obj &&
|
||||
(typeof obj === "object" || typeof obj === "function") &&
|
||||
typeof obj.then === "function"
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue