@broxus/js-bridge-essentials
Version:
Bridge JavaScript Essentials library
42 lines (41 loc) • 1.58 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ProtoSocket = void 0;
// @ts-expect-error S2307: Cannot find module or its corresponding type declarations.
const core_1 = __importDefault(require("everscale-standalone-client/core"));
const DEFAULT_HEADERS = {
'Content-Type': 'application/x-protobuf',
};
class ProtoSocket {
async connect(params) {
class ProtoSender {
endpoint;
endpointAgent;
constructor(_params) {
this.endpoint = params.endpoint;
this.endpointAgent = core_1.default.fetchAgent(this.endpoint);
}
send(data, handler, _) {
(async () => {
try {
const response = await fetch(this.endpoint, {
agent: this.endpointAgent,
body: new Uint8Array(data),
headers: DEFAULT_HEADERS,
method: 'post',
}).then(res => res.arrayBuffer());
handler.onReceive(new Uint8Array(response));
}
catch (e) {
handler.onError(e);
}
})();
}
}
return new core_1.default.nekoton.ProtoConnection(new ProtoSender(params));
}
}
exports.ProtoSocket = ProtoSocket;