31 lines
897 B
JavaScript
31 lines
897 B
JavaScript
// Placeholder for WebRTC Voice Logic
|
|
class VoiceChannel {
|
|
constructor(ws) {
|
|
this.ws = ws;
|
|
this.localStream = null;
|
|
this.peers = {};
|
|
}
|
|
|
|
async join(channelId) {
|
|
console.log('Joining voice channel:', channelId);
|
|
try {
|
|
this.localStream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
|
this.ws.send(JSON.stringify({
|
|
type: 'voice_join',
|
|
channel_id: channelId
|
|
}));
|
|
// Signalization would happen here via WS
|
|
} catch (e) {
|
|
console.error('Failed to get local stream:', e);
|
|
alert('Could not access microphone.');
|
|
}
|
|
}
|
|
|
|
leave() {
|
|
if (this.localStream) {
|
|
this.localStream.getTracks().forEach(track => track.stop());
|
|
}
|
|
this.ws.send(JSON.stringify({ type: 'voice_leave' }));
|
|
}
|
|
}
|