Compare commits

..

No commits in common. "824881ed88477155ece20a4dcfae73be7d36002a" and "b6f1df264d552cc0ed50d277e94719076bef7447" have entirely different histories.

6 changed files with 21 additions and 73 deletions

View File

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

View File

@ -27,7 +27,6 @@
"@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",
@ -109,8 +108,7 @@
"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"
} }
} }
} }

View File

@ -1,36 +0,0 @@
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,19 +265,11 @@ async function handleLs(aq: ActiveQuery) {
} }
let aborted = false; let aborted = false;
let nextChunk = defer();
aq.setReceiveUpdate?.((data: any) => { aq.setReceiveUpdate?.(() => {
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 ?? {}
@ -288,8 +280,6 @@ 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();
@ -304,18 +294,9 @@ async function handleCat(aq: ActiveQuery) {
} }
let aborted = false; let aborted = false;
let nextChunk = defer();
aq.setReceiveUpdate?.((data: any) => { aq.setReceiveUpdate?.(() => {
switch (data) {
case "abort":
aborted = true; aborted = true;
break;
case "next":
nextChunk.resolve();
nextChunk = defer();
break;
}
}); });
const iterable = fs.cat( const iterable = fs.cat(
@ -329,8 +310,6 @@ async function handleCat(aq: ActiveQuery) {
} }
aq.sendUpdate(chunk); aq.sendUpdate(chunk);
await nextChunk.promise;
} }
aq.respond(); aq.respond();

View File

@ -3,7 +3,6 @@ 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");
@ -51,8 +50,8 @@ export class Socket extends Duplex {
return this._peer; return this._peer;
} }
public async _write(data: any, cb: any): Promise<void> { public _write(data: any, cb: any): void {
(await maybeGetAsyncProperty(this._peer.messages.writeSocket))?.send({ this._peer.messages.writeSocket?.send({
id: this._id, id: this._id,
remoteId: this._remoteId, remoteId: this._remoteId,
data, data,
@ -60,8 +59,8 @@ export class Socket extends Duplex {
cb(); cb();
} }
public async _destroy(cb: Callback) { public _destroy(cb: Callback) {
(await maybeGetAsyncProperty(this._peer.messages.closeSocket))?.send({ this._peer.messages.closeSocket?.send({
id: this._id, id: this._id,
remoteId: this._remoteId, remoteId: this._remoteId,
} as SocketRequest); } as SocketRequest);
@ -69,8 +68,8 @@ export class Socket extends Duplex {
this._manager.sockets.delete(this._id); this._manager.sockets.delete(this._id);
} }
public async connect() { public connect() {
(await maybeGetAsyncProperty(this._peer.messages.openSocket))?.send({ this._peer.messages.openSocket?.send({
...this._options, ...this._options,
id: this._id, id: this._id,
}); });

8
timers.js Normal file
View File

@ -0,0 +1,8 @@
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;