# WebRTC Setup for Cluebase VMS

## Local Network Usage

WebRTC works inside a local network by default.  
No additional configuration is required.

A TURN server is only needed if remote access to Cluebase VMS is required over the Internet.

---

## 1. Install a TURN Server in Docker on a VPS

Create a `compose.yaml` file with the following content:

```yaml
services:
  coturn:
    image: coturn/coturn
    container_name: coturn
    restart: always
    network_mode: 'host'
    command:
      - -n
      - --log-file=stdout
      - --listening-ip=0.0.0.0
      - --relay-ip=local_ip
      - --external-ip=public_ip
      - --min-port=40000
      - --max-port=59000
      - --no-auth

```

Replace the following values:

- `local_ip` — local IP address of the VPS
- `public_ip` — public IP address of the VPS

Start the TURN server:

```bash
docker compose up -d
```

---

## 2. Using the Same Server for Cluebase VMS and TURN

If the server where Cluebase VMS is installed has a public IP address, the TURN server can be installed on the same server.

In this case:

- Install the TURN server on the same machine as Cluebase VMS
- Configure port forwarding on the router

Ports that need to be forwarded in the router:

- `3478` TCP and UDP
- `40000-59000` UDP

If a firewall is enabled, make sure these ports are allowed in the firewall rules.

---

## 3. Configure Cluebase VMS

Edit the `.env` file of Cluebase VMS.

Change:

```env
ENABLE_STUN_TURN=0
```

to:

```env
ENABLE_STUN_TURN=1
```

Add the following parameters:

```env
STUN_SERVER_HOST=turn_server_ip
STUN_SERVER_PORT=3478
```

Replace `turn_server_ip` with the IP address of your TURN server.