You've already forked fm-dx-webserver
mirror of
https://github.com/KubaPro010/fm-dx-webserver.git
synced 2026-02-27 06:23:53 +01:00
remote control support
This commit is contained in:
@@ -6,10 +6,10 @@ FM-DX Webserver is a cross-platform web server designed for FM DXers who want to
|
|||||||
|
|
||||||
- 🌐 **Web-Based Control:** Access and control your TEF6686 / F1HD receiver from any device with a web browser.
|
- 🌐 **Web-Based Control:** Access and control your TEF6686 / F1HD receiver from any device with a web browser.
|
||||||
- 📻 **FM DXing:** Enhance your FM DXing experience with a user-friendly web interface.
|
- 📻 **FM DXing:** Enhance your FM DXing experience with a user-friendly web interface.
|
||||||
|
- **Cross-Platform:** You can run this on both Windows and Linux servers along with xdrd.
|
||||||
|
|
||||||
## Features to be added
|
## Features to be added
|
||||||
- **Tuner control:** Currently the tuner info is read only, however in the near future you will also be able to control via password authentication.
|
- **Tuner control:** Currently the tuner info is read only, however in the near future you will also be able to control via password authentication.
|
||||||
- **Cross-Platform:** Our main priority, as we use librdsparser, we are patiently waiting for a Windows version.
|
|
||||||
- **Low-latency streaming**: Currently planned as a feature similar to WebSDRs to provide a zero-delay audio using your browser.
|
- **Low-latency streaming**: Currently planned as a feature similar to WebSDRs to provide a zero-delay audio using your browser.
|
||||||
- **Pre-compiled app version**: Currently planned right after finishing the low-latency streaming feature.
|
- **Pre-compiled app version**: Currently planned right after finishing the low-latency streaming feature.
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ koffi.proto('void callback_ptyn(void *rds, void *user_data)');
|
|||||||
|
|
||||||
const rdsparser = {
|
const rdsparser = {
|
||||||
new: lib.func('void* rdsparser_new()'),
|
new: lib.func('void* rdsparser_new()'),
|
||||||
clear: lib.func('void* rdsparser_clear()'),
|
clear: lib.func('void rdsparser_clear(void *rds)'),
|
||||||
free: lib.func('void rdsparser_free(void *rds)'),
|
free: lib.func('void rdsparser_free(void *rds)'),
|
||||||
parse_string: lib.func('bool rdsparser_parse_string(void *rds, const char *input)'),
|
parse_string: lib.func('bool rdsparser_parse_string(void *rds, const char *input)'),
|
||||||
get_pi: lib.func('int32_t rdsparser_get_pi(void *rds)'),
|
get_pi: lib.func('int32_t rdsparser_get_pi(void *rds)'),
|
||||||
@@ -107,8 +107,8 @@ const callbacks = {
|
|||||||
}, 'callback_rt *'),
|
}, 'callback_rt *'),
|
||||||
|
|
||||||
ptyn: koffi.register((rds, flag) => (
|
ptyn: koffi.register((rds, flag) => (
|
||||||
value = decode_unicode(rdsparser.get_ptyn(rds)),
|
value = decode_unicode(rdsparser.get_ptyn(rds))
|
||||||
console.log('PTYN: ' + value)
|
/*console.log('PTYN: ' + value)*/
|
||||||
), 'callback_ptyn *')
|
), 'callback_ptyn *')
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
68
index.js
68
index.js
@@ -6,29 +6,37 @@ const path = require('path');
|
|||||||
const net = require('net');
|
const net = require('net');
|
||||||
const cors = require('cors');
|
const cors = require('cors');
|
||||||
const axios = require('axios');
|
const axios = require('axios');
|
||||||
|
const crypto = require('crypto');
|
||||||
|
|
||||||
|
let receivedSalt = '';
|
||||||
|
let receivedPassword = false;
|
||||||
// Other JS files
|
// Other JS files
|
||||||
const dataHandler = require('./datahandler');
|
const dataHandler = require('./datahandler');
|
||||||
|
const config = require('./userconfig');
|
||||||
|
|
||||||
/* Server settings */
|
/* Server settings */
|
||||||
const webServerHost = '192.168.1.14'; // IP of the web server
|
const webServerHost = config.webServerHost; // IP of the web server
|
||||||
const webServerPort = 8080; // web server port
|
const webServerPort = config.webServerPort; // web server port
|
||||||
|
|
||||||
const xdrdServerHost = '192.168.1.15'; // xdrd server iP
|
const xdrdServerHost = config.xdrdServerHost; // xdrd server iP
|
||||||
const xdrdServerPort = 7373; // xdrd server port
|
const xdrdServerPort = config.xdrdServerPort; // xdrd server port
|
||||||
|
const xdrdPassword = config.xdrdPassword;
|
||||||
|
|
||||||
const wss = new WebSocket.Server({ noServer: true });
|
const wss = new WebSocket.Server({ noServer: true });
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
const httpServer = http.createServer(app);
|
const httpServer = http.createServer(app);
|
||||||
|
/* connection to xdrd */
|
||||||
|
const client = new net.Socket();
|
||||||
|
|
||||||
/* webSocket handlers */
|
/* webSocket handlers */
|
||||||
wss.on('connection', (ws) => {
|
wss.on('connection', (ws) => {
|
||||||
console.log('WebSocket client connected');
|
console.log('WebSocket client connected');
|
||||||
|
|
||||||
ws.on('message', (message) => {
|
ws.on('message', (message) => {
|
||||||
console.log('Received message from client:', message);
|
console.log('Received message from client:', message.toString());
|
||||||
|
newFreq = message.toString() * 1000;
|
||||||
|
client.write("T" + newFreq + '\n');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -36,15 +44,56 @@ wss.on('connection', (ws) => {
|
|||||||
// Serve static files from the "web" folder
|
// Serve static files from the "web" folder
|
||||||
app.use(express.static(path.join(__dirname, 'web')));
|
app.use(express.static(path.join(__dirname, 'web')));
|
||||||
|
|
||||||
/* connection to xdrd */
|
// Function to authenticate with the xdrd server
|
||||||
const client = new net.Socket();
|
function authenticateWithXdrd(client, salt, password) {
|
||||||
|
const sha1 = crypto.createHash('sha1');
|
||||||
|
|
||||||
|
// Convert salt and password to buffers
|
||||||
|
const saltBuffer = Buffer.from(salt, 'utf-8');
|
||||||
|
const passwordBuffer = Buffer.from(password, 'utf-8');
|
||||||
|
|
||||||
|
// Update the hash context with salt and password
|
||||||
|
sha1.update(saltBuffer);
|
||||||
|
sha1.update(passwordBuffer);
|
||||||
|
|
||||||
|
// Finalize the hash and get the hashed password
|
||||||
|
const hashedPassword = sha1.digest('hex');
|
||||||
|
client.write(hashedPassword + '\n');
|
||||||
|
client.write('x\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
// WebSocket client connection
|
||||||
client.connect(xdrdServerPort, xdrdServerHost, () => {
|
client.connect(xdrdServerPort, xdrdServerHost, () => {
|
||||||
console.log('Connected to xdrd');
|
console.log('Connected to xdrd');
|
||||||
|
|
||||||
|
client.once('data', (data) => {
|
||||||
|
const receivedData = data.toString();
|
||||||
|
const lines = receivedData.split('\n');
|
||||||
|
|
||||||
|
// Assuming that the first message contains the salt
|
||||||
|
if (lines.length > 0 && !receivedPassword) {
|
||||||
|
receivedSalt = lines[0].trim();
|
||||||
|
authenticateWithXdrd(client, receivedSalt, xdrdPassword);
|
||||||
|
receivedPassword = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on('data', (data) => {
|
client.on('data', (data) => {
|
||||||
const receivedData = data.toString();
|
const receivedData = data.toString();
|
||||||
|
|
||||||
|
const lines = receivedData.split('\n');
|
||||||
|
|
||||||
|
// If there's at least one line, set it as the received salt
|
||||||
|
/*if (lines.length > 0 && receivedPassword === false) {
|
||||||
|
receivedSalt = lines[0].trim(); // Trim any leading or trailing whitespace
|
||||||
|
console.log('Received Salt:', receivedSalt);
|
||||||
|
|
||||||
|
// Authentication logic
|
||||||
|
authenticateWithXdrd(client, receivedSalt, xdrdPassword);
|
||||||
|
receivedPassword = true;
|
||||||
|
}*/
|
||||||
|
|
||||||
wss.clients.forEach((client) => {
|
wss.clients.forEach((client) => {
|
||||||
if (client.readyState === WebSocket.OPEN) {
|
if (client.readyState === WebSocket.OPEN) {
|
||||||
dataHandler.handleData(client, receivedData);
|
dataHandler.handleData(client, receivedData);
|
||||||
@@ -52,12 +101,11 @@ client.on('data', (data) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
client.on('close', () => {
|
client.on('close', () => {
|
||||||
console.log('Disconnected from xdrd');
|
console.log('Disconnected from xdrd');
|
||||||
});
|
});
|
||||||
|
|
||||||
client.write('x');
|
|
||||||
|
|
||||||
/* HTTP Server */
|
/* HTTP Server */
|
||||||
|
|
||||||
httpServer.on('upgrade', (request, socket, head) => {
|
httpServer.on('upgrade', (request, socket, head) => {
|
||||||
|
|||||||
10
userconfig.js
Normal file
10
userconfig.js
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
const webServerHost = '192.168.1.14'; // IP of the web server
|
||||||
|
const webServerPort = 8080; // web server port
|
||||||
|
|
||||||
|
const xdrdServerHost = '192.168.1.15'; // xdrd server iP
|
||||||
|
const xdrdServerPort = 7373; // xdrd server port
|
||||||
|
const xdrdPassword = ''; // xdrd password (optional)
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
webServerHost, webServerPort, xdrdServerHost, xdrdServerPort, xdrdPassword
|
||||||
|
};
|
||||||
@@ -51,8 +51,9 @@
|
|||||||
<input type="range" id="volumeSlider" min="0" max="1" step="0.01" value="1">
|
<input type="range" id="volumeSlider" min="0" max="1" step="0.01" value="1">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="panel-33" style="opacity: 0;">
|
<div class="panel-33" style="opacity: 1;">
|
||||||
<button id="playButton">play</button>
|
<!--<button id="playButton">play</button>-->
|
||||||
|
<input type="text" id="commandinput" inputmode="numeric" placeholder="Frequency">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="panel-33" style="height: 48px;">
|
<div class="panel-33" style="height: 48px;">
|
||||||
@@ -74,7 +75,10 @@
|
|||||||
<div id="data-container" style="display: none;"></div>
|
<div id="data-container" style="display: none;"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="data-af" style="text-align: center;"></div>
|
<div class="panel-100" style="overflow: hidden">
|
||||||
|
<h2 style="margin: 0;">AF</h2>
|
||||||
|
<div id="data-af" style="text-align: center;"></div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button id="settings"><i class="fa-solid fa-gear"></i></button>
|
<button id="settings"><i class="fa-solid fa-gear"></i></button>
|
||||||
@@ -92,7 +96,7 @@
|
|||||||
<option value="theme4">Cyan</option>
|
<option value="theme4">Cyan</option>
|
||||||
<option value="theme5">Orange</option>
|
<option value="theme5">Orange</option>
|
||||||
</select>
|
</select>
|
||||||
<p class="text-small" style="margin-bottom: 50px;">FM-DX WebServer uses librds by <a href="https://fmdx.pl" target="_blank">Konrad Kosmatka</a>.</p>
|
<p class="text-small" style="margin-bottom: 50px;">FM-DX WebServer uses librdsparser by <a href="https://fmdx.pl" target="_blank">Konrad Kosmatka</a>.</p>
|
||||||
<button class="button-close" id="closeModalButton">Close</button>
|
<button class="button-close" id="closeModalButton">Close</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
65
web/main.js
65
web/main.js
@@ -166,3 +166,68 @@ signalToggle.addEventListener("change", function() {
|
|||||||
signalText.textContent = 'dBf';
|
signalText.textContent = 'dBf';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const textInput = document.getElementById('commandinput');
|
||||||
|
|
||||||
|
textInput.addEventListener('keyup', function (event) {
|
||||||
|
// Get the current input value
|
||||||
|
let inputValue = textInput.value;
|
||||||
|
|
||||||
|
// Remove non-digit characters
|
||||||
|
inputValue = inputValue.replace(/[^0-9]/g, '');
|
||||||
|
|
||||||
|
console.log("InputValue contains dot: ", inputValue.toLowerCase().includes("."));
|
||||||
|
|
||||||
|
// Determine where to add the dot based on the frequency range
|
||||||
|
if (inputValue.includes(".") === false) {
|
||||||
|
if (inputValue.startsWith('10') && inputValue.length > 2) {
|
||||||
|
// For frequencies starting with '10', add the dot after the third digit
|
||||||
|
inputValue = inputValue.slice(0, 3) + '.' + inputValue.slice(3);
|
||||||
|
textInput.value = inputValue;
|
||||||
|
} else if (inputValue.length > 2) {
|
||||||
|
// For other frequencies, add the dot after the second digit
|
||||||
|
inputValue = inputValue.slice(0, 2) + '.' + inputValue.slice(2);
|
||||||
|
textInput.value = inputValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the input value
|
||||||
|
|
||||||
|
// Check if the pressed key is 'Enter' (key code 13)
|
||||||
|
if (event.key === 'Enter') {
|
||||||
|
// Retrieve the input value
|
||||||
|
const inputValue = textInput.value;
|
||||||
|
|
||||||
|
// Send the input value to the WebSocket
|
||||||
|
if (socket.readyState === WebSocket.OPEN) {
|
||||||
|
socket.send(inputValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear the input field if needed
|
||||||
|
textInput.value = '';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
document.onkeydown = checkKey;
|
||||||
|
|
||||||
|
function checkKey(e) {
|
||||||
|
e = e || window.event;
|
||||||
|
currentFreq = document.getElementById("data-frequency").textContent;
|
||||||
|
currentFreq = parseFloat(currentFreq).toFixed(3);
|
||||||
|
currentFreq = parseFloat(currentFreq);
|
||||||
|
|
||||||
|
if (socket.readyState === WebSocket.OPEN) {
|
||||||
|
if (e.keyCode == '38') {
|
||||||
|
socket.send((currentFreq + 0.01).toFixed(3));
|
||||||
|
}
|
||||||
|
else if (e.keyCode == '40') {
|
||||||
|
socket.send((currentFreq - 0.01).toFixed(3));
|
||||||
|
}
|
||||||
|
else if (e.keyCode == '37') {
|
||||||
|
socket.send((currentFreq - 0.10).toFixed(3));
|
||||||
|
}
|
||||||
|
else if (e.keyCode == '39') {
|
||||||
|
socket.send((currentFreq + 0.10).toFixed(3));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -130,7 +130,22 @@ h2 {
|
|||||||
background: #100d1f;
|
background: #100d1f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input[type="text"] {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
min-height: 46px;
|
||||||
|
border-radius: 30px;
|
||||||
|
padding-left: 20px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
border: 0;
|
||||||
|
color: white;
|
||||||
|
background-color: var(--color-1);
|
||||||
|
font-family: 'Titillium Web', sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type="text"]:focus {
|
||||||
|
outline: 2px solid var(--color-main-bright);
|
||||||
|
}
|
||||||
|
|
||||||
@media only screen and (max-width: 768px) {
|
@media only screen and (max-width: 768px) {
|
||||||
.flex-container {
|
.flex-container {
|
||||||
|
|||||||
Reference in New Issue
Block a user