agora-token 2.0.4 → 2.0.6

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.
@@ -16,7 +16,9 @@ class ApaasTokenBuilder {
16
16
  * @param userUuid The user's id, must be unique.
17
17
  * @param role The user's role.
18
18
  * @param expire represented by the number of seconds elapsed since now. If, for example, you want to access the
19
- * Agora Service within 10 minutes after the token is generated, set expire as 600(seconds).
19
+ * Agora Service within 10 minutes after the token is generated, set expire as
20
+ * 600(seconds). This value is the whole token expiration and the service
21
+ * privilege expiration. The whole token is invalid after this time.
20
22
  * @return The user room token.
21
23
  */
22
24
  static buildRoomUserToken(appId, appCertificate, roomUuid, userUuid, role, expire) {
@@ -45,7 +47,9 @@ class ApaasTokenBuilder {
45
47
  * the Agora Dashboard. See Get an App Certificate.
46
48
  * @param userUuid The user's id, must be unique.
47
49
  * @param expire represented by the number of seconds elapsed since now. If, for example, you want to access the
48
- * Agora Service within 10 minutes after the token is generated, set expire as 600(seconds).
50
+ * Agora Service within 10 minutes after the token is generated, set expire as
51
+ * 600(seconds). This value is the whole token expiration and the service
52
+ * privilege expiration. The whole token is invalid after this time.
49
53
  * @return The user token.
50
54
  */
51
55
  static buildUserToken(appId, appCertificate, userUuid, expire) {
@@ -64,7 +68,9 @@ class ApaasTokenBuilder {
64
68
  * @param appCertificate Certificate of the application that you registered in
65
69
  * the Agora Dashboard. See Get an App Certificate.
66
70
  * @param expire represented by the number of seconds elapsed since now. If, for example, you want to access the
67
- * Agora Service within 10 minutes after the token is generated, set expire as 600(seconds).
71
+ * Agora Service within 10 minutes after the token is generated, set expire as
72
+ * 600(seconds). This value is the whole token expiration and the service privilege
73
+ * expiration. The whole token is invalid after this time.
68
74
  * @return The app token.
69
75
  */
70
76
  static buildAppToken(appId, appCertificate, expire) {
@@ -11,7 +11,9 @@ class ChatTokenBuilder {
11
11
  * the Agora Dashboard. See Get an App Certificate.
12
12
  * @param userUuid The user's id, must be unique.
13
13
  * @param expire represented by the number of seconds elapsed since now. If, for example, you want to access the
14
- * Agora Service within 10 minutes after the token is generated, set expire as 600(seconds).
14
+ * Agora Service within 10 minutes after the token is generated, set expire as 600(seconds). This value is
15
+ * the whole token expiration and the service privilege expiration. The whole token is invalid after this
16
+ * time.
15
17
  * @return The Chat User token.
16
18
  */
17
19
  static buildUserToken(appId, appCertificate, userUuid, expire) {
@@ -30,7 +32,9 @@ class ChatTokenBuilder {
30
32
  * @param appCertificate Certificate of the application that you registered in
31
33
  * the Agora Dashboard. See Get an App Certificate.
32
34
  * @param expire represented by the number of seconds elapsed since now. If, for example, you want to access the
33
- * Agora Service within 10 minutes after the token is generated, set expire as 600(seconds).
35
+ * Agora Service within 10 minutes after the token is generated, set expire as 600(seconds). This value is
36
+ * the whole token expiration and the service privilege expiration. The whole token is invalid after this
37
+ * time.
34
38
  * @return The Chat App token.
35
39
  */
36
40
  static buildAppToken(appId, appCertificate, expire) {
@@ -0,0 +1,68 @@
1
+ const AccessToken = require('../src/AccessToken2').AccessToken2
2
+ const ServiceConvoAI = require('../src/AccessToken2').ServiceConvoAI
3
+ const ServiceRtc = require('../src/AccessToken2').ServiceRtc
4
+ const ServiceRtm = require('../src/AccessToken2').ServiceRtm
5
+ const Role = require('../src/RtcTokenBuilder2').Role
6
+
7
+ class ConvoAITokenBuilder {
8
+ /**
9
+ * Builds a Token007 that carries RTC, RTM, and ConvoAI services.
10
+ * @param {*} appId The App ID issued to you by Agora.
11
+ * @param {*} appCertificate Certificate of the application that you registered in the Agora Dashboard.
12
+ * @param {*} channelName The unique channel name for the AgoraRTC session in the string format.
13
+ * @param {*} rtcAccount The RTC user's account, max length is 255 bytes.
14
+ * @param {*} rtcRole Role.PUBLISHER for a broadcaster or Role.SUBSCRIBER for an audience member.
15
+ * @param {*} rtcTokenExpire Represented by the number of seconds elapsed since now. This is the whole
16
+ * token expiration. The whole token is invalid after this time, even if a privilege expiration time is
17
+ * later.
18
+ * @param {*} joinChannelPrivilegeExpire Represented by the number of seconds elapsed since now. This
19
+ * value must not exceed rtcTokenExpire; otherwise, the privilege is limited by the token expiration time.
20
+ * @param {*} pubAudioPrivilegeExpire Represented by the number of seconds elapsed since now. This value
21
+ * must not exceed rtcTokenExpire; otherwise, the privilege is limited by the token expiration time.
22
+ * @param {*} pubVideoPrivilegeExpire Represented by the number of seconds elapsed since now. This value
23
+ * must not exceed rtcTokenExpire; otherwise, the privilege is limited by the token expiration time.
24
+ * @param {*} pubDataStreamPrivilegeExpire Represented by the number of seconds elapsed since now. This
25
+ * value must not exceed rtcTokenExpire; otherwise, the privilege is limited by the token expiration time.
26
+ * @param {*} rtmUserId The RTM user's account, max length is 255 bytes.
27
+ * @param {*} rtmTokenExpire Represented by the number of seconds elapsed since now. This value must not
28
+ * exceed rtcTokenExpire; otherwise, the RTM login privilege is limited by the token expiration time.
29
+ * @return The RTC, RTM, and ConvoAI token.
30
+ */
31
+ static buildToken(
32
+ appId,
33
+ appCertificate,
34
+ channelName,
35
+ rtcAccount,
36
+ rtcRole,
37
+ rtcTokenExpire,
38
+ joinChannelPrivilegeExpire,
39
+ pubAudioPrivilegeExpire,
40
+ pubVideoPrivilegeExpire,
41
+ pubDataStreamPrivilegeExpire,
42
+ rtmUserId,
43
+ rtmTokenExpire
44
+ ) {
45
+ const token = new AccessToken(appId, appCertificate, 0, rtcTokenExpire)
46
+
47
+ const serviceRtc = new ServiceRtc(channelName, rtcAccount)
48
+ serviceRtc.add_privilege(ServiceRtc.kPrivilegeJoinChannel, joinChannelPrivilegeExpire)
49
+ if (rtcRole === Role.PUBLISHER) {
50
+ serviceRtc.add_privilege(ServiceRtc.kPrivilegePublishAudioStream, pubAudioPrivilegeExpire)
51
+ serviceRtc.add_privilege(ServiceRtc.kPrivilegePublishVideoStream, pubVideoPrivilegeExpire)
52
+ serviceRtc.add_privilege(ServiceRtc.kPrivilegePublishDataStream, pubDataStreamPrivilegeExpire)
53
+ }
54
+ token.add_service(serviceRtc)
55
+
56
+ const serviceRtm = new ServiceRtm(rtmUserId)
57
+ serviceRtm.add_privilege(ServiceRtm.kPrivilegeLogin, rtmTokenExpire)
58
+ token.add_service(serviceRtm)
59
+
60
+ token.add_service(new ServiceConvoAI())
61
+
62
+ return token.build()
63
+ }
64
+ }
65
+
66
+ module.exports = {
67
+ ConvoAITokenBuilder
68
+ }
@@ -16,7 +16,9 @@ class EducationTokenBuilder {
16
16
  * @param userUuid The user's id, must be unique.
17
17
  * @param role The user's role.
18
18
  * @param expire represented by the number of seconds elapsed since now. If, for example, you want to access the
19
- * Agora Service within 10 minutes after the token is generated, set expire as 600(seconds).
19
+ * Agora Service within 10 minutes after the token is generated, set expire as
20
+ * 600(seconds). This value is the whole token expiration and the service
21
+ * privilege expiration. The whole token is invalid after this time.
20
22
  * @return The user room token.
21
23
  */
22
24
  static buildRoomUserToken(appId, appCertificate, roomUuid, userUuid, role, expire) {
@@ -45,7 +47,9 @@ class EducationTokenBuilder {
45
47
  * the Agora Dashboard. See Get an App Certificate.
46
48
  * @param userUuid The user's id, must be unique.
47
49
  * @param expire represented by the number of seconds elapsed since now. If, for example, you want to access the
48
- * Agora Service within 10 minutes after the token is generated, set expire as 600(seconds).
50
+ * Agora Service within 10 minutes after the token is generated, set expire as
51
+ * 600(seconds). This value is the whole token expiration and the service
52
+ * privilege expiration. The whole token is invalid after this time.
49
53
  * @return The user token.
50
54
  */
51
55
  static buildUserToken(appId, appCertificate, userUuid, expire) {
@@ -64,7 +68,9 @@ class EducationTokenBuilder {
64
68
  * @param appCertificate Certificate of the application that you registered in
65
69
  * the Agora Dashboard. See Get an App Certificate.
66
70
  * @param expire represented by the number of seconds elapsed since now. If, for example, you want to access the
67
- * Agora Service within 10 minutes after the token is generated, set expire as 600(seconds).
71
+ * Agora Service within 10 minutes after the token is generated, set expire as
72
+ * 600(seconds). This value is the whole token expiration and the service privilege
73
+ * expiration. The whole token is invalid after this time.
68
74
  * @return The app token.
69
75
  */
70
76
  static buildAppToken(appId, appCertificate, expire) {
@@ -8,7 +8,7 @@ class FpaTokenBuilder {
8
8
  * Agora Dashboard if it is missing from your kit. See Get an App ID.
9
9
  * @param appCertificate Certificate of the application that you registered in
10
10
  * the Agora Dashboard. See Get an App Certificate.
11
- * @return The FPA token.
11
+ * @return The FPA token. The token expires 24 hours after generation.
12
12
  */
13
13
  static buildToken(appId, appCertificate) {
14
14
  let token = new AccessToken(appId, appCertificate, 0, 24 * 3600)
@@ -36,8 +36,13 @@ class RtcTokenBuilder {
36
36
  * @param {*} role See #userRole.
37
37
  * - Role.PUBLISHER; RECOMMENDED. Use this role for a voice/video call or a live broadcast.
38
38
  * - Role.SUBSCRIBER: ONLY use this role if your live-broadcast scenario requires authentication for [Co-host](https://docs.agora.io/en/video-calling/get-started/authentication-workflow?#co-host-token-authentication). In order for this role to take effect, please contact our support team to enable authentication for Co-host for you. Otherwise, Role_Subscriber still has the same privileges as Role_Publisher.
39
- * @param {*} tokenExpire epresented 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 tokenExpire as 600(seconds)
40
- * @param {*} privilegeExpire represented by the number of seconds elapsed since now. If, for example, you want to enable your privilege for 10 minutes, set privilegeExpire as 600(seconds).
39
+ * @param {*} tokenExpire represented by the number of seconds elapsed since now. If, for example, you
40
+ * want to access the Agora Service within 10 minutes after the token is generated, set tokenExpire as
41
+ * 600(seconds). This is the whole token expiration. The whole token is invalid after this time, even if a
42
+ * privilege expiration time is later.
43
+ * @param {*} privilegeExpire represented by the number of seconds elapsed since now. If, for example, you
44
+ * want to enable your privilege for 10 minutes, set privilegeExpire as 600(seconds). This value must not
45
+ * exceed the token expiration value; otherwise, the privilege is limited by the token expiration time.
41
46
  * @return The RTC Token.
42
47
  */
43
48
  static buildTokenWithUid(appId, appCertificate, channelName, uid, role, tokenExpire, privilegeExpire = 0) {
@@ -66,8 +71,13 @@ class RtcTokenBuilder {
66
71
  * @param {*} role See #userRole.
67
72
  * - Role.PUBLISHER; RECOMMENDED. Use this role for a voice/video call or a live broadcast.
68
73
  * - Role.SUBSCRIBER: ONLY use this role if your live-broadcast scenario requires authentication for [Co-host](https://docs.agora.io/en/video-calling/get-started/authentication-workflow?#co-host-token-authentication). In order for this role to take effect, please contact our support team to enable authentication for Co-host for you. Otherwise, Role_Subscriber still has the same privileges as Role_Publisher.
69
- * @param {*} tokenExpire epresented 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 tokenExpire as 600(seconds)
70
- * @param {*} privilegeExpire represented by the number of seconds elapsed since now. If, for example, you want to enable your privilege for 10 minutes, set privilegeExpire as 600(seconds).
74
+ * @param {*} tokenExpire represented by the number of seconds elapsed since now. If, for example, you
75
+ * want to access the Agora Service within 10 minutes after the token is generated, set tokenExpire as
76
+ * 600(seconds). This is the whole token expiration. The whole token is invalid after this time, even if a
77
+ * privilege expiration time is later.
78
+ * @param {*} privilegeExpire represented by the number of seconds elapsed since now. If, for example, you
79
+ * want to enable your privilege for 10 minutes, set privilegeExpire as 600(seconds). This value must not
80
+ * exceed the token expiration value; otherwise, the privilege is limited by the token expiration time.
71
81
  * @return The RTC Token.
72
82
  */
73
83
  static buildTokenWithUserAccount(
@@ -128,15 +138,25 @@ class RtcTokenBuilder {
128
138
  * - "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", " {", "}", "|", "~", ",".
129
139
  * @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.
130
140
  * @param tokenExpire represented by the number of seconds elapsed since now. If, for example, you want to access the
131
- * Agora Service within 10 minutes after the token is generated, set tokenExpire as 600(seconds).
141
+ * Agora Service within 10 minutes after the token is generated, set tokenExpire as 600(seconds). This is
142
+ * the whole token expiration. The whole token is invalid after this time, even if a privilege expiration
143
+ * time is later.
132
144
  * @param joinChannelPrivilegeExpire represented by the number of seconds elapsed since now.
133
- * If, for example, you want to join channel and expect stay in the channel for 10 minutes, set joinChannelPrivilegeExpire as 600(seconds).
145
+ * If, for example, you want to join channel and expect stay in the channel for 10 minutes, set
146
+ * joinChannelPrivilegeExpire as 600(seconds). This value must not exceed the token expiration value;
147
+ * otherwise, the privilege is limited by the token expiration time.
134
148
  * @param pubAudioPrivilegeExpire represented by the number of seconds elapsed since now.
135
- * If, for example, you want to enable publish audio privilege for 10 minutes, set pubAudioPrivilegeExpire as 600(seconds).
149
+ * If, for example, you want to enable publish audio privilege for 10 minutes, set pubAudioPrivilegeExpire
150
+ * as 600(seconds). This value must not exceed the token expiration value; otherwise, the privilege is
151
+ * limited by the token expiration time.
136
152
  * @param pubVideoPrivilegeExpire represented by the number of seconds elapsed since now.
137
- * If, for example, you want to enable publish video privilege for 10 minutes, set pubVideoPrivilegeExpire as 600(seconds).
153
+ * If, for example, you want to enable publish video privilege for 10 minutes, set pubVideoPrivilegeExpire
154
+ * as 600(seconds). This value must not exceed the token expiration value; otherwise, the privilege is
155
+ * limited by the token expiration time.
138
156
  * @param pubDataStreamPrivilegeExpire represented by the number of seconds elapsed since now.
139
- * If, for example, you want to enable publish data stream privilege for 10 minutes, set pubDataStreamPrivilegeExpire as 600(seconds).
157
+ * If, for example, you want to enable publish data stream privilege for 10 minutes, set
158
+ * pubDataStreamPrivilegeExpire as 600(seconds). This value must not exceed the token expiration value;
159
+ * otherwise, the privilege is limited by the token expiration time.
140
160
  * @return The RTC Token
141
161
  */
142
162
  static buildTokenWithUidAndPrivilege(
@@ -198,15 +218,25 @@ class RtcTokenBuilder {
198
218
  * - "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", " {", "}", "|", "~", ",".
199
219
  * @param userAccount The user account.
200
220
  * @param tokenExpire represented by the number of seconds elapsed since now. If, for example, you want to access the
201
- * Agora Service within 10 minutes after the token is generated, set tokenExpire as 600(seconds).
221
+ * Agora Service within 10 minutes after the token is generated, set tokenExpire as 600(seconds). This is
222
+ * the whole token expiration. The whole token is invalid after this time, even if a privilege expiration
223
+ * time is later.
202
224
  * @param joinChannelPrivilegeExpire represented by the number of seconds elapsed since now.
203
- * If, for example, you want to join channel and expect stay in the channel for 10 minutes, set joinChannelPrivilegeExpire as 600(seconds).
225
+ * If, for example, you want to join channel and expect stay in the channel for 10 minutes, set
226
+ * joinChannelPrivilegeExpire as 600(seconds). This value must not exceed the token expiration value;
227
+ * otherwise, the privilege is limited by the token expiration time.
204
228
  * @param pubAudioPrivilegeExpire represented by the number of seconds elapsed since now.
205
- * If, for example, you want to enable publish audio privilege for 10 minutes, set pubAudioPrivilegeExpire as 600(seconds).
229
+ * If, for example, you want to enable publish audio privilege for 10 minutes, set pubAudioPrivilegeExpire
230
+ * as 600(seconds). This value must not exceed the token expiration value; otherwise, the privilege is
231
+ * limited by the token expiration time.
206
232
  * @param pubVideoPrivilegeExpire represented by the number of seconds elapsed since now.
207
- * If, for example, you want to enable publish video privilege for 10 minutes, set pubVideoPrivilegeExpire as 600(seconds).
233
+ * If, for example, you want to enable publish video privilege for 10 minutes, set pubVideoPrivilegeExpire
234
+ * as 600(seconds). This value must not exceed the token expiration value; otherwise, the privilege is
235
+ * limited by the token expiration time.
208
236
  * @param pubDataStreamPrivilegeExpire represented by the number of seconds elapsed since now.
209
- * If, for example, you want to enable publish data stream privilege for 10 minutes, set pubDataStreamPrivilegeExpire as 600(seconds).
237
+ * If, for example, you want to enable publish data stream privilege for 10 minutes, set
238
+ * pubDataStreamPrivilegeExpire as 600(seconds). This value must not exceed the token expiration value;
239
+ * otherwise, the privilege is limited by the token expiration time.
210
240
  * @return The RTC Token.
211
241
  */
212
242
  static BuildTokenWithUserAccountAndPrivilege(
@@ -246,8 +276,13 @@ class RtcTokenBuilder {
246
276
  * @param {*} role See #userRole.
247
277
  * - Role.PUBLISHER; RECOMMENDED. Use this role for a voice/video call or a live broadcast.
248
278
  * - Role.SUBSCRIBER: ONLY use this role if your live-broadcast scenario requires authentication for [Co-host](https://docs.agora.io/en/video-calling/get-started/authentication-workflow?#co-host-token-authentication). In order for this role to take effect, please contact our support team to enable authentication for Co-host for you. Otherwise, Role_Subscriber still has the same privileges as Role_Publisher.
249
- * @param {*} tokenExpire epresented 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 tokenExpire as 600(seconds)
250
- * @param {*} privilegeExpire represented by the number of seconds elapsed since now. If, for example, you want to enable your privilege for 10 minutes, set privilegeExpire as 600(seconds).
279
+ * @param {*} tokenExpire represented by the number of seconds elapsed since now. If, for example, you
280
+ * want to access the Agora Service within 10 minutes after the token is generated, set tokenExpire as
281
+ * 600(seconds). This is the whole token expiration. The whole token is invalid after this time, even if a
282
+ * privilege expiration time is later.
283
+ * @param {*} privilegeExpire represented by the number of seconds elapsed since now. If, for example, you
284
+ * want to enable your privilege for 10 minutes, set privilegeExpire as 600(seconds). This value must not
285
+ * exceed the token expiration value; otherwise, the privilege is limited by the token expiration time.
251
286
  * @return The RTC and RTM Token.
252
287
  */
253
288
  static buildTokenWithRtm(appId, appCertificate, channelName, account, role, tokenExpire, privilegeExpire = 0) {
@@ -268,6 +303,79 @@ class RtcTokenBuilder {
268
303
 
269
304
  return token.build()
270
305
  }
306
+
307
+ /**
308
+ * Build an RTC and RTM token with account.
309
+ * @param {*} appId The App ID issued to you by Agora.
310
+ * @param {*} appCertificate Certificate of the application that you registered in the Agora Dashboard.
311
+ * @param {*} channelName 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:
312
+ * - The 26 lowercase English letters: a to z.
313
+ * - The 26 uppercase English letters: A to Z.
314
+ * - The 10 digits: 0 to 9.
315
+ * - The space.
316
+ * - "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", " {", "}", "|", "~", ",".
317
+ * @param {*} rtcAccount The RTC user's account, max length is 255 Bytes.
318
+ * @param {*} rtcRole See #userRole.
319
+ * - Role.PUBLISHER; RECOMMENDED. Use this role for a voice/video call or a live broadcast.
320
+ * - Role.SUBSCRIBER: ONLY use this role if your live-broadcast scenario requires authentication for [Co-host](https://docs.agora.io/en/video-calling/get-started/authentication-workflow?#co-host-token-authentication). In order for this role to take effect, please contact our support team to enable authentication for Co-host for you. Otherwise, Role_Subscriber still has the same privileges as Role_Publisher.
321
+ * @param {*} rtcTokenExpire represented by the number of seconds elapsed since now. If, for example, you
322
+ * want to access the Agora Service within 10 minutes after the token is generated, set rtcTokenExpire as
323
+ * 600(seconds). This is the whole token expiration. The whole token is invalid after this time, even if a
324
+ * privilege expiration time is later.
325
+ * @param {*} joinChannelPrivilegeExpire represented by the number of seconds elapsed since now.
326
+ * If, for example, you want to join channel and expect stay in the channel for 10 minutes, set
327
+ * joinChannelPrivilegeExpire as 600(seconds). This value must not exceed the token expiration value;
328
+ * otherwise, the privilege is limited by the token expiration time.
329
+ * @param {*} pubAudioPrivilegeExpire represented by the number of seconds elapsed since now.
330
+ * If, for example, you want to enable publish audio privilege for 10 minutes, set pubAudioPrivilegeExpire
331
+ * as 600(seconds). This value must not exceed the token expiration value; otherwise, the privilege is
332
+ * limited by the token expiration time.
333
+ * @param {*} pubVideoPrivilegeExpire represented by the number of seconds elapsed since now.
334
+ * If, for example, you want to enable publish video privilege for 10 minutes, set pubVideoPrivilegeExpire
335
+ * as 600(seconds). This value must not exceed the token expiration value; otherwise, the privilege is
336
+ * limited by the token expiration time.
337
+ * @param {*} pubDataStreamPrivilegeExpire represented by the number of seconds elapsed since now.
338
+ * If, for example, you want to enable publish data stream privilege for 10 minutes, set
339
+ * pubDataStreamPrivilegeExpire as 600(seconds). This value must not exceed the token expiration value;
340
+ * otherwise, the privilege is limited by the token expiration time.
341
+ * @param {*} rtmUserId: The RTM user's account, max length is 255 Bytes.
342
+ * @param {*} rtmTokenExpire: represented by the number of seconds elapsed since now. If, for example,
343
+ * you want to access the Agora Service within 10 minutes after the token is generated, set rtmTokenExpire
344
+ * as 600(seconds). This value must not exceed the RTC token expiration value; otherwise, the RTM login
345
+ * privilege is limited by the token expiration time.
346
+ * * @return The RTC and RTM Token.
347
+ */
348
+ static buildTokenWithRtm2(
349
+ appId,
350
+ appCertificate,
351
+ channelName,
352
+ rtcAccount,
353
+ rtcRole,
354
+ rtcTokenExpire,
355
+ joinChannelPrivilegeExpire,
356
+ pubAudioPrivilegeExpire,
357
+ pubVideoPrivilegeExpire,
358
+ pubDataStreamPrivilegeExpire,
359
+ rtmUserId,
360
+ rtmTokenExpire
361
+ ) {
362
+ let token = new AccessToken(appId, appCertificate, 0, rtcTokenExpire)
363
+
364
+ let serviceRtc = new ServiceRtc(channelName, rtcAccount)
365
+ serviceRtc.add_privilege(ServiceRtc.kPrivilegeJoinChannel, joinChannelPrivilegeExpire)
366
+ if (rtcRole == Role.PUBLISHER) {
367
+ serviceRtc.add_privilege(ServiceRtc.kPrivilegePublishAudioStream, pubAudioPrivilegeExpire)
368
+ serviceRtc.add_privilege(ServiceRtc.kPrivilegePublishVideoStream, pubVideoPrivilegeExpire)
369
+ serviceRtc.add_privilege(ServiceRtc.kPrivilegePublishDataStream, pubDataStreamPrivilegeExpire)
370
+ }
371
+ token.add_service(serviceRtc)
372
+
373
+ let serviceRtm = new ServiceRtm(rtmUserId)
374
+ serviceRtm.add_privilege(ServiceRtm.kPrivilegeLogin, rtmTokenExpire)
375
+ token.add_service(serviceRtm)
376
+
377
+ return token.build()
378
+ }
271
379
  }
272
380
 
273
381
  module.exports.RtcTokenBuilder = RtcTokenBuilder
@@ -1,5 +1,6 @@
1
1
  const AccessToken = require('../src/AccessToken2').AccessToken2
2
2
  const ServiceRtm = require('../src/AccessToken2').ServiceRtm
3
+ const ServiceRtm2 = require('../src/AccessToken2').ServiceRtm2
3
4
 
4
5
  class RtmTokenBuilder {
5
6
  /**
@@ -11,7 +12,9 @@ class RtmTokenBuilder {
11
12
  * the Agora Dashboard. See Get an App Certificate.
12
13
  * @param userId The user's account, max length is 64 Bytes.
13
14
  * @param expire represented by the number of seconds elapsed since now. If, for example, you want to access the
14
- * Agora Service within 10 minutes after the token is generated, set expire as 600(seconds).
15
+ * Agora Service within 10 minutes after the token is generated, set expire as 600(seconds). This value is
16
+ * the whole token expiration and the service privilege expiration. The whole token is invalid after this
17
+ * time.
15
18
  * @return The RTM token.
16
19
  */
17
20
  static buildToken(appId, appCertificate, userId, expire) {
@@ -23,6 +26,27 @@ class RtmTokenBuilder {
23
26
 
24
27
  return token.build()
25
28
  }
29
+
30
+ /**
31
+ * Build an RTM2 token with resource-level permissions.
32
+ *
33
+ * This special interface requires Agora assistance for proper usage.
34
+ *
35
+ * @param appId The App ID issued to you by Agora.
36
+ * @param appCertificate Certificate of the application registered in the Agora Dashboard.
37
+ * @param userId The user's account, max length is 64 bytes.
38
+ * @param permissions The RTM2 resource-level permissions.
39
+ * @param expire The number of seconds from now before the token expires. This value is the whole token
40
+ * expiration and the service privilege expiration. The whole token is invalid after this time.
41
+ * @return The RTM2 token.
42
+ */
43
+ static buildTokenWithPermissions(appId, appCertificate, userId, permissions, expire) {
44
+ const token = new AccessToken(appId, appCertificate, null, expire)
45
+ const serviceRtm2 = new ServiceRtm2(userId, permissions)
46
+ serviceRtm2.add_privilege(ServiceRtm2.kPrivilegeLogin, expire)
47
+ token.add_service(serviceRtm2)
48
+ return token.build()
49
+ }
26
50
  }
27
51
 
28
52
  module.exports.RtmTokenBuilder = RtmTokenBuilder
@@ -0,0 +1,68 @@
1
+ const AccessToken = require('../src/AccessToken2').AccessToken2
2
+ const ServiceRtc = require('../src/AccessToken2').ServiceRtc
3
+ const ServiceRtm = require('../src/AccessToken2').ServiceRtm
4
+ const ServiceStt = require('../src/AccessToken2').ServiceStt
5
+ const Role = require('../src/RtcTokenBuilder2').Role
6
+
7
+ class SttTokenBuilder {
8
+ /**
9
+ * Builds a Token007 that carries RTC, RTM, and STT services.
10
+ * @param {*} appId The App ID issued to you by Agora.
11
+ * @param {*} appCertificate Certificate of the application that you registered in the Agora Dashboard.
12
+ * @param {*} channelName The unique channel name for the AgoraRTC session in the string format.
13
+ * @param {*} rtcAccount The RTC user's account, max length is 255 bytes.
14
+ * @param {*} rtcRole Role.PUBLISHER for a broadcaster or Role.SUBSCRIBER for an audience member.
15
+ * @param {*} rtcTokenExpire Represented by the number of seconds elapsed since now. This is the whole
16
+ * token expiration. The whole token is invalid after this time, even if a privilege expiration time is
17
+ * later.
18
+ * @param {*} joinChannelPrivilegeExpire Represented by the number of seconds elapsed since now. This
19
+ * value must not exceed rtcTokenExpire; otherwise, the privilege is limited by the token expiration time.
20
+ * @param {*} pubAudioPrivilegeExpire Represented by the number of seconds elapsed since now. This value
21
+ * must not exceed rtcTokenExpire; otherwise, the privilege is limited by the token expiration time.
22
+ * @param {*} pubVideoPrivilegeExpire Represented by the number of seconds elapsed since now. This value
23
+ * must not exceed rtcTokenExpire; otherwise, the privilege is limited by the token expiration time.
24
+ * @param {*} pubDataStreamPrivilegeExpire Represented by the number of seconds elapsed since now. This
25
+ * value must not exceed rtcTokenExpire; otherwise, the privilege is limited by the token expiration time.
26
+ * @param {*} rtmUserId The RTM user's account, max length is 255 bytes.
27
+ * @param {*} rtmTokenExpire Represented by the number of seconds elapsed since now. This value must not
28
+ * exceed rtcTokenExpire; otherwise, the RTM login privilege is limited by the token expiration time.
29
+ * @return The RTC, RTM, and STT token.
30
+ */
31
+ static buildToken(
32
+ appId,
33
+ appCertificate,
34
+ channelName,
35
+ rtcAccount,
36
+ rtcRole,
37
+ rtcTokenExpire,
38
+ joinChannelPrivilegeExpire,
39
+ pubAudioPrivilegeExpire,
40
+ pubVideoPrivilegeExpire,
41
+ pubDataStreamPrivilegeExpire,
42
+ rtmUserId,
43
+ rtmTokenExpire
44
+ ) {
45
+ const token = new AccessToken(appId, appCertificate, 0, rtcTokenExpire)
46
+
47
+ const serviceRtc = new ServiceRtc(channelName, rtcAccount)
48
+ serviceRtc.add_privilege(ServiceRtc.kPrivilegeJoinChannel, joinChannelPrivilegeExpire)
49
+ if (rtcRole === Role.PUBLISHER) {
50
+ serviceRtc.add_privilege(ServiceRtc.kPrivilegePublishAudioStream, pubAudioPrivilegeExpire)
51
+ serviceRtc.add_privilege(ServiceRtc.kPrivilegePublishVideoStream, pubVideoPrivilegeExpire)
52
+ serviceRtc.add_privilege(ServiceRtc.kPrivilegePublishDataStream, pubDataStreamPrivilegeExpire)
53
+ }
54
+ token.add_service(serviceRtc)
55
+
56
+ const serviceRtm = new ServiceRtm(rtmUserId)
57
+ serviceRtm.add_privilege(ServiceRtm.kPrivilegeLogin, rtmTokenExpire)
58
+ token.add_service(serviceRtm)
59
+
60
+ token.add_service(new ServiceStt())
61
+
62
+ return token.build()
63
+ }
64
+ }
65
+
66
+ module.exports = {
67
+ SttTokenBuilder
68
+ }