UNPKG

homebridge-nest-cam-ft

Version:

Nest cam plugin for homebridge: https://homebridge.io/

62 lines 2.07 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.reservePorts = exports.RtpSplitter = void 0; const dgram_1 = require("dgram"); const get_port_1 = __importDefault(require("get-port")); function getPayloadType(message) { return message.readUInt8(1) & 0x7f; } function isRtpMessage(message) { const payloadType = getPayloadType(message); return payloadType > 90 || payloadType === 0; } class RtpSplitter { constructor(serverPort, audioRTCPPort, returnAudioPort) { this.socket = (0, dgram_1.createSocket)('udp4'); const socket = this.socket; socket.on('error', (error) => { console.log('Error: ' + error); socket.close(); }); socket.on('message', (msg) => { if (isRtpMessage(msg)) { if (msg.length > 50) { socket.send(msg, returnAudioPort, 'localhost'); } else { socket.send(msg, audioRTCPPort, 'localhost'); } } else { socket.send(msg, audioRTCPPort, 'localhost'); socket.send(msg, returnAudioPort, 'localhost'); } }); socket.bind(serverPort); } close() { this.socket.close(); } } exports.RtpSplitter = RtpSplitter; async function reservePorts(count = 1) { const port = await (0, get_port_1.default)(); const ports = [port]; const tryAgain = () => { return reservePorts(count); }; for (let i = 1; i < count; i++) { const targetConsecutivePort = port + i; const openPort = await (0, get_port_1.default)({ port: targetConsecutivePort }); if (openPort !== targetConsecutivePort) { return tryAgain(); } ports.push(openPort); } return ports; } exports.reservePorts = reservePorts; //# sourceMappingURL=rtp.js.map