1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-06-15 23:00:36 +02:00

Display link to resources and display them via server.

This commit is contained in:
Laurent Cozic
2017-10-24 20:40:15 +01:00
parent 3cb52a4107
commit 13b4f3f4ea
15 changed files with 228 additions and 34 deletions

View File

@ -1,5 +1,7 @@
import { shim } from 'lib/shim.js'
const tcpPortUsed = require('tcp-port-used');
const netUtils = {};
netUtils.ip = async () => {
@ -12,4 +14,20 @@ netUtils.ip = async () => {
return ip.ip;
}
netUtils.findAvailablePort = async (possiblePorts, extraRandomPortsToTry = 20) => {
for (let i = 0; i < extraRandomPortsToTry; i++) {
possiblePorts.push(Math.floor(8000 + Math.random() * 2000));
}
let port = null;
for (let i = 0; i < possiblePorts.length; i++) {
let inUse = await tcpPortUsed.check(possiblePorts[i]);
if (!inUse) {
port = possiblePorts[i];
break;
}
}
return port;
}
export { netUtils };