mirror of
https://github.com/bluenviron/mediamtx.git
synced 2025-12-30 06:51:59 -08:00
feat(adapter): add adapter and api server; add client UI
This commit is contained in:
parent
b8e8d8edab
commit
ae9cde4400
23 changed files with 6790 additions and 1 deletions
67
client/scripts/inspect-mqtt.js
Normal file
67
client/scripts/inspect-mqtt.js
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
#!/usr/bin/env node
|
||||
// Simple MQTT inspector: subscribe to a topic and print raw payloads (pretty JSON when possible)
|
||||
// Usage: node inspect-mqtt.js <brokerUrl> <username> <password> <topic>
|
||||
// Example: node inspect-mqtt.js wss://beta-broker-mqtt.fcam.vn:8084/mqtt myuser mypass "ipc/fss/#"
|
||||
|
||||
const mqtt = require('mqtt');
|
||||
|
||||
function tryParseJSON(s) {
|
||||
try {
|
||||
return JSON.parse(s);
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
const args = process.argv.slice(2);
|
||||
if (args.length < 4) {
|
||||
console.error('Usage: node inspect-mqtt.js <brokerUrl> <username> <password> <topic>');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const [brokerUrl, username, password, topic] = args;
|
||||
|
||||
const options = {
|
||||
username,
|
||||
password,
|
||||
reconnectPeriod: 5000,
|
||||
connectTimeout: 30000,
|
||||
};
|
||||
|
||||
console.log(`Connecting to ${brokerUrl} ...`);
|
||||
const client = mqtt.connect(brokerUrl, options);
|
||||
|
||||
client.on('connect', () => {
|
||||
console.log('Connected. Subscribing to', topic);
|
||||
client.subscribe(topic, { qos: 1 }, (err) => {
|
||||
if (err) console.error('Subscribe error', err);
|
||||
});
|
||||
});
|
||||
|
||||
client.on('message', (t, payloadBuffer) => {
|
||||
const payload = payloadBuffer.toString();
|
||||
const parsed = tryParseJSON(payload);
|
||||
console.log('---');
|
||||
console.log('Topic:', t);
|
||||
if (parsed !== null) {
|
||||
try {
|
||||
console.log('JSON payload:');
|
||||
console.log(JSON.stringify(parsed, null, 2));
|
||||
} catch (e) {
|
||||
console.log('Could not stringify JSON:', e.message);
|
||||
console.log('Raw payload:', payload);
|
||||
}
|
||||
} else {
|
||||
console.log('Raw payload (non-JSON):');
|
||||
console.log(payload);
|
||||
}
|
||||
});
|
||||
|
||||
client.on('error', (err) => {
|
||||
console.error('MQTT error:', err.message || err);
|
||||
});
|
||||
|
||||
process.on('SIGINT', () => {
|
||||
console.log('\nDisconnecting...');
|
||||
client.end(() => process.exit(0));
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue