This commit is contained in:
september
2025-09-03 06:51:24 -07:00
commit 54a81cbdcf
95 changed files with 17637 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
[*.{js,jsx,mjs,cjs,ts,tsx,mts,cts,vue,css,scss,sass,less,styl}]
charset = utf-8
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
end_of_line = lf
max_line_length = 100

View File

@@ -0,0 +1,3 @@
VITE_API_BASE_URL=https://yourdomain.com/api
VITE_WS_BASE_URL=wss://yourdomain.com
VITE_APP_NAME=Video Call App

1
videocall-frontend/.gitattributes vendored Normal file
View File

@@ -0,0 +1 @@
* text=auto eol=lf

30
videocall-frontend/.gitignore vendored Normal file
View File

@@ -0,0 +1,30 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
.DS_Store
dist
dist-ssr
coverage
*.local
/cypress/videos/
/cypress/screenshots/
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
*.tsbuildinfo

View File

@@ -0,0 +1,6 @@
{
"$schema": "https://json.schemastore.org/prettierrc",
"semi": false,
"singleQuote": true,
"printWidth": 100
}

View File

@@ -0,0 +1,27 @@
FROM node:20-alpine AS builder
WORKDIR /app
# Копирование package.json и установка всех зависимостей
COPY package*.json ./
RUN npm ci
# Копирование исходного кода и сборка
COPY . .
RUN npm run build
# Production стадия с nginx
FROM nginx:alpine
# Удаление дефолтной конфигурации nginx
RUN rm /etc/nginx/conf.d/default.conf
# Копирование собранного приложения
COPY --from=builder /app/dist /usr/share/nginx/html
# Копирование кастомной конфигурации nginx для SPA
COPY nginx-spa.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

View File

@@ -0,0 +1,26 @@
import { defineConfig, globalIgnores } from 'eslint/config'
import globals from 'globals'
import js from '@eslint/js'
import pluginVue from 'eslint-plugin-vue'
import skipFormatting from '@vue/eslint-config-prettier/skip-formatting'
export default defineConfig([
{
name: 'app/files-to-lint',
files: ['**/*.{js,mjs,jsx,vue}'],
},
globalIgnores(['**/dist/**', '**/dist-ssr/**', '**/coverage/**']),
{
languageOptions: {
globals: {
...globals.browser,
},
},
},
js.configs.recommended,
...pluginVue.configs['flat/essential'],
skipFormatting,
])

View File

@@ -0,0 +1,182 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
<!-- Primary Meta Tags -->
<title>Video Call App</title>
<meta name="title" content="Video Call App" />
<meta
name="description"
content="Secure video calling without registration. Create rooms, share links, and connect instantly."
/>
<!-- Tailwind CSS - ВАЖНО: загружается перед основными стилями -->
<script src="https://cdn.tailwindcss.com"></script>
<script>
// Конфигурация Tailwind для dark mode
tailwind.config = {
darkMode: 'class',
theme: {
extend: {
colors: {
primary: {
50: '#f0fdf4',
500: '#22c55e',
600: '#16a34a',
700: '#15803d',
},
},
},
},
}
</script>
<!-- Security Headers -->
<meta http-equiv="Referrer-Policy" content="strict-origin-when-cross-origin" />
<meta http-equiv="X-Content-Type-Options" content="nosniff" />
<meta http-equiv="X-Frame-Options" content="DENY" />
<!-- PWA Meta Tags -->
<meta name="theme-color" content="#22c55e" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="default" />
<meta name="apple-mobile-web-app-title" content="VideoCall" />
<!-- Open Graph / Facebook -->
<meta property="og:type" content="website" />
<meta property="og:title" content="Video Call App" />
<meta property="og:description" content="Secure video calling without registration" />
<!-- Apple Touch Icons -->
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" />
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" />
<link rel="manifest" href="/site.webmanifest" />
<!-- Основные стили приложения -->
<style>
/* Базовые стили до загрузки приложения */
body {
font-family:
system-ui,
-apple-system,
BlinkMacSystemFont,
'Segoe UI',
Roboto,
sans-serif;
margin: 0;
padding: 0;
background-color: #f9fafb;
}
.dark body {
background-color: #111827;
color: white;
}
/* Загрузочный экран */
#loading-screen {
position: fixed;
inset: 0;
background: #f9fafb;
display: flex;
align-items: center;
justify-content: center;
z-index: 9999;
}
.dark #loading-screen {
background: #111827;
}
.spinner {
width: 40px;
height: 40px;
border: 4px solid #e5e7eb;
border-top: 4px solid #22c55e;
border-radius: 50%;
animation: spin 1s linear infinite;
}
@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
/* Скрыть загрузочный экран после загрузки приложения */
.app-loaded #loading-screen {
display: none;
}
</style>
</head>
<body class="font-sans antialiased">
<!-- Загрузочный экран -->
<div id="loading-screen">
<div class="text-center">
<div class="spinner"></div>
<p class="mt-4 text-gray-600 dark:text-gray-300">Loading...</p>
</div>
</div>
<noscript>
<div
style="
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: #f3f4f6;
display: flex;
align-items: center;
justify-content: center;
text-align: center;
padding: 2rem;
font-family:
system-ui,
-apple-system,
sans-serif;
"
>
<div>
<h1 style="font-size: 1.5rem; margin-bottom: 1rem">JavaScript Required</h1>
<p style="color: #6b7280">
This video calling application requires JavaScript to function properly.
Please enable JavaScript in your browser settings and refresh the page.
</p>
</div>
</div>
</noscript>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
<!-- Скрипт для скрытия загрузочного экрана -->
<script>
// Скрыть загрузочный экран после загрузки DOM
document.addEventListener('DOMContentLoaded', () => {
setTimeout(() => {
document.body.classList.add('app-loaded')
}, 100)
})
// Error Handling
window.addEventListener('error', function (e) {
console.error('Global error:', e.error)
document.body.classList.add('app-loaded') // Скрыть загрузочный экран даже при ошибке
})
window.addEventListener('unhandledrejection', function (e) {
console.error('Unhandled promise rejection:', e.reason)
e.preventDefault()
})
</script>
</body>
</html>

View File

@@ -0,0 +1,8 @@
{
"compilerOptions": {
"paths": {
"@/*": ["./src/*"]
}
},
"exclude": ["node_modules", "dist"]
}

View File

@@ -0,0 +1,45 @@
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
index index.html;
# Enable gzip compression
gzip on;
gzip_vary on;
gzip_min_length 1024;
gzip_types
text/plain
text/css
text/xml
text/javascript
application/javascript
application/xml+rss
application/atom+xml
image/svg+xml;
# Handle SPA routing - fallback to index.html for all routes
location / {
try_files $uri $uri/ /index.html;
# Cache static assets
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
expires 1y;
add_header Cache-Control "public, immutable";
}
# Ensure the SPA shell is always fresh
location = /index.html {
add_header Cache-Control "no-store, no-cache, must-revalidate, proxy-revalidate";
expires 0;
}
}
# Security headers
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "no-referrer-when-downgrade" always;
}

8850
videocall-frontend/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,36 @@
{
"name": "videocall-frontend",
"version": "1.0.0",
"description": "Video call application frontend",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview",
"lint": "eslint src --ext .vue,.js,.ts --fix",
"type-check": "vue-tsc --noEmit"
},
"dependencies": {
"@headlessui/vue": "^1.7.16",
"@vueuse/core": "^10.5.0",
"axios": "^1.6.2",
"pinia": "^2.1.7",
"qrcode": "^1.5.3",
"socket.io-client": "^4.7.4",
"vue": "^3.3.8",
"vue-router": "^4.2.5"
},
"devDependencies": {
"@types/qrcode": "^1.5.5",
"@vitejs/plugin-vue": "^4.5.0",
"autoprefixer": "^10.4.16",
"eslint": "^8.54.0",
"eslint-plugin-vue": "^9.18.1",
"postcss": "^8.4.32",
"tailwindcss": "^3.3.6",
"typescript": "^5.3.2",
"vite": "^5.0.4",
"vite-plugin-pwa": "^0.17.5",
"vue-tsc": "^1.8.22",
"workbox-window": "^7.0.0"
}
}

View File

@@ -0,0 +1,6 @@
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

@@ -0,0 +1,80 @@
// public/site.webmanifest - PWA manifest
{
"name": "Video Call App",
"short_name": "VideoCall",
"description": "Secure video calling without registration",
"start_url": "/",
"display": "standalone",
"background_color": "#ffffff",
"theme_color": "#00C853",
"orientation": "portrait-primary",
"scope": "/",
"lang": "en",
"categories": ["communication", "productivity"],
"icons": [
{
"src": "pwa-64x64.png",
"sizes": "64x64",
"type": "image/png"
},
{
"src": "pwa-192x192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "pwa-512x512.png",
"sizes": "512x512",
"type": "image/png"
},
{
"src": "maskable-icon-512x512.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "maskable"
}
],
"screenshots": [
{
"src": "screenshot1.png",
"sizes": "1280x720",
"type": "image/png",
"form_factor": "wide",
"label": "Video call interface"
},
{
"src": "screenshot2.png",
"sizes": "375x812",
"type": "image/png",
"form_factor": "narrow",
"label": "Mobile video call"
}
],
"shortcuts": [
{
"name": "Create Room",
"short_name": "Create",
"description": "Start a new video call",
"url": "/?action=create",
"icons": [
{
"src": "shortcut-create.png",
"sizes": "96x96"
}
]
},
{
"name": "Join Room",
"short_name": "Join",
"description": "Join an existing video call",
"url": "/?action=join",
"icons": [
{
"src": "shortcut-join.png",
"sizes": "96x96"
}
]
}
]
}

View File

@@ -0,0 +1,93 @@
// src/App.vue - Main application component
<template>
<div id="app" class="min-h-screen bg-gray-50 dark:bg-gray-900 transition-colors">
<router-view />
<!-- Global loading indicator -->
<Teleport to="body">
<div
v-if="globalStore.isLoading"
class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50"
>
<div class="bg-white dark:bg-gray-800 rounded-2xl p-6 shadow-xl">
<div class="animate-spin rounded-full h-8 w-8 border-b-2 border-green-500 mx-auto"></div>
<p class="mt-4 text-gray-600 dark:text-gray-300 text-sm">{{ globalStore.loadingMessage }}</p>
</div>
</div>
</Teleport>
<!-- Global notifications -->
<Teleport to="body">
<div class="fixed top-4 right-4 z-40 space-y-2">
<div
v-for="notification in globalStore.notifications"
:key="notification.id"
:class="[
'notification',
notification.type === 'error' ? 'bg-red-500' :
notification.type === 'success' ? 'bg-green-500' : 'bg-blue-500'
]"
class="text-white p-4 rounded-lg shadow-lg max-w-sm animate-slide-in"
>
<div class="flex items-center justify-between">
<p class="text-sm font-medium">{{ notification.message }}</p>
<button
@click="globalStore.removeNotification(notification.id)"
class="ml-2 text-white hover:text-gray-200 transition-colors"
>
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
</svg>
</button>
</div>
</div>
</div>
</Teleport>
</div>
</template>
<script setup>
import { onMounted } from 'vue'
import { useGlobalStore } from './stores/global'
const globalStore = useGlobalStore()
onMounted(() => {
// Check authentication on app load
globalStore.checkAuthentication()
// Set up dark mode detection
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)')
globalStore.setDarkMode(mediaQuery.matches)
mediaQuery.addEventListener('change', (e) => {
globalStore.setDarkMode(e.matches)
})
// Set up network status monitoring
window.addEventListener('online', () => {
globalStore.setNetworkStatus(true)
})
window.addEventListener('offline', () => {
globalStore.setNetworkStatus(false)
})
})
</script>
<style scoped>
.notification {
animation: slideIn 0.3s ease-out;
}
@keyframes slideIn {
from {
transform: translateX(100%);
opacity: 0;
}
to {
transform: translateX(0);
opacity: 1;
}
}
</style>

View File

@@ -0,0 +1,86 @@
/* color palette from <https://github.com/vuejs/theme> */
:root {
--vt-c-white: #ffffff;
--vt-c-white-soft: #f8f8f8;
--vt-c-white-mute: #f2f2f2;
--vt-c-black: #181818;
--vt-c-black-soft: #222222;
--vt-c-black-mute: #282828;
--vt-c-indigo: #2c3e50;
--vt-c-divider-light-1: rgba(60, 60, 60, 0.29);
--vt-c-divider-light-2: rgba(60, 60, 60, 0.12);
--vt-c-divider-dark-1: rgba(84, 84, 84, 0.65);
--vt-c-divider-dark-2: rgba(84, 84, 84, 0.48);
--vt-c-text-light-1: var(--vt-c-indigo);
--vt-c-text-light-2: rgba(60, 60, 60, 0.66);
--vt-c-text-dark-1: var(--vt-c-white);
--vt-c-text-dark-2: rgba(235, 235, 235, 0.64);
}
/* semantic color variables for this project */
:root {
--color-background: var(--vt-c-white);
--color-background-soft: var(--vt-c-white-soft);
--color-background-mute: var(--vt-c-white-mute);
--color-border: var(--vt-c-divider-light-2);
--color-border-hover: var(--vt-c-divider-light-1);
--color-heading: var(--vt-c-text-light-1);
--color-text: var(--vt-c-text-light-1);
--section-gap: 160px;
}
@media (prefers-color-scheme: dark) {
:root {
--color-background: var(--vt-c-black);
--color-background-soft: var(--vt-c-black-soft);
--color-background-mute: var(--vt-c-black-mute);
--color-border: var(--vt-c-divider-dark-2);
--color-border-hover: var(--vt-c-divider-dark-1);
--color-heading: var(--vt-c-text-dark-1);
--color-text: var(--vt-c-text-dark-2);
}
}
*,
*::before,
*::after {
box-sizing: border-box;
margin: 0;
font-weight: normal;
}
body {
min-height: 100vh;
color: var(--color-text);
background: var(--color-background);
transition:
color 0.5s,
background-color 0.5s;
line-height: 1.6;
font-family:
Inter,
-apple-system,
BlinkMacSystemFont,
'Segoe UI',
Roboto,
Oxygen,
Ubuntu,
Cantarell,
'Fira Sans',
'Droid Sans',
'Helvetica Neue',
sans-serif;
font-size: 15px;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 261.76 226.69"><path d="M161.096.001l-30.225 52.351L100.647.001H-.005l130.877 226.688L261.749.001z" fill="#41b883"/><path d="M161.096.001l-30.225 52.351L100.647.001H52.346l78.526 136.01L209.398.001z" fill="#34495e"/></svg>

After

Width:  |  Height:  |  Size: 276 B

View File

@@ -0,0 +1,35 @@
@import './base.css';
#app {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
font-weight: normal;
}
a,
.green {
text-decoration: none;
color: hsla(160, 100%, 37%, 1);
transition: 0.4s;
padding: 3px;
}
@media (hover: hover) {
a:hover {
background-color: hsla(160, 100%, 37%, 0.2);
}
}
@media (min-width: 1024px) {
body {
display: flex;
place-items: center;
}
#app {
display: grid;
grid-template-columns: 1fr 1fr;
padding: 0 2rem;
}
}

View File

@@ -0,0 +1,87 @@
// src/components/ActionCard.vue - Reusable action card component
<template>
<div class="card p-6 hover:shadow-lg transition-shadow cursor-pointer" @click="handleClick">
<div class="flex items-center justify-between mb-4">
<div
:class="[
'w-12 h-12 rounded-full flex items-center justify-center',
loading ? 'bg-gray-200 dark:bg-gray-700' : 'bg-green-100 dark:bg-green-900',
]"
>
<div
v-if="loading"
class="animate-spin rounded-full h-6 w-6 border-b-2 border-green-500"
></div>
<svg
v-else-if="icon === 'plus'"
class="w-6 h-6 text-green-600 dark:text-green-400"
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M12 6v6m0 0v6m0-6h6m-6 0H6"
></path>
</svg>
<svg
v-else-if="icon === 'login'"
class="w-6 h-6 text-green-600 dark:text-green-400"
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M11 16l-4-4m0 0l4-4m-4 4h14m-5 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h7a3 3 0 013 3v1"
></path>
</svg>
</div>
</div>
<h3 class="text-lg font-semibold text-gray-900 dark:text-white mb-2">{{ title }}</h3>
<p class="text-gray-600 dark:text-gray-300 text-sm">{{ description }}</p>
<div class="mt-4 flex justify-end">
<svg class="w-5 h-5 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M9 5l7 7-7 7"
></path>
</svg>
</div>
</div>
</template>
<script setup>
defineProps({
title: {
type: String,
required: true,
},
description: {
type: String,
required: true,
},
icon: {
type: String,
required: true,
},
loading: {
type: Boolean,
default: false,
},
})
const emit = defineEmits(['click'])
const handleClick = () => {
emit('click')
}
</script>

View File

@@ -0,0 +1,212 @@
// src/components/Dashboard.vue - Main dashboard component
<template>
<div class="min-h-screen bg-gray-50 dark:bg-gray-900">
<!-- Header -->
<header
class="bg-white dark:bg-gray-800 shadow-sm border-b border-gray-200 dark:border-gray-700"
>
<div class="max-w-4xl mx-auto px-4 py-4 flex items-center justify-between">
<div class="flex items-center space-x-3">
<div class="w-10 h-10 bg-green-500 rounded-full flex items-center justify-center">
<svg class="w-6 h-6 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M15 10l4.553-2.276A1 1 0 0121 8.618v6.764a1 1 0 01-1.447.894L15 14M5 18h8a2 2 0 002-2V8a2 2 0 00-2-2H5a2 2 0 00-2 2v8a2 2 0 002 2z"
></path>
</svg>
</div>
<h1 class="text-xl font-semibold text-gray-900 dark:text-white">Video Call</h1>
</div>
<button
@click="handleLogout"
class="text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200 transition-colors"
>
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M17 16l4-4m0 0l-4-4m4 4H7m6 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h4a3 3 0 013 3v1"
></path>
</svg>
</button>
</div>
</header>
<!-- Main Content -->
<main class="max-w-4xl mx-auto px-4 py-8">
<!-- Video Preview -->
<div class="mb-8">
<VideoPreview />
</div>
<!-- Action Buttons -->
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-8">
<ActionCard
title="Create Link"
description="Start a new video call and share the link"
icon="plus"
:loading="roomsStore.isCreatingRoom"
@click="handleCreateRoom"
/>
<ActionCard
title="Join Call"
description="Enter a room code or link to join"
icon="login"
@click="showJoinModal = true"
/>
</div>
<!-- Room History -->
<div v-if="roomsStore.roomHistory.length > 0" class="mb-8">
<h2 class="text-lg font-semibold text-gray-900 dark:text-white mb-4">Recent Rooms</h2>
<div class="space-y-2">
<div
v-for="room in roomsStore.roomHistory.slice(0, 5)"
:key="room.room_id"
class="card p-4 flex items-center justify-between"
>
<div class="flex-1">
<p class="font-medium text-gray-900 dark:text-white">{{ room.short_code }}</p>
<p class="text-sm text-gray-500 dark:text-gray-400">
{{ utils.formatRelativeTime(new Date(room.joined_at)) }}
</p>
</div>
<button
@click="handleJoinRoom(room.short_code)"
:disabled="roomsStore.isJoiningRoom"
class="btn-secondary px-4 py-2 text-sm"
>
Rejoin
</button>
</div>
</div>
</div>
</main>
<!-- Join Room Modal -->
<Teleport to="body">
<div
v-if="showJoinModal"
class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4"
@click="showJoinModal = false"
>
<div class="card w-full max-w-md p-6 animate-slide-up" @click.stop>
<h3 class="text-lg font-semibold text-gray-900 dark:text-white mb-4">Join Video Call</h3>
<form @submit.prevent="handleJoinSubmit" class="space-y-4">
<div>
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
Room Code or Link
</label>
<input
v-model="joinInput"
type="text"
placeholder="Enter room code or paste link"
class="input-field"
:disabled="roomsStore.isJoiningRoom"
/>
</div>
<div class="flex space-x-3">
<button
type="button"
@click="showJoinModal = false"
class="btn-secondary flex-1"
:disabled="roomsStore.isJoiningRoom"
>
Cancel
</button>
<button
type="submit"
:disabled="!joinInput.trim() || roomsStore.isJoiningRoom"
class="btn-primary flex-1 disabled:opacity-50"
>
<span v-if="roomsStore.isJoiningRoom">Joining...</span>
<span v-else>Join</span>
</button>
</div>
</form>
</div>
</div>
</Teleport>
<!-- Room Created Modal -->
<RoomCreatedModal
v-if="showRoomCreatedModal && createdRoom"
:room="createdRoom"
@close="showRoomCreatedModal = false"
/>
</div>
</template>
<script setup>
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { useGlobalStore } from '../stores/global'
import { useRoomsStore } from '../stores/rooms'
import { utils } from '../services/utils'
import VideoPreview from './VideoPreview.vue'
import ActionCard from './ActionCard.vue'
import RoomCreatedModal from './RoomCreatedModal.vue'
const router = useRouter()
const globalStore = useGlobalStore()
const roomsStore = useRoomsStore()
// Reactive state
const showJoinModal = ref(false)
const showRoomCreatedModal = ref(false)
const joinInput = ref('')
const createdRoom = ref(null)
// Methods
const handleLogout = async () => {
await globalStore.logout()
router.push('/login')
}
const handleCreateRoom = async () => {
const result = await roomsStore.createRoom()
if (result.success) {
createdRoom.value = result.room
showRoomCreatedModal.value = true
}
}
const handleJoinRoom = async (roomIdentifier) => {
const result = await roomsStore.joinRoom(roomIdentifier)
if (result.success) {
router.push(`/call/${result.room.room_id}`)
}
}
const handleJoinSubmit = async () => {
if (!joinInput.value.trim()) return
// Extract room code from URL if needed
let roomIdentifier = joinInput.value.trim()
// If it's a full URL, extract the room code
if (roomIdentifier.includes('/join/')) {
const match = roomIdentifier.match(/\/join\/([A-Z0-9]+)/)
if (match) {
roomIdentifier = match[1]
}
}
showJoinModal.value = false
await handleJoinRoom(roomIdentifier)
joinInput.value = ''
}
onMounted(() => {
roomsStore.loadHistory()
})
</script>

View File

@@ -0,0 +1,44 @@
<script setup>
defineProps({
msg: {
type: String,
required: true,
},
})
</script>
<template>
<div class="greetings">
<h1 class="green">{{ msg }}</h1>
<h3>
You’ve successfully created a project with
<a href="https://vite.dev/" target="_blank" rel="noopener">Vite</a> +
<a href="https://vuejs.org/" target="_blank" rel="noopener">Vue 3</a>.
</h3>
</div>
</template>
<style scoped>
h1 {
font-weight: 500;
font-size: 2.6rem;
position: relative;
top: -10px;
}
h3 {
font-size: 1.2rem;
}
.greetings h1,
.greetings h3 {
text-align: center;
}
@media (min-width: 1024px) {
.greetings h1,
.greetings h3 {
text-align: left;
}
}
</style>

View File

@@ -0,0 +1,104 @@
<template>
<div class="min-h-screen bg-gray-50 dark:bg-gray-900 flex items-center justify-center p-4">
<div class="card w-full max-w-md p-8 animate-fade-in">
<div class="text-center mb-8">
<div
class="w-16 h-16 bg-green-500 rounded-full flex items-center justify-center mx-auto mb-4"
>
<svg class="w-8 h-8 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M11 16l-4-4m0 0l4-4m-4 4h14m-5 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h7a3 3 0 013 3v1"
></path>
</svg>
</div>
<h1 class="text-2xl font-semibold text-gray-900 dark:text-white mb-2">Join Video Call</h1>
<p class="text-gray-600 dark:text-gray-300">
Room code: <span class="font-mono font-bold text-lg">{{ roomCode }}</span>
</p>
</div>
<div v-if="isJoining" class="text-center py-8">
<div
class="animate-spin rounded-full h-12 w-12 border-b-2 border-green-500 mx-auto mb-4"
></div>
<p class="text-gray-600 dark:text-gray-300">Joining room...</p>
</div>
<div v-else-if="error" class="text-center py-8">
<div
class="w-16 h-16 bg-red-100 rounded-full flex items-center justify-center mx-auto mb-4"
>
<svg class="w-8 h-8 text-red-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
></path>
</svg>
</div>
<h3 class="text-lg font-semibold text-gray-900 dark:text-white mb-2">Room Not Found</h3>
<p class="text-gray-600 dark:text-gray-300 mb-4">{{ error }}</p>
<button @click="$router.push('/')" class="btn-primary px-6 py-2">Back to Dashboard</button>
</div>
<div v-else class="space-y-6">
<div class="text-center">
<button @click="joinRoom" class="btn-primary w-full py-4 text-lg">Join Call</button>
</div>
<div class="text-center">
<button
@click="$router.push('/')"
class="text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200"
>
Back to Dashboard
</button>
</div>
</div>
</div>
</div>
</template>
<script setup>
import { ref, onMounted } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { useRoomsStore } from '../stores/rooms'
import { useGlobalStore } from '../stores/global'
const route = useRoute()
const router = useRouter()
const roomsStore = useRoomsStore()
const globalStore = useGlobalStore()
const roomCode = ref('')
const isJoining = ref(false)
const error = ref('')
onMounted(() => {
roomCode.value = route.params.shortCode
if (!roomCode.value) {
router.push('/')
}
})
const joinRoom = async () => {
try {
isJoining.value = true
const result = await roomsStore.joinRoom(roomCode.value)
if (result.success) {
router.push(`/call/${result.room.room_id}`)
} else {
error.value = result.error
}
} catch (err) {
error.value = 'Failed to join room'
} finally {
isJoining.value = false
}
}
</script>

View File

@@ -0,0 +1,94 @@
<template>
<div
class="min-h-screen flex items-center justify-center bg-gradient-to-br from-green-50 to-blue-50 dark:from-gray-900 dark:to-gray-800 p-4"
>
<div class="card w-full max-w-md p-8 animate-fade-in">
<div class="text-center mb-8">
<div
class="w-16 h-16 bg-green-500 rounded-full flex items-center justify-center mx-auto mb-4"
>
<svg class="w-8 h-8 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M15 10l4.553-2.276A1 1 0 0121 8.618v6.764a1 1 0 01-1.447.894L15 14M5 18h8a2 2 0 002-2V8a2 2 0 00-2-2H5a2 2 0 00-2 2v8a2 2 0 002 2z"
></path>
</svg>
</div>
<h1 class="text-2xl font-semibold text-gray-900 dark:text-white mb-2">Video Call</h1>
<p class="text-gray-600 dark:text-gray-300">Enter the access password to continue</p>
</div>
<form @submit.prevent="handleLogin" class="space-y-6">
<div>
<label
for="password"
class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2"
>
Password
</label>
<input
id="password"
v-model="password"
type="password"
placeholder="Enter password"
class="input-field"
:disabled="isLoading"
required
/>
</div>
<div>
<button
type="submit"
:disabled="!password.trim() || isLoading"
class="btn-primary w-full disabled:opacity-50 disabled:cursor-not-allowed"
>
<span v-if="isLoading" class="flex items-center justify-center">
<div class="animate-spin rounded-full h-5 w-5 border-b-2 border-white mr-2"></div>
Signing in...
</span>
<span v-else>Sign In</span>
</button>
</div>
</form>
<div class="mt-6 text-center">
<p class="text-xs text-gray-500 dark:text-gray-400">
Secure video calling without registration
</p>
</div>
</div>
</div>
</template>
<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { useGlobalStore } from '../stores/global'
const router = useRouter()
const globalStore = useGlobalStore()
const password = ref('')
const isLoading = ref(false)
const handleLogin = async () => {
if (!password.value.trim()) return
try {
isLoading.value = true
const result = await globalStore.login(password.value)
if (result.success) {
const redirectTo = new URLSearchParams(window.location.search).get('redirect') || '/'
router.push(redirectTo)
}
} catch (error) {
console.error('Login failed:', error)
} finally {
isLoading.value = false
}
}
</script>

View File

@@ -0,0 +1,40 @@
<template>
<div class="min-h-screen bg-gray-50 dark:bg-gray-900 flex items-center justify-center p-4">
<div class="text-center max-w-md mx-auto">
<div
class="w-24 h-24 bg-red-100 dark:bg-red-900/20 rounded-full flex items-center justify-center mx-auto mb-6"
>
<svg
class="w-12 h-12 text-red-500 dark:text-red-400"
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
></path>
</svg>
</div>
<h1 class="text-6xl font-bold text-gray-900 dark:text-white mb-4">404</h1>
<h2 class="text-2xl font-semibold text-gray-700 dark:text-gray-300 mb-4">Page Not Found</h2>
<p class="text-gray-600 dark:text-gray-400 mb-8">
The page you're looking for doesn't exist or may have been moved.
</p>
<div class="space-y-4">
<button @click="$router.push('/')" class="btn-primary px-8 py-3 w-full">
Back to Dashboard
</button>
<button @click="$router.go(-1)" class="btn-secondary px-8 py-3 w-full">Go Back</button>
</div>
</div>
</div>
</template>
<script setup>
// Component logic can be added here if needed
</script>

View File

@@ -0,0 +1,136 @@
// src/components/RoomCreatedModal.vue - Room creation success modal
<template>
<div class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4">
<div class="card w-full max-w-lg p-6 animate-slide-up">
<div class="text-center mb-6">
<div
class="w-16 h-16 bg-green-500 rounded-full flex items-center justify-center mx-auto mb-4"
>
<svg class="w-8 h-8 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M5 13l4 4L19 7"
></path>
</svg>
</div>
<h3 class="text-xl font-semibold text-gray-900 dark:text-white">Room Created!</h3>
<p class="text-gray-600 dark:text-gray-300 mt-2">Share the link or code to invite others</p>
</div>
<!-- Room Code -->
<div class="mb-6">
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2"
>Room Code</label
>
<div class="flex items-center space-x-2">
<input
:value="room.short_code"
readonly
class="input-field flex-1 font-mono text-lg text-center tracking-wider"
/>
<button @click="copyCode" class="btn-secondary px-4 py-3 min-w-[80px]">
{{ codeCopied ? 'Copied!' : 'Copy' }}
</button>
</div>
</div>
<!-- Room Link -->
<div class="mb-6">
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2"
>Room Link</label
>
<div class="flex items-center space-x-2">
<input :value="room.room_url" readonly class="input-field flex-1 text-sm" />
<button @click="copyLink" class="btn-secondary px-4 py-3 min-w-[80px]">
{{ linkCopied ? 'Copied!' : 'Copy' }}
</button>
</div>
</div>
<!-- QR Code -->
<div class="mb-6 text-center">
<p class="text-sm font-medium text-gray-700 dark:text-gray-300 mb-3">QR Code</p>
<div class="inline-block p-4 bg-white rounded-xl shadow-sm">
<img :src="room.qr_code" alt="QR Code" class="w-32 h-32" />
</div>
</div>
<!-- Action Buttons -->
<div class="flex space-x-3">
<button @click="emit('close')" class="btn-secondary flex-1">Close</button>
<button @click="joinRoom" class="btn-primary flex-1">Join Room</button>
</div>
<!-- Room Info -->
<div class="mt-6 pt-4 border-t border-gray-200 dark:border-gray-700 text-center">
<p class="text-xs text-gray-500 dark:text-gray-400">
Room expires in {{ formatExpiryTime(room.expires_at) }}
</p>
</div>
</div>
</div>
</template>
<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { utils } from '../services/utils'
const router = useRouter()
const props = defineProps({
room: {
type: Object,
required: true,
},
})
const emit = defineEmits(['close'])
// Reactive state
const codeCopied = ref(false)
const linkCopied = ref(false)
// Methods
const copyCode = async () => {
const result = await utils.copyToClipboard(props.room.short_code)
if (result.success) {
codeCopied.value = true
setTimeout(() => {
codeCopied.value = false
}, 2000)
}
}
const copyLink = async () => {
const result = await utils.copyToClipboard(props.room.room_url)
if (result.success) {
linkCopied.value = true
setTimeout(() => {
linkCopied.value = false
}, 2000)
}
}
const joinRoom = () => {
emit('close')
router.push(`/call/${props.room.room_id}`)
}
const formatExpiryTime = (expiryDate) => {
const expiry = new Date(expiryDate)
const now = new Date()
const diffHours = Math.ceil((expiry - now) / (1000 * 60 * 60))
if (diffHours <= 1) {
return 'less than 1 hour'
} else if (diffHours < 24) {
return `${diffHours} hours`
} else {
const diffDays = Math.ceil(diffHours / 24)
return `${diffDays} days`
}
}
</script>

View File

@@ -0,0 +1,94 @@
<script setup>
import WelcomeItem from './WelcomeItem.vue'
import DocumentationIcon from './icons/IconDocumentation.vue'
import ToolingIcon from './icons/IconTooling.vue'
import EcosystemIcon from './icons/IconEcosystem.vue'
import CommunityIcon from './icons/IconCommunity.vue'
import SupportIcon from './icons/IconSupport.vue'
const openReadmeInEditor = () => fetch('/__open-in-editor?file=README.md')
</script>
<template>
<WelcomeItem>
<template #icon>
<DocumentationIcon />
</template>
<template #heading>Documentation</template>
Vue’s
<a href="https://vuejs.org/" target="_blank" rel="noopener">official documentation</a>
provides you with all information you need to get started.
</WelcomeItem>
<WelcomeItem>
<template #icon>
<ToolingIcon />
</template>
<template #heading>Tooling</template>
This project is served and bundled with
<a href="https://vite.dev/guide/features.html" target="_blank" rel="noopener">Vite</a>. The
recommended IDE setup is
<a href="https://code.visualstudio.com/" target="_blank" rel="noopener">VSCode</a>
+
<a href="https://github.com/vuejs/language-tools" target="_blank" rel="noopener">Vue - Official</a>. If
you need to test your components and web pages, check out
<a href="https://vitest.dev/" target="_blank" rel="noopener">Vitest</a>
and
<a href="https://www.cypress.io/" target="_blank" rel="noopener">Cypress</a>
/
<a href="https://playwright.dev/" target="_blank" rel="noopener">Playwright</a>.
<br />
More instructions are available in
<a href="javascript:void(0)" @click="openReadmeInEditor"><code>README.md</code></a
>.
</WelcomeItem>
<WelcomeItem>
<template #icon>
<EcosystemIcon />
</template>
<template #heading>Ecosystem</template>
Get official tools and libraries for your project:
<a href="https://pinia.vuejs.org/" target="_blank" rel="noopener">Pinia</a>,
<a href="https://router.vuejs.org/" target="_blank" rel="noopener">Vue Router</a>,
<a href="https://test-utils.vuejs.org/" target="_blank" rel="noopener">Vue Test Utils</a>, and
<a href="https://github.com/vuejs/devtools" target="_blank" rel="noopener">Vue Dev Tools</a>. If
you need more resources, we suggest paying
<a href="https://github.com/vuejs/awesome-vue" target="_blank" rel="noopener">Awesome Vue</a>
a visit.
</WelcomeItem>
<WelcomeItem>
<template #icon>
<CommunityIcon />
</template>
<template #heading>Community</template>
Got stuck? Ask your question on
<a href="https://chat.vuejs.org" target="_blank" rel="noopener">Vue Land</a>
(our official Discord server), or
<a href="https://stackoverflow.com/questions/tagged/vue.js" target="_blank" rel="noopener"
>StackOverflow</a
>. You should also follow the official
<a href="https://bsky.app/profile/vuejs.org" target="_blank" rel="noopener">@vuejs.org</a>
Bluesky account or the
<a href="https://x.com/vuejs" target="_blank" rel="noopener">@vuejs</a>
X account for latest news in the Vue world.
</WelcomeItem>
<WelcomeItem>
<template #icon>
<SupportIcon />
</template>
<template #heading>Support Vue</template>
As an independent project, Vue relies on community backing for its sustainability. You can help
us by
<a href="https://vuejs.org/sponsor/" target="_blank" rel="noopener">becoming a sponsor</a>.
</WelcomeItem>
</template>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,612 @@
<!-- src/components/VideoPreview.vue - Complete local video preview component -->
<template>
<div class="relative">
<div class="video-container aspect-video max-w-2xl mx-auto">
<!-- Video Element -->
<video
ref="videoRef"
autoplay
muted
playsinline
class="w-full h-full object-cover"
:class="{ mirror: shouldMirror }"
></video>
<!-- Overlay controls (show on hover) -->
<div
class="absolute inset-0 bg-black bg-opacity-0 hover:bg-opacity-30 transition-all duration-300 flex items-center justify-center opacity-0 hover:opacity-100"
>
<div class="flex space-x-4">
<!-- Video Toggle -->
<button
@click="toggleVideo"
:class="[
'control-button transform hover:scale-110 transition-transform',
webrtcStore.isVideoEnabled ? 'control-button-active' : 'control-button-inactive',
]"
:title="webrtcStore.isVideoEnabled ? 'Turn off camera' : 'Turn on camera'"
:disabled="!webrtcStore.localStream"
>
<svg
v-if="webrtcStore.isVideoEnabled"
class="w-6 h-6"
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M15 10l4.553-2.276A1 1 0 0121 8.618v6.764a1 1 0 01-1.447.894L15 14M5 18h8a2 2 0 002-2V8a2 2 0 00-2-2H5a2 2 0 00-2 2v8a2 2 0 002 2z"
></path>
</svg>
<svg v-else class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M18.364 18.364A9 9 0 005.636 5.636m12.728 12.728L5.636 5.636m12.728 12.728L18 21l-1.5-1.5m-6.364-6.364L8.5 14.5 7 13l1.636-1.636"
></path>
</svg>
</button>
<!-- Audio Toggle -->
<button
@click="toggleAudio"
:class="[
'control-button transform hover:scale-110 transition-transform',
webrtcStore.isAudioEnabled ? 'control-button-active' : 'control-button-inactive',
]"
:title="webrtcStore.isAudioEnabled ? 'Mute microphone' : 'Unmute microphone'"
:disabled="!webrtcStore.localStream"
>
<svg
v-if="webrtcStore.isAudioEnabled"
class="w-6 h-6"
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M19 11a7 7 0 01-7 7m0 0a7 7 0 01-7-7m7 7v4m0 0H8m4 0h4m-4-8a3 3 0 01-3-3V5a3 3 0 116 0v6a3 3 0 01-3 3z"
></path>
</svg>
<svg v-else class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M5.586 15H4a1 1 0 01-1-1v-4a1 1 0 011-1h1m0 0V7a3 3 0 013-3h8a3 3 0 013 3v2M4 9h1m11 0h5m-9 0a1 1 0 011-1v-1a1 1 0 011-1m-1 1v1a1 1 0 001 1M9 7h8a3 3 0 013 3v2"
></path>
</svg>
</button>
<!-- Settings Button -->
<button
@click="showSettings = !showSettings"
class="control-button control-button-inactive transform hover:scale-110 transition-transform"
title="Video settings"
>
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"
></path>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"
></path>
</svg>
</button>
</div>
</div>
<!-- No video placeholder -->
<div
v-if="!webrtcStore.hasLocalVideo || !webrtcStore.isVideoEnabled"
class="absolute inset-0 flex items-center justify-center bg-gray-800"
>
<div class="text-center">
<div
class="w-20 h-20 bg-gray-600 rounded-full flex items-center justify-center mx-auto mb-4 animate-pulse-slow"
>
<svg
class="w-10 h-10 text-gray-400"
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"
></path>
</svg>
</div>
<p class="text-gray-400 text-lg font-medium">
{{ !webrtcStore.hasLocalVideo ? 'No camera detected' : 'Camera is off' }}
</p>
<p class="text-gray-500 text-sm mt-2">
{{
!webrtcStore.hasLocalVideo
? 'Check your camera connection'
: 'Click the camera button to turn on'
}}
</p>
</div>
</div>
<!-- Loading overlay -->
<div
v-if="isInitializing"
class="absolute inset-0 flex items-center justify-center bg-black bg-opacity-50"
>
<div class="text-center text-white">
<div
class="animate-spin rounded-full h-12 w-12 border-b-2 border-green-500 mx-auto mb-4"
></div>
<p class="text-lg font-medium">{{ loadingMessage }}</p>
</div>
</div>
<!-- Video quality indicator -->
<div
v-if="webrtcStore.hasLocalVideo && showQualityIndicator"
class="absolute top-4 right-4 flex items-center space-x-2 bg-black bg-opacity-50 px-3 py-2 rounded-lg text-white text-sm"
>
<div
:class="[
'w-3 h-3 rounded-full',
videoQuality === 'high'
? 'bg-green-400'
: videoQuality === 'medium'
? 'bg-yellow-400'
: 'bg-red-400',
]"
></div>
<span>{{ videoQualityText }}</span>
</div>
</div>
<!-- Media access error -->
<div
v-if="mediaError"
class="mt-4 bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-800 rounded-xl p-4 animate-fade-in"
>
<div class="flex">
<svg
class="w-5 h-5 text-yellow-400 mt-0.5 mr-3 flex-shrink-0"
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L3.732 16.5c-.77.833.192 2.5 1.732 2.5z"
></path>
</svg>
<div class="flex-1">
<p class="text-sm text-yellow-800 dark:text-yellow-300 font-medium">
Camera access needed
</p>
<p class="text-sm text-yellow-700 dark:text-yellow-400 mt-1">{{ mediaError }}</p>
<div class="mt-3 flex space-x-3">
<button
@click="initializeMedia"
class="text-sm bg-yellow-100 hover:bg-yellow-200 dark:bg-yellow-800 dark:hover:bg-yellow-700 text-yellow-800 dark:text-yellow-200 px-3 py-1 rounded-md font-medium transition-colors"
>
Try again
</button>
<button
@click="showPermissionHelp = !showPermissionHelp"
class="text-sm text-yellow-600 dark:text-yellow-400 underline hover:no-underline"
>
Need help?
</button>
</div>
<!-- Permission help -->
<div
v-if="showPermissionHelp"
class="mt-3 p-3 bg-yellow-100 dark:bg-yellow-800/30 rounded-md"
>
<p class="text-sm text-yellow-700 dark:text-yellow-300 font-medium mb-2">
To enable camera access:
</p>
<ul class="text-xs text-yellow-600 dark:text-yellow-400 space-y-1">
<li>• Click the camera icon in your browser's address bar</li>
<li>• Select "Allow" when prompted for camera permission</li>
<li>• Refresh the page if needed</li>
<li>• Make sure no other app is using your camera</li>
</ul>
</div>
</div>
</div>
</div>
<!-- Settings Panel -->
<div v-if="showSettings" class="mt-4 card p-4 animate-slide-up">
<h3 class="text-lg font-semibold text-gray-900 dark:text-white mb-4">Video Settings</h3>
<!-- Video Devices -->
<div v-if="videoDevices.length > 0" class="mb-4">
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2"
>Camera</label
>
<select v-model="selectedVideoDevice" @change="switchVideoDevice" class="input-field">
<option v-for="device in videoDevices" :key="device.deviceId" :value="device.deviceId">
{{ device.label || `Camera ${videoDevices.indexOf(device) + 1}` }}
</option>
</select>
</div>
<!-- Audio Devices -->
<div v-if="audioDevices.length > 0" class="mb-4">
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2"
>Microphone</label
>
<select v-model="selectedAudioDevice" @change="switchAudioDevice" class="input-field">
<option v-for="device in audioDevices" :key="device.deviceId" :value="device.deviceId">
{{ device.label || `Microphone ${audioDevices.indexOf(device) + 1}` }}
</option>
</select>
</div>
<!-- Video Quality Settings -->
<div class="mb-4">
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2"
>Video Quality</label
>
<select v-model="selectedQuality" @change="changeVideoQuality" class="input-field">
<option value="720p">HD (720p)</option>
<option value="480p">SD (480p)</option>
<option value="360p">Low (360p)</option>
</select>
</div>
<!-- Mirror Video -->
<div class="flex items-center justify-between">
<label class="text-sm font-medium text-gray-700 dark:text-gray-300">Mirror video</label>
<button
@click="shouldMirror = !shouldMirror"
:class="[
'relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-green-500 focus:ring-offset-2',
shouldMirror ? 'bg-green-500' : 'bg-gray-200 dark:bg-gray-600',
]"
>
<span
:class="[
'inline-block h-4 w-4 transform rounded-full bg-white transition-transform',
shouldMirror ? 'translate-x-6' : 'translate-x-1',
]"
></span>
</button>
</div>
<!-- Close Settings -->
<div class="mt-4 flex justify-end">
<button @click="showSettings = false" class="btn-secondary px-4 py-2">Done</button>
</div>
</div>
</div>
</template>
<script setup>
import { ref, onMounted, onUnmounted, watch, computed } from 'vue'
import { useWebRTCStore } from '../stores/webrtc'
import { useMediaDevices } from '../composables/useMediaDevices'
import { mediaService } from '../services/media'
const webrtcStore = useWebRTCStore()
const {
videoDevices,
audioDevices,
selectedVideoDevice,
selectedAudioDevice,
switchVideoDevice: switchVideo,
switchAudioDevice: switchAudio,
} = useMediaDevices()
// Template refs
const videoRef = ref(null)
// Reactive state
const mediaError = ref('')
const isInitializing = ref(false)
const loadingMessage = ref('')
const showPermissionHelp = ref(false)
const showSettings = ref(false)
const showQualityIndicator = ref(false)
const shouldMirror = ref(true)
const selectedQuality = ref('720p')
const videoQuality = ref('high')
// Computed
const videoQualityText = computed(() => {
switch (videoQuality.value) {
case 'high':
return 'HD'
case 'medium':
return 'SD'
case 'low':
return 'Low'
default:
return 'Unknown'
}
})
// Quality presets
const qualityPresets = {
'720p': { width: 1280, height: 720 },
'480p': { width: 640, height: 480 },
'360p': { width: 480, height: 360 },
}
// Methods
const initializeMedia = async () => {
try {
isInitializing.value = true
mediaError.value = ''
loadingMessage.value = 'Accessing camera and microphone...'
const result = await webrtcStore.initializeLocalMedia()
if (!result.success) {
mediaError.value = result.error
showQualityIndicator.value = false
} else {
showQualityIndicator.value = true
detectVideoQuality()
}
} catch (error) {
console.error('Failed to initialize media:', error)
mediaError.value = 'Failed to access camera or microphone'
} finally {
isInitializing.value = false
}
}
const toggleVideo = () => {
webrtcStore.toggleVideo()
if (webrtcStore.isVideoEnabled) {
detectVideoQuality()
}
}
const toggleAudio = () => {
webrtcStore.toggleAudio()
}
const switchVideoDevice = async () => {
try {
if (selectedVideoDevice.value) {
loadingMessage.value = 'Switching camera...'
isInitializing.value = true
// Stop current stream
if (webrtcStore.localStream) {
webrtcStore.localStream.getVideoTracks().forEach((track) => track.stop())
}
// Create new stream with selected device
const constraints = {
video: {
deviceId: selectedVideoDevice.value,
...qualityPresets[selectedQuality.value],
},
audio: selectedAudioDevice.value
? {
deviceId: selectedAudioDevice.value,
}
: true,
}
const stream = await navigator.mediaDevices.getUserMedia(constraints)
webrtcStore.localStream = stream
detectVideoQuality()
}
} catch (error) {
console.error('Failed to switch video device:', error)
mediaError.value = 'Failed to switch camera'
} finally {
isInitializing.value = false
}
}
const switchAudioDevice = async () => {
try {
if (selectedAudioDevice.value) {
loadingMessage.value = 'Switching microphone...'
isInitializing.value = true
// Similar logic for audio device switching
if (webrtcStore.localStream) {
webrtcStore.localStream.getAudioTracks().forEach((track) => track.stop())
}
const constraints = {
video: selectedVideoDevice.value
? {
deviceId: selectedVideoDevice.value,
...qualityPresets[selectedQuality.value],
}
: true,
audio: {
deviceId: selectedAudioDevice.value,
echoCancellation: true,
noiseSuppression: true,
autoGainControl: true,
},
}
const stream = await navigator.mediaDevices.getUserMedia(constraints)
webrtcStore.localStream = stream
}
} catch (error) {
console.error('Failed to switch audio device:', error)
mediaError.value = 'Failed to switch microphone'
} finally {
isInitializing.value = false
}
}
const changeVideoQuality = async () => {
try {
if (webrtcStore.localStream && selectedQuality.value) {
loadingMessage.value = 'Changing video quality...'
isInitializing.value = true
const videoTrack = webrtcStore.localStream.getVideoTracks()[0]
if (videoTrack) {
const constraints = qualityPresets[selectedQuality.value]
await videoTrack.applyConstraints(constraints)
detectVideoQuality()
}
}
} catch (error) {
console.error('Failed to change video quality:', error)
mediaError.value = 'Failed to change video quality'
} finally {
isInitializing.value = false
}
}
const detectVideoQuality = () => {
if (!webrtcStore.localStream) return
const videoTrack = webrtcStore.localStream.getVideoTracks()[0]
if (videoTrack) {
const settings = videoTrack.getSettings()
const width = settings.width || 0
if (width >= 1280) {
videoQuality.value = 'high'
} else if (width >= 640) {
videoQuality.value = 'medium'
} else {
videoQuality.value = 'low'
}
}
}
const handlePermissionDenied = () => {
mediaError.value =
'Camera and microphone access denied. Please allow permissions in your browser settings and refresh the page.'
showPermissionHelp.value = true
}
const checkMediaPermissions = async () => {
try {
const permissions = await mediaService.checkMediaPermissions()
if (permissions.camera === 'denied' || permissions.microphone === 'denied') {
handlePermissionDenied()
}
} catch (error) {
console.warn('Could not check media permissions:', error)
}
}
// Watch for local stream changes
watch(
() => webrtcStore.localStream,
(newStream) => {
if (videoRef.value && newStream) {
videoRef.value.srcObject = newStream
}
},
{ immediate: true },
)
// Watch for video enabled changes
watch(
() => webrtcStore.isVideoEnabled,
(enabled) => {
if (enabled) {
detectVideoQuality()
}
},
)
// Lifecycle
onMounted(async () => {
await initializeMedia()
await checkMediaPermissions()
// Show quality indicator after 2 seconds
setTimeout(() => {
if (webrtcStore.hasLocalVideo) {
showQualityIndicator.value = true
}
}, 2000)
})
onUnmounted(() => {
// Cleanup is handled by the WebRTC store
})
</script>
<style scoped>
.mirror {
transform: scaleX(-1);
}
.video-container {
position: relative;
overflow: hidden;
}
.control-button {
transition: all 0.2s ease-in-out;
}
.control-button:disabled {
opacity: 0.5;
cursor: not-allowed;
transform: none !important;
}
/* Custom animations */
@keyframes pulse-slow {
0%,
100% {
opacity: 1;
}
50% {
opacity: 0.5;
}
}
.animate-pulse-slow {
animation: pulse-slow 3s ease-in-out infinite;
}
/* Custom scrollbar for settings */
.settings-scroll::-webkit-scrollbar {
width: 4px;
}
.settings-scroll::-webkit-scrollbar-track {
background: transparent;
}
.settings-scroll::-webkit-scrollbar-thumb {
background: rgba(156, 163, 175, 0.5);
border-radius: 2px;
}
.settings-scroll::-webkit-scrollbar-thumb:hover {
background: rgba(156, 163, 175, 0.7);
}
</style>

View File

@@ -0,0 +1,86 @@
<template>
<div class="item">
<i>
<slot name="icon"></slot>
</i>
<div class="details">
<h3>
<slot name="heading"></slot>
</h3>
<slot></slot>
</div>
</div>
</template>
<style scoped>
.item {
margin-top: 2rem;
display: flex;
position: relative;
}
.details {
flex: 1;
margin-left: 1rem;
}
i {
display: flex;
place-items: center;
place-content: center;
width: 32px;
height: 32px;
color: var(--color-text);
}
h3 {
font-size: 1.2rem;
font-weight: 500;
margin-bottom: 0.4rem;
color: var(--color-heading);
}
@media (min-width: 1024px) {
.item {
margin-top: 0;
padding: 0.4rem 0 1rem calc(var(--section-gap) / 2);
}
i {
top: calc(50% - 25px);
left: -26px;
position: absolute;
border: 1px solid var(--color-border);
background: var(--color-background);
border-radius: 8px;
width: 50px;
height: 50px;
}
.item:before {
content: ' ';
border-left: 1px solid var(--color-border);
position: absolute;
left: 0;
bottom: calc(50% + 25px);
height: calc(50% - 25px);
}
.item:after {
content: ' ';
border-left: 1px solid var(--color-border);
position: absolute;
left: 0;
top: calc(50% + 25px);
height: calc(50% - 25px);
}
.item:first-of-type:before {
display: none;
}
.item:last-of-type:after {
display: none;
}
}
</style>

View File

@@ -0,0 +1,7 @@
<template>
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor">
<path
d="M15 4a1 1 0 1 0 0 2V4zm0 11v-1a1 1 0 0 0-1 1h1zm0 4l-.707.707A1 1 0 0 0 16 19h-1zm-4-4l.707-.707A1 1 0 0 0 11 14v1zm-4.707-1.293a1 1 0 0 0-1.414 1.414l1.414-1.414zm-.707.707l-.707-.707.707.707zM9 11v-1a1 1 0 0 0-.707.293L9 11zm-4 0h1a1 1 0 0 0-1-1v1zm0 4H4a1 1 0 0 0 1.707.707L5 15zm10-9h2V4h-2v2zm2 0a1 1 0 0 1 1 1h2a3 3 0 0 0-3-3v2zm1 1v6h2V7h-2zm0 6a1 1 0 0 1-1 1v2a3 3 0 0 0 3-3h-2zm-1 1h-2v2h2v-2zm-3 1v4h2v-4h-2zm1.707 3.293l-4-4-1.414 1.414 4 4 1.414-1.414zM11 14H7v2h4v-2zm-4 0c-.276 0-.525-.111-.707-.293l-1.414 1.414C5.42 15.663 6.172 16 7 16v-2zm-.707 1.121l3.414-3.414-1.414-1.414-3.414 3.414 1.414 1.414zM9 12h4v-2H9v2zm4 0a3 3 0 0 0 3-3h-2a1 1 0 0 1-1 1v2zm3-3V3h-2v6h2zm0-6a3 3 0 0 0-3-3v2a1 1 0 0 1 1 1h2zm-3-3H3v2h10V0zM3 0a3 3 0 0 0-3 3h2a1 1 0 0 1 1-1V0zM0 3v6h2V3H0zm0 6a3 3 0 0 0 3 3v-2a1 1 0 0 1-1-1H0zm3 3h2v-2H3v2zm1-1v4h2v-4H4zm1.707 4.707l.586-.586-1.414-1.414-.586.586 1.414 1.414z"
/>
</svg>
</template>

View File

@@ -0,0 +1,7 @@
<template>
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="17" fill="currentColor">
<path
d="M11 2.253a1 1 0 1 0-2 0h2zm-2 13a1 1 0 1 0 2 0H9zm.447-12.167a1 1 0 1 0 1.107-1.666L9.447 3.086zM1 2.253L.447 1.42A1 1 0 0 0 0 2.253h1zm0 13H0a1 1 0 0 0 1.553.833L1 15.253zm8.447.833a1 1 0 1 0 1.107-1.666l-1.107 1.666zm0-14.666a1 1 0 1 0 1.107 1.666L9.447 1.42zM19 2.253h1a1 1 0 0 0-.447-.833L19 2.253zm0 13l-.553.833A1 1 0 0 0 20 15.253h-1zm-9.553-.833a1 1 0 1 0 1.107 1.666L9.447 14.42zM9 2.253v13h2v-13H9zm1.553-.833C9.203.523 7.42 0 5.5 0v2c1.572 0 2.961.431 3.947 1.086l1.107-1.666zM5.5 0C3.58 0 1.797.523.447 1.42l1.107 1.666C2.539 2.431 3.928 2 5.5 2V0zM0 2.253v13h2v-13H0zm1.553 13.833C2.539 15.431 3.928 15 5.5 15v-2c-1.92 0-3.703.523-5.053 1.42l1.107 1.666zM5.5 15c1.572 0 2.961.431 3.947 1.086l1.107-1.666C9.203 13.523 7.42 13 5.5 13v2zm5.053-11.914C11.539 2.431 12.928 2 14.5 2V0c-1.92 0-3.703.523-5.053 1.42l1.107 1.666zM14.5 2c1.573 0 2.961.431 3.947 1.086l1.107-1.666C18.203.523 16.421 0 14.5 0v2zm3.5.253v13h2v-13h-2zm1.553 12.167C18.203 13.523 16.421 13 14.5 13v2c1.573 0 2.961.431 3.947 1.086l1.107-1.666zM14.5 13c-1.92 0-3.703.523-5.053 1.42l1.107 1.666C11.539 15.431 12.928 15 14.5 15v-2z"
/>
</svg>
</template>

View File

@@ -0,0 +1,7 @@
<template>
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="20" fill="currentColor">
<path
d="M11.447 8.894a1 1 0 1 0-.894-1.789l.894 1.789zm-2.894-.789a1 1 0 1 0 .894 1.789l-.894-1.789zm0 1.789a1 1 0 1 0 .894-1.789l-.894 1.789zM7.447 7.106a1 1 0 1 0-.894 1.789l.894-1.789zM10 9a1 1 0 1 0-2 0h2zm-2 2.5a1 1 0 1 0 2 0H8zm9.447-5.606a1 1 0 1 0-.894-1.789l.894 1.789zm-2.894-.789a1 1 0 1 0 .894 1.789l-.894-1.789zm2 .789a1 1 0 1 0 .894-1.789l-.894 1.789zm-1.106-2.789a1 1 0 1 0-.894 1.789l.894-1.789zM18 5a1 1 0 1 0-2 0h2zm-2 2.5a1 1 0 1 0 2 0h-2zm-5.447-4.606a1 1 0 1 0 .894-1.789l-.894 1.789zM9 1l.447-.894a1 1 0 0 0-.894 0L9 1zm-2.447.106a1 1 0 1 0 .894 1.789l-.894-1.789zm-6 3a1 1 0 1 0 .894 1.789L.553 4.106zm2.894.789a1 1 0 1 0-.894-1.789l.894 1.789zm-2-.789a1 1 0 1 0-.894 1.789l.894-1.789zm1.106 2.789a1 1 0 1 0 .894-1.789l-.894 1.789zM2 5a1 1 0 1 0-2 0h2zM0 7.5a1 1 0 1 0 2 0H0zm8.553 12.394a1 1 0 1 0 .894-1.789l-.894 1.789zm-1.106-2.789a1 1 0 1 0-.894 1.789l.894-1.789zm1.106 1a1 1 0 1 0 .894 1.789l-.894-1.789zm2.894.789a1 1 0 1 0-.894-1.789l.894 1.789zM8 19a1 1 0 1 0 2 0H8zm2-2.5a1 1 0 1 0-2 0h2zm-7.447.394a1 1 0 1 0 .894-1.789l-.894 1.789zM1 15H0a1 1 0 0 0 .553.894L1 15zm1-2.5a1 1 0 1 0-2 0h2zm12.553 2.606a1 1 0 1 0 .894 1.789l-.894-1.789zM17 15l.447.894A1 1 0 0 0 18 15h-1zm1-2.5a1 1 0 1 0-2 0h2zm-7.447-5.394l-2 1 .894 1.789 2-1-.894-1.789zm-1.106 1l-2-1-.894 1.789 2 1 .894-1.789zM8 9v2.5h2V9H8zm8.553-4.894l-2 1 .894 1.789 2-1-.894-1.789zm.894 0l-2-1-.894 1.789 2 1 .894-1.789zM16 5v2.5h2V5h-2zm-4.553-3.894l-2-1-.894 1.789 2 1 .894-1.789zm-2.894-1l-2 1 .894 1.789 2-1L8.553.106zM1.447 5.894l2-1-.894-1.789-2 1 .894 1.789zm-.894 0l2 1 .894-1.789-2-1-.894 1.789zM0 5v2.5h2V5H0zm9.447 13.106l-2-1-.894 1.789 2 1 .894-1.789zm0 1.789l2-1-.894-1.789-2 1 .894 1.789zM10 19v-2.5H8V19h2zm-6.553-3.894l-2-1-.894 1.789 2 1 .894-1.789zM2 15v-2.5H0V15h2zm13.447 1.894l2-1-.894-1.789-2 1 .894 1.789zM18 15v-2.5h-2V15h2z"
/>
</svg>
</template>

View File

@@ -0,0 +1,7 @@
<template>
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor">
<path
d="M10 3.22l-.61-.6a5.5 5.5 0 0 0-7.666.105 5.5 5.5 0 0 0-.114 7.665L10 18.78l8.39-8.4a5.5 5.5 0 0 0-.114-7.665 5.5 5.5 0 0 0-7.666-.105l-.61.61z"
/>
</svg>
</template>

View File

@@ -0,0 +1,19 @@
<!-- This icon is from <https://github.com/Templarian/MaterialDesign>, distributed under Apache 2.0 (https://www.apache.org/licenses/LICENSE-2.0) license-->
<template>
<svg
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
aria-hidden="true"
role="img"
class="iconify iconify--mdi"
width="24"
height="24"
preserveAspectRatio="xMidYMid meet"
viewBox="0 0 24 24"
>
<path
d="M20 18v-4h-3v1h-2v-1H9v1H7v-1H4v4h16M6.33 8l-1.74 4H7v-1h2v1h6v-1h2v1h2.41l-1.74-4H6.33M9 5v1h6V5H9m12.84 7.61c.1.22.16.48.16.8V18c0 .53-.21 1-.6 1.41c-.4.4-.85.59-1.4.59H4c-.55 0-1-.19-1.4-.59C2.21 19 2 18.53 2 18v-4.59c0-.32.06-.58.16-.8L4.5 7.22C4.84 6.41 5.45 6 6.33 6H7V5c0-.55.18-1 .57-1.41C7.96 3.2 8.44 3 9 3h6c.56 0 1.04.2 1.43.59c.39.41.57.86.57 1.41v1h.67c.88 0 1.49.41 1.83 1.22l2.34 5.39z"
fill="currentColor"
></path>
</svg>
</template>

View File

@@ -0,0 +1,95 @@
// src/composables/useMediaDevices.js - Composable for media device management
import { ref, onMounted, onUnmounted } from 'vue'
import { mediaService } from '../services/media'
export function useMediaDevices() {
const videoDevices = ref([])
const audioDevices = ref([])
const audioOutputDevices = ref([])
const selectedVideoDevice = ref('')
const selectedAudioDevice = ref('')
const selectedAudioOutputDevice = ref('')
let deviceChangeHandler = null
const loadDevices = async () => {
try {
const devices = await mediaService.getMediaDevices()
videoDevices.value = devices.videoDevices
audioDevices.value = devices.audioDevices
audioOutputDevices.value = devices.audioOutputDevices
// Set default selected devices
if (videoDevices.value.length > 0 && !selectedVideoDevice.value) {
selectedVideoDevice.value = videoDevices.value[0].deviceId
}
if (audioDevices.value.length > 0 && !selectedAudioDevice.value) {
selectedAudioDevice.value = audioDevices.value[0].deviceId
}
if (audioOutputDevices.value.length > 0 && !selectedAudioOutputDevice.value) {
selectedAudioOutputDevice.value = audioOutputDevices.value[0].deviceId
}
} catch (error) {
console.error('Failed to load media devices:', error)
}
}
const switchVideoDevice = async () => {
// This will be implemented in the component that uses this composable
console.log('Switching to video device:', selectedVideoDevice.value)
}
const switchAudioDevice = async () => {
// This will be implemented in the component that uses this composable
console.log('Switching to audio device:', selectedAudioDevice.value)
}
const switchAudioOutputDevice = async () => {
// This will be implemented in the component that uses this composable
console.log('Switching to audio output device:', selectedAudioOutputDevice.value)
}
const refreshDevices = async () => {
await loadDevices()
}
onMounted(() => {
loadDevices()
// Listen for device changes
if (navigator.mediaDevices && navigator.mediaDevices.addEventListener) {
deviceChangeHandler = () => {
console.log('Media devices changed, reloading...')
loadDevices()
}
navigator.mediaDevices.addEventListener('devicechange', deviceChangeHandler)
}
})
onUnmounted(() => {
if (
deviceChangeHandler &&
navigator.mediaDevices &&
navigator.mediaDevices.removeEventListener
) {
navigator.mediaDevices.removeEventListener('devicechange', deviceChangeHandler)
}
})
return {
videoDevices,
audioDevices,
audioOutputDevices,
selectedVideoDevice,
selectedAudioDevice,
selectedAudioOutputDevice,
switchVideoDevice,
switchAudioDevice,
switchAudioOutputDevice,
refreshDevices,
loadDevices,
}
}

View File

@@ -0,0 +1,99 @@
// src/main.js - Vue.js application entry point with PWA support
import { createApp } from 'vue'
import { createPinia } from 'pinia'
import router from './router'
import App from './App.vue'
import { apiService } from './services/api'
import './style.css'
const app = createApp(App)
const pinia = createPinia()
app.use(pinia)
app.use(router)
// Initialize API service with CSRF token
apiService
.initialize()
.then(() => {
console.log('API service initialized')
})
.catch((error) => {
console.warn('Failed to initialize API service:', error)
})
app.mount('#app')
// PWA Service Worker Registration
if ('serviceWorker' in navigator) {
// Use dynamic import to handle virtual modules
import('virtual:pwa-register')
.then(({ registerSW }) => {
const updateSW = registerSW({
onNeedRefresh() {
// Show update available notification
console.log('App update available')
// You can show a custom notification here
const shouldUpdate = confirm('New version available! Click OK to update.')
if (shouldUpdate) {
updateSW(true)
}
},
onOfflineReady() {
console.log('App ready for offline use')
// Optional: Show offline ready notification
// You can integrate this with your notification system
},
onRegisterError(error) {
console.error('Service Worker registration failed:', error)
},
})
// Optional: Periodic update checks (every 60 seconds)
setInterval(() => {
updateSW()
}, 60000)
})
.catch((error) => {
console.error('Failed to register service worker:', error)
})
}
// Network status monitoring for PWA
window.addEventListener('online', () => {
console.log('App is online')
})
window.addEventListener('offline', () => {
console.log('App is offline')
})
// Install prompt handling
let deferredPrompt
window.addEventListener('beforeinstallprompt', (e) => {
// Prevent the mini-infobar from appearing on mobile
e.preventDefault()
// Stash the event so it can be triggered later
deferredPrompt = e
console.log('PWA install prompt available')
})
// Handle app installation
window.addEventListener('appinstalled', () => {
console.log('PWA was installed')
deferredPrompt = null
})
// Export install prompt function for components to use
window.showInstallPrompt = async () => {
if (deferredPrompt) {
deferredPrompt.prompt()
const { outcome } = await deferredPrompt.userChoice
console.log(`User response to install prompt: ${outcome}`)
deferredPrompt = null
return outcome === 'accepted'
}
return false
}

View File

@@ -0,0 +1,609 @@
// src/router/index.js - Complete Vue Router configuration with auth guards and transitions
import { createRouter, createWebHistory } from 'vue-router'
import { useGlobalStore } from '../stores/global'
import { useRoomsStore } from '../stores/rooms'
// Lazy load components for better performance
const LoginForm = () => import('../components/LoginForm.vue')
const Dashboard = () => import('../components/Dashboard.vue')
const VideoCall = () => import('../components/VideoCall.vue')
const NotFound = () => import('../components/NotFound.vue')
const JoinRoom = () => import('../components/JoinRoom.vue')
// Route definitions with comprehensive metadata
const routes = [
{
path: '/',
name: 'Dashboard',
component: Dashboard,
meta: {
requiresAuth: true,
title: 'Video Call Dashboard',
description: 'Create or join video calls',
showInNav: true,
icon: 'home',
},
},
{
path: '/login',
name: 'Login',
component: LoginForm,
meta: {
requiresAuth: false,
title: 'Sign In - Video Call',
description: 'Access the video calling platform',
hideForAuth: true, // Hide this route if user is already authenticated
showInNav: false,
},
},
{
path: '/call/:roomId',
name: 'VideoCall',
component: VideoCall,
meta: {
requiresAuth: true,
title: 'Video Call',
description: 'Active video call session',
showInNav: false,
fullScreen: true,
preventLeave: true, // Show confirmation before leaving
},
props: true,
beforeEnter: async (to, from, next) => {
// Validate room ID format (UUID v4)
const roomIdPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i
if (!roomIdPattern.test(to.params.roomId)) {
console.warn('Invalid room ID format:', to.params.roomId)
next({ name: 'NotFound' })
return
}
next()
},
},
{
path: '/join/:shortCode',
name: 'JoinRoom',
component: JoinRoom,
meta: {
requiresAuth: true,
title: 'Join Room',
description: 'Join video call by room code',
showInNav: false,
},
props: true,
beforeEnter: (to, from, next) => {
// Validate short code format (6-8 alphanumeric characters)
const shortCodePattern = /^[A-Z0-9]{6,8}$/i
if (!shortCodePattern.test(to.params.shortCode)) {
console.warn('Invalid short code format:', to.params.shortCode)
next({ name: 'NotFound' })
return
}
next()
},
},
{
path: '/room/:identifier',
redirect: (to) => {
// Redirect old room URLs to appropriate new format
const identifier = to.params.identifier
// Check if it looks like a UUID (room ID)
const uuidPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i
if (uuidPattern.test(identifier)) {
return { name: 'VideoCall', params: { roomId: identifier } }
}
// Otherwise assume it's a short code
return { name: 'JoinRoom', params: { shortCode: identifier } }
},
},
// {
// path: '/privacy',
// name: 'Privacy',
// component: () => import('../components/Privacy.vue'),
// meta: {
// requiresAuth: false,
// title: 'Privacy Policy',
// description: 'Our privacy policy and data handling practices',
// showInNav: true,
// icon: 'shield',
// },
// },
// {
// path: '/terms',
// name: 'Terms',
// component: () => import('../components/Terms.vue'),
// meta: {
// requiresAuth: false,
// title: 'Terms of Service',
// description: 'Terms and conditions of use',
// showInNav: true,
// icon: 'document',
// },
// },
// {
// path: '/help',
// name: 'Help',
// component: () => import('../components/Help.vue'),
// meta: {
// requiresAuth: false,
// title: 'Help & Support',
// description: 'Get help with using the video calling platform',
// showInNav: true,
// icon: 'question',
// },
// },
// Catch-all route for 404
{
path: '/:pathMatch(.*)*',
name: 'NotFound',
component: NotFound,
meta: {
requiresAuth: false,
title: '404 - Page Not Found',
description: 'The requested page could not be found',
showInNav: false,
},
},
]
// Create router instance with configuration
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
routes,
scrollBehavior(to, from, savedPosition) {
// Handle scroll behavior for different scenarios
if (savedPosition) {
// When using browser back/forward buttons
return savedPosition
} else if (to.hash) {
// When navigating to an anchor
return { el: to.hash, behavior: 'smooth' }
} else if (to.name !== from.name) {
// When navigating to a different page
return { top: 0, behavior: 'smooth' }
}
// Otherwise maintain current scroll position
return {}
},
// Configure link active classes
linkActiveClass: 'router-link-active',
linkExactActiveClass: 'router-link-exact-active',
})
// Global navigation guards
router.beforeEach(async (to, from, next) => {
const globalStore = useGlobalStore()
const roomsStore = useRoomsStore()
console.log(`Navigating from ${from.name} to ${to.name}`)
// Set document title and meta tags
updateDocumentMeta(to)
// Handle loading state
if (to.name !== from.name) {
globalStore.setLoading(true, 'Loading page...')
}
// Check authentication requirement
const requiresAuth = to.meta.requiresAuth
const hideForAuth = to.meta.hideForAuth
const isAuthenticated = globalStore.isAuthenticated
// If route should be hidden for authenticated users
if (hideForAuth && isAuthenticated) {
const redirectTo = to.query.redirect || from.fullPath || '/'
next(redirectTo)
return
}
// If route requires auth and user is not authenticated
if (requiresAuth && !isAuthenticated) {
// Try to check auth status from server first
await globalStore.checkAuthentication()
if (!globalStore.isAuthenticated) {
// Store intended destination
const redirectQuery = to.fullPath !== '/' ? { redirect: to.fullPath } : {}
next({ name: 'Login', query: redirectQuery })
return
}
}
// Handle special route logic
await handleSpecialRoutes(to, from, next, { globalStore, roomsStore })
})
router.beforeResolve(async (to, from, next) => {
// This runs after all in-component guards and async route components are resolved
console.log(`Resolving route: ${to.name}`)
next()
})
router.afterEach((to, from, failure) => {
const globalStore = useGlobalStore()
// Clear loading state
globalStore.setLoading(false)
if (failure) {
console.error('Navigation failed:', failure)
globalStore.addNotification('Navigation failed', 'error', 3000)
} else {
console.log(`Successfully navigated to ${to.name}`)
// Track page view (could integrate with analytics here)
trackPageView(to)
}
// Handle route-specific post-navigation logic
handlePostNavigation(to, from)
})
// Route-specific handlers
async function handleSpecialRoutes(to, from, next, { globalStore, roomsStore }) {
switch (to.name) {
case 'VideoCall':
// Special handling for video call routes
if (from.name !== 'JoinRoom' && from.name !== 'Dashboard') {
// If coming from external source, show warning about media permissions
globalStore.addNotification(
'Please allow camera and microphone access when prompted',
'info',
5000,
)
}
break
case 'JoinRoom':
// Check if we already have room info
const shortCode = to.params.shortCode
if (roomsStore.currentRoom?.short_code === shortCode) {
// Redirect directly to video call if already in this room
next({ name: 'VideoCall', params: { roomId: roomsStore.currentRoom.room_id } })
return
}
break
case 'Dashboard':
// Load room history when entering dashboard
roomsStore.loadHistory()
break
}
next()
}
function updateDocumentMeta(to) {
// Update document title
if (to.meta.title) {
document.title = to.meta.title
}
// Update meta description
if (to.meta.description) {
let metaDescription = document.querySelector('meta[name="description"]')
if (!metaDescription) {
metaDescription = document.createElement('meta')
metaDescription.setAttribute('name', 'description')
document.head.appendChild(metaDescription)
}
metaDescription.setAttribute('content', to.meta.description)
}
// Update Open Graph tags
updateOpenGraphTags(to)
}
function updateOpenGraphTags(to) {
const ogTags = [
{ property: 'og:title', content: to.meta.title },
{ property: 'og:description', content: to.meta.description },
{ property: 'og:url', content: window.location.href },
]
ogTags.forEach(({ property, content }) => {
if (!content) return
let tag = document.querySelector(`meta[property="${property}"]`)
if (!tag) {
tag = document.createElement('meta')
tag.setAttribute('property', property)
document.head.appendChild(tag)
}
tag.setAttribute('content', content)
})
}
function trackPageView(to) {
// Basic page view tracking (could be enhanced with analytics)
if (typeof gtag !== 'undefined') {
gtag('config', 'GA_MEASUREMENT_ID', {
page_title: to.meta.title,
page_location: window.location.href,
page_path: to.path,
})
}
// Custom analytics could go here
console.log('Page view:', {
path: to.path,
name: to.name,
title: to.meta.title,
timestamp: new Date().toISOString(),
})
}
function handlePostNavigation(to, from) {
// Handle route-specific post-navigation tasks
// Add body classes for styling
document.body.className = document.body.className
.replace(/route-\S+/g, '') // Remove existing route classes
.trim()
if (to.name) {
document.body.classList.add(`route-${to.name.toLowerCase()}`)
}
// Handle full-screen routes
if (to.meta.fullScreen) {
document.body.classList.add('fullscreen-route')
} else {
document.body.classList.remove('fullscreen-route')
}
// Handle prevent leave for important routes
if (to.meta.preventLeave) {
setupBeforeUnloadHandler()
} else {
removeBeforeUnloadHandler()
}
}
// Prevent leaving important pages accidentally
let beforeUnloadHandler = null
function setupBeforeUnloadHandler() {
beforeUnloadHandler = (event) => {
const message = 'Are you sure you want to leave this video call?'
event.preventDefault()
event.returnValue = message
return message
}
window.addEventListener('beforeunload', beforeUnloadHandler)
}
function removeBeforeUnloadHandler() {
if (beforeUnloadHandler) {
window.removeEventListener('beforeunload', beforeUnloadHandler)
beforeUnloadHandler = null
}
}
// Navigation helpers
export const navigationHelpers = {
/**
* Navigate to room by code or ID
*/
async goToRoom(identifier, options = {}) {
const { replace = false } = options
// Determine if it's a room ID (UUID) or short code
const uuidPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i
const route = uuidPattern.test(identifier)
? { name: 'VideoCall', params: { roomId: identifier } }
: { name: 'JoinRoom', params: { shortCode: identifier } }
if (replace) {
return router.replace(route)
} else {
return router.push(route)
}
},
/**
* Navigate back with fallback
*/
goBack(fallbackRoute = { name: 'Dashboard' }) {
if (window.history.length > 1) {
router.go(-1)
} else {
router.push(fallbackRoute)
}
},
/**
* Get navigation items for menus
*/
getNavigationItems(authenticated = false) {
return routes
.filter((route) => route.meta?.showInNav)
.filter((route) => {
if (route.meta?.requiresAuth && !authenticated) return false
if (route.meta?.hideForAuth && authenticated) return false
return true
})
.map((route) => ({
name: route.name,
path: route.path,
title: route.meta?.title || route.name,
icon: route.meta?.icon,
description: route.meta?.description,
}))
},
/**
* Check if current route matches
*/
isCurrentRoute(routeName) {
return router.currentRoute.value.name === routeName
},
/**
* Get current route info
*/
getCurrentRoute() {
const route = router.currentRoute.value
return {
name: route.name,
path: route.path,
params: route.params,
query: route.query,
meta: route.meta,
}
},
}
// Route transition configurations
export const routeTransitions = {
// Default transition
default: {
name: 'fade',
mode: 'out-in',
},
// Slide transition for mobile
slide: {
name: 'slide',
mode: 'out-in',
},
// No transition for video calls
none: {
name: '',
mode: 'out-in',
},
}
// Route middleware system
const middlewares = {
auth: async (to, from, next) => {
const globalStore = useGlobalStore()
if (!globalStore.isAuthenticated) {
await globalStore.checkAuthentication()
if (!globalStore.isAuthenticated) {
next({ name: 'Login', query: { redirect: to.fullPath } })
return
}
}
next()
},
guest: (to, from, next) => {
const globalStore = useGlobalStore()
if (globalStore.isAuthenticated) {
next({ name: 'Dashboard' })
return
}
next()
},
validateRoom: async (to, from, next) => {
const roomsStore = useRoomsStore()
const roomId = to.params.roomId
if (roomId) {
const result = await roomsStore.getRoomInfo(roomId)
if (!result.success) {
next({ name: 'NotFound' })
return
}
}
next()
},
}
// Apply middleware to routes
function applyMiddleware(to, from, next, middlewareList = []) {
if (middlewareList.length === 0) {
next()
return
}
const middleware = middlewares[middlewareList[0]]
if (!middleware) {
console.warn(`Middleware ${middlewareList[0]} not found`)
applyMiddleware(to, from, next, middlewareList.slice(1))
return
}
middleware(to, from, (nextArg) => {
if (nextArg) {
next(nextArg)
} else {
applyMiddleware(to, from, next, middlewareList.slice(1))
}
})
}
// Error handling for navigation
router.onError((error, to, from) => {
console.error('Router error:', error)
const globalStore = useGlobalStore()
globalStore.setLoading(false)
// Handle specific error types
if (error.name === 'ChunkLoadError') {
// Handle code splitting errors
globalStore.addNotification('Failed to load page. Please refresh and try again.', 'error', 8000)
// Retry navigation after a short delay
setTimeout(() => {
window.location.reload()
}, 2000)
} else {
globalStore.addNotification('Navigation error occurred', 'error', 5000)
}
})
// Cleanup on app unmount
export function cleanupRouter() {
removeBeforeUnloadHandler()
document.body.className = document.body.className
.replace(/route-\S+/g, '')
.replace('fullscreen-route', '')
.trim()
}
// Development helpers
if (import.meta.env.DEV) {
// Add router debugging in development
router.beforeEach((to, from, next) => {
console.group('🧭 Router Navigation')
console.log('From:', from.name, from.path)
console.log('To:', to.name, to.path)
console.log('Query:', to.query)
console.log('Params:', to.params)
console.log('Meta:', to.meta)
console.groupEnd()
next()
})
// Expose router to global scope for debugging
window.__router__ = router
window.__navigationHelpers__ = navigationHelpers
}
// Export router instance
export default router
// Export route configurations for testing
export { routes, middlewares }

View File

@@ -0,0 +1,258 @@
// src/services/api.js - API service layer with CSRF support
import axios from 'axios'
// Create axios instance with base configuration
const apiClient = axios.create({
baseURL: import.meta.env.VITE_API_BASE_URL || '/api',
timeout: 30000,
headers: {
'Content-Type': 'application/json',
},
withCredentials: true, // Include session cookies
})
// Get CSRF token from cookie
const getCSRFToken = () => {
const name = 'csrftoken'
let cookieValue = null
if (document.cookie && document.cookie !== '') {
const cookies = document.cookie.split(';')
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i].trim()
if (cookie.substring(0, name.length + 1) === name + '=') {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1))
break
}
}
}
return cookieValue
}
// Request interceptor for adding auth headers and logging
apiClient.interceptors.request.use(
(config) => {
console.log(`API Request: ${config.method?.toUpperCase()} ${config.url}`)
// Add CSRF token for non-GET requests
if (config.method && !['get', 'head', 'options'].includes(config.method.toLowerCase())) {
const csrfToken = getCSRFToken()
if (csrfToken) {
config.headers['X-CSRFToken'] = csrfToken
}
}
return config
},
(error) => {
console.error('API Request Error:', error)
return Promise.reject(error)
},
)
// Response interceptor for handling errors and logging
apiClient.interceptors.response.use(
(response) => {
console.log(`API Response: ${response.status} ${response.config.url}`)
return response
},
async (error) => {
console.error('API Response Error:', {
status: error.response?.status,
message: error.response?.data?.error || error.message,
url: error.config?.url,
})
// Handle specific error cases
if (error.response?.status === 401) {
// Unauthorized - redirect to login if needed
console.log('Unauthorized access detected')
} else if (error.response?.status === 403) {
// Forbidden - might be CSRF issue, try to get new token
console.log('Forbidden access - possible CSRF issue')
// Try to refresh CSRF token and retry once
if (!error.config._retry) {
error.config._retry = true
try {
await getCsrfToken()
return apiClient(error.config)
} catch (retryError) {
console.error('Failed to retry with new CSRF token:', retryError)
}
}
} else if (error.response?.status === 429) {
// Rate limited
console.log('Rate limit exceeded')
} else if (error.response?.status >= 500) {
// Server error
console.log('Server error occurred')
}
return Promise.reject(error)
},
)
// Get CSRF token endpoint
const getCsrfToken = async () => {
try {
const response = await apiClient.get('/csrf/')
const token = response.data.csrfToken
if (token) {
// Set token for future requests
apiClient.defaults.headers.common['X-CSRFToken'] = token
}
return token
} catch (error) {
console.warn('Failed to get CSRF token:', error)
return null
}
}
// Initialize CSRF token
let csrfInitialized = false
const initializeCSRF = async () => {
if (!csrfInitialized) {
const token = await getCsrfToken()
csrfInitialized = !!token
}
}
// API service object with all endpoint methods
export const apiService = {
// Initialize CSRF
async initialize() {
await initializeCSRF()
},
// Authentication endpoints
async login(password) {
await initializeCSRF()
return apiClient.post('/auth/login/', { password })
},
async logout() {
return apiClient.post('/auth/logout/')
},
async checkAuth() {
return apiClient.get('/auth/check/')
},
// Room management endpoints
async createRoom() {
await initializeCSRF()
return apiClient.post('/rooms/create/')
},
async getRoomInfo(roomId) {
return apiClient.get(`/rooms/${roomId}/`)
},
async joinRoom(roomIdentifier) {
await initializeCSRF()
return apiClient.post('/rooms/join/', {
room_identifier: roomIdentifier,
})
},
async leaveRoom(roomId) {
await initializeCSRF()
return apiClient.post(`/rooms/${roomId}/leave/`)
},
async deleteRoom(roomId) {
await initializeCSRF()
return apiClient.delete(`/rooms/${roomId}/delete/`)
},
// System endpoints
async healthCheck() {
return apiClient.get('/health/')
},
}
// Utility functions for API handling
export const apiUtils = {
/**
* Extract error message from API response
*/
getErrorMessage(error) {
if (error.response?.data?.error) {
return error.response.data.error
} else if (error.response?.data?.message) {
return error.response.data.message
} else if (error.message) {
return error.message
} else {
return 'An unexpected error occurred'
}
},
/**
* Check if error is due to network issues
*/
isNetworkError(error) {
return !error.response || error.code === 'NETWORK_ERROR'
},
/**
* Check if error is due to authentication
*/
isAuthError(error) {
return error.response?.status === 401
},
/**
* Check if error is due to CSRF
*/
isCSRFError(error) {
return error.response?.status === 403
},
/**
* Check if error is due to rate limiting
*/
isRateLimitError(error) {
return error.response?.status === 429
},
/**
* Retry API call with exponential backoff
*/
async retryWithBackoff(apiCall, maxRetries = 3, baseDelay = 1000) {
let lastError
for (let attempt = 0; attempt < maxRetries; attempt++) {
try {
return await apiCall()
} catch (error) {
lastError = error
// Retry CSRF errors once
if (this.isCSRFError(error) && attempt === 0) {
await initializeCSRF()
continue
}
// Don't retry on client errors (4xx) except CSRF
if (
error.response?.status >= 400 &&
error.response?.status < 500 &&
!this.isCSRFError(error)
) {
break
}
// Wait before retrying (exponential backoff)
if (attempt < maxRetries - 1) {
const delay = baseDelay * Math.pow(2, attempt)
await new Promise((resolve) => setTimeout(resolve, delay))
}
}
}
throw lastError
},
}

View File

@@ -0,0 +1,160 @@
// src/services/media.js - Media handling utilities
export const mediaService = {
/**
* Get available media devices
*/
async getMediaDevices() {
try {
const devices = await navigator.mediaDevices.enumerateDevices()
return {
videoDevices: devices.filter((device) => device.kind === 'videoinput'),
audioDevices: devices.filter((device) => device.kind === 'audioinput'),
audioOutputDevices: devices.filter((device) => device.kind === 'audiooutput'),
}
} catch (error) {
console.error('Failed to get media devices:', error)
return {
videoDevices: [],
audioDevices: [],
audioOutputDevices: [],
}
}
},
/**
* Check if user has granted media permissions
*/
async checkMediaPermissions() {
try {
const permissions = await Promise.all([
navigator.permissions.query({ name: 'camera' }),
navigator.permissions.query({ name: 'microphone' }),
])
return {
camera: permissions[0].state,
microphone: permissions[1].state,
}
} catch (error) {
console.error('Failed to check media permissions:', error)
return {
camera: 'unknown',
microphone: 'unknown',
}
}
},
/**
* Get optimal media constraints based on device capabilities
*/
async getOptimalConstraints() {
try {
const devices = await this.getMediaDevices()
// Default constraints
let constraints = {
video: {
width: { ideal: 1280, max: 1920 },
height: { ideal: 720, max: 1080 },
frameRate: { ideal: 30, max: 60 },
},
audio: {
echoCancellation: true,
noiseSuppression: true,
autoGainControl: true,
},
}
// Adjust constraints based on available devices
if (devices.videoDevices.length === 0) {
constraints.video = false
}
if (devices.audioDevices.length === 0) {
constraints.audio = false
}
return constraints
} catch (error) {
console.error('Failed to get optimal constraints:', error)
return {
video: true,
audio: true,
}
}
},
/**
* Test media access without keeping the stream
*/
async testMediaAccess() {
try {
const stream = await navigator.mediaDevices.getUserMedia({
video: true,
audio: true,
})
// Immediately stop all tracks
stream.getTracks().forEach((track) => track.stop())
return {
success: true,
hasVideo: stream.getVideoTracks().length > 0,
hasAudio: stream.getAudioTracks().length > 0,
}
} catch (error) {
return {
success: false,
error: error.name,
message: this.getMediaErrorMessage(error),
}
}
},
/**
* Get user-friendly error message for media errors
*/
getMediaErrorMessage(error) {
switch (error.name) {
case 'NotAllowedError':
return 'Camera and microphone access denied. Please allow permissions and try again.'
case 'NotFoundError':
return 'No camera or microphone found on this device.'
case 'NotReadableError':
return 'Camera or microphone is already in use by another application.'
case 'OverconstrainedError':
return 'Camera or microphone does not support the requested settings.'
case 'SecurityError':
return 'Media access blocked due to security restrictions.'
case 'AbortError':
return 'Media access was aborted.'
default:
return 'Failed to access camera or microphone.'
}
},
/**
* Create media stream with fallback options
*/
async createStreamWithFallback(preferredConstraints) {
const fallbackOptions = [
preferredConstraints,
{ video: true, audio: true }, // Basic constraints
{ video: { width: 640, height: 480 }, audio: true }, // Lower resolution
{ video: false, audio: true }, // Audio only
]
for (const constraints of fallbackOptions) {
try {
const stream = await navigator.mediaDevices.getUserMedia(constraints)
return { success: true, stream, constraints }
} catch (error) {
console.warn('Failed to create stream with constraints:', constraints, error)
continue
}
}
throw new Error('Failed to create media stream with any constraints')
},
}

View File

@@ -0,0 +1,85 @@
// src/services/storage.js - Local storage utilities
export const storageService = {
/**
* Safely get item from localStorage
*/
getItem(key, defaultValue = null) {
try {
const item = localStorage.getItem(key)
return item ? JSON.parse(item) : defaultValue
} catch (error) {
console.warn(`Failed to get item from localStorage: ${key}`, error)
return defaultValue
}
},
/**
* Safely set item in localStorage
*/
setItem(key, value) {
try {
localStorage.setItem(key, JSON.stringify(value))
return true
} catch (error) {
console.warn(`Failed to set item in localStorage: ${key}`, error)
return false
}
},
/**
* Safely remove item from localStorage
*/
removeItem(key) {
try {
localStorage.removeItem(key)
return true
} catch (error) {
console.warn(`Failed to remove item from localStorage: ${key}`, error)
return false
}
},
/**
* Clear all items from localStorage
*/
clear() {
try {
localStorage.clear()
return true
} catch (error) {
console.warn('Failed to clear localStorage', error)
return false
}
},
/**
* Get storage usage information
*/
getStorageInfo() {
try {
const used = new Blob(Object.values(localStorage)).size
return {
used: used,
usedFormatted: this.formatBytes(used),
available: 5 * 1024 * 1024 - used, // Assuming 5MB limit
availableFormatted: this.formatBytes(5 * 1024 * 1024 - used),
}
} catch (error) {
console.warn('Failed to get storage info', error)
return null
}
},
/**
* Format bytes to human readable format
*/
formatBytes(bytes) {
if (bytes === 0) return '0 Bytes'
const k = 1024
const sizes = ['Bytes', 'KB', 'MB', 'GB']
const i = Math.floor(Math.log(bytes) / Math.log(k))
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]
},
}

View File

@@ -0,0 +1,192 @@
// src/services/utils.js - Utility functions
export const utils = {
/**
* Generate random string
*/
generateRandomString(length = 8) {
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
let result = ''
for (let i = 0; i < length; i++) {
result += chars.charAt(Math.floor(Math.random() * chars.length))
}
return result
},
/**
* Copy text to clipboard
*/
async copyToClipboard(text) {
try {
if (navigator.clipboard && window.isSecureContext) {
await navigator.clipboard.writeText(text)
return { success: true }
} else {
// Fallback for older browsers
const textArea = document.createElement('textarea')
textArea.value = text
textArea.style.position = 'fixed'
textArea.style.left = '-999999px'
textArea.style.top = '-999999px'
document.body.appendChild(textArea)
textArea.focus()
textArea.select()
const success = document.execCommand('copy')
textArea.remove()
return { success }
}
} catch (error) {
console.error('Failed to copy to clipboard:', error)
return { success: false, error: error.message }
}
},
/**
* Debounce function
*/
debounce(func, wait) {
let timeout
return function executedFunction(...args) {
const later = () => {
clearTimeout(timeout)
func(...args)
}
clearTimeout(timeout)
timeout = setTimeout(later, wait)
}
},
/**
* Throttle function
*/
throttle(func, limit) {
let inThrottle
return function (...args) {
if (!inThrottle) {
func.apply(this, args)
inThrottle = true
setTimeout(() => (inThrottle = false), limit)
}
}
},
/**
* Format time duration
*/
formatDuration(seconds) {
const hrs = Math.floor(seconds / 3600)
const mins = Math.floor((seconds % 3600) / 60)
const secs = Math.floor(seconds % 60)
if (hrs > 0) {
return `${hrs}:${mins.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`
} else {
return `${mins}:${secs.toString().padStart(2, '0')}`
}
},
/**
* Format relative time
*/
formatRelativeTime(date) {
const now = new Date()
const diffInSeconds = Math.floor((now - date) / 1000)
if (diffInSeconds < 60) {
return 'Just now'
} else if (diffInSeconds < 3600) {
const minutes = Math.floor(diffInSeconds / 60)
return `${minutes} minute${minutes === 1 ? '' : 's'} ago`
} else if (diffInSeconds < 86400) {
const hours = Math.floor(diffInSeconds / 3600)
return `${hours} hour${hours === 1 ? '' : 's'} ago`
} else {
const days = Math.floor(diffInSeconds / 86400)
return `${days} day${days === 1 ? '' : 's'} ago`
}
},
/**
* Validate URL
*/
isValidUrl(string) {
try {
new URL(string)
return true
} catch (_) {
return false
}
},
/**
* Generate QR code data URL
*/
async generateQRCode(text, options = {}) {
const QRCode = await import('qrcode')
const defaultOptions = {
width: 256,
margin: 2,
color: {
dark: '#000000',
light: '#ffffff',
},
}
try {
const dataURL = await QRCode.toDataURL(text, { ...defaultOptions, ...options })
return { success: true, dataURL }
} catch (error) {
console.error('Failed to generate QR code:', error)
return { success: false, error: error.message }
}
},
/**
* Detect mobile device
*/
isMobileDevice() {
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
navigator.userAgent,
)
},
/**
* Detect iOS device
*/
isIOSDevice() {
return /iPad|iPhone|iPod/.test(navigator.userAgent)
},
/**
* Get browser info
*/
getBrowserInfo() {
const userAgent = navigator.userAgent
let browserName = 'Unknown'
let browserVersion = 'Unknown'
if (userAgent.indexOf('Chrome') > -1) {
browserName = 'Chrome'
browserVersion = userAgent.match(/Chrome\/([0-9.]+)/)?.[1] || 'Unknown'
} else if (userAgent.indexOf('Safari') > -1) {
browserName = 'Safari'
browserVersion = userAgent.match(/Version\/([0-9.]+)/)?.[1] || 'Unknown'
} else if (userAgent.indexOf('Firefox') > -1) {
browserName = 'Firefox'
browserVersion = userAgent.match(/Firefox\/([0-9.]+)/)?.[1] || 'Unknown'
} else if (userAgent.indexOf('Edge') > -1) {
browserName = 'Edge'
browserVersion = userAgent.match(/Edge\/([0-9.]+)/)?.[1] || 'Unknown'
}
return {
name: browserName,
version: browserVersion,
userAgent: userAgent,
isMobile: this.isMobileDevice(),
isIOS: this.isIOSDevice(),
}
},
}

View File

@@ -0,0 +1,136 @@
// src/services/webrtc.js - WebRTC utility functions
export const webrtcService = {
/**
* Get STUN/TURN server configuration
*/
getIceServerConfig() {
return {
iceServers: [
{ urls: 'stun:stun.l.google.com:19302' },
{ urls: 'stun:stun1.l.google.com:19302' },
{ urls: 'stun:stun2.l.google.com:19302' },
// Add TURN servers for production
// {
// urls: 'turn:your-turn-server.com:3478',
// username: 'username',
// credential: 'password'
// }
],
iceCandidatePoolSize: 10,
}
},
/**
* Test WebRTC support
*/
isWebRTCSupported() {
return !!(
window.RTCPeerConnection ||
window.webkitRTCPeerConnection ||
window.mozRTCPeerConnection
)
},
/**
* Get WebRTC statistics
*/
async getConnectionStats(peerConnection) {
if (!peerConnection) return null
try {
const stats = await peerConnection.getStats()
const result = {
video: {},
audio: {},
connection: {},
}
stats.forEach((report) => {
if (report.type === 'inbound-rtp' && report.mediaType === 'video') {
result.video.inbound = {
bytesReceived: report.bytesReceived,
packetsReceived: report.packetsReceived,
packetsLost: report.packetsLost,
frameWidth: report.frameWidth,
frameHeight: report.frameHeight,
framesPerSecond: report.framesPerSecond,
}
} else if (report.type === 'outbound-rtp' && report.mediaType === 'video') {
result.video.outbound = {
bytesSent: report.bytesSent,
packetsSent: report.packetsSent,
frameWidth: report.frameWidth,
frameHeight: report.frameHeight,
framesPerSecond: report.framesPerSecond,
}
} else if (report.type === 'candidate-pair' && report.state === 'succeeded') {
result.connection = {
currentRoundTripTime: report.currentRoundTripTime,
availableOutgoingBitrate: report.availableOutgoingBitrate,
bytesReceived: report.bytesReceived,
bytesSent: report.bytesSent,
}
}
})
return result
} catch (error) {
console.error('Failed to get connection stats:', error)
return null
}
},
/**
* Monitor connection quality
*/
createQualityMonitor(peerConnection, callback, interval = 5000) {
if (!peerConnection || typeof callback !== 'function') {
return null
}
const monitor = setInterval(async () => {
try {
const stats = await this.getConnectionStats(peerConnection)
if (stats) {
const quality = this.calculateQuality(stats)
callback(quality, stats)
}
} catch (error) {
console.error('Quality monitoring error:', error)
}
}, interval)
return monitor
},
/**
* Calculate connection quality score (0-100)
*/
calculateQuality(stats) {
let score = 100
// Reduce score based on packet loss
if (stats.video.inbound?.packetsLost && stats.video.inbound?.packetsReceived) {
const lossRate = stats.video.inbound.packetsLost / stats.video.inbound.packetsReceived
score -= lossRate * 50 // Up to 50 points for packet loss
}
// Reduce score based on round trip time
if (stats.connection?.currentRoundTripTime) {
const rtt = stats.connection.currentRoundTripTime * 1000 // Convert to ms
if (rtt > 150) {
score -= Math.min(30, (rtt - 150) / 10) // Up to 30 points for high latency
}
}
// Reduce score based on low frame rate
if (stats.video.inbound?.framesPerSecond) {
const fps = stats.video.inbound.framesPerSecond
if (fps < 15) {
score -= (15 - fps) * 2 // Up to 30 points for low FPS
}
}
return Math.max(0, Math.min(100, Math.round(score)))
},
}

View File

@@ -0,0 +1,12 @@
import { ref, computed } from 'vue'
import { defineStore } from 'pinia'
export const useCounterStore = defineStore('counter', () => {
const count = ref(0)
const doubleCount = computed(() => count.value * 2)
function increment() {
count.value++
}
return { count, doubleCount, increment }
})

View File

@@ -0,0 +1,139 @@
// src/stores/global.js - Global application state management
import { defineStore } from 'pinia'
import { ref, computed } from 'vue'
import { apiService } from '../services/api'
export const useGlobalStore = defineStore('global', () => {
// State
const isAuthenticated = ref(false)
const isLoading = ref(false)
const loadingMessage = ref('')
const notifications = ref([])
const isDarkMode = ref(false)
const isOnline = ref(navigator.onLine)
// Computed
const canUseApp = computed(() => isAuthenticated.value && isOnline.value)
// Actions
const setAuthenticated = (value) => {
isAuthenticated.value = value
}
const setLoading = (loading, message = '') => {
isLoading.value = loading
loadingMessage.value = message
}
const addNotification = (message, type = 'info', duration = 5000) => {
const id = Date.now() + Math.random()
const notification = { id, message, type }
notifications.value.push(notification)
if (duration > 0) {
setTimeout(() => {
removeNotification(id)
}, duration)
}
return id
}
const removeNotification = (id) => {
const index = notifications.value.findIndex((n) => n.id === id)
if (index > -1) {
notifications.value.splice(index, 1)
}
}
const clearNotifications = () => {
notifications.value = []
}
const setDarkMode = (dark) => {
isDarkMode.value = dark
document.documentElement.classList.toggle('dark', dark)
}
const setNetworkStatus = (online) => {
isOnline.value = online
if (online) {
addNotification('Connection restored', 'success', 3000)
} else {
addNotification('Connection lost. Some features may not work.', 'error', 0)
}
}
const checkAuthentication = async () => {
try {
setLoading(true, 'Checking authentication...')
const response = await apiService.checkAuth()
setAuthenticated(response.data.authenticated)
} catch (error) {
console.error('Auth check failed:', error)
setAuthenticated(false)
} finally {
setLoading(false)
}
}
const login = async (password) => {
try {
setLoading(true, 'Authenticating...')
const response = await apiService.login(password)
if (response.data.success) {
setAuthenticated(true)
addNotification('Login successful', 'success', 3000)
return { success: true }
} else {
return { success: false, error: 'Login failed' }
}
} catch (error) {
const errorMessage = error.response?.data?.error || 'Authentication failed'
addNotification(errorMessage, 'error', 5000)
return { success: false, error: errorMessage }
} finally {
setLoading(false)
}
}
const logout = async () => {
try {
await apiService.logout()
setAuthenticated(false)
addNotification('Logged out successfully', 'info', 3000)
} catch (error) {
console.error('Logout failed:', error)
// Force logout even if API call fails
setAuthenticated(false)
addNotification('Logged out', 'info', 3000)
}
}
return {
// State
isAuthenticated,
isLoading,
loadingMessage,
notifications,
isDarkMode,
isOnline,
// Computed
canUseApp,
// Actions
setAuthenticated,
setLoading,
addNotification,
removeNotification,
clearNotifications,
setDarkMode,
setNetworkStatus,
checkAuthentication,
login,
logout,
}
})

View File

@@ -0,0 +1,360 @@
// src/stores/rooms.js - Complete room management state
import { defineStore } from 'pinia'
import { ref, computed } from 'vue'
import { apiService } from '../services/api'
import { useGlobalStore } from './global'
import { utils } from '../services/utils'
export const useRoomsStore = defineStore('rooms', () => {
const globalStore = useGlobalStore()
// State
const currentRoom = ref(null)
const roomHistory = ref([])
const isCreatingRoom = ref(false)
const isJoiningRoom = ref(false)
const isLeavingRoom = ref(false)
const roomParticipants = ref([])
// Computed
const hasActiveRoom = computed(() => currentRoom.value !== null)
const currentRoomId = computed(() => currentRoom.value?.room_id || null)
const currentRoomCode = computed(() => currentRoom.value?.short_code || null)
const participantCount = computed(() => roomParticipants.value.length)
const canJoinRoom = computed(() => !isJoiningRoom.value && !hasActiveRoom.value)
// Actions
const createRoom = async () => {
try {
isCreatingRoom.value = true
globalStore.setLoading(true, 'Creating room...')
const response = await apiService.createRoom()
const roomData = response.data
currentRoom.value = {
room_id: roomData.room_id,
short_code: roomData.short_code,
room_url: roomData.room_url,
qr_code: roomData.qr_code,
expires_at: roomData.expires_at,
max_participants: roomData.max_participants,
created_at: new Date().toISOString(),
}
addToHistory(currentRoom.value)
globalStore.addNotification('Room created successfully', 'success', 3000)
return { success: true, room: currentRoom.value }
} catch (error) {
console.error('Failed to create room:', error)
const errorMessage = error.response?.data?.error || 'Failed to create room'
globalStore.addNotification(errorMessage, 'error', 5000)
return { success: false, error: errorMessage }
} finally {
isCreatingRoom.value = false
globalStore.setLoading(false)
}
}
const joinRoom = async (roomIdentifier) => {
try {
isJoiningRoom.value = true
globalStore.setLoading(true, 'Joining room...')
// Clean room identifier (remove URL parts if present)
let cleanIdentifier = roomIdentifier.trim()
// Extract room code from URL if it's a full URL
if (cleanIdentifier.includes('/join/')) {
const match = cleanIdentifier.match(/\/join\/([A-Z0-9]+)/)
if (match) {
cleanIdentifier = match[1]
}
} else if (cleanIdentifier.includes('/call/')) {
const match = cleanIdentifier.match(/\/call\/([a-f0-9-]+)/)
if (match) {
cleanIdentifier = match[1]
}
}
const response = await apiService.joinRoom(cleanIdentifier)
const roomData = response.data
currentRoom.value = {
room_id: roomData.room_id,
short_code: roomData.short_code,
participant_count: roomData.participant_count,
participant_id: roomData.participant_id,
joined_at: new Date().toISOString(),
}
addToHistory(currentRoom.value)
globalStore.addNotification('Joined room successfully', 'success', 3000)
return { success: true, room: currentRoom.value }
} catch (error) {
console.error('Failed to join room:', error)
const errorMessage = error.response?.data?.error || 'Failed to join room'
globalStore.addNotification(errorMessage, 'error', 5000)
return { success: false, error: errorMessage }
} finally {
isJoiningRoom.value = false
globalStore.setLoading(false)
}
}
const leaveRoom = async (roomId) => {
try {
isLeavingRoom.value = true
if (currentRoom.value && currentRoom.value.room_id === roomId) {
await apiService.leaveRoom(roomId)
// Clear current room and participants
currentRoom.value = null
roomParticipants.value = []
globalStore.addNotification('Left room', 'info', 3000)
return { success: true }
}
return { success: false, error: 'Room not found' }
} catch (error) {
console.error('Failed to leave room:', error)
const errorMessage = error.response?.data?.error || 'Failed to leave room'
return { success: false, error: errorMessage }
} finally {
isLeavingRoom.value = false
}
}
const getRoomInfo = async (roomId) => {
try {
const response = await apiService.getRoomInfo(roomId)
return { success: true, room: response.data }
} catch (error) {
console.error('Failed to get room info:', error)
const errorMessage = error.response?.data?.error || 'Room not found'
return { success: false, error: errorMessage }
}
}
const deleteRoom = async (roomId) => {
try {
await apiService.deleteRoom(roomId)
if (currentRoom.value && currentRoom.value.room_id === roomId) {
currentRoom.value = null
roomParticipants.value = []
}
globalStore.addNotification('Room deleted', 'info', 3000)
return { success: true }
} catch (error) {
console.error('Failed to delete room:', error)
const errorMessage = error.response?.data?.error || 'Failed to delete room'
globalStore.addNotification(errorMessage, 'error', 5000)
return { success: false, error: errorMessage }
}
}
const updateParticipants = (participants) => {
roomParticipants.value = participants || []
}
const addParticipant = (participant) => {
const existingIndex = roomParticipants.value.findIndex((p) => p.id === participant.id)
if (existingIndex === -1) {
roomParticipants.value.push(participant)
} else {
// Update existing participant
roomParticipants.value[existingIndex] = {
...roomParticipants.value[existingIndex],
...participant,
}
}
}
const removeParticipant = (participantId) => {
roomParticipants.value = roomParticipants.value.filter((p) => p.id !== participantId)
}
const addToHistory = (roomData) => {
const historyEntry = {
room_id: roomData.room_id,
short_code: roomData.short_code,
joined_at: roomData.joined_at || new Date().toISOString(),
room_url: roomData.room_url || `${window.location.origin}/join/${roomData.short_code}`,
duration: null,
status: 'active',
}
// Remove existing entry if it exists
roomHistory.value = roomHistory.value.filter((entry) => entry.room_id !== roomData.room_id)
// Add to beginning of array
roomHistory.value.unshift(historyEntry)
// Keep only last 20 rooms
roomHistory.value = roomHistory.value.slice(0, 20)
// Save to localStorage
saveHistoryToStorage()
}
const updateHistoryEntry = (roomId, updates) => {
const entryIndex = roomHistory.value.findIndex((entry) => entry.room_id === roomId)
if (entryIndex !== -1) {
roomHistory.value[entryIndex] = { ...roomHistory.value[entryIndex], ...updates }
saveHistoryToStorage()
}
}
const loadHistory = () => {
try {
const saved = localStorage.getItem('videocall_room_history')
if (saved) {
const parsedHistory = JSON.parse(saved)
// Validate and clean history data
roomHistory.value = parsedHistory
.filter((entry) => entry.room_id && entry.short_code) // Filter invalid entries
.map((entry) => ({
room_id: entry.room_id,
short_code: entry.short_code,
joined_at: entry.joined_at || new Date().toISOString(),
room_url: entry.room_url || `${window.location.origin}/join/${entry.short_code}`,
duration: entry.duration || null,
status: entry.status || 'completed',
}))
.slice(0, 20) // Keep only latest 20
}
} catch (error) {
console.warn('Failed to load room history from localStorage:', error)
roomHistory.value = []
}
}
const saveHistoryToStorage = () => {
try {
localStorage.setItem('videocall_room_history', JSON.stringify(roomHistory.value))
} catch (error) {
console.warn('Failed to save room history to localStorage:', error)
}
}
const clearHistory = () => {
roomHistory.value = []
try {
localStorage.removeItem('videocall_room_history')
} catch (error) {
console.warn('Failed to clear room history from localStorage:', error)
}
}
const getRecentRooms = (limit = 5) => {
return roomHistory.value.filter((room) => room.short_code && room.room_id).slice(0, limit)
}
const searchHistory = (query) => {
if (!query || query.trim() === '') {
return roomHistory.value
}
const searchTerm = query.toLowerCase().trim()
return roomHistory.value.filter(
(room) =>
room.short_code.toLowerCase().includes(searchTerm) ||
room.room_id.toLowerCase().includes(searchTerm),
)
}
const getRoomByCode = async (shortCode) => {
try {
// First try to find in current room
if (currentRoom.value && currentRoom.value.short_code === shortCode) {
return { success: true, room: currentRoom.value }
}
// Then try to join/get room info
const result = await joinRoom(shortCode)
return result
} catch (error) {
console.error('Failed to get room by code:', error)
return { success: false, error: 'Room not found' }
}
}
const validateRoomCode = (code) => {
// Room codes should be 6-8 alphanumeric characters
const codeRegex = /^[A-Z0-9]{6,8}$/
return codeRegex.test(code.toUpperCase())
}
const validateRoomUrl = (url) => {
try {
const urlObj = new URL(url)
return urlObj.pathname.includes('/join/') || urlObj.pathname.includes('/call/')
} catch {
return false
}
}
const cleanup = () => {
currentRoom.value = null
roomParticipants.value = []
isCreatingRoom.value = false
isJoiningRoom.value = false
isLeavingRoom.value = false
}
// Auto-save history when it changes
const startHistoryAutoSave = () => {
// Save history every 30 seconds if there are changes
setInterval(() => {
if (roomHistory.value.length > 0) {
saveHistoryToStorage()
}
}, 30000)
}
return {
// State
currentRoom,
roomHistory,
isCreatingRoom,
isJoiningRoom,
isLeavingRoom,
roomParticipants,
// Computed
hasActiveRoom,
currentRoomId,
currentRoomCode,
participantCount,
canJoinRoom,
// Actions
createRoom,
joinRoom,
leaveRoom,
getRoomInfo,
deleteRoom,
updateParticipants,
addParticipant,
removeParticipant,
addToHistory,
updateHistoryEntry,
loadHistory,
saveHistoryToStorage,
clearHistory,
getRecentRooms,
searchHistory,
getRoomByCode,
validateRoomCode,
validateRoomUrl,
cleanup,
startHistoryAutoSave,
}
})

View File

@@ -0,0 +1,446 @@
// src/stores/webrtc.js - WebRTC and media state management
import { defineStore } from 'pinia'
import { ref, computed } from 'vue'
import { useGlobalStore } from './global'
export const useWebRTCStore = defineStore('webrtc', () => {
const globalStore = useGlobalStore()
// State
const localStream = ref(null)
const remoteStream = ref(null)
const peerConnection = ref(null)
const websocket = ref(null)
const isConnected = ref(false)
const isVideoEnabled = ref(true)
const isAudioEnabled = ref(true)
const connectionState = ref('new') // new, connecting, connected, disconnected, failed
const remoteParticipants = ref([])
const localParticipantId = ref(null)
// Media constraints
const mediaConstraints = ref({
video: {
width: { ideal: 1280, max: 1920 },
height: { ideal: 720, max: 1080 },
frameRate: { ideal: 30, max: 60 },
},
audio: {
echoCancellation: true,
noiseSuppression: true,
autoGainControl: true,
},
})
// Computed
const hasLocalVideo = computed(() => localStream.value !== null)
const hasRemoteVideo = computed(() => remoteStream.value !== null)
const isCallActive = computed(
() => isConnected.value && (hasLocalVideo.value || hasRemoteVideo.value),
)
// WebRTC configuration
const rtcConfiguration = {
iceServers: [
{ urls: 'stun:stun.l.google.com:19302' },
{ urls: 'stun:stun1.l.google.com:19302' },
// Add TURN servers here for production
],
iceCandidatePoolSize: 10,
}
// Actions
const initializeLocalMedia = async () => {
try {
globalStore.setLoading(true, 'Accessing camera and microphone...')
localStream.value = await navigator.mediaDevices.getUserMedia(mediaConstraints.value)
// Set initial media states based on stream tracks
const videoTrack = localStream.value.getVideoTracks()[0]
const audioTrack = localStream.value.getAudioTracks()[0]
if (videoTrack) {
isVideoEnabled.value = videoTrack.enabled
}
if (audioTrack) {
isAudioEnabled.value = audioTrack.enabled
}
return { success: true }
} catch (error) {
let errorMessage = 'Failed to access camera or microphone'
if (error.name === 'NotAllowedError') {
errorMessage =
'Camera and microphone access denied. Please allow permissions and try again.'
} else if (error.name === 'NotFoundError') {
errorMessage = 'No camera or microphone found on this device.'
} else if (error.name === 'NotReadableError') {
errorMessage = 'Camera or microphone is already in use by another application.'
}
globalStore.addNotification(errorMessage, 'error', 8000)
return { success: false, error: errorMessage }
} finally {
globalStore.setLoading(false)
}
}
const createPeerConnection = () => {
try {
peerConnection.value = new RTCPeerConnection(rtcConfiguration)
// Add local stream tracks to peer connection
if (localStream.value) {
localStream.value.getTracks().forEach((track) => {
peerConnection.value.addTrack(track, localStream.value)
})
}
// Handle remote stream
peerConnection.value.ontrack = (event) => {
console.log('Received remote track:', event)
remoteStream.value = event.streams[0]
}
// Handle ICE candidates
peerConnection.value.onicecandidate = (event) => {
if (event.candidate && websocket.value) {
sendWebSocketMessage({
type: 'ice_candidate',
candidate: event.candidate,
})
}
}
// Handle connection state changes
peerConnection.value.onconnectionstatechange = () => {
connectionState.value = peerConnection.value.connectionState
console.log('Connection state:', connectionState.value)
if (connectionState.value === 'connected') {
isConnected.value = true
globalStore.addNotification('Video call connected', 'success', 3000)
} else if (connectionState.value === 'disconnected' || connectionState.value === 'failed') {
isConnected.value = false
if (connectionState.value === 'failed') {
globalStore.addNotification('Call connection failed', 'error', 5000)
}
}
}
return { success: true }
} catch (error) {
console.error('Failed to create peer connection:', error)
return { success: false, error: error.message }
}
}
const connectWebSocket = (roomId) => {
return new Promise((resolve, reject) => {
try {
// WebSocket должен подключаться к бэкенду (порт 8000), а не к фронтенду
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'
const wsHost = import.meta.env.VITE_WS_HOST || window.location.host
const wsUrl = `${protocol}//${wsHost}/ws/room/${roomId}/`
console.log('Connecting to WebSocket:', wsUrl)
websocket.value = new WebSocket(wsUrl)
websocket.value.onopen = () => {
console.log('WebSocket connected')
resolve()
}
websocket.value.onmessage = async (event) => {
try {
const data = JSON.parse(event.data)
await handleWebSocketMessage(data)
} catch (error) {
console.error('Failed to handle WebSocket message:', error)
}
}
websocket.value.onclose = (event) => {
console.log('WebSocket closed:', event.code, event.reason)
isConnected.value = false
if (event.code !== 1000) {
// Not a normal closure
globalStore.addNotification('Connection lost', 'error', 5000)
}
}
websocket.value.onerror = (error) => {
console.error('WebSocket error:', error)
reject(error)
}
// Set timeout for connection
setTimeout(() => {
if (websocket.value && websocket.value.readyState !== WebSocket.OPEN) {
websocket.value.close()
reject(new Error('WebSocket connection timeout'))
}
}, 10000) // 10 second timeout
} catch (error) {
reject(error)
}
})
}
const handleWebSocketMessage = async (data) => {
console.log('Received WebSocket message:', data.type)
switch (data.type) {
case 'user_joined':
handleUserJoined(data)
break
case 'user_left':
handleUserLeft(data)
break
case 'webrtc_offer':
await handleWebRTCOffer(data)
break
case 'webrtc_answer':
await handleWebRTCAnswer(data)
break
case 'ice_candidate':
await handleICECandidate(data)
break
case 'media_state_update':
handleMediaStateUpdate(data)
break
case 'pong':
// Handle ping response
break
case 'error':
globalStore.addNotification(data.message, 'error', 5000)
break
}
}
const handleUserJoined = (data) => {
const participantId = data.participant_id
if (!remoteParticipants.value.find((p) => p.id === participantId)) {
remoteParticipants.value.push({
id: participantId,
joined_at: data.timestamp,
stream: null,
})
}
globalStore.addNotification('Someone joined the call', 'info', 3000)
// If we are already in the room, send an offer to the new participant
if (peerConnection.value && localStream.value) {
createOffer()
}
}
const handleUserLeft = (data) => {
const participantId = data.participant_id
remoteParticipants.value = remoteParticipants.value.filter((p) => p.id !== participantId)
globalStore.addNotification('Someone left the call', 'info', 3000)
// Clear remote stream if this was the connected peer
if (remoteStream.value) {
remoteStream.value = null
}
}
const handleWebRTCOffer = async (data) => {
try {
if (!peerConnection.value) {
createPeerConnection()
}
await peerConnection.value.setRemoteDescription(new RTCSessionDescription(data.offer))
const answer = await peerConnection.value.createAnswer()
await peerConnection.value.setLocalDescription(answer)
sendWebSocketMessage({
type: 'answer',
answer: answer,
target: data.sender,
})
} catch (error) {
console.error('Failed to handle WebRTC offer:', error)
}
}
const handleWebRTCAnswer = async (data) => {
try {
await peerConnection.value.setRemoteDescription(new RTCSessionDescription(data.answer))
} catch (error) {
console.error('Failed to handle WebRTC answer:', error)
}
}
const handleICECandidate = async (data) => {
try {
await peerConnection.value.addIceCandidate(new RTCIceCandidate(data.candidate))
} catch (error) {
console.error('Failed to handle ICE candidate:', error)
}
}
const handleMediaStateUpdate = (data) => {
const participant = remoteParticipants.value.find((p) => p.id === data.participant_id)
if (participant) {
participant.mediaState = data.state
}
}
const createOffer = async () => {
try {
if (!peerConnection.value) {
createPeerConnection()
}
const offer = await peerConnection.value.createOffer()
await peerConnection.value.setLocalDescription(offer)
sendWebSocketMessage({
type: 'offer',
offer: offer,
})
} catch (error) {
console.error('Failed to create offer:', error)
}
}
const sendWebSocketMessage = (message) => {
if (websocket.value && websocket.value.readyState === WebSocket.OPEN) {
websocket.value.send(JSON.stringify(message))
} else {
console.warn('WebSocket not connected, message not sent:', message)
}
}
const toggleVideo = () => {
if (localStream.value) {
const videoTrack = localStream.value.getVideoTracks()[0]
if (videoTrack) {
videoTrack.enabled = !videoTrack.enabled
isVideoEnabled.value = videoTrack.enabled
// Notify other participants
sendWebSocketMessage({
type: 'media_state',
state: {
video: isVideoEnabled.value,
audio: isAudioEnabled.value,
},
})
globalStore.addNotification(
isVideoEnabled.value ? 'Camera turned on' : 'Camera turned off',
'info',
2000,
)
}
}
}
const toggleAudio = () => {
if (localStream.value) {
const audioTrack = localStream.value.getAudioTracks()[0]
if (audioTrack) {
audioTrack.enabled = !audioTrack.enabled
isAudioEnabled.value = audioTrack.enabled
// Notify other participants
sendWebSocketMessage({
type: 'media_state',
state: {
video: isVideoEnabled.value,
audio: isAudioEnabled.value,
},
})
globalStore.addNotification(
isAudioEnabled.value ? 'Microphone turned on' : 'Microphone turned off',
'info',
2000,
)
}
}
}
const endCall = async () => {
try {
// Close peer connection
if (peerConnection.value) {
peerConnection.value.close()
peerConnection.value = null
}
// Close WebSocket
if (websocket.value) {
websocket.value.close(1000, 'Call ended') // Normal closure
websocket.value = null
}
// Stop local media tracks
if (localStream.value) {
localStream.value.getTracks().forEach((track) => track.stop())
localStream.value = null
}
// Clear remote stream
remoteStream.value = null
// Reset state
isConnected.value = false
connectionState.value = 'new'
remoteParticipants.value = []
console.log('Call ended successfully')
} catch (error) {
console.error('Failed to end call:', error)
}
}
return {
// State
localStream,
remoteStream,
peerConnection,
websocket,
isConnected,
isVideoEnabled,
isAudioEnabled,
connectionState,
remoteParticipants,
localParticipantId,
mediaConstraints,
// Computed
hasLocalVideo,
hasRemoteVideo,
isCallActive,
// Actions
initializeLocalMedia,
createPeerConnection,
connectWebSocket,
createOffer,
sendWebSocketMessage,
toggleVideo,
toggleAudio,
endCall,
}
})

View File

@@ -0,0 +1,99 @@
/* Base styles */
@import 'tailwindcss/base';
@import 'tailwindcss/components';
@import 'tailwindcss/utilities';
/* Custom component styles */
.card {
@apply bg-white dark:bg-gray-800 rounded-xl shadow-sm border border-gray-200 dark:border-gray-700;
}
.btn-primary {
@apply bg-green-500 hover:bg-green-600 text-white font-medium py-2 px-4 rounded-lg transition-colors focus:outline-none focus:ring-2 focus:ring-green-500 focus:ring-opacity-50;
}
.btn-secondary {
@apply bg-gray-200 hover:bg-gray-300 dark:bg-gray-700 dark:hover:bg-gray-600 text-gray-900 dark:text-white font-medium py-2 px-4 rounded-lg transition-colors focus:outline-none focus:ring-2 focus:ring-gray-500 focus:ring-opacity-50;
}
.input-field {
@apply w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white placeholder-gray-500 dark:placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-green-500 focus:border-transparent;
}
.control-button {
@apply p-3 rounded-full shadow-lg transition-all duration-200 hover:scale-105 active:scale-95;
}
.control-button-active {
@apply bg-green-500 hover:bg-green-600 text-white;
}
.control-button-inactive {
@apply bg-gray-200 dark:bg-gray-700 hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-200;
}
.control-button-danger {
@apply bg-red-500 hover:bg-red-600 text-white;
}
/* Animations */
@keyframes fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
@keyframes slideUp {
from {
opacity: 0;
transform: translateY(20px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@keyframes slideIn {
from {
transform: translateX(100%);
opacity: 0;
}
to {
transform: translateX(0);
opacity: 1;
}
}
.animate-fade-in {
animation: fadeIn 0.3s ease-out;
}
.animate-slide-up {
animation: slideUp 0.3s ease-out;
}
.animate-slide-in {
animation: slideIn 0.3s ease-out;
}
/* Dark mode support */
@media (prefers-color-scheme: dark) {
:root {
color-scheme: dark;
}
}
/* Mobile responsive adjustments */
@media (max-width: 768px) {
.control-button {
@apply p-2;
}
.control-button svg {
@apply w-5 h-5;
}
}

View File

@@ -0,0 +1,15 @@
<template>
<div class="about">
<h1>This is an about page</h1>
</div>
</template>
<style>
@media (min-width: 1024px) {
.about {
min-height: 100vh;
display: flex;
align-items: center;
}
}
</style>

View File

@@ -0,0 +1,9 @@
<script setup>
import TheWelcome from '../components/TheWelcome.vue'
</script>
<template>
<main>
<TheWelcome />
</main>
</template>

View File

@@ -0,0 +1,9 @@
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [],
theme: {
extend: {},
},
plugins: [],
}

View File

@@ -0,0 +1,108 @@
import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { VitePWA } from 'vite-plugin-pwa'
// https://vite.dev/config/
export default defineConfig({
plugins: [
vue(),
VitePWA({
registerType: 'autoUpdate',
workbox: {
globPatterns: ['**/*.{js,css,html,ico,png,svg}'],
runtimeCaching: [
{
urlPattern: /^https:\/\/api\./i,
handler: 'NetworkFirst',
options: {
cacheName: 'api-cache',
expiration: {
maxEntries: 10,
maxAgeSeconds: 60 * 60 * 24 * 7, // 1 week
},
},
},
],
},
includeAssets: ['favicon.ico', 'apple-touch-icon.png', 'masked-icon.svg'],
manifest: {
name: 'Video Call App',
short_name: 'VideoCall',
description: 'Secure video calling without registration',
theme_color: '#00C853',
background_color: '#ffffff',
display: 'standalone',
orientation: 'portrait',
start_url: '/',
scope: '/',
categories: ['communication', 'productivity'],
icons: [
{
src: 'pwa-192x192.png',
sizes: '192x192',
type: 'image/png',
},
{
src: 'pwa-512x512.png',
sizes: '512x512',
type: 'image/png',
},
{
src: 'pwa-512x512.png',
sizes: '512x512',
type: 'image/png',
purpose: 'any maskable',
},
],
shortcuts: [
{
name: 'Create Room',
short_name: 'Create',
description: 'Start a new video call',
url: '/?action=create',
icons: [
{
src: 'pwa-192x192.png',
sizes: '192x192',
},
],
},
{
name: 'Join Room',
short_name: 'Join',
description: 'Join an existing video call',
url: '/?action=join',
icons: [
{
src: 'pwa-192x192.png',
sizes: '192x192',
},
],
},
],
},
devOptions: {
enabled: true, // Enable PWA in development
},
}),
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
},
},
server: {
host: true,
port: 3000,
strictPort: true,
},
build: {
target: 'esnext',
sourcemap: true,
},
define: {
__VUE_OPTIONS_API__: false,
__VUE_PROD_DEVTOOLS__: false,
},
})