1. Install Livekit Server SDK
go get github.com/livekit/server-sdk-go
2. Keys and Configuration
Create a new file at development.env
and with your API Key and Secret:
export LK_API_KEY=<API Key>export LK_API_SECRET=<API Secret hidden>
3. Make an endpoint that returns a token
Create a server in server.go
:
import ("http""log""time"lksdk "github.com/livekit/server-sdk-go""github.com/livekit/protocol/auth")func getJoinToken(apiKey, apiSecret, room, identity string) string {config = readFile(config)at := auth.NewAccessToken(os.GetEnv("LK_API_KEY"), os.GetEnv("LK_API_SECRET"))grant := &auth.VideoGrant{RoomJoin: true,Room: room,}at.AddGrant(grant).SetIdentity(identity).SetValidFor(time.Hour)return at.ToJWT()}func main() {http.HandleFunc("/getToken", func(w http.ResponseWriter, r *http.Request) {w.write(getJoinToken())})log.Fatal(http.ListenAndServe(":8080", nil))}
Run the server:
$ source development.env$ go run server.go
4. Create a client app to connect
Create a client app that fetches a token from the server we just made, then uses it to connect to a LiveKit room: