DappMeetingV3 / public /join.html
Luisnguyen1
no final
fb2d702
Raw
History Blame Contribute Delete
11.5 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Join Meeting Room</title>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/ethers/5.7.2/ethers.umd.min.js"></script>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Poppins', sans-serif;
}
body {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
padding: 20px;
}
.app-container {
max-width: 500px;
width: 100%;
margin: 0 auto;
}
.join-form {
background: rgba(255, 255, 255, 0.95);
padding: 40px;
border-radius: 20px;
box-shadow: 0 10px 30px rgba(0,0,0,0.1);
backdrop-filter: blur(10px);
}
h2 {
color: #333;
text-align: center;
margin-bottom: 30px;
font-size: 28px;
font-weight: 600;
}
.form-group {
margin-bottom: 25px;
position: relative;
}
.form-group input {
width: 100%;
padding: 15px;
border: 2px solid #e1e1e1;
border-radius: 12px;
font-size: 16px;
transition: all 0.3s ease;
background: white;
}
.form-group input:focus {
border-color: #667eea;
outline: none;
box-shadow: 0 0 0 4px rgba(102,126,234,0.1);
}
.button-group {
display: flex;
gap: 15px;
margin-top: 35px;
}
button {
width: 100%;
padding: 15px;
border: none;
border-radius: 12px;
cursor: pointer;
font-size: 16px;
font-weight: 500;
transition: all 0.3s ease;
text-transform: uppercase;
letter-spacing: 1px;
}
.primary-btn {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
}
.secondary-btn {
background: #e0e0e0;
color: #333;
}
.primary-btn:hover {
transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(102,126,234,0.4);
}
.secondary-btn:hover {
background: #d5d5d5;
}
.wallet-btn {
background: #FF9800;
color: white;
margin-bottom: 25px;
display: flex;
align-items: center;
justify-content: center;
gap: 10px;
}
.wallet-btn:hover {
background: #F57C00;
}
.wallet-status {
display: flex;
align-items: center;
justify-content: center;
padding: 10px;
margin-bottom: 20px;
background: #f0f0f0;
border-radius: 10px;
font-size: 14px;
}
.wallet-status.connected {
background: #e8f5e9;
color: #2e7d32;
}
.wallet-status i {
margin-right: 8px;
}
.disabled-btn {
opacity: 0.6;
cursor: not-allowed;
}
@media (max-width: 480px) {
.join-form {
padding: 30px 20px;
}
h2 {
font-size: 24px;
}
.form-group input {
padding: 12px;
font-size: 14px;
}
button {
padding: 12px;
font-size: 14px;
}
}
</style>
</head>
<body>
<div class="app-container">
<div class="join-form">
<h2>Join Meeting</h2>
<div id="walletStatus" class="wallet-status">
<i class="material-icons">account_balance_wallet</i>
<span>Wallet not connected</span>
</div>
<button id="connectWalletBtn" class="wallet-btn">
<i class="material-icons">account_balance_wallet</i>
Connect Wallet
</button>
<div class="form-group">
<input type="text" id="usernameInput" placeholder="Enter your name" required>
</div>
<div class="form-group">
<input type="text" id="roomIdInput" placeholder="Enter Room ID" required>
</div>
<div class="button-group">
<button class="secondary-btn" onclick="window.location.href='index.html'">Back</button>
<button id="joinMeetingBtn" class="primary-btn disabled-btn" disabled>Join Meeting</button>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/webrtc-adapter/8.1.2/adapter.min.js"></script>
<script type="module">
import CloudflareCalls from './js/CloudflareCalls.js';
import web3Auth from './js/auth.js';
// Lấy current URL và cấu hình endpoints
// const currentUrl = 'https://manhteky123-dappmeetingv3.hf.space';
const currentUrl = window.location.origin;
const isLocalhost = currentUrl.includes('localhost') || currentUrl.includes('127.0.0.1');
// Cấu hình endpoints dựa trên môi trường
const config = {
backendUrl: isLocalhost ? 'http://localhost:50000' : currentUrl,
websocketUrl: isLocalhost
? 'ws://localhost:50000/ws'
: 'wss://manhteky123-dappmeetingv3.hf.space/ws'
};
const baseAPI = isLocalhost ? 'http://localhost:50000' : 'https://manhteky123-dappmeetingv3.hf.space';
const calls = new CloudflareCalls(config);
const usernameInput = document.getElementById('usernameInput');
const roomIdInput = document.getElementById('roomIdInput');
const joinMeetingBtn = document.getElementById('joinMeetingBtn');
const connectWalletBtn = document.getElementById('connectWalletBtn');
const walletStatus = document.getElementById('walletStatus');
// Check if wallet is already connected
async function checkWalletConnection() {
const isConnected = await web3Auth.checkConnection();
updateWalletUI(isConnected);
}
// Update UI based on wallet connection status
function updateWalletUI(isConnected) {
if (isConnected) {
walletStatus.classList.add('connected');
walletStatus.innerHTML = `
<i class="material-icons">check_circle</i>
<span>Connected: ${web3Auth.getShortAddress()}</span>
`;
connectWalletBtn.style.display = 'none';
// Enable join button
joinMeetingBtn.classList.remove('disabled-btn');
joinMeetingBtn.disabled = false;
} else {
walletStatus.classList.remove('connected');
walletStatus.innerHTML = `
<i class="material-icons">account_balance_wallet</i>
<span>Wallet not connected</span>
`;
connectWalletBtn.style.display = 'block';
// Disable join button
joinMeetingBtn.classList.add('disabled-btn');
joinMeetingBtn.disabled = true;
}
}
// Connect wallet
async function connectWallet() {
try {
const result = await web3Auth.connect();
if (result.success) {
updateWalletUI(true);
} else {
alert('Failed to connect wallet: ' + result.error);
}
} catch (error) {
console.error('Error connecting wallet:', error);
alert('Error connecting wallet. Make sure MetaMask is installed and unlocked.');
}
}
// Get token and initialize calls
async function ensureInitialized(username) {
if (!calls.token) {
try {
const response = await fetch(`${baseAPI}/auth/token`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
username,
walletAddress: web3Auth.userAddress // Add wallet address to user info
})
});
const { token } = await response.json();
calls.setToken(token);
return true;
} catch (err) {
console.error('Error getting token:', err);
alert('Failed to initialize. Please check if the server is running.');
return false;
}
}
return true;
}
async function joinMeeting() {
if (!web3Auth.isConnected) {
alert('Please connect your wallet first');
return;
}
const username = usernameInput.value.trim();
const roomId = roomIdInput.value.trim();
if (!username || !roomId) {
alert('Please enter both your name and Room ID');
return;
}
try {
// Initialize calls
if (!await ensureInitialized(username)) {
return;
}
// Store information in localStorage
localStorage.setItem('username', username);
localStorage.setItem('roomId', roomId);
localStorage.setItem('walletAddress', web3Auth.userAddress);
// Redirect to device check page
window.location.href = './check.html';
} catch (err) {
console.error('Error joining room:', err);
alert('Failed to join room: ' + err.message);
}
}
// Event Listeners
connectWalletBtn.addEventListener('click', connectWallet);
joinMeetingBtn.addEventListener('click', joinMeeting);
// Handle enter key
document.addEventListener('keypress', (e) => {
if (e.key === 'Enter' && !joinMeetingBtn.disabled) {
joinMeeting();
}
});
// Listen for wallet account changes
web3Auth.addAccountsChangedListener((address) => {
updateWalletUI(!!address);
});
// Check wallet connection on page load
document.addEventListener('DOMContentLoaded', checkWalletConnection);
</script>
</body>
</html>