-
Notifications
You must be signed in to change notification settings - Fork 4
LivekitVideochat
This guide covers how to set up two servers needed for the new video chat system:
- OpenVidu or Livekit Server for handling video streams.
- Node.js Server for generating authentication tokens to join the video chat.
Note: You can choose either OpenVidu or Livekit as your video stream server. You do not need to set up both. If you're unable to use Docker, Livekit is a good alternative to OpenVidu.
To set up an OpenVidu server on your local machine, follow the official guide provided here: OpenVidu Local Self-Hosting Guide.
Prerequisites:
- Docker and Docker Compose installed on your machine.
Installation Steps:
- Clone the following repository:
git clone https://github.com/OpenVidu/openvidu-local-deployment
- Configure the local deployment:
cd openvidu-local-deployment/community
./configure_lan_private_ip_linux.sh
- Run OpenVidu:
docker compose up
To set up a Livekit server on your local machine, follow the official guide provided here: Livekit Server Setup Guide.
- Install Livekit Server on Linux with:
curl -sSL https://get.livekit.io | bash
- You can start LiveKit in development mode by running:
livekit-server --dev
You’ll need a Node.js server to generate tokens for clients to join rooms on the video chat. The following steps will guide you through creating a basic Node.js server using express and livekit-server-sdk.
Note: For more detailed information, you can refer to the official documentation on generating tokens here: Livekit Token Generation Guide.
- Install Node.js and npm
- Create a new directory for the Node.js server:
mkdir livekit-token-server
cd livekit-token-server
- Initialize a new Node.js project:
npm init -y
- Install necessary dependencies:
npm install express dotenv
npm install livekit-server-sdk --save
- Create the server.js file: In the root directory, create a server.js file with the following content:
import express from 'express';
import { AccessToken } from 'livekit-server-sdk';
const createToken = async (roomName, participantName) => {
const at = new AccessToken(process.env.LIVEKIT_API_KEY, process.env.LIVEKIT_API_SECRET, {
identity: participantName,
ttl: '1m', // Token expires after 1 minute
});
at.addGrant({ roomJoin: true, room: roomName });
return await at.toJwt();
}
const app = express();
const port = 3000;
app.get('/getToken', async (req, res) => {
const roomName = req.query.roomName;
const participantName = req.query.participantName;
res.send(await createToken(roomName, participantName));
});
app.listen(port, () => {
console.log(`Server listening on port ${port}`);
});
- Create the .env file:
LIVEKIT_API_KEY=devkey
LIVEKIT_API_SECRET=secret
- Run the Node.js server:
source .env
node server.js
Once both servers are set up and running, you can test their functionality by following these steps:
- Use your Node.js token server to generate a token by making a GET request in your browser or via
curl
: http://localhost:3000/getToken?roomName=testRoom&participantName=JohnDoe - Open your browser and visit: https://meet.livekit.io/?tab=custom
In the Custom Server tab:
- Enter the URL of your OpenVidu or Livekit server.
- Use the token generated in step 1 to join the room.