
Build a UGC Live Streaming App with Amazon IVS: Generating Stage Participant Tokens (Lesson 4.2)
Welcome to Lesson 4.2 in this series where we're looking at building a web based user-generated content live streaming application with Amazon IVS. This entire series is available in video format on the AWS Developers YouTube channel and all of the code related to the sample application used in this series can be viewed on GitHub. Refer to the links at the end of the post for more information.
User
has a one-to-one relationship with a Stage
entity. The Stage
entity has a one-to-many relationship with the StageToken
entity. ivs-realtime
module of the SDK for JavaScript. The StreamCat RealTimeService
passes a CreateParticipantTokenCommandInput
object to a new CreateParticipantTokenCommand
, and sends that command with an instance of the IvsRealTimeClient
(docs). The CreateParticipantTokenCommandInput
requires a userId
(the StreamCat user's id
), an attributes
object that accepts any arbitrary key/value pairs that to associate with the token, and the stageArn
.1
2
3
4
5
6
7
8
9
10
public async createStageToken(userId: string, username: string, stageArn: string): Promise <CreateParticipantTokenCommandOutput> {
const request: CreateParticipantTokenCommand = new CreateParticipantTokenCommand({
userId,
attributes: {
username,
},
stageArn,
});
return await this.ivsRealtimeClient.send(request);
};
createStageToken()
method of the RealTimeService
is invoked, and the values returned from the CreateParticipantTokenCommandOutput
are persisted to the database. For example, here's how StreamCat issues a token when a host invites a user to join their real-time stream.1
2
3
4
5
6
7
8
let token = await RealTimeService.createStageToken(userId, username, stageArn);
await StageToken.create({
participantId: token.participantToken?.participantId,
token: token.participantToken?.token,
userId: Number(token.participantToken?.userId),
expiresAt: DateTime.fromJSDate(token.participantToken?.expirationTime!),
stageId: auth.user?.stage.id,
});
Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.