callfusion-server
v2.0.0
Published
A WebRTC signaling and peer connection server library
Downloads
11
Maintainers
Readme
CallFusion
CallFusion
is a JavaScript class for managing real-time client connections and handling communication events such as calls, messages, and client disconnections using Socket.IO.
Features
- Client Management: Register, deregister, and track clients using
accountId
,socketId
, and custom names. - Real-time Messaging: Handle messages between clients, including notifications for calls, call acceptance, and denial.
- Custom Handlers: Define custom handlers for broadcasting client lists, notifying calls, and relaying messages.
Prerequisites
- Node.js: Ensure you have Node.js installed. Download Node.js
- Socket.IO: For real-time communication.
Installation
Clone the repository or integrate the
CallFusion
class into your project.Install dependencies:
npm install socket.io
Note: Mongoose is not a dependency of
CallFusion
. It's only used as part of an example setup. If you're using MongoDB for user management, you'll need to install it separately:npm install mongoose
Usage
Step 1: Set Up Mongoose (Optional)
If you are using MongoDB to store user/client information, define your Mongoose model for storing user/client information. This could include fields like accountId
, name
, email
, and socketId
.
// userModel.js
const mongoose = require("mongoose");
const userSchema = new mongoose.Schema({
accountId: { type: String, required: true, unique: true },
name: { type: String, required: true },
email: { type: String, required: true, unique: true },
socketId: { type: String }, // Optional, for storing socket information
});
const User = mongoose.model("User", userSchema);
module.exports = User;
Step 2: Set Up Socket.IO with CallFusion
Here’s an example of how to use the CallFusion
class with Socket.IO. This setup also includes an optional example using Mongoose for MongoDB, but Mongoose is not a required dependency of CallFusion
.
const http = require("http");
const socketIo = require("socket.io");
const { CallFusion } = require("./callFusion"); // Import the CallFusion class
const User = require("./userModel"); // Example: Import the Mongoose user model (optional)
// Create HTTP server and initialize Socket.IO
const server = http.createServer();
const io = socketIo(server);
// Initialize CallFusion instance
const callFusion = new CallFusion();
// Example: Connect to MongoDB (optional)
mongoose.connect("mongodb://localhost:27017/your-database", {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
});
// Handle client connections via Socket.IO
const cf = new CallFusion(io);
io.on("connection", (socket) => {
let clientId = uuidv4();
cf.registerClient(socket, {
clientId: clientId,
name: "User-" + clientId,
});
});
// Start the server
const port = 5200;
server.listen(port, () => {
console.log(`Server is running on port ${port}`);
});
License
This project is licensed under the MIT License.