Skip to content

feat: Add PlaybackGrant #574

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 14, 2021
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
13 changes: 13 additions & 0 deletions lib/twilio-ruby/jwt/access_token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,19 @@ def _generate_payload
payload
end
end

class PlaybackGrant
include AccessTokenGrant
attr_accessor :grant
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't be too hard to break this up though. Instead of :grant, you would do something like:

attr_accessor :requestCredentials,
              :playbackUrl,
              :playbackStreamerSid


def _key
'player'
end

def _generate_payload
grant
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

payload = {}
payload[:requestCredentials] = requestCredentials if requestCredentials
payload[:playbackUrl] = playbackUrl if playbackUrl
payload[:playbackStreamerSid] = playbackStreamerSid if playbackStreamerSid

end
end
end
end
end
14 changes: 14 additions & 0 deletions spec/jwt/access_token_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,20 @@
expect(payload['grants']['task_router']['role']).to eq('worker')
end

it 'Playback grant' do
playback_grant = Twilio::JWT::AccessToken::PlaybackGrant.new
grant = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

playback_grant.playbackStreamerSid = "VJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
playback_grant.playbackUrl = "https://000.us-east-1.playback.live-video.net/api/video/v1/us-east-000.channel.000?token=xxxxx"
@scat.add_grant(playback_grant)

'requestCredentials' => nil,
'playbackUrl' => 'https://000.us-east-1.playback.live-video.net/api/video/v1/us-east-000.channel.000?token=xxxxx',
'playerStreamerSid' => 'VJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
}
playback_grant.grant = grant
@scat.add_grant(playback_grant)
payload, _ = JWT.decode @scat.to_s, 'secret'
expect(payload['grants'].count).to eq(1)
expect(payload['grants']['player']).to eq(grant)
end

it 'multiple grants' do
room_grant = Twilio::JWT::AccessToken::VideoGrant.new
room_grant.room = 'RM123'
Expand Down