UNPKG

@deepkit/rpc-tcp

Version:

49 lines 1.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RpcTcpClientAdapter = void 0; const core_1 = require("@deepkit/core"); const net_1 = require("net"); /* * Uses the node `net` module to connect. Supports unix sockets. */ class RpcTcpClientAdapter { constructor(host) { this.host = (0, core_1.parseHost)(host); } async connect(connection) { const port = this.host.port || 8811; const socket = this.host.isUnixSocket ? (0, net_1.connect)({ path: this.host.unixSocket }) : (0, net_1.connect)({ port: port, host: this.host.host }); socket.on('data', (data) => { connection.readBinary(data); }); socket.on('close', () => { connection.onClose('socket closed'); }); socket.on('error', (error) => { error = error instanceof Error ? error : new Error(String(error)); connection.onError(error); }); socket.on('connect', async () => { connection.onConnected({ clientAddress: () => { return this.host.toString(); }, bufferedAmount() { //implement that to step back when too big return socket.bufferSize; }, close() { socket.end(); }, writeBinary(message) { socket.write(message); } }); }); } } exports.RpcTcpClientAdapter = RpcTcpClientAdapter; //# sourceMappingURL=client.js.map