Skip to content

Instantly share code, notes, and snippets.

@abelorian
Last active September 22, 2023 11:35
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abelorian/200696537b8b4e1bee5ac2caeb7f624a to your computer and use it in GitHub Desktop.
Save abelorian/200696537b8b4e1bee5ac2caeb7f624a to your computer and use it in GitHub Desktop.
Agora dynamic Key ruby RTC example. Gem agora_dynamic_key https://rubygems.org/gems/agora_dynamic_key
# In Gemfile: gem 'agora_dynamic_key', '~> 0.1.0'
require 'dynamic_key'
class Agora
EXPIRATION_TIME_IN_SECONDS = 3600*3
def generate_rtc_token channel_name = 'any_channel_name'
params = {
app_id: '970CA35de60c44645bbae8a215061b33',
app_certificate: '5CFd2fd1755d40ecb72977518be15d3b',
channel_name: channel_name,
uid: 0, # important: 0 for testing
role: AgoraDynamicKey::RTCTokenBuilder::Role::PUBLISHER,
privilege_expired_ts: Time.now.to_i + EXPIRATION_TIME_IN_SECONDS
}
AgoraDynamicKey::RTCTokenBuilder.build_token_with_uid params
end
end
# Test in console: Agora.new.generate_rtc_token "prueba1"
# "0069e2660ec8cd74be7bae7d56a24dd2fa0IACWEy4sNhSrCYRGLLPKb/HKASHDKJAHSDKASDHIUWHJBJKWKJABKJSDBJKABJSDKJBASDbkj5e"
# source: https://github.com/AgoraIO/Tools/blob/master/DynamicKey/AgoraDynamicKey/ruby/sample/rtc_token_builder_sample.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment