github.com/whoyao/protocol@v0.0.0-20230519045905-2d8ace718ca5/egress/token.go (about) 1 package egress 2 3 import ( 4 "time" 5 6 "github.com/whoyao/protocol/auth" 7 ) 8 9 func BuildEgressToken(egressID, apiKey, secret, roomName string) (string, error) { 10 f := false 11 t := true 12 grant := &auth.VideoGrant{ 13 RoomJoin: true, 14 Room: roomName, 15 CanSubscribe: &t, 16 CanPublish: &f, 17 CanPublishData: &f, 18 Hidden: true, 19 Recorder: true, 20 } 21 22 at := auth.NewAccessToken(apiKey, secret). 23 AddGrant(grant). 24 SetIdentity(egressID). 25 SetValidFor(24 * time.Hour) 26 27 return at.ToJWT() 28 }