Project: vocalls-flashwave
URL: https://run.gptengineer.app/projects/dcfca732-04c7-42e8-91ce-5810ee18e94f/improve
Description: Combine https://a-kcmnisi00-gmail-com-api.appasapgateway.app/api-docs/#/auth/post_auth_register withflashcall-video/ ├── backend/ │ ├── controllers/ │ │ ├── authController.js │ │ ├── callController.js │ ├── models/ │ │ ├── user.js │ │ ├── call.js │ ├── routes/ │ │ ├── authRoutes.js │ │ ├── callRoutes.js │ ├── services/ │ │ ├── videoService.js │ │ ├── flashService.js │ ├── utils/ │ │ ├── db.js │ │ ├── authMiddleware.js │ ├── app.js │ ├── package.json ├── frontend/ │ ├── src/ │ │ ├── components/ │ │ │ ├── Auth/ │ │ │ │ ├── Login.js │ │ │ │ ├── Register.js │ │ │ ├── Call/ │ │ │ │ ├── CallPage.js │ │ │ │ ├── VideoStream.js │ │ ├── services/ │ │ │ ├── authService.js │ │ │ ├── callService.js │ │ ├── App.js │ │ ├── index.js │ ├── public/ │ ├── package.json
### Backend Code
**backend/app.js:**
```javascript
const express = require('express');
const http = require('http');
const socketIo = require('socket.io');
const bodyParser = require('body-parser');
const authRoutes = require('./routes/authRoutes');
const callRoutes = require('./routes/callRoutes');
const { authMiddleware } = require('./utils/authMiddleware');
const { connectDB } = require('./utils/db');
const app = express();
app.use(bodyParser.json());
// Database connection
connectDB();
// Routes
app.use('/api/auth', authRoutes);
app.use('/api/calls', callRoutes);
const server = http.createServer(app);
const io = socketIo(server);
// Middleware for authentication
io.use(authMiddleware);
// Socket.io connection
io.on('connection', (socket) => {
console.log('User connected');
socket.on('disconnect', () => {
console.log('User disconnected');
});
});
server.listen(3000, () => {
console.log('Server is running on port 3000');
});
backend/controllers/authController.js:
const User = require('../models/user');
exports.register = async (req, res) => {
const { username, password } = req.body;
const user = new User({ username, password });
await user.save();
res.status(201).json({ message: 'User registered successfully' });
};
exports.login = async (req, res) => {
const { username, password } = req.body;
const user = await User.findOne({ username });
if (!user || !user.comparePassword(password)) {
return res.status(401).json({ message: 'Invalid credentials' });
}
const token = user.generateAuthToken();
res.status(200).json({ token });
};
backend/controllers/callController.js:
const Call = require('../models/call');
const { optimizeVideoQuality } = require('../services/videoService');
const { applyFlashEffect } = require('../services/flashService');
exports.startCall = async (req, res) => {
const { callerId, receiverId } = req.body;
const call = new Call({ callerId, receiverId });
await call.save();
// Optimizing video quality
optimizeVideoQuality(call._id);
// Applying flash effect
applyFlashEffect(call._id);
res.status(201).json({ message: 'Call started', callId: call._id });
};
exports.endCall = async (req, res) => {
const { callId } = req.body;
await Call.findByIdAndUpdate(callId, { status: 'ended' });
res.status(200).json({ message: 'Call ended' });
};
backend/models/user.js:
const mongoose = require('mongoose');
const bcrypt = require('bcrypt');
const jwt = require('jsonwebtoken');
const userSchema = new mongoose.Schema({
username: { type: String, required: true, unique: true },
password: { type: String, required: true }
});
userSchema.pre('save', async function (next) {
if (!this.isModified('password')) return next();
const salt = await bcrypt.genSalt(10);
this.password = await bcrypt.hash(this.password, salt);
next();
});
userSchema.methods.comparePassword = function (password) {
return bcrypt.compare(password, this.password);
};
userSchema.methods.generateAuthToken = function () {
return jwt.sign({ _id: this._id }, process.env.JWT_SECRET);
};
module.exports = mongoose.model('User', userSchema);
backend/models/call.js:
const mongoose = require('mongoose');
const callSchema = new mongoose.Schema({
callerId: { type: mongoose.Schema.Types.ObjectId, ref: 'User', required: true },
receiverId: { type: mongoose.Schema.Types.ObjectId, ref: 'User', required: true },
status: { type: String, enum: ['started', 'ended'], default: 'started' },
startedAt: { type: Date, default: Date.now },
endedAt: { type: Date }
});
module.exports = mongoose.model('Call', callSchema);
backend/routes/authRoutes.js:
const express = require('express');
const { register, login } = require('../controllers/authController');
const router = express.Router();
router.post('/register', register);
router.post('/login', login);
module.exports = router;
backend/routes/callRoutes.js:
const express = require('express');
const { startCall, endCall } = require('../controllers/callController');
const { authMiddleware } = require('../utils/authMiddleware');
const router = express.Router();
router.post('/start', authMiddleware, startCall);
router.post('/end', authMiddleware, endCall);
module.exports = router;
backend/services/videoService.js:
exports.optimizeVideoQuality = (callId) => {
// Logic to optimize video quality based on available bandwidth
console.log(`Optimizing video quality for call ${callId}`);
};
backend/services/flashService.js:
exports.applyFlashEffect = (callId) => {
// Logic to apply flash effect during video calls
console.log(`Applying flash effect for call ${callId}`);
};
backend/utils/db.js:
const mongoose = require('mongoose');
exports.connectDB = async () => {
try {
await mongoose.connect(process.env.MONGO_URI, { useNewUrlParser: true, useUnifiedTopology: true });
console.log('MongoDB connected');
} catch (err) {
console.error('Error connecting to MongoDB:', err);
process.exit(1);
}
};
backend/utils/authMiddleware.js:
const jwt = require('jsonwebtoken');
exports.authMiddleware = (socket, next) => {
const token = socket.handshake.auth.token;
if (!token) {
return next(new Error('Authentication error'));
}
jwt.verify(token, process.env.JWT_SECRET, (err, decoded) => {
if (err) {
return next(new Error('Authentication error'));
}
socket.user = decoded;
next();
});
};
backend/package.json:
{
"name": "vocalls-backend",
"version": "1.0.0",
"description": "Backend for Vocalls video calling app",
"main": "app.js",
"scripts": {
"start": "node app.js"
},
"dependencies": {
"bcrypt": "^5.0.1",
"body-parser": "^1.19.0",
"express": "^4.17.1",
"jsonwebtoken": "^8.5.1",
"mongoose": "^5.12.3",
"socket.io": "^4.0.1"
}
}
frontend/src/index.js:
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
ReactDOM.render(<App />, document.getElementById('root'));
frontend/src/App.js:
import React from 'react';
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
import Login from './components/Auth/Login';
import Register from './components/Auth/Register';
import CallPage from './components/Call/CallPage';
function App() {
return (
<Router>
<Switch>
<Route path="/login" component={Login} />
<Route path="/register" component={Register} />
<Route path="/call" component={CallPage} />
</Switch>
</Router> and add a call record and flashlight display play of call,add a 7 generation functionalities and features and user experience
## Who is the owner of this repository?
By default, GPT Engineer projects are created with public GitHub repositories.
However, you can easily transfer the repository to your own GitHub account by navigating to your [GPT Engineer project](https://run.gptengineer.app/projects/dcfca732-04c7-42e8-91ce-5810ee18e94f/improve) and selecting Settings -> GitHub.
## How can I edit this code?
There are several ways of editing your application.
**Use GPT Engineer**
Simply visit the GPT Engineer project at [GPT Engineer](https://run.gptengineer.app/projects/dcfca732-04c7-42e8-91ce-5810ee18e94f/improve) and start prompting.
Changes made via gptengineer.app will be committed automatically to this repo.
**Use your preferred IDE**
If you want to work locally using your own IDE, you can clone this repo and push changes. Pushed changes will also be reflected in the GPT Engineer UI.
The only requirement is having Node.js & npm installed - [install with nvm](https://github.com/nvm-sh/nvm#installing-and-updating)
Follow these steps:
```sh
git clone https://github.com/GPT-Engineer-App/vocalls-flashwave.git
cd vocalls-flashwave
npm i
# This will run a dev server with auto reloading and an instant preview.
npm run dev
Edit a file directly in GitHub
- Navigate to the desired file(s).
- Click the "Edit" button (pencil icon) at the top right of the file view.
- Make your changes and commit the changes.
Use GitHub Codespaces
- Navigate to the main page of your repository.
- Click on the "Code" button (green button) near the top right.
- Select the "Codespaces" tab.
- Click on "New codespace" to launch a new Codespace environment.
- Edit files directly within the Codespace and commit and push your changes once you're done.
This project is built with .
- Vite
- React
- shadcn-ui
- Tailwind CSS
All GPT Engineer projects can be deployed directly via the GPT Engineer app.
Simply visit your project at GPT Engineer and click on Share -> Publish.
We don't support custom domains (yet). If you want to deploy your project under your own domain, then we recommend GitHub Pages.
To use GitHub Pages you will need to follow these steps: