@jsonjoy.com/reactive-rpc
Version:
Reactive-RPC is a library for building reactive APIs over WebSocket, HTTP, and other RPCs.
46 lines • 1.66 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FetchRpcClient = void 0;
const StaticRpcClient_1 = require("./StaticRpcClient");
const EncodedStaticRpcClient_1 = require("./EncodedStaticRpcClient");
class FetchRpcClient {
constructor(options) {
const { msgCodec, reqCodec, resCodec = reqCodec, url } = options;
let contentType = `application/x.rpc.${msgCodec.id}.${reqCodec.id}`;
if (reqCodec.id !== resCodec.id)
contentType += `-${resCodec.id}`;
const currentFetch = options.fetch || fetch;
this.client = new EncodedStaticRpcClient_1.EncodedStaticRpcClient({
client: new StaticRpcClient_1.StaticRpcClient({
bufferSize: options.bufferSize,
bufferTime: options.bufferTime,
}),
msgCodec,
reqCodec,
resCodec,
send: async (body) => {
const response = await currentFetch(url, {
method: 'POST',
headers: {
'Content-Type': contentType,
},
body,
});
const buffer = await response.arrayBuffer();
return new Uint8Array(buffer);
},
});
}
call$(method, data) {
return this.client.call$(method, data);
}
async call(method, request) {
return this.client.call(method, request);
}
notify(method, data) {
this.client.notify(method, data);
}
stop() { }
}
exports.FetchRpcClient = FetchRpcClient;
//# sourceMappingURL=FetchRpcClient.js.map