Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changes/jwt-video-grant-claim-names
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
patch type="fixed" "`LiveKitVideoGrant` now reads the camelCase keys of the `video` claim (`roomJoin`, `canPublish`, and so on), so `TokenSourceResponse.jwtPayload?.video` returns the grants of a real LiveKit token instead of null fields"
21 changes: 2 additions & 19 deletions lib/src/token_source/jwt.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,35 +132,18 @@ class LiveKitJwtPayload {
/// LiveKit-specific video grants embedded within a JWT.
@JsonSerializable()
class LiveKitVideoGrant {
// Field names match the camelCase keys of the `video` claim that LiveKit
// server SDKs write, so they need no `@JsonKey` renames.
final String? room;

@JsonKey(name: 'room_create')
final bool? roomCreate;

@JsonKey(name: 'room_join')
final bool? roomJoin;

@JsonKey(name: 'room_list')
final bool? roomList;

@JsonKey(name: 'room_record')
final bool? roomRecord;

@JsonKey(name: 'room_admin')
final bool? roomAdmin;

@JsonKey(name: 'can_publish')
final bool? canPublish;

@JsonKey(name: 'can_subscribe')
final bool? canSubscribe;

@JsonKey(name: 'can_publish_data')
final bool? canPublishData;

@JsonKey(name: 'can_publish_sources')
final List<String>? canPublishSources;

final bool? hidden;
final bool? recorder;

Expand Down
36 changes: 18 additions & 18 deletions lib/src/token_source/jwt.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions test/token/token_source_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,12 @@ void main() {
attributes: {'role': 'host'},
video: {
'room': 'demo-room',
'room_join': true,
'room_create': true,
'can_publish': true,
'can_publish_data': true,
'can_publish_sources': ['camera', 'screen'],
'roomJoin': true,
'roomCreate': true,
'canPublish': true,
'canSubscribe': false,
'canPublishData': true,
'canPublishSources': ['camera', 'screen'],
'hidden': false,
'recorder': true,
},
Expand Down Expand Up @@ -205,6 +206,7 @@ void main() {
expect(grant.roomJoin, isTrue);
expect(grant.roomCreate, isTrue);
expect(grant.canPublish, isTrue);
expect(grant.canSubscribe, isFalse);
expect(grant.canPublishData, isTrue);
expect(grant.canPublishSources, ['camera', 'screen']);
expect(grant.hidden, isFalse);
Expand Down Expand Up @@ -509,7 +511,7 @@ String _generateToken({
video ??
{
'room': 'test-room',
'room_join': true,
'roomJoin': true,
},
};

Expand Down
Loading