Hopefully fix browser websocket issue, npm 0.3.2

This commit is contained in:
nitowa
2024-10-14 04:47:05 +02:00
parent b5c71753cc
commit d345e87bf0
8 changed files with 1902 additions and 1242 deletions
+3 -3
View File
@@ -25,10 +25,10 @@ export type Options = {
export const defaultOptions: Options = {
debug: false,
connectionTimeout: 100000,
readFreshApi: true,
connectionTimeout: 5000,
readFreshApi: false,
readMaxRetry: 50,
readRetryTimeout: 750,
writeMaxRetry: 10,
writeRetryTimeout: 10000
writeRetryTimeout: 1000
}
+3 -6
View File
@@ -1,5 +1,7 @@
const path = require('path');
const webpack = require('webpack');
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');
module.exports = {
mode: "production",
@@ -13,12 +15,6 @@ module.exports = {
resolve: {
extensions: [".ts", ".tsx", ".js"],
fallback: {
"https": require.resolve("https-browserify"),
"zlib": require.resolve("browserify-zlib"),
"stream": require.resolve("stream-browserify"),
"crypto": require.resolve("crypto-browserify"),
"http": require.resolve("stream-http"),
"https": require.resolve("https-browserify")
}
},
module: {
@@ -35,6 +31,7 @@ module.exports = {
externals: {
},
plugins: [
new NodePolyfillPlugin(),
new webpack.ProvidePlugin({
process: 'process/browser',
Buffer: ['buffer', 'Buffer']
+4 -22
View File
@@ -16,7 +16,6 @@ const PAYLOAD_SIZE = 925
const XRP_PER_DROP = 0.000001
const DROP_PER_XRP = 1000000
export class xrpIO {
private api: Client
@@ -85,7 +84,7 @@ export class xrpIO {
Memos: [{
Memo: {
MemoData: hexEncode(data.data || ""),
MemoFormat: hexEncode(data.format || "0"),
MemoFormat: hexEncode(data.format || ""),
MemoType: hexEncode(data.type || "")
}
}]
@@ -217,33 +216,16 @@ export class xrpIO {
return await this.treeWrite(JSON.stringify(hashes), to, secret, `${hashes.length}`)
}
private maxMemos = 0
public async treeRead(hashes: string[], verifyOwner?:string, progressCallback:(max:number,finished:number)=>void = ()=>{}): Promise<string> {
public async treeRead(hashes: string[], verifyOwner?:string): Promise<string> {
const bad_hash = hashes.find(hash => !NON_ZERO_TX_HASH.test(hash))
if (bad_hash)
throw new BadTxHashError(bad_hash)
let count = 0;
const memos = await Promise.all(hashes.map(async hash => {
const memo = await this.readRaw(hash, verifyOwner)
if(String(memo.format) === '0'){
count += 1;
progressCallback(count, this.maxMemos)
if(count === this.maxMemos){
this.maxMemos = 0;
}
}else{
this.maxMemos = Math.max(this.maxMemos, Number(memo.format))
progressCallback(-1, this.maxMemos)
}
return memo
}))
const memos = await Promise.all(hashes.map(async hash => this.readRaw(hash, verifyOwner)))
const payload: string = await decompressB64(memos.map(memo => memo.data).join(''))
if (memos.some(memo => memo.format !== '0')) {
return await this.treeRead(JSON.parse(payload), verifyOwner, progressCallback)
return await this.treeRead(JSON.parse(payload), verifyOwner)
}
return payload