Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ Set environment variables to configure the service:
| `LIVEKIT_KEY` / `LIVEKIT_KEY_FROM_FILE` | API key or file path for LiveKit SFU | ✅ Yes |
| `LIVEKIT_SECRET` / `LIVEKIT_SECRET_FROM_FILE` | API secret or file path for LiveKit SFU | ✅ Yes |
| `LIVEKIT_KEY_FILE` | File path with `APIkey: secret` format | ⚠️ mutually exclusive with `LIVEKIT_KEY` and `LIVEKIT_SECRET` |
| `LIVEKIT_JWT_PORT` | Port to listen on (default: `8080`) | ❌ No |
| `LIVEKIT_JWT_BIND` | Address to bind the server to (default: `:8080`) | ❌ No |
| `LIVEKIT_FULL_ACCESS_HOMESERVERS` | Comma-separated list of fully authorized homeservers (`*` for all) | ❌ Default: `*` |

> [!IMPORTANT]
Expand Down
34 changes: 16 additions & 18 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"crypto/tls"
"encoding/json"
"errors"
"fmt"
"log"
"net/http"
"os"
Expand Down Expand Up @@ -130,7 +129,7 @@ func exchangeOpenIdUserInfo(
if skipVerifyTLS {
log.Printf("!!! WARNING !!! Skipping TLS verification for matrix client connection to %s", token.MatrixServerName)
// Disable TLS verification on the default HTTP Transport for the well-known lookup
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{ InsecureSkipVerify: true }
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
}
client := fclient.NewClient(fclient.WithWellKnownSRVLookups(true), fclient.WithSkipVerify(skipVerifyTLS))

Expand Down Expand Up @@ -164,7 +163,6 @@ func (h *Handler) prepareMux() *http.ServeMux {
return mux
}


func (h *Handler) healthcheck(w http.ResponseWriter, r *http.Request) {
log.Printf("Health check from %s", r.RemoteAddr)

Expand Down Expand Up @@ -244,7 +242,7 @@ func (h *Handler) handle(w http.ResponseWriter, r *http.Request) {

// TODO: is DeviceID required? If so then we should have validated at the start of the request processing
lkIdentity := userInfo.Sub + ":" + sfuAccessRequest.DeviceID
token, err := getJoinToken(h.key, h.secret, sfuAccessRequest.Room, lkIdentity)
token, err := getJoinToken(h.key, h.secret, sfuAccessRequest.Room, lkIdentity)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
err = json.NewEncoder(w).Encode(gomatrix.RespError{
Expand All @@ -262,16 +260,16 @@ func (h *Handler) handle(w http.ResponseWriter, r *http.Request) {
creationStart := time.Now().Unix()
room, err := roomClient.CreateRoom(
context.Background(), &livekit.CreateRoomRequest{
Name: sfuAccessRequest.Room,
EmptyTimeout: 5 * 60, // 5 Minutes to keep the room open if no one joins
DepartureTimeout: 20, // number of seconds to keep the room after everyone leaves
MaxParticipants: 0, // 0 == no limitation
Name: sfuAccessRequest.Room,
EmptyTimeout: 5 * 60, // 5 Minutes to keep the room open if no one joins
DepartureTimeout: 20, // number of seconds to keep the room after everyone leaves
MaxParticipants: 0, // 0 == no limitation
},
)

if err != nil {
log.Printf("Unable to create room %s. Error message: %v", sfuAccessRequest.Room, err)

w.WriteHeader(http.StatusInternalServerError)
err = json.NewEncoder(w).Encode(gomatrix.RespError{
ErrCode: "M_UNKNOWN",
Expand All @@ -284,11 +282,11 @@ func (h *Handler) handle(w http.ResponseWriter, r *http.Request) {
}

// Log the room creation time and the user info
isNewRoom := room.GetCreationTime() >= creationStart && room.GetCreationTime() <= time.Now().Unix()
isNewRoom := room.GetCreationTime() >= creationStart && room.GetCreationTime() <= time.Now().Unix()
log.Printf(
"%s LiveKit room sid: %s (alias: %s) for full-access Matrix user %s (LiveKit identity: %s)",
map[bool]string{true: "Created", false: "Using"}[isNewRoom],
room.Sid, sfuAccessRequest.Room, userInfo.Sub , lkIdentity,
room.Sid, sfuAccessRequest.Room, userInfo.Sub, lkIdentity,
)
}

Expand Down Expand Up @@ -323,7 +321,7 @@ func main() {
}

fullAccessHomeservers := os.Getenv("LIVEKIT_FULL_ACCESS_HOMESERVERS")

if len(fullAccessHomeservers) == 0 {
// For backward compatibility we also check for LIVEKIT_LOCAL_HOMESERVERS
// TODO: Remove this backward compatibility in the near future.
Expand All @@ -339,12 +337,12 @@ func main() {
}
}

lkJwtPort := os.Getenv("LIVEKIT_JWT_PORT")
if lkJwtPort == "" {
lkJwtPort = "8080"
lkJwtBind := os.Getenv("LIVEKIT_JWT_BIND")
if lkJwtBind == "" {
lkJwtBind = ":8080"
}

log.Printf("LIVEKIT_URL: %s, LIVEKIT_JWT_PORT: %s", lkUrl, lkJwtPort)
log.Printf("LIVEKIT_URL: %s, LIVEKIT_JWT_BIND: %s", lkUrl, lkJwtBind)
log.Printf("LIVEKIT_FULL_ACCESS_HOMESERVERS: %v", fullAccessHomeservers)

handler := &Handler{
Expand All @@ -355,5 +353,5 @@ func main() {
fullAccessHomeservers: strings.Split(fullAccessHomeservers, ","),
}

log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", lkJwtPort), handler.prepareMux()))
}
log.Fatal(http.ListenAndServe(lkJwtBind, handler.prepareMux()))
}