Compare commits

...

6 Commits

6 changed files with 73 additions and 21 deletions

View File

@ -10,5 +10,5 @@ esbuild.buildSync({
define: { define: {
global: "self", global: "self",
}, },
inject: ["timers.js", "polyfill.js"], inject: ["polyfill.js"],
}); });

View File

@ -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",
@ -108,7 +109,8 @@
"protomux": "git+https://git.lumeweb.com/LumeWeb/kernel-protomux-client.git" "protomux": "git+https://git.lumeweb.com/LumeWeb/kernel-protomux-client.git"
}, },
"patchedDependencies": { "patchedDependencies": {
"@libp2p/tcp@6.1.5": "patches/@libp2p__tcp@6.1.5.patch" "@libp2p/tcp@6.1.5": "patches/@libp2p__tcp@6.1.5.patch",
"b4a@1.6.3": "patches/b4a@1.6.3.patch"
} }
} }
} }

36
patches/b4a@1.6.3.patch Normal file
View File

@ -0,0 +1,36 @@
diff --git a/browser.js b/browser.js
index e07f78d17b7b4a2963e4f0062047cc96e6025f9e..a9f266a2644f3f8ebd0f6684b3e11a7519059851 100644
--- a/browser.js
+++ b/browser.js
@@ -3,6 +3,7 @@ const base64 = require('./lib/base64')
const hex = require('./lib/hex')
const utf8 = require('./lib/utf8')
const utf16le = require('./lib/utf16le')
+const Buffer = require('buffer').Buffer
const LE = new Uint8Array(Uint16Array.of(0xff).buffer)[0] === 0xff
diff --git a/index.js b/index.js
index a751d6b4d27c7dd903efbfdc87a98f61044a62b8..8bd32640afdcfbc475168d458c51f8b9162d1656 100644
--- a/index.js
+++ b/index.js
@@ -1,3 +1,5 @@
+const Buffer = require('buffer').Buffer
+
function isBuffer (value) {
return Buffer.isBuffer(value) || value instanceof Uint8Array
}
diff --git a/package.json b/package.json
index eb0f792709b27e66f26658054781b4099507b5ed..69c4ff39c48b0bdd5f0bc7ebbade517e7c5d76e4 100644
--- a/package.json
+++ b/package.json
@@ -8,9 +8,6 @@
"index.js",
"lib"
],
- "browser": {
- "./index.js": "./browser.js"
- },
"scripts": {
"test": "standard && brittle test/*.mjs"
},

View File

@ -265,11 +265,19 @@ async function handleLs(aq: ActiveQuery) {
} }
let aborted = false; let aborted = false;
let nextChunk = defer();
aq.setReceiveUpdate?.(() => { aq.setReceiveUpdate?.((data: any) => {
switch (data) {
case "abort":
aborted = true; aborted = true;
break;
case "next":
nextChunk.resolve();
nextChunk = defer();
break;
}
}); });
const iterable = fs.ls( const iterable = fs.ls(
getCID(aq.callerInput.cid), getCID(aq.callerInput.cid),
aq.callerInput.options ?? {} aq.callerInput.options ?? {}
@ -280,6 +288,8 @@ async function handleLs(aq: ActiveQuery) {
break; break;
} }
aq.sendUpdate(JSON.parse(JSON.stringify(item))); aq.sendUpdate(JSON.parse(JSON.stringify(item)));
await nextChunk.promise;
} }
aq.respond(); aq.respond();
@ -294,9 +304,18 @@ async function handleCat(aq: ActiveQuery) {
} }
let aborted = false; let aborted = false;
let nextChunk = defer();
aq.setReceiveUpdate?.(() => { aq.setReceiveUpdate?.((data: any) => {
switch (data) {
case "abort":
aborted = true; aborted = true;
break;
case "next":
nextChunk.resolve();
nextChunk = defer();
break;
}
}); });
const iterable = fs.cat( const iterable = fs.cat(
@ -310,6 +329,8 @@ async function handleCat(aq: ActiveQuery) {
} }
aq.sendUpdate(chunk); aq.sendUpdate(chunk);
await nextChunk.promise;
} }
aq.respond(); aq.respond();

View File

@ -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,
}); });

View File

@ -1,8 +0,0 @@
import { setTimeout, setInterval, clearTimeout, clearInterval } from 'timers-browserify'
var scope = typeof self !== "undefined" && self || typeof self !== "undefined" && self || window;
scope.setTimeout = setTimeout;
scope.setInterval = setInterval;
scope.clearTimeout = clearTimeout;
scope.clearInterval = clearInterval;