Class: Agora::AgoraDynamicKey2::RtmTokenBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/agora/dynamic_key2/rtm_token_builder.rb

Class Method Summary collapse

Class Method Details

.build_token(app_id, app_certificate, user_id, expire) ⇒ Object

Build the RTM token.

Parameters:

  • app_id:

    The App ID issued to you by Agora. Apply for a new App ID from Agora Dashboard if it is missing from your kit. See Get an App ID.

  • app_certificate:

    Certificate of the application that you registered in the Agora Dashboard. See Get an App Certificate.

  • user_id:

    The user’s account, max length is 64 Bytes.

  • expire:

    represented by the number of seconds elapsed since now. If, for example, you want to access the Agora Service within 10 minutes after the token is generated, set expire as 600(seconds).

Returns:

  • The RTM token.



13
14
15
16
17
18
19
20
# File 'lib/agora/dynamic_key2/rtm_token_builder.rb', line 13

def self.build_token(app_id, app_certificate, user_id, expire)
  access_token = Agora::AgoraDynamicKey2::AccessToken.new(app_id, app_certificate, expire)
  service_rtm = Agora::AgoraDynamicKey2::ServiceRtm.new(user_id)

  service_rtm.add_privilege(Agora::AgoraDynamicKey2::ServiceRtm::PRIVILEGE_JOIN_LOGIN, expire)
  access_token.add_service(service_rtm)
  access_token.build
end