agora-ruby 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +6 -0
  5. data/Gemfile +11 -0
  6. data/Gemfile.lock +56 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +187 -0
  9. data/Rakefile +6 -0
  10. data/agora-ruby.gemspec +29 -0
  11. data/bin/console +13 -0
  12. data/bin/setup +8 -0
  13. data/lib/agora/cloud_recording/client.rb +139 -0
  14. data/lib/agora/config.rb +12 -0
  15. data/lib/agora/dynamic_key/access_token.rb +55 -0
  16. data/lib/agora/dynamic_key/rtc_token_builder.rb +112 -0
  17. data/lib/agora/dynamic_key/rtm_token_builder.rb +46 -0
  18. data/lib/agora/dynamic_key/sign.rb +73 -0
  19. data/lib/agora/dynamic_key.rb +13 -0
  20. data/lib/agora/dynamic_key2/access_token.rb +220 -0
  21. data/lib/agora/dynamic_key2/apaas_token_builder.rb +73 -0
  22. data/lib/agora/dynamic_key2/chat_token_builder.rb +42 -0
  23. data/lib/agora/dynamic_key2/education_token_builder.rb +73 -0
  24. data/lib/agora/dynamic_key2/fpa_token_builder.rb +21 -0
  25. data/lib/agora/dynamic_key2/rtc_token_builder.rb +215 -0
  26. data/lib/agora/dynamic_key2/rtm_token_builder.rb +22 -0
  27. data/lib/agora/dynamic_key2/util.rb +60 -0
  28. data/lib/agora/dynamic_key2.rb +12 -0
  29. data/lib/agora/errors.rb +14 -0
  30. data/lib/agora/version.rb +3 -0
  31. data/lib/agora-ruby.rb +18 -0
  32. data/sample/README.md +12 -0
  33. data/sample/apaas_token_builder_sample.rb +29 -0
  34. data/sample/chat_token_builder_sample.rb +23 -0
  35. data/sample/education_token_builder_sample.rb +29 -0
  36. data/sample/fpa_token_builder_sample.rb +16 -0
  37. data/sample/rtc_token_builder2_sample.rb +55 -0
  38. data/sample/rtc_token_builder_sample.rb +40 -0
  39. data/sample/rtm_token_builder_sample.rb +27 -0
  40. data/token_compare.md +143 -0
  41. metadata +101 -0
@@ -0,0 +1,215 @@
1
+ module Agora::AgoraDynamicKey2
2
+ class RtcTokenBuilder
3
+ # RECOMMENDED. Use this role for a voice/video call or a live broadcast, if
4
+ # your scenario does not require authentication for
5
+ # [Co-host](https://docs.agora.io/en/video-calling/get-started/authentication-workflow?#co-host-token-authentication).
6
+ ROLE_PUBLISHER = 1
7
+
8
+ # Only use this role if your scenario require authentication for
9
+ # [Co-host](https://docs.agora.io/en/video-calling/get-started/authentication-workflow?#co-host-token-authentication).
10
+ # @note In order for this role to take effect, please contact our support team
11
+ # to enable authentication for Hosting-in for you. Otherwise, Role_Subscriber
12
+ # still has the same privileges as Role_Publisher.
13
+ ROLE_SUBSCRIBER = 2
14
+
15
+ # Build the RTC token with uid.
16
+ #
17
+ # app_id: The App ID issued to you by Agora. Apply for a new App ID from Agora Dashboard if it is missing
18
+ # from your kit. See Get an App ID.
19
+ # app_certificate: Certificate of the application that you registered in the Agora Dashboard.
20
+ # See Get an App Certificate.
21
+ # channel_name: Unique channel name for the AgoraRTC session in the string format.
22
+ # uid: User ID. A 32-bit unsigned integer with a value ranging from 1 to (2^32-1).
23
+ # uid must be unique.
24
+ # role: ROLE_PUBLISHER: A broadcaster/host in a live-broadcast profile.
25
+ # ROLE_SUBSCRIBER: An audience(default) in a live-broadcast profile.
26
+ # token_expire: represented by the number of seconds elapsed since now. If, for example,
27
+ # you want to access the Agora Service within 10 minutes after the token is generated,
28
+ # set token_expire as 600(seconds).
29
+ # privilege_expire: represented by the number of seconds elapsed since now. If, for example,
30
+ # you want to enable your privilege for 10 minutes, set privilege_expire as 600(seconds).
31
+ # return: The RTC token.
32
+ def self.build_token_with_uid(app_id, app_certificate, channel_name, uid, role, token_expire, privilege_expire = 0)
33
+ build_token_with_user_account(app_id, app_certificate, channel_name, uid, role, token_expire, privilege_expire)
34
+ end
35
+
36
+ # Build the RTC token with account.
37
+ #
38
+ # app_id: The App ID issued to you by Agora. Apply for a new App ID from Agora Dashboard if it is missing
39
+ # from your kit. See Get an App ID.
40
+ # app_certificate: Certificate of the application that you registered in the Agora Dashboard.
41
+ # See Get an App Certificate.
42
+ # channel_name: Unique channel name for the AgoraRTC session in the string format.
43
+ # uid: User ID. A 32-bit unsigned integer with a value ranging from 1 to (2^32-1).
44
+ # uid must be unique.
45
+ # role: ROLE_PUBLISHER: A broadcaster/host in a live-broadcast profile.
46
+ # ROLE_SUBSCRIBER: An audience(default) in a live-broadcast profile.
47
+ # token_expire: represented by the number of seconds elapsed since now. If, for example,
48
+ # you want to access the Agora Service within 10 minutes after the token is generated,
49
+ # set token_expire as 600(seconds).
50
+ # privilege_expire: represented by the number of seconds elapsed since now. If, for example,
51
+ # you want to enable your privilege for 10 minutes, set privilege_expire as 600(seconds).
52
+ # return: The RTC token.
53
+ def self.build_token_with_user_account(app_id, app_certificate, channel_name, account, role, token_expire, privilege_expire = 0)
54
+ access_token = Agora::AgoraDynamicKey2::AccessToken.new(app_id, app_certificate, token_expire)
55
+ service_rtc = Agora::AgoraDynamicKey2::ServiceRtc.new(channel_name, account)
56
+
57
+ service_rtc.add_privilege(Agora::AgoraDynamicKey2::ServiceRtc::PRIVILEGE_JOIN_CHANNEL, privilege_expire)
58
+ if role == ROLE_PUBLISHER
59
+ service_rtc.add_privilege(Agora::AgoraDynamicKey2::ServiceRtc::PRIVILEGE_PUBLISH_AUDIO_STREAM, privilege_expire)
60
+ service_rtc.add_privilege(Agora::AgoraDynamicKey2::ServiceRtc::PRIVILEGE_PUBLISH_VIDEO_STREAM, privilege_expire)
61
+ service_rtc.add_privilege(Agora::AgoraDynamicKey2::ServiceRtc::PRIVILEGE_PUBLISH_DATA_STREAM, privilege_expire)
62
+ end
63
+ access_token.add_service(service_rtc)
64
+ access_token.build
65
+ end
66
+
67
+ # Generates an RTC token with the specified privilege.
68
+ #
69
+ # This method supports generating a token with the following privileges:
70
+ # - Joining an RTC channel.
71
+ # - Publishing audio in an RTC channel.
72
+ # - Publishing video in an RTC channel.
73
+ # - Publishing data streams in an RTC channel.
74
+ #
75
+ # The privileges for publishing audio, video, and data streams in an RTC channel apply only if you have
76
+ # enabled co-host authentication.
77
+ #
78
+ # A user can have multiple privileges. Each privilege is valid for a maximum of 24 hours.
79
+ # The SDK triggers the onTokenPrivilegeWillExpire and onRequestToken callbacks when the token is about to expire
80
+ # or has expired. The callbacks do not report the specific privilege affected, and you need to maintain
81
+ # the respective timestamp for each privilege in your app logic. After receiving the callback, you need
82
+ # to generate a new token, and then call renewToken to pass the new token to the SDK, or call joinChannel to re-join
83
+ # the channel.
84
+ #
85
+ # @note
86
+ # Agora recommends setting a reasonable timestamp for each privilege according to your scenario.
87
+ # Suppose the expiration timestamp for joining the channel is set earlier than that for publishing audio.
88
+ # When the token for joining the channel expires, the user is immediately kicked off the RTC channel
89
+ # and cannot publish any audio stream, even though the timestamp for publishing audio has not expired.
90
+ #
91
+ # @param app_id The App ID of your Agora project.
92
+ # @param app_certificate The App Certificate of your Agora project.
93
+ # @param channel_name The unique channel name for the Agora RTC session in string format. The string length must be less than 64 bytes. The channel name may contain the following characters:
94
+ # - All lowercase English letters: a to z.
95
+ # - All uppercase English letters: A to Z.
96
+ # - All numeric characters: 0 to 9.
97
+ # - The space character.
98
+ # - "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", " {", "}", "|", "~", ",".
99
+ # @param uid The user ID. A 32-bit unsigned integer with a value range from 1 to (2^32 - 1). It must be unique. Set uid as 0, if you do not want to authenticate the user ID, that is, any uid from the app client can join the channel.
100
+ # @param token_expire represented by the number of seconds elapsed since now. If, for example, you want to access the
101
+ # Agora Service within 10 minutes after the token is generated, set token_expire as 600(seconds).
102
+ # @param join_channel_privilege_expire represented by the number of seconds elapsed since now.
103
+ # If, for example, you want to join channel and expect stay in the channel for 10 minutes, set join_channel_privilege_expire as 600(seconds).
104
+ # @param pub_audio_privilege_expire represented by the number of seconds elapsed since now.
105
+ # If, for example, you want to enable publish audio privilege for 10 minutes, set pub_audio_privilege_expire as 600(seconds).
106
+ # @param pub_video_privilege_expire represented by the number of seconds elapsed since now.
107
+ # If, for example, you want to enable publish video privilege for 10 minutes, set pub_video_privilege_expire as 600(seconds).
108
+ # @param pub_data_stream_privilege_expire represented by the number of seconds elapsed since now.
109
+ # If, for example, you want to enable publish data stream privilege for 10 minutes, set pub_data_stream_privilege_expire as 600(seconds).
110
+ # @return The RTC Token
111
+ def self.build_token_with_uid_and_privilege(app_id, app_certificate, channel_name, uid, token_expire,
112
+ join_channel_privilege_expire, pub_audio_privilege_expire,
113
+ pub_video_privilege_expire, pub_data_stream_privilege_expire)
114
+ build_token_with_user_account_and_privilege(
115
+ app_id, app_certificate, channel_name, uid, token_expire, join_channel_privilege_expire,
116
+ pub_audio_privilege_expire, pub_video_privilege_expire, pub_data_stream_privilege_expire
117
+ )
118
+ end
119
+
120
+ # Generates an RTC token with the specified privilege.
121
+ #
122
+ # This method supports generating a token with the following privileges:
123
+ # - Joining an RTC channel.
124
+ # - Publishing audio in an RTC channel.
125
+ # - Publishing video in an RTC channel.
126
+ # - Publishing data streams in an RTC channel.
127
+ #
128
+ # The privileges for publishing audio, video, and data streams in an RTC channel apply only if you have
129
+ # enabled co-host authentication.
130
+ #
131
+ # A user can have multiple privileges. Each privilege is valid for a maximum of 24 hours.
132
+ # The SDK triggers the onTokenPrivilegeWillExpire and onRequestToken callbacks when the token is about to expire
133
+ # or has expired. The callbacks do not report the specific privilege affected, and you need to maintain
134
+ # the respective timestamp for each privilege in your app logic. After receiving the callback, you need
135
+ # to generate a new token, and then call renewToken to pass the new token to the SDK, or call joinChannel to re-join
136
+ # the channel.
137
+ #
138
+ # @note
139
+ # Agora recommends setting a reasonable timestamp for each privilege according to your scenario.
140
+ # Suppose the expiration timestamp for joining the channel is set earlier than that for publishing audio.
141
+ # When the token for joining the channel expires, the user is immediately kicked off the RTC channel
142
+ # and cannot publish any audio stream, even though the timestamp for publishing audio has not expired.
143
+ #
144
+ # @param app_id The App ID of your Agora project.
145
+ # @param app_certificate The App Certificate of your Agora project.
146
+ # @param channel_name The unique channel name for the Agora RTC session in string format. The string length must be less than 64 bytes. The channel name may contain the following characters:
147
+ # - All lowercase English letters: a to z.
148
+ # - All uppercase English letters: A to Z.
149
+ # - All numeric characters: 0 to 9.
150
+ # - The space character.
151
+ # - "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", " {", "}", "|", "~", ",".
152
+ # @param account The user account.
153
+ # @param token_expire represented by the number of seconds elapsed since now. If, for example, you want to access the
154
+ # Agora Service within 10 minutes after the token is generated, set token_expire as 600(seconds).
155
+ # @param join_channel_privilege_expire represented by the number of seconds elapsed since now.
156
+ # If, for example, you want to join channel and expect stay in the channel for 10 minutes, set join_channel_privilege_expire as 600(seconds).
157
+ # @param pub_audio_privilege_expire represented by the number of seconds elapsed since now.
158
+ # If, for example, you want to enable publish audio privilege for 10 minutes, set pub_audio_privilege_expire as 600(seconds).
159
+ # @param pub_video_privilege_expire represented by the number of seconds elapsed since now.
160
+ # If, for example, you want to enable publish video privilege for 10 minutes, set pub_video_privilege_expire as 600(seconds).
161
+ # @param pub_data_stream_privilege_expire represented by the number of seconds elapsed since now.
162
+ # If, for example, you want to enable publish data stream privilege for 10 minutes, set pub_data_stream_privilege_expire as 600(seconds).
163
+ # @return The RTC Token
164
+ def self.build_token_with_user_account_and_privilege(app_id, app_certificate, channel_name, account, token_expire,
165
+ join_channel_privilege_expire, pub_audio_privilege_expire,
166
+ pub_video_privilege_expire, pub_data_stream_privilege_expire)
167
+ access_token = Agora::AgoraDynamicKey2::AccessToken.new(app_id, app_certificate, token_expire)
168
+ service_rtc = Agora::AgoraDynamicKey2::ServiceRtc.new(channel_name, account)
169
+
170
+ service_rtc.add_privilege(Agora::AgoraDynamicKey2::ServiceRtc::PRIVILEGE_JOIN_CHANNEL, join_channel_privilege_expire)
171
+ service_rtc.add_privilege(Agora::AgoraDynamicKey2::ServiceRtc::PRIVILEGE_PUBLISH_AUDIO_STREAM, pub_audio_privilege_expire)
172
+ service_rtc.add_privilege(Agora::AgoraDynamicKey2::ServiceRtc::PRIVILEGE_PUBLISH_VIDEO_STREAM, pub_video_privilege_expire)
173
+ service_rtc.add_privilege(Agora::AgoraDynamicKey2::ServiceRtc::PRIVILEGE_PUBLISH_DATA_STREAM, pub_data_stream_privilege_expire)
174
+ access_token.add_service(service_rtc)
175
+ access_token.build
176
+ end
177
+
178
+ # Build the RTC and RTM token with account.
179
+ #
180
+ # app_id: The App ID issued to you by Agora. Apply for a new App ID from Agora Dashboard if it is missing
181
+ # from your kit. See Get an App ID.
182
+ # app_certificate: Certificate of the application that you registered in the Agora Dashboard.
183
+ # See Get an App Certificate.
184
+ # channel_name: Unique channel name for the AgoraRTC session in the string format.
185
+ # uid: User ID. A 32-bit unsigned integer with a value ranging from 1 to (2^32-1).
186
+ # uid must be unique.
187
+ # role: ROLE_PUBLISHER: A broadcaster/host in a live-broadcast profile.
188
+ # ROLE_SUBSCRIBER: An audience(default) in a live-broadcast profile.
189
+ # token_expire: represented by the number of seconds elapsed since now. If, for example,
190
+ # you want to access the Agora Service within 10 minutes after the token is generated,
191
+ # set token_expire as 600(seconds).
192
+ # privilege_expire: represented by the number of seconds elapsed since now. If, for example,
193
+ # you want to enable your privilege for 10 minutes, set privilege_expire as 600(seconds).
194
+ # return: The RTC and RTM token.
195
+ def self.build_token_with_rtm(app_id, app_certificate, channel_name, account, role, token_expire, privilege_expire = 0)
196
+ access_token = Agora::AgoraDynamicKey2::AccessToken.new(app_id, app_certificate, token_expire)
197
+ service_rtc = Agora::AgoraDynamicKey2::ServiceRtc.new(channel_name, account)
198
+
199
+ service_rtc.add_privilege(Agora::AgoraDynamicKey2::ServiceRtc::PRIVILEGE_JOIN_CHANNEL, privilege_expire)
200
+ if role == ROLE_PUBLISHER
201
+ service_rtc.add_privilege(Agora::AgoraDynamicKey2::ServiceRtc::PRIVILEGE_PUBLISH_AUDIO_STREAM, privilege_expire)
202
+ service_rtc.add_privilege(Agora::AgoraDynamicKey2::ServiceRtc::PRIVILEGE_PUBLISH_VIDEO_STREAM, privilege_expire)
203
+ service_rtc.add_privilege(Agora::AgoraDynamicKey2::ServiceRtc::PRIVILEGE_PUBLISH_DATA_STREAM, privilege_expire)
204
+ end
205
+ access_token.add_service(service_rtc)
206
+
207
+ service_rtm = Agora::AgoraDynamicKey2::ServiceRtm.new(account)
208
+
209
+ service_rtm.add_privilege(Agora::AgoraDynamicKey2::ServiceRtm::PRIVILEGE_JOIN_LOGIN, token_expire)
210
+ access_token.add_service(service_rtm)
211
+
212
+ access_token.build
213
+ end
214
+ end
215
+ end
@@ -0,0 +1,22 @@
1
+ module Agora::AgoraDynamicKey2
2
+ class RtmTokenBuilder
3
+ # Build the RTM token.
4
+ #
5
+ # @param app_id: The App ID issued to you by Agora. Apply for a new App ID from
6
+ # Agora Dashboard if it is missing from your kit. See Get an App ID.
7
+ # @param app_certificate: Certificate of the application that you registered in
8
+ # the Agora Dashboard. See Get an App Certificate.
9
+ # @param user_id: The user's account, max length is 64 Bytes.
10
+ # @param expire: represented by the number of seconds elapsed since now. If, for example, you want to access the
11
+ # Agora Service within 10 minutes after the token is generated, set expire as 600(seconds).
12
+ # @return The RTM token.
13
+ def self.build_token(app_id, app_certificate, user_id, expire)
14
+ access_token = Agora::AgoraDynamicKey2::AccessToken.new(app_id, app_certificate, expire)
15
+ service_rtm = Agora::AgoraDynamicKey2::ServiceRtm.new(user_id)
16
+
17
+ service_rtm.add_privilege(Agora::AgoraDynamicKey2::ServiceRtm::PRIVILEGE_JOIN_LOGIN, expire)
18
+ access_token.add_service(service_rtm)
19
+ access_token.build
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,60 @@
1
+ require 'base64'
2
+
3
+ module Agora::AgoraDynamicKey2
4
+ class Util
5
+ def self.pack_int16(int)
6
+ [int].pack('s')
7
+ end
8
+
9
+ def self.unpack_int16(data)
10
+ [data[0..2].unpack1('s'), data[2..-1]]
11
+ end
12
+
13
+ def self.pack_uint16(int)
14
+ [int].pack('v')
15
+ end
16
+
17
+ def self.unpack_uint16(data)
18
+ [data[0..2].unpack1('v'), data[2..-1]]
19
+ end
20
+
21
+ def self.pack_uint32(int)
22
+ [int].pack('V')
23
+ end
24
+
25
+ def self.unpack_uint32(data)
26
+ [data[0..4].unpack1('V'), data[4..-1]]
27
+ end
28
+
29
+ def self.pack_string(str)
30
+ pack_uint16(str.bytesize) + str
31
+ end
32
+
33
+ def self.unpack_string(data)
34
+ len, data = unpack_uint16(data)
35
+ if len.zero?
36
+ return ['', data[len..-1]]
37
+ end
38
+ [data[0..len - 1], data[len..-1]]
39
+ end
40
+
41
+ def self.pack_map_uint32(map)
42
+ kv = ''
43
+ Hash[map.sort].each do |k, v|
44
+ kv += pack_uint16(k) + pack_uint32(v)
45
+ end
46
+ (pack_uint16(map.size) + kv).force_encoding('utf-8')
47
+ end
48
+
49
+ def self.unpack_map_uint32(data)
50
+ len, data = unpack_uint16(data)
51
+ map = {}
52
+ (1..len).each do
53
+ k, data = unpack_uint16(data)
54
+ v, data = unpack_uint32(data)
55
+ map[k] = v
56
+ end
57
+ [map, data]
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,12 @@
1
+ module Agora
2
+ module DynamicKey2
3
+ require_relative 'dynamic_key2/access_token'
4
+ require_relative 'dynamic_key2/apaas_token_builder'
5
+ require_relative 'dynamic_key2/chat_token_builder'
6
+ require_relative 'dynamic_key2/education_token_builder'
7
+ require_relative 'dynamic_key2/fpa_token_builder'
8
+ require_relative 'dynamic_key2/rtc_token_builder'
9
+ require_relative 'dynamic_key2/rtm_token_builder'
10
+ require_relative 'dynamic_key2/util'
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ module Agora
2
+ module Errors
3
+ class AgoraError < StandardError; end
4
+ class ConfigurationError < AgoraError; end
5
+ class APIError < AgoraError
6
+ attr_reader :response
7
+
8
+ def initialize(message, response = nil)
9
+ super(message)
10
+ @response = response
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module Agora
2
+ VERSION = "0.1.0"
3
+ end
data/lib/agora-ruby.rb ADDED
@@ -0,0 +1,18 @@
1
+ require "httparty"
2
+ require_relative "agora/version"
3
+ require_relative "agora/config"
4
+ require_relative "agora/errors"
5
+ require_relative "agora/cloud_recording/client"
6
+ require_relative "agora/dynamic_key"
7
+ require_relative "agora/dynamic_key2"
8
+
9
+ module Agora
10
+ class << self
11
+ attr_accessor :config
12
+ end
13
+
14
+ def self.configure
15
+ self.config ||= Agora::Config.new # 使用 Agora::Config 类
16
+ yield(config) if block_given?
17
+ end
18
+ end
data/sample/README.md ADDED
@@ -0,0 +1,12 @@
1
+ - **rtc_token_builder.rb**: Source code for generating a token for the following SDKs:
2
+ - Agora Native SDK v2.1+
3
+
4
+ - Agora Web SDK v2.4+
5
+
6
+ - Agora Recording SDK v2.1+
7
+
8
+ - Agora RTSA SDK
9
+
10
+ > The Agora RTSA SDK supports joining multiple channels. If you join multiple channels at the same time, then you MUST generate a specific token for each channel you join.
11
+ - **rtm_token_builder.rb**: Source code for generating a token for the Agora RTM SDK.
12
+ - **access_token.rb**: Implements all the underlying algorithms for generating a token. Both **rtc_token_builder.rb** and **rtm_token_builder.rb** are a wrapper of **access_token.rb** and have much easier-to-use APIs. We recommend using **rtc_token_builder.rb** for generating an RTC token or **rtm_token_builder.rb** for an RTM token.
@@ -0,0 +1,29 @@
1
+ require_relative '../lib/dynamic_key2'
2
+
3
+ # Need to set environment variable AGORA_APP_ID
4
+ app_id = ENV.fetch('AGORA_APP_ID', nil)
5
+ # Need to set environment variable AGORA_APP_CERTIFICATE
6
+ app_certificate = ENV.fetch('AGORA_APP_CERTIFICATE', nil)
7
+
8
+ room_uuid = '123'
9
+ user_uuid = '2882341273'
10
+ role = 1
11
+ token_expiration_in_seconds = 3600
12
+
13
+ puts "App Id: #{app_id}"
14
+ puts "App Certificate: #{app_certificate}"
15
+ if !app_id || app_id == '' || !app_certificate || app_certificate == ''
16
+ puts 'Need to set environment variable AGORA_APP_ID and AGORA_APP_CERTIFICATE'
17
+ exit
18
+ end
19
+
20
+ token = Agora::AgoraDynamicKey2::ApaasTokenBuilder.build_room_user_token(app_id, app_certificate, room_uuid, user_uuid,
21
+ role, token_expiration_in_seconds)
22
+ puts "Apaas room user token: #{token}"
23
+
24
+ token = Agora::AgoraDynamicKey2::ApaasTokenBuilder.build_user_token(app_id, app_certificate, user_uuid,
25
+ token_expiration_in_seconds)
26
+ puts "Apaas user token: #{token}"
27
+
28
+ token = Agora::AgoraDynamicKey2::ApaasTokenBuilder.build_app_token(app_id, app_certificate, token_expiration_in_seconds)
29
+ puts "Apaas app token: #{token}"
@@ -0,0 +1,23 @@
1
+ require_relative '../lib/dynamic_key2'
2
+
3
+ # Need to set environment variable AGORA_APP_ID
4
+ app_id = ENV['AGORA_APP_ID']
5
+ # Need to set environment variable AGORA_APP_CERTIFICATE
6
+ app_certificate = ENV['AGORA_APP_CERTIFICATE']
7
+
8
+ user_id = '2882341273'
9
+ token_expiration_in_seconds = 600
10
+
11
+ puts "App Id: #{app_id}"
12
+ puts "App Certificate: #{app_certificate}"
13
+ if !app_id || app_id == '' || !app_certificate || app_certificate == ''
14
+ puts 'Need to set environment variable AGORA_APP_ID and AGORA_APP_CERTIFICATE'
15
+ exit
16
+ end
17
+
18
+ token = Agora::AgoraDynamicKey2::ChatTokenBuilder.build_user_token(app_id, app_certificate, user_id,
19
+ token_expiration_in_seconds)
20
+ puts "Chat user token : #{token}"
21
+
22
+ token = Agora::AgoraDynamicKey2::ChatTokenBuilder.build_app_token(app_id, app_certificate, token_expiration_in_seconds)
23
+ puts "Chat app token: #{token}"
@@ -0,0 +1,29 @@
1
+ require_relative '../lib/dynamic_key2'
2
+
3
+ # Need to set environment variable AGORA_APP_ID
4
+ app_id = ENV['AGORA_APP_ID']
5
+ # Need to set environment variable AGORA_APP_CERTIFICATE
6
+ app_certificate = ENV['AGORA_APP_CERTIFICATE']
7
+
8
+ room_uuid = '123'
9
+ user_uuid = '2882341273'
10
+ role = 1
11
+ token_expiration_in_seconds = 3600
12
+
13
+ puts "App Id: #{app_id}"
14
+ puts "App Certificate: #{app_certificate}"
15
+ if !app_id || app_id == '' || !app_certificate || app_certificate == ''
16
+ puts 'Need to set environment variable AGORA_APP_ID and AGORA_APP_CERTIFICATE'
17
+ exit
18
+ end
19
+
20
+ token = Agora::AgoraDynamicKey2::EducationTokenBuilder.build_room_user_token(app_id, app_certificate, room_uuid, user_uuid,
21
+ role, token_expiration_in_seconds)
22
+ puts "Education room user token: #{token}"
23
+
24
+ token = Agora::AgoraDynamicKey2::EducationTokenBuilder.build_user_token(app_id, app_certificate, user_uuid,
25
+ token_expiration_in_seconds)
26
+ puts "Education user token: #{token}"
27
+
28
+ token = Agora::AgoraDynamicKey2::EducationTokenBuilder.build_app_token(app_id, app_certificate, token_expiration_in_seconds)
29
+ puts "Education app token: #{token}"
@@ -0,0 +1,16 @@
1
+ require_relative '../lib/dynamic_key2'
2
+
3
+ # Need to set environment variable AGORA_APP_ID
4
+ app_id = ENV['AGORA_APP_ID']
5
+ # Need to set environment variable AGORA_APP_CERTIFICATE
6
+ app_certificate = ENV['AGORA_APP_CERTIFICATE']
7
+
8
+ puts "App Id: #{app_id}"
9
+ puts "App Certificate: #{app_certificate}"
10
+ if !app_id || app_id == '' || !app_certificate || app_certificate == ''
11
+ puts 'Need to set environment variable AGORA_APP_ID and AGORA_APP_CERTIFICATE'
12
+ exit
13
+ end
14
+
15
+ token = Agora::AgoraDynamicKey2::FpaTokenBuilder.build_token(app_id, app_certificate)
16
+ puts "Token with FPA service: #{token}"
@@ -0,0 +1,55 @@
1
+ require_relative '../lib/dynamic_key2'
2
+
3
+ # Need to set environment variable AGORA_APP_ID
4
+ app_id = ENV.fetch('AGORA_APP_ID', nil)
5
+ # Need to set environment variable AGORA_APP_CERTIFICATE
6
+ app_certificate = ENV.fetch('AGORA_APP_CERTIFICATE', nil)
7
+
8
+ channel_name = '7d72365eb983485397e3e3f9d460bdda'
9
+ uid = 2_882_341_273
10
+ account = '2882341273'
11
+ token_expiration_in_seconds = 3600
12
+ privilege_expiration_in_seconds = 3600
13
+ join_channel_privilege_expiration_in_seconds = 3600
14
+ pub_audio_privilege_expiration_in_seconds = 3600
15
+ pub_video_privilege_expiration_in_seconds = 3600
16
+ pub_data_stream_privilege_expiration_in_seconds = 3600
17
+
18
+ puts "App Id: #{app_id}"
19
+ puts "App Certificate: #{app_certificate}"
20
+ if !app_id || app_id == '' || !app_certificate || app_certificate == ''
21
+ puts 'Need to set environment variable AGORA_APP_ID and AGORA_APP_CERTIFICATE'
22
+ exit
23
+ end
24
+
25
+ token = Agora::AgoraDynamicKey2::RtcTokenBuilder.build_token_with_uid(
26
+ app_id, app_certificate, channel_name, uid,
27
+ Agora::AgoraDynamicKey2::RtcTokenBuilder::ROLE_PUBLISHER, token_expiration_in_seconds, privilege_expiration_in_seconds
28
+ )
29
+ puts "Token with int uid: #{token}"
30
+
31
+ token = Agora::AgoraDynamicKey2::RtcTokenBuilder.build_token_with_user_account(
32
+ app_id, app_certificate, channel_name, account,
33
+ Agora::AgoraDynamicKey2::RtcTokenBuilder::ROLE_PUBLISHER, token_expiration_in_seconds, privilege_expiration_in_seconds
34
+ )
35
+ puts "Token with user account: #{token}"
36
+
37
+ token = Agora::AgoraDynamicKey2::RtcTokenBuilder.build_token_with_uid_and_privilege(
38
+ app_id, app_certificate, channel_name, uid, token_expiration_in_seconds,
39
+ join_channel_privilege_expiration_in_seconds, pub_audio_privilege_expiration_in_seconds,
40
+ pub_video_privilege_expiration_in_seconds, pub_data_stream_privilege_expiration_in_seconds
41
+ )
42
+ puts "Token with int uid and privilege: #{token}"
43
+
44
+ token = Agora::AgoraDynamicKey2::RtcTokenBuilder.build_token_with_user_account_and_privilege(
45
+ app_id, app_certificate, channel_name, account, token_expiration_in_seconds,
46
+ join_channel_privilege_expiration_in_seconds, pub_audio_privilege_expiration_in_seconds,
47
+ pub_video_privilege_expiration_in_seconds, pub_data_stream_privilege_expiration_in_seconds
48
+ )
49
+ puts "Token with user account and privilege: #{token}"
50
+
51
+ token = Agora::AgoraDynamicKey2::RtcTokenBuilder.build_token_with_rtm(
52
+ app_id, app_certificate, channel_name, account,
53
+ Agora::AgoraDynamicKey2::RtcTokenBuilder::ROLE_PUBLISHER, token_expiration_in_seconds, privilege_expiration_in_seconds
54
+ )
55
+ puts "Token with RTM: #{token}"
@@ -0,0 +1,40 @@
1
+ require_relative '../lib/dynamic_key'
2
+
3
+ # Need to set environment variable AGORA_APP_ID
4
+ app_id = ENV['AGORA_APP_ID']
5
+ # Need to set environment variable AGORA_APP_CERTIFICATE
6
+ app_certificate = ENV['AGORA_APP_CERTIFICATE']
7
+
8
+ expiration_time_in_seconds = 3600
9
+ current_time_stamps = Time.now.to_i
10
+
11
+ puts "App Id: #{app_id}"
12
+ puts "App Certificate: #{app_certificate}"
13
+ if !app_id || app_id == '' || !app_certificate || app_certificate == ''
14
+ puts 'Need to set environment variable AGORA_APP_ID and AGORA_APP_CERTIFICATE'
15
+ exit
16
+ end
17
+
18
+ params = {
19
+ app_id: app_id,
20
+ app_certificate: app_certificate,
21
+ channel_name: '7d72365eb983485397e3e3f9d460bdda',
22
+ uid: 2_882_341_273,
23
+ role: Agora::AgoraDynamicKey::RTCTokenBuilder::Role::PUBLISHER,
24
+ privilege_expired_ts: current_time_stamps + expiration_time_in_seconds
25
+ }
26
+
27
+ result = Agora::AgoraDynamicKey::RTCTokenBuilder.build_token_with_uid params
28
+ puts "Token With Int Uid: #{result}"
29
+
30
+ params_with_account = {
31
+ app_id: app_id,
32
+ app_certificate: app_certificate,
33
+ channel_name: '7d72365eb983485397e3e3f9d460bdda',
34
+ account: 'test_user',
35
+ role: Agora::AgoraDynamicKey::RTCTokenBuilder::Role::PUBLISHER,
36
+ privilege_expired_ts: current_time_stamps + expiration_time_in_seconds
37
+ }
38
+
39
+ result = Agora::AgoraDynamicKey::RTCTokenBuilder.build_token_with_account params_with_account
40
+ puts "Token With UserAccount: #{result}"
@@ -0,0 +1,27 @@
1
+ require_relative '../lib/dynamic_key'
2
+
3
+ # Need to set environment variable AGORA_APP_ID
4
+ app_id = ENV['AGORA_APP_ID']
5
+ # Need to set environment variable AGORA_APP_CERTIFICATE
6
+ app_certificate = ENV['AGORA_APP_CERTIFICATE']
7
+
8
+ expiration_time_in_seconds = 3600
9
+ current_time_stamps = Time.now.to_i
10
+
11
+ puts "App Id: #{app_id}"
12
+ puts "App Certificate: #{app_certificate}"
13
+ if !app_id || app_id == '' || !app_certificate || app_certificate == ''
14
+ puts 'Need to set environment variable AGORA_APP_ID and AGORA_APP_CERTIFICATE'
15
+ exit
16
+ end
17
+
18
+ params = {
19
+ app_id: app_id,
20
+ app_certificate: app_certificate,
21
+ account: 'test_user_id',
22
+ role: Agora::AgoraDynamicKey::RTMTokenBuilder::Role::RTM_USER,
23
+ privilege_expired_ts: current_time_stamps + expiration_time_in_seconds
24
+ }
25
+
26
+ result = Agora::AgoraDynamicKey::RTMTokenBuilder.build_token params
27
+ puts "Rtm Token: #{result}"