diff --git a/wasm/src/in3.d.ts b/wasm/src/in3.d.ts index b82556279..eda9ae8b0 100644 --- a/wasm/src/in3.d.ts +++ b/wasm/src/in3.d.ts @@ -37,6 +37,13 @@ * All properties are optional and will be verified when sending the next request. */ export declare interface IN3Config { + /** + * sets the transport-function. + * + * @param fn the function to fetch the response for the given url + */ + transport?: (url: string, payload: string, timeout?: number) => Promise + /** * if true the nodelist will be automaticly updated if the lastBlock is newer. * @@ -462,7 +469,7 @@ export default class IN3Generic { /** - * changes the transport-function. + * changes the default transport-function. * * @param fn the function to fetch the response for the given url */ diff --git a/wasm/src/in3.js b/wasm/src/in3.js index 1add858da..017f4aa4e 100644 --- a/wasm/src/in3.js +++ b/wasm/src/in3.js @@ -185,6 +185,10 @@ class IN3 { } this.needsSetConfig = !this.ptr if (this.ptr) { + if (this.config.transport) { + this.transport = this.config.transport + delete this.config.transport + } const r = in3w.ccall('in3_config', 'number', ['number', 'string'], [this.ptr, JSON.stringify(this.config)]); if (r) { const ex = new Error(UTF8ToString(r)) @@ -361,7 +365,8 @@ function url_queue(req) { let counter = 0 const promises = [], responses = [] if (req.in3.config.debug) console.log("send req (" + req.ctx + ") to " + req.urls.join() + ' : ', JSON.stringify(req.payload, null, 2)) - req.urls.forEach((url, i) => in3w.transport(url, JSON.stringify(req.payload), req.timeout || 30000).then( + const transport = req.in3.transport || in3w.transport + req.urls.forEach((url, i) => transport(url, JSON.stringify(req.payload), req.timeout || 30000).then( response => { responses.push({ i, url, response }); trigger() }, error => { responses.push({ i, url, error }); trigger() } ))