274 lines
8.6 KiB
HTML
274 lines
8.6 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Discord Audio Transmitter</title>
|
|
<style>
|
|
:root {
|
|
--primary: #5865F2;
|
|
--bg: #36393f;
|
|
--card-bg: #2f3136;
|
|
--text: #ffffff;
|
|
--text-muted: #b9bbbe;
|
|
}
|
|
|
|
body {
|
|
font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
|
background-color: var(--bg);
|
|
color: var(--text);
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
height: 100vh;
|
|
margin: 0;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.card {
|
|
background-color: var(--card-bg);
|
|
padding: 2rem;
|
|
border-radius: 12px;
|
|
box-shadow: 0 8px 24px rgba(0,0,0,0.2);
|
|
text-align: center;
|
|
width: 100%;
|
|
max-width: 400px;
|
|
transition: transform 0.3s ease;
|
|
}
|
|
|
|
.card:hover {
|
|
transform: translateY(-5px);
|
|
}
|
|
|
|
h1 {
|
|
font-size: 1.5rem;
|
|
margin-bottom: 0.5rem;
|
|
}
|
|
|
|
p {
|
|
color: var(--text-muted);
|
|
margin-bottom: 2rem;
|
|
}
|
|
|
|
.status {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
margin-bottom: 2rem;
|
|
font-size: 0.9rem;
|
|
}
|
|
|
|
.indicator {
|
|
width: 12px;
|
|
height: 12px;
|
|
border-radius: 50%;
|
|
background-color: #ff4747;
|
|
margin-right: 8px;
|
|
box-shadow: 0 0 8px #ff4747;
|
|
}
|
|
|
|
.indicator.active {
|
|
background-color: #43b581;
|
|
box-shadow: 0 0 8px #43b581;
|
|
}
|
|
|
|
button {
|
|
background-color: var(--primary);
|
|
color: white;
|
|
border: none;
|
|
padding: 12px 24px;
|
|
font-size: 1rem;
|
|
font-weight: 600;
|
|
border-radius: 4px;
|
|
cursor: pointer;
|
|
transition: background-color 0.2s, transform 0.1s;
|
|
width: 100%;
|
|
}
|
|
|
|
button:hover {
|
|
background-color: #4752c4;
|
|
}
|
|
|
|
button:active {
|
|
transform: scale(0.98);
|
|
}
|
|
|
|
button:disabled {
|
|
background-color: #4f545c;
|
|
cursor: not-allowed;
|
|
}
|
|
|
|
.visualizer {
|
|
width: 100%;
|
|
height: 60px;
|
|
background: rgba(0,0,0,0.1);
|
|
margin-top: 2rem;
|
|
border-radius: 4px;
|
|
display: flex;
|
|
align-items: flex-end;
|
|
gap: 2px;
|
|
padding: 4px;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
.bar {
|
|
flex: 1;
|
|
background: var(--primary);
|
|
height: 2px;
|
|
transition: height 0.1s ease;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="card">
|
|
<h1>Audio Transmitter</h1>
|
|
<p>Transmit your microphone to Discord Voice</p>
|
|
|
|
<div class="status">
|
|
<div id="indicator" class="indicator"></div>
|
|
<span id="statusText">Disconnected</span>
|
|
</div>
|
|
|
|
<button id="toggleBtn">Start Transmitting</button>
|
|
|
|
<div style="margin-top: 2rem; border-top: 1px solid #4f545c; padding-top: 1.5rem;">
|
|
<h3>Listen to Discord</h3>
|
|
<button id="listenBtn" style="margin-bottom: 0.5rem; background-color: #43b581;">Join Listen Channel</button>
|
|
<audio id="discordAudio" controls style="width: 100%; display: none;"></audio>
|
|
<p id="listenStatus" style="font-size: 0.8rem; margin-top: 0.5rem;">Click button to listen</p>
|
|
</div>
|
|
|
|
<div class="visualizer" id="visualizer">
|
|
<!-- Bars will be generated by JS -->
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
const toggleBtn = document.getElementById('toggleBtn');
|
|
const indicator = document.getElementById('indicator');
|
|
const statusText = document.getElementById('statusText');
|
|
const visualizer = document.getElementById('visualizer');
|
|
const discordAudio = document.getElementById('discordAudio');
|
|
const listenStatus = document.getElementById('listenStatus');
|
|
const listenBtn = document.getElementById('listenBtn');
|
|
|
|
let isListening = false;
|
|
listenBtn.onclick = () => {
|
|
if (isListening) {
|
|
discordAudio.pause();
|
|
discordAudio.src = '';
|
|
discordAudio.style.display = 'none';
|
|
listenBtn.innerText = 'Join Listen Channel';
|
|
listenBtn.style.backgroundColor = '#43b581';
|
|
listenStatus.innerText = 'Disconnected';
|
|
isListening = false;
|
|
} else {
|
|
discordAudio.src = '/listen';
|
|
discordAudio.style.display = 'block';
|
|
discordAudio.play();
|
|
listenBtn.innerText = 'Stop Listening';
|
|
listenBtn.style.backgroundColor = '#f04747';
|
|
listenStatus.innerText = 'Listening live...';
|
|
isListening = true;
|
|
}
|
|
};
|
|
|
|
// Create visualizer bars
|
|
for (let i = 0; i < 32; i++) {
|
|
const bar = document.createElement('div');
|
|
bar.className = 'bar';
|
|
visualizer.appendChild(bar);
|
|
}
|
|
const bars = document.querySelectorAll('.bar');
|
|
|
|
let isStreaming = false;
|
|
let socket = null;
|
|
let mediaRecorder = null;
|
|
let audioContext = null;
|
|
let analyser = null;
|
|
let dataArray = null;
|
|
|
|
toggleBtn.onclick = async () => {
|
|
if (isStreaming) {
|
|
stopStreaming();
|
|
} else {
|
|
await startStreaming();
|
|
}
|
|
};
|
|
|
|
async function startStreaming() {
|
|
try {
|
|
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
|
|
|
// WebSocket Setup
|
|
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
socket = new WebSocket(`${protocol}//${window.location.host}`);
|
|
socket.binaryType = 'arraybuffer';
|
|
|
|
socket.onopen = () => {
|
|
indicator.classList.add('active');
|
|
statusText.innerText = 'Transmitting...';
|
|
toggleBtn.innerText = 'Stop Transmitting';
|
|
isStreaming = true;
|
|
|
|
// MediaRecorder Setup
|
|
mediaRecorder = new MediaRecorder(stream, {
|
|
mimeType: 'audio/webm;codecs=opus'
|
|
});
|
|
|
|
mediaRecorder.ondataavailable = async (event) => {
|
|
if (event.data.size > 0 && socket.readyState === WebSocket.OPEN) {
|
|
socket.send(await event.data.arrayBuffer());
|
|
}
|
|
};
|
|
|
|
mediaRecorder.start(100); // 100ms chunks
|
|
};
|
|
|
|
socket.onclose = () => {
|
|
stopStreaming();
|
|
};
|
|
|
|
// Visualizer Setup
|
|
audioContext = new (window.AudioContext || window.webkitAudioContext)();
|
|
const source = audioContext.createMediaStreamSource(stream);
|
|
analyser = audioContext.createAnalyser();
|
|
analyser.fftSize = 64;
|
|
source.connect(analyser);
|
|
dataArray = new Uint8Array(analyser.frequencyBinCount);
|
|
draw();
|
|
|
|
} catch (err) {
|
|
console.error('Error accessing microphone:', err);
|
|
alert('Could not access microphone. Make sure you are on HTTPS or localhost.');
|
|
}
|
|
}
|
|
|
|
function stopStreaming() {
|
|
if (mediaRecorder) mediaRecorder.stop();
|
|
if (socket) socket.close();
|
|
if (audioContext) audioContext.close();
|
|
|
|
indicator.classList.remove('active');
|
|
statusText.innerText = 'Disconnected';
|
|
toggleBtn.innerText = 'Start Transmitting';
|
|
isStreaming = false;
|
|
|
|
bars.forEach(bar => bar.style.height = '2px');
|
|
}
|
|
|
|
function draw() {
|
|
if (!isStreaming) return;
|
|
requestAnimationFrame(draw);
|
|
analyser.getByteFrequencyData(dataArray);
|
|
|
|
bars.forEach((bar, index) => {
|
|
const value = dataArray[index] || 0;
|
|
const percent = (value / 255) * 100;
|
|
bar.style.height = `${Math.max(2, percent)}%`;
|
|
});
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|