* simulate-job * generated protobuf * wip * job_cost * Update livekit_agent.proto * generated protobuf * Update livekit_agent.proto * generated protobuf * Update livekit_agent.proto * Update livekit_agent.proto * Update livekit_agent.proto * generated protobuf * Update livekit_agent.proto * renamed to pong Co-authored-by: David Zhao <dz@livekit.io> * Update livekit_agent.proto * Update livekit_agent.proto * generated protobuf * remove job_cost & ParticipantPermission * generated protobuf * Update livekit_agent.proto * generated protobuf * wip * generated protobuf * generated protobuf * Update livekit_agent.proto * generated protobuf * generated protobuf * handler namespace * generated protobuf --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: David Zhao <dz@livekit.io> Co-authored-by: David Colburn <xero73@gmail.com>
32 lines
921 B
Go
32 lines
921 B
Go
package agent
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/livekit/protocol/auth"
|
|
"github.com/livekit/protocol/livekit"
|
|
)
|
|
|
|
func BuildAgentToken(apiKey, secret, roomName, participantIdentity, participantName, participantMetadata string, permissions *livekit.ParticipantPermission) (string, error) {
|
|
grant := &auth.VideoGrant{
|
|
RoomJoin: true,
|
|
Agent: true,
|
|
Room: roomName,
|
|
CanSubscribe: &permissions.CanSubscribe,
|
|
CanPublish: &permissions.CanPublish,
|
|
CanPublishData: &permissions.CanPublishData,
|
|
Hidden: permissions.Hidden,
|
|
CanUpdateOwnMetadata: &permissions.CanUpdateMetadata,
|
|
}
|
|
|
|
at := auth.NewAccessToken(apiKey, secret).
|
|
AddGrant(grant).
|
|
SetIdentity(participantIdentity).
|
|
SetName(participantName).
|
|
SetKind(livekit.ParticipantInfo_AGENT).
|
|
SetValidFor(1 * time.Hour).
|
|
SetMetadata(participantMetadata)
|
|
|
|
return at.ToJWT()
|
|
}
|