removed fingerprint again and added salt for the name creator
This commit is contained in:
parent
4e4bd6a145
commit
d02a51f0ca
118
client.html
118
client.html
@ -151,67 +151,37 @@
|
||||
</div>
|
||||
|
||||
<script type="module">
|
||||
const fpPromise = import('https://openfpcdn.io/fingerprintjs/v5')
|
||||
.then(FingerprintJS => FingerprintJS.load());
|
||||
|
||||
// ── Name generation from IP ───────────────────────────────────────────
|
||||
function hashString(str) {
|
||||
let hash = 5381;
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
hash = ((hash << 5) + hash) + str.charCodeAt(i);
|
||||
hash = hash & 0x7fffffff; // keep positive 31-bit
|
||||
hash = hash & 0x7fffffff;
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
function visitorIdToName(input) {
|
||||
const adjectives = [
|
||||
'Fast', 'Slow', 'Red', 'Blue', 'Green', 'Dark', 'Bright', 'Wild',
|
||||
'Cool', 'Hot', 'Big', 'Small', 'Sharp', 'Brave', 'Swift', 'Bold'
|
||||
];
|
||||
const nouns = [
|
||||
'Wolf', 'Eagle', 'Tiger', 'Bear', 'Fox', 'Lion', 'Hawk', 'Shark',
|
||||
'Snake', 'Raven', 'Storm', 'Rock', 'Fire', 'Ice', 'Wind', 'Steel'
|
||||
];
|
||||
const h1 = hashString(input);
|
||||
const h2 = hashString(input + '1');
|
||||
const h3 = hashString(input + '2');
|
||||
const adjIndex = h1 % adjectives.length;
|
||||
const nounIndex = h2 % nouns.length;
|
||||
const number = h3 % 9999;
|
||||
return `${adjectives[adjIndex]} ${nouns[nounIndex]} ${number}`;
|
||||
}
|
||||
|
||||
let visitorName = null;
|
||||
|
||||
async function initVisitorName() {
|
||||
try {
|
||||
const fp = await fpPromise;
|
||||
const result = await fp.get();
|
||||
if (result.visitorId) {
|
||||
visitorName = visitorIdToName(result.visitorId);
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
}
|
||||
// Fallback: request IP from server
|
||||
// Wait until WebSocket is open
|
||||
const waitForIp = new Promise(resolve => {
|
||||
await new Promise(resolve => {
|
||||
const handler = e => {
|
||||
if (e.data instanceof Blob) return;
|
||||
const msg = JSON.parse(e.data);
|
||||
if (msg.type === 'your_ip') {
|
||||
visitorName = visitorIdToName(msg.ip);
|
||||
sigWs.removeEventListener('message', handler);
|
||||
resolve();
|
||||
}
|
||||
try {
|
||||
const msg = JSON.parse(e.data);
|
||||
if (msg.type === 'your_ip') {
|
||||
visitorName = msg.ip; // server already sent the name
|
||||
sigWs.removeEventListener('message', handler);
|
||||
resolve();
|
||||
}
|
||||
} catch {}
|
||||
};
|
||||
sigWs.addEventListener('message', handler);
|
||||
sigWs.send(JSON.stringify({ type: 'get_ip' }));
|
||||
});
|
||||
await waitForIp;
|
||||
}
|
||||
|
||||
|
||||
// ── State ─────────────────────────────────────────────────────────────
|
||||
const SIG_URL = `${location.protocol === 'https:' ? 'wss' : 'ws'}://${location.host}`;
|
||||
|
||||
const statusEl = document.getElementById('status');
|
||||
@ -220,17 +190,15 @@
|
||||
const queueList = document.getElementById('queue-list');
|
||||
const loadingEl = document.getElementById('loading-overlay');
|
||||
|
||||
let sigWs = null;
|
||||
let pc = null;
|
||||
let sessionId = null;
|
||||
let pointerLocked = false;
|
||||
let isControlling = false;
|
||||
let isInQueue = false;
|
||||
let sigWs = null;
|
||||
let pc = null;
|
||||
let sessionId = null;
|
||||
let pointerLocked = false;
|
||||
let isControlling = false;
|
||||
let isInQueue = false;
|
||||
let isWaitingForRestart = false;
|
||||
|
||||
function setStatus(msg) {
|
||||
statusEl.textContent = msg;
|
||||
}
|
||||
function setStatus(msg) { statusEl.textContent = msg; }
|
||||
|
||||
function setLoading(visible) {
|
||||
loadingEl.classList.toggle('visible', visible);
|
||||
@ -270,9 +238,7 @@
|
||||
video: false,
|
||||
});
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
} catch (e) { return false; }
|
||||
}
|
||||
|
||||
async function startMic() {
|
||||
@ -292,7 +258,9 @@
|
||||
if (sigWs && sigWs.readyState === WebSocket.OPEN) sigWs.send(int16.buffer);
|
||||
};
|
||||
source.connect(micProcessor);
|
||||
micProcessor.connect(audioContext.destination);
|
||||
// Connect to a dummy destination to keep onaudioprocess firing
|
||||
// without routing audio to speakers
|
||||
micProcessor.connect(audioContext.createMediaStreamDestination());
|
||||
micActive = true;
|
||||
}
|
||||
|
||||
@ -316,9 +284,9 @@
|
||||
}
|
||||
|
||||
function enterControl() {
|
||||
isControlling = true;
|
||||
isInQueue = false;
|
||||
isWaitingForRestart = false;
|
||||
isControlling = true;
|
||||
isInQueue = false;
|
||||
isWaitingForRestart = false;
|
||||
canvas.classList.replace('watching', 'controlling');
|
||||
canvas.muted = false;
|
||||
canvas.requestPointerLock();
|
||||
@ -326,15 +294,13 @@
|
||||
}
|
||||
|
||||
function exitControl() {
|
||||
isControlling = false;
|
||||
isInQueue = false;
|
||||
isWaitingForRestart = false;
|
||||
isControlling = false;
|
||||
isInQueue = false;
|
||||
isWaitingForRestart = false;
|
||||
canvas.classList.replace('controlling', 'watching');
|
||||
hintEl.textContent = 'Click to take control';
|
||||
stopMic();
|
||||
if (document.pointerLockElement === canvas) {
|
||||
document.exitPointerLock();
|
||||
}
|
||||
if (document.pointerLockElement === canvas) document.exitPointerLock();
|
||||
}
|
||||
|
||||
// ── WebRTC ────────────────────────────────────────────────────────────
|
||||
@ -366,12 +332,11 @@
|
||||
setStatus('Connecting...');
|
||||
sigWs = new WebSocket(SIG_URL);
|
||||
|
||||
sigWs.onopen = () => {
|
||||
setStatus('Connected — setting up stream...');
|
||||
initVisitorName().then(() => {
|
||||
});
|
||||
setupPeerConnection();
|
||||
};
|
||||
sigWs.onopen = () => {
|
||||
setStatus('Connected — setting up stream...');
|
||||
initVisitorName();
|
||||
setupPeerConnection();
|
||||
};
|
||||
|
||||
sigWs.onmessage = async e => {
|
||||
if (e.data instanceof Blob) return;
|
||||
@ -443,13 +408,12 @@
|
||||
}
|
||||
|
||||
canvas.addEventListener('click', () => {
|
||||
if (isControlling) {
|
||||
// Already controller, just recapture pointer lock
|
||||
canvas.muted = false;
|
||||
canvas.requestPointerLock();
|
||||
} else {
|
||||
requestControl();
|
||||
}
|
||||
if (isControlling) {
|
||||
canvas.muted = false;
|
||||
canvas.requestPointerLock();
|
||||
} else {
|
||||
requestControl();
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener('pointerlockchange', () => {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
cd ~/webclient_css_ze/streaming-agent
|
||||
CF_APP_ID= CF_APP_TOKEN= node signaling-server.js &> ../signaling.log &
|
||||
CF_APP_ID= CF_APP_TOKEN= NAME_SALT= node signaling-server.js &> ../signaling.log &
|
||||
echo "Signaling server started (PID $!), logs at webclient_css_ze/signaling.log"
|
||||
|
||||
#pkill -f signaling-server.js
|
||||
|
||||
@ -204,6 +204,29 @@ function stopPacat(browserSessId) {
|
||||
if (pacat) { pacat.kill(); pacatProcesses.delete(browserSessId); }
|
||||
}
|
||||
|
||||
const NAME_SALT = process.env.NAME_SALT || 'change-this-secret';
|
||||
|
||||
function hashString(str) {
|
||||
let hash = 5381;
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
hash = ((hash << 5) + hash) + str.charCodeAt(i);
|
||||
hash = hash & 0x7fffffff;
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
function ipToName(ip) {
|
||||
const adjectives = ['Fast','Slow','Red','Blue','Green','Dark','Bright','Wild',
|
||||
'Cool','Hot','Big','Small','Sharp','Brave','Swift','Bold'];
|
||||
const nouns = ['Wolf','Eagle','Tiger','Bear','Fox','Lion','Hawk','Shark',
|
||||
'Snake','Raven','Storm','Rock','Fire','Ice','Wind','Steel'];
|
||||
const salted = ip + NAME_SALT;
|
||||
const h1 = hashString(salted);
|
||||
const h2 = hashString(salted + '1');
|
||||
const h3 = hashString(salted + '2');
|
||||
return `${adjectives[h1 % adjectives.length]} ${nouns[h2 % nouns.length]} ${h3 % 9999}`;
|
||||
}
|
||||
|
||||
// ── WebSocket handler ─────────────────────────────────────────────────────────
|
||||
wss.on('connection', ws => {
|
||||
let role = null;
|
||||
@ -337,7 +360,8 @@ wss.on('connection', ws => {
|
||||
}
|
||||
else if (msg.type === 'get_ip') {
|
||||
const ip = ws._socket.remoteAddress.replace('::ffff:', '');
|
||||
ws.send(JSON.stringify({ type: 'your_ip', ip }));
|
||||
const name = ipToName(ip);
|
||||
ws.send(JSON.stringify({ type: 'your_ip', ip: name }));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user