mirror of
https://github.com/livekit/livekit.git
synced 2026-05-23 10:26:19 +00:00
258f5add2d
In order to avoid race conditions with WebRTC, where either side could initiate an offer when tracks have changes, we'll always initiate them from the SFU side.
69 lines
1.3 KiB
Go
69 lines
1.3 KiB
Go
package commands
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
"github.com/livekit/livekit-server/pkg/auth"
|
|
)
|
|
|
|
var (
|
|
roomFlag = &cli.StringFlag{
|
|
Name: "room",
|
|
Usage: "name or id of the room",
|
|
}
|
|
roomHostFlag = &cli.StringFlag{
|
|
Name: "host",
|
|
Value: "http://localhost:7880",
|
|
}
|
|
rtcHostFlag = &cli.StringFlag{
|
|
Name: "host",
|
|
Value: "ws://localhost:7881",
|
|
}
|
|
apiKeyFlag = &cli.StringFlag{
|
|
Name: "api-key",
|
|
EnvVars: []string{"LK_API_KEY"},
|
|
Required: true,
|
|
}
|
|
secretFlag = &cli.StringFlag{
|
|
Name: "api-secret",
|
|
EnvVars: []string{"LK_API_SECRET"},
|
|
Required: true,
|
|
}
|
|
)
|
|
|
|
func PrintJSON(obj interface{}) {
|
|
txt, _ := json.MarshalIndent(obj, "", " ")
|
|
fmt.Println(string(txt))
|
|
}
|
|
|
|
func ExpandUser(p string) string {
|
|
if strings.HasPrefix(p, "~") {
|
|
home, _ := os.UserHomeDir()
|
|
return filepath.Join(home, p[1:])
|
|
}
|
|
|
|
return p
|
|
}
|
|
|
|
func accessToken(c *cli.Context, grant *auth.VideoGrant, identity string) (value string, err error) {
|
|
apiKey := c.String("api-key")
|
|
apiSecret := c.String("api-secret")
|
|
if apiKey == "" && apiSecret == "" {
|
|
// not provided, don't sign request
|
|
return
|
|
}
|
|
|
|
at := auth.NewAccessToken(apiKey, apiSecret).
|
|
AddGrant(grant).
|
|
SetIdentity(identity).
|
|
SetValidFor(time.Hour * 24)
|
|
return at.ToJWT()
|
|
}
|