Files
livekit/cmd/cli/commands/utils.go
T
David Zhao 258f5add2d protocol update: explicit AddTrack to move negotiation initiation to server side.
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.
2021-01-09 23:40:29 -08:00

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()
}