Class: AgoraDynamicKey::RTCTokenBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/dynamic_key/rtc_token_builder.rb

Defined Under Namespace

Modules: Role Classes: InvalidParamsError

Class Method Summary collapse

Class Method Details

.build_token_with_account(payload) ⇒ Object

Builds an RTC token using a string user_account. :app_id The App ID issued to you by Agora. :app_certificate Certificate of the application that you registered in the Agora Dashboard. :channel_name The unique channel name for the AgoraRTC session in the string format. The string length must be less than 64 bytes. Supported character scopes are:

  • The 26 lowercase English letters: a to z.

  • The 26 uppercase English letters: A to Z.

  • The 10 digits: 0 to 9.

  • The space.

  • “!”, “#”, “$”, “%”, “&”, “(”, “)”, “+”, “-”, “:”, “;”, “<”, “=”, “.”, “>”, “?”, “@”, “[”, “]”, “^”, “_”, “ “”, “|”, “~”, “,”.

:account The user account. :role See #userRole.

  • Role::PUBLISHER; RECOMMENDED. Use this role for a voice/video call or a live broadcast.

  • Role::SUBSCRIBER: ONLY use this role if your live-broadcast scenario requires authentication for [Hosting-in](docs.agora.io/en/Agora%20Platform/terms?platform=All%20Platforms#hosting-in). In order for this role to take effect, please contact our support team to enable authentication for Hosting-in for you. Otherwise, Role_Subscriber still has the same privileges as Role_Publisher.

:privilege_expired_ts represented by the number of seconds elapsed since 1/1/1970. If, for example, you want to access the Agora Service within 10 minutes after the token is generated, set expireTimestamp as the current timestamp + 600 (seconds).

Parameters:

  • payload

Returns:

  • The new Token.



73
74
75
76
77
# File 'lib/dynamic_key/rtc_token_builder.rb', line 73

def  payload
  check! payload, %i[app_id app_certificate channel_name role account privilege_expired_ts]
  @params.merge!(:uid => @params[:account])
  generate_access_token!
end

.build_token_with_uid(payload) ⇒ Object

Builds an RTC token using an Integer uid. :app_id The App ID issued to you by Agora. :app_certificate Certificate of the application that you registered in the Agora Dashboard. :channel_name The unique channel name for the AgoraRTC session in the string format. The string length must be less than 64 bytes. Supported character scopes are:

  • The 26 lowercase English letters: a to z.

  • The 26 uppercase English letters: A to Z.

  • The 10 digits: 0 to 9.

  • The space.

  • “!”, “#”, “$”, “%”, “&”, “(”, “)”, “+”, “-”, “:”, “;”, “<”, “=”, “.”, “>”, “?”, “@”, “[”, “]”, “^”, “_”, “ “”, “|”, “~”, “,”.

:uid User ID. A 32-bit unsigned integer with a value ranging from 1 to (2^32-1). :role See #userRole.

  • Role::PUBLISHER; RECOMMENDED. Use this role for a voice/video call or a live broadcast.

  • Role::SUBSCRIBER: ONLY use this role if your live-broadcast scenario requires authentication for [Hosting-in](docs.agora.io/en/Agora%20Platform/terms?platform=All%20Platforms#hosting-in). In order for this role to take effect, please contact our support team to enable authentication for Hosting-in for you. Otherwise, Role_Subscriber still has the same privileges as Role_Publisher.

:privilege_expired_ts represented by the number of seconds elapsed since 1/1/1970. If, for example, you want to access the Agora Service within 10 minutes after the token is generated, set expireTimestamp as the current timestamp + 600 (seconds).

Parameters:

  • payload

Returns:

  • The new Token.



49
50
51
52
# File 'lib/dynamic_key/rtc_token_builder.rb', line 49

def build_token_with_uid payload
  check! payload, %i[app_id app_certificate channel_name role uid privilege_expired_ts]
   @params.merge(:account => @params[:uid])
end