* Add '@lumeweb/libkernel-universal' as dependency and make socket.ts asynchronous using 'maybeGetAsyncProperty'.
This commit is contained in:
parent
1dedb7b240
commit
50271fad44
|
@ -27,6 +27,7 @@
|
||||||
"@libp2p/utils": "^3.0.7",
|
"@libp2p/utils": "^3.0.7",
|
||||||
"@lumeweb/kernel-protomux-client": "git+https://git.lumeweb.com/LumeWeb/kernel-protomux-client.git",
|
"@lumeweb/kernel-protomux-client": "git+https://git.lumeweb.com/LumeWeb/kernel-protomux-client.git",
|
||||||
"@lumeweb/kernel-swarm-client": "git+https://git.lumeweb.com/LumeWeb/kernel-swarm-client.git",
|
"@lumeweb/kernel-swarm-client": "git+https://git.lumeweb.com/LumeWeb/kernel-swarm-client.git",
|
||||||
|
"@lumeweb/libkernel-universal": "git+https://git.lumeweb.com/LumeWeb/libkernel-universal.git",
|
||||||
"@multiformats/mafmt": "^11.1.2",
|
"@multiformats/mafmt": "^11.1.2",
|
||||||
"@peculiar/webcrypto": "git+https://git.lumeweb.com/LumeWeb/webcrypto.git",
|
"@peculiar/webcrypto": "git+https://git.lumeweb.com/LumeWeb/webcrypto.git",
|
||||||
"b4a": "^1.6.3",
|
"b4a": "^1.6.3",
|
||||||
|
|
|
@ -3,6 +3,7 @@ import { TcpSocketConnectOpts } from "net";
|
||||||
import { PeerEntity, SocketRequest, WriteSocketRequest } from "./types.js";
|
import { PeerEntity, SocketRequest, WriteSocketRequest } from "./types.js";
|
||||||
import PeerManager from "./peerManager.js";
|
import PeerManager from "./peerManager.js";
|
||||||
import { clearTimeout } from "timers";
|
import { clearTimeout } from "timers";
|
||||||
|
import { maybeGetAsyncProperty } from "@lumeweb/libkernel-universal";
|
||||||
|
|
||||||
const asyncIterator = Symbol.asyncIterator || Symbol("asyncIterator");
|
const asyncIterator = Symbol.asyncIterator || Symbol("asyncIterator");
|
||||||
|
|
||||||
|
@ -50,8 +51,8 @@ export class Socket extends Duplex {
|
||||||
return this._peer;
|
return this._peer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public _write(data: any, cb: any): void {
|
public async _write(data: any, cb: any): Promise<void> {
|
||||||
this._peer.messages.writeSocket?.send({
|
(await maybeGetAsyncProperty(this._peer.messages.writeSocket))?.send({
|
||||||
id: this._id,
|
id: this._id,
|
||||||
remoteId: this._remoteId,
|
remoteId: this._remoteId,
|
||||||
data,
|
data,
|
||||||
|
@ -59,8 +60,8 @@ export class Socket extends Duplex {
|
||||||
cb();
|
cb();
|
||||||
}
|
}
|
||||||
|
|
||||||
public _destroy(cb: Callback) {
|
public async _destroy(cb: Callback) {
|
||||||
this._peer.messages.closeSocket?.send({
|
(await maybeGetAsyncProperty(this._peer.messages.closeSocket))?.send({
|
||||||
id: this._id,
|
id: this._id,
|
||||||
remoteId: this._remoteId,
|
remoteId: this._remoteId,
|
||||||
} as SocketRequest);
|
} as SocketRequest);
|
||||||
|
@ -68,8 +69,8 @@ export class Socket extends Duplex {
|
||||||
this._manager.sockets.delete(this._id);
|
this._manager.sockets.delete(this._id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public connect() {
|
public async connect() {
|
||||||
this._peer.messages.openSocket?.send({
|
(await maybeGetAsyncProperty(this._peer.messages.openSocket))?.send({
|
||||||
...this._options,
|
...this._options,
|
||||||
id: this._id,
|
id: this._id,
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue