UNPKG

@tgsnake/core

Version:

Pure Telegram MTProto library for nodejs

32 lines (31 loc) 1.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TCPIntermediate = void 0; const platform_node_js_1 = require("../../platform.node.js"); const tcp_js_1 = require("./tcp.js"); class TCPIntermediate extends tcp_js_1.TCP { constructor() { super(); } async connect(ip, port, proxy, dcId) { await super.connect(ip, port, proxy, dcId); await super.send(platform_node_js_1.Buffer.concat([ platform_node_js_1.Buffer.from('ee', 'hex'), platform_node_js_1.Buffer.from('ee', 'hex'), platform_node_js_1.Buffer.from('ee', 'hex'), platform_node_js_1.Buffer.from('ee', 'hex'), ])); } async send(data) { const allocLength = platform_node_js_1.Buffer.alloc(4); allocLength.writeInt32LE(platform_node_js_1.Buffer.byteLength(data), 0); await super.send(platform_node_js_1.Buffer.concat([allocLength, data])); } async recv(_length = 0) { const length = await super.recv(4); if (!length) return; return await super.recv(length.readInt32LE(0)); } } exports.TCPIntermediate = TCPIntermediate;