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.
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "AgoraDynamicKey-nodejs",
3
+ "image": "node:22.4",
4
+ "customizations": {
5
+ "vscode": {
6
+ "extensions": [
7
+ "swellaby.node-pack",
8
+ "esbenp.prettier-vscode"
9
+ ],
10
+ "settings": {
11
+ "[javascript]": {
12
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
13
+ },
14
+ "[typescript]": {
15
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
16
+ }
17
+ }
18
+ }
19
+ },
20
+ "workspaceMount": "source=${localWorkspaceFolder},target=/app,type=bind",
21
+ "workspaceFolder": "/app"
22
+ }
package/.prettierrc ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "arrowParens": "avoid",
3
+ "bracketSameLine": false,
4
+ "bracketSpacing": true,
5
+ "jsxSingleQuote": false,
6
+ "printWidth": 120,
7
+ "semi": false,
8
+ "singleQuote": true,
9
+ "tabWidth": 4,
10
+ "trailingComma": "none",
11
+ "useTabs": false
12
+ }
package/index.d.ts CHANGED
@@ -1,3 +1,19 @@
1
+ /** Stores RTM2 resource-level permissions. */
2
+ export class Rtm2Permissions {
3
+ static readonly kMessageChannels: number
4
+ static readonly kStreamChannels: number
5
+ static readonly kGroupChannels: number
6
+ static readonly kServerGroups: number
7
+ static readonly kUsers: number
8
+ static readonly kRead: number
9
+ static readonly kWrite: number
10
+
11
+ details: { [resourceType: number]: { [permissionType: number]: string[] } }
12
+
13
+ /** Adds or replaces resources for a resource and permission type. */
14
+ add(resourceType: number, permissionType: number, resources: string[]): void
15
+ }
16
+
1
17
  export namespace ApaasTokenBuilder {
2
18
  /**
3
19
  * build user room token
@@ -9,7 +25,9 @@ export namespace ApaasTokenBuilder {
9
25
  * @param userUuid The user's id, must be unique.
10
26
  * @param role The user's role.
11
27
  * @param expire represented by the number of seconds elapsed since now. If, for example, you want to access the
12
- * Agora Service within 10 minutes after the token is generated, set expire as 600(seconds).
28
+ * Agora Service within 10 minutes after the token is generated, set expire as
29
+ * 600(seconds). This value is the whole token expiration and the service
30
+ * privilege expiration. The whole token is invalid after this time.
13
31
  * @return The user room token.
14
32
  */
15
33
  export function buildRoomUserToken(
@@ -29,7 +47,9 @@ export namespace ApaasTokenBuilder {
29
47
  * the Agora Dashboard. See Get an App Certificate.
30
48
  * @param userUuid The user's id, must be unique.
31
49
  * @param expire represented by the number of seconds elapsed since now. If, for example, you want to access the
32
- * 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.
33
53
  * @return The user token.
34
54
  */
35
55
  export function buildUserToken(
@@ -46,7 +66,9 @@ export namespace ApaasTokenBuilder {
46
66
  * @param appCertificate Certificate of the application that you registered in
47
67
  * the Agora Dashboard. See Get an App Certificate.
48
68
  * @param expire represented by the number of seconds elapsed since now. If, for example, you want to access the
49
- * Agora Service within 10 minutes after the token is generated, set expire as 600(seconds).
69
+ * Agora Service within 10 minutes after the token is generated, set expire as
70
+ * 600(seconds). This value is the whole token expiration and the service privilege
71
+ * expiration. The whole token is invalid after this time.
50
72
  * @return The app token.
51
73
  */
52
74
  export function buildAppToken(appId: string, appCertificate: string, expire: number): string
@@ -62,7 +84,9 @@ export namespace ChatTokenBuilder {
62
84
  * the Agora Dashboard. See Get an App Certificate.
63
85
  * @param userUuid The user's id, must be unique.
64
86
  * @param expire represented by the number of seconds elapsed since now. If, for example, you want to access the
65
- * Agora Service within 10 minutes after the token is generated, set expire as 600(seconds).
87
+ * Agora Service within 10 minutes after the token is generated, set expire as 600(seconds). This value is
88
+ * the whole token expiration and the service privilege expiration. The whole token is invalid after this
89
+ * time.
66
90
  * @return The chat user token.
67
91
  */
68
92
  export function buildUserToken(
@@ -80,7 +104,9 @@ export namespace ChatTokenBuilder {
80
104
  * @param appCertificate Certificate of the application that you registered in
81
105
  * the Agora Dashboard. See Get an App Certificate.
82
106
  * @param expire represented by the number of seconds elapsed since now. If, for example, you want to access the
83
- * Agora Service within 10 minutes after the token is generated, set expire as 600(seconds).
107
+ * Agora Service within 10 minutes after the token is generated, set expire as 600(seconds). This value is
108
+ * the whole token expiration and the service privilege expiration. The whole token is invalid after this
109
+ * time.
84
110
  * @return The chat App token.
85
111
  */
86
112
  export function buildAppToken(appId: string, appCertificate: string, expire: number): string
@@ -97,7 +123,9 @@ export namespace EducationTokenBuilder {
97
123
  * @param userUuid The user's id, must be unique.
98
124
  * @param role The user's role.
99
125
  * @param expire represented by the number of seconds elapsed since now. If, for example, you want to access the
100
- * Agora Service within 10 minutes after the token is generated, set expire as 600(seconds).
126
+ * Agora Service within 10 minutes after the token is generated, set expire as
127
+ * 600(seconds). This value is the whole token expiration and the service
128
+ * privilege expiration. The whole token is invalid after this time.
101
129
  * @return The user room token.
102
130
  */
103
131
  export function buildRoomUserToken(
@@ -117,7 +145,9 @@ export namespace EducationTokenBuilder {
117
145
  * the Agora Dashboard. See Get an App Certificate.
118
146
  * @param userUuid The user's id, must be unique.
119
147
  * @param expire represented by the number of seconds elapsed since now. If, for example, you want to access the
120
- * Agora Service within 10 minutes after the token is generated, set expire as 600(seconds).
148
+ * Agora Service within 10 minutes after the token is generated, set expire as
149
+ * 600(seconds). This value is the whole token expiration and the service
150
+ * privilege expiration. The whole token is invalid after this time.
121
151
  * @return The user token.
122
152
  */
123
153
  export function buildUserToken(
@@ -134,7 +164,9 @@ export namespace EducationTokenBuilder {
134
164
  * @param appCertificate Certificate of the application that you registered in
135
165
  * the Agora Dashboard. See Get an App Certificate.
136
166
  * @param expire represented by the number of seconds elapsed since now. If, for example, you want to access the
137
- * Agora Service within 10 minutes after the token is generated, set expire as 600(seconds).
167
+ * Agora Service within 10 minutes after the token is generated, set expire as
168
+ * 600(seconds). This value is the whole token expiration and the service privilege
169
+ * expiration. The whole token is invalid after this time.
138
170
  * @return The app token.
139
171
  */
140
172
  export function buildAppToken(appId: string, appCertificate: string, expire: number): string
@@ -147,7 +179,7 @@ export namespace FpaTokenBuilder {
147
179
  * Agora Dashboard if it is missing from your kit. See Get an App ID.
148
180
  * @param appCertificate Certificate of the application that you registered in
149
181
  * the Agora Dashboard. See Get an App Certificate.
150
- * @return The FPA token.
182
+ * @return The FPA token. The token expires 24 hours after generation.
151
183
  */
152
184
  export function buildToken(appId: string, appCertificate: string): string
153
185
  }
@@ -172,8 +204,13 @@ export namespace RtcTokenBuilder {
172
204
  * @param {*} role See #userRole.
173
205
  * - Role.PUBLISHER; RECOMMENDED. Use this role for a voice/video call or a live broadcast.
174
206
  * - 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.
175
- * @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)
176
- * @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).
207
+ * @param {*} tokenExpire represented by the number of seconds elapsed since now. If, for example, you
208
+ * want to access the Agora Service within 10 minutes after the token is generated, set tokenExpire as
209
+ * 600(seconds). This is the whole token expiration. The whole token is invalid after this time, even if a
210
+ * privilege expiration time is later.
211
+ * @param {*} privilegeExpire represented by the number of seconds elapsed since now. If, for example, you
212
+ * want to enable your privilege for 10 minutes, set privilegeExpire as 600(seconds). This value must not
213
+ * exceed the token expiration value; otherwise, the privilege is limited by the token expiration time.
177
214
  * @return The RTC Token.
178
215
  */
179
216
  export function buildTokenWithUid(
@@ -200,8 +237,13 @@ export namespace RtcTokenBuilder {
200
237
  * @param {*} role See #userRole.
201
238
  * - Role.PUBLISHER; RECOMMENDED. Use this role for a voice/video call or a live broadcast.
202
239
  * - 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.
203
- * @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)
204
- * @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).
240
+ * @param {*} tokenExpire represented by the number of seconds elapsed since now. If, for example, you
241
+ * want to access the Agora Service within 10 minutes after the token is generated, set tokenExpire as
242
+ * 600(seconds). This is the whole token expiration. The whole token is invalid after this time, even if a
243
+ * privilege expiration time is later.
244
+ * @param {*} privilegeExpire represented by the number of seconds elapsed since now. If, for example, you
245
+ * want to enable your privilege for 10 minutes, set privilegeExpire as 600(seconds). This value must not
246
+ * exceed the token expiration value; otherwise, the privilege is limited by the token expiration time.
205
247
  * @return The RTC Token.
206
248
  */
207
249
  export function buildTokenWithUserAccount(
@@ -249,15 +291,25 @@ export namespace RtcTokenBuilder {
249
291
  * - "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", " {", "}", "|", "~", ",".
250
292
  * @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.
251
293
  * @param tokenExpire represented by the number of seconds elapsed since now. If, for example, you want to access the
252
- * Agora Service within 10 minutes after the token is generated, set tokenExpire as 600(seconds).
294
+ * Agora Service within 10 minutes after the token is generated, set tokenExpire as 600(seconds). This is
295
+ * the whole token expiration. The whole token is invalid after this time, even if a privilege expiration
296
+ * time is later.
253
297
  * @param joinChannelPrivilegeExpire represented by the number of seconds elapsed since now.
254
- * If, for example, you want to join channel and expect stay in the channel for 10 minutes, set joinChannelPrivilegeExpire as 600(seconds).
298
+ * If, for example, you want to join channel and expect stay in the channel for 10 minutes, set
299
+ * joinChannelPrivilegeExpire as 600(seconds). This value must not exceed the token expiration value;
300
+ * otherwise, the privilege is limited by the token expiration time.
255
301
  * @param pubAudioPrivilegeExpire represented by the number of seconds elapsed since now.
256
- * If, for example, you want to enable publish audio privilege for 10 minutes, set pubAudioPrivilegeExpire as 600(seconds).
302
+ * If, for example, you want to enable publish audio privilege for 10 minutes, set pubAudioPrivilegeExpire
303
+ * as 600(seconds). This value must not exceed the token expiration value; otherwise, the privilege is
304
+ * limited by the token expiration time.
257
305
  * @param pubVideoPrivilegeExpire represented by the number of seconds elapsed since now.
258
- * If, for example, you want to enable publish video privilege for 10 minutes, set pubVideoPrivilegeExpire as 600(seconds).
306
+ * If, for example, you want to enable publish video privilege for 10 minutes, set pubVideoPrivilegeExpire
307
+ * as 600(seconds). This value must not exceed the token expiration value; otherwise, the privilege is
308
+ * limited by the token expiration time.
259
309
  * @param pubDataStreamPrivilegeExpire represented by the number of seconds elapsed since now.
260
- * If, for example, you want to enable publish data stream privilege for 10 minutes, set pubDataStreamPrivilegeExpire as 600(seconds).
310
+ * If, for example, you want to enable publish data stream privilege for 10 minutes, set
311
+ * pubDataStreamPrivilegeExpire as 600(seconds). This value must not exceed the token expiration value;
312
+ * otherwise, the privilege is limited by the token expiration time.
261
313
  * @return The RTC Token
262
314
  */
263
315
  export function buildTokenWithUidAndPrivilege(
@@ -307,15 +359,25 @@ export namespace RtcTokenBuilder {
307
359
  * - "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", " {", "}", "|", "~", ",".
308
360
  * @param userAccount The user account.
309
361
  * @param tokenExpire represented by the number of seconds elapsed since now. If, for example, you want to access the
310
- * Agora Service within 10 minutes after the token is generated, set tokenExpire as 600(seconds).
362
+ * Agora Service within 10 minutes after the token is generated, set tokenExpire as 600(seconds). This is
363
+ * the whole token expiration. The whole token is invalid after this time, even if a privilege expiration
364
+ * time is later.
311
365
  * @param joinChannelPrivilegeExpire represented by the number of seconds elapsed since now.
312
- * If, for example, you want to join channel and expect stay in the channel for 10 minutes, set joinChannelPrivilegeExpire as 600(seconds).
366
+ * If, for example, you want to join channel and expect stay in the channel for 10 minutes, set
367
+ * joinChannelPrivilegeExpire as 600(seconds). This value must not exceed the token expiration value;
368
+ * otherwise, the privilege is limited by the token expiration time.
313
369
  * @param pubAudioPrivilegeExpire represented by the number of seconds elapsed since now.
314
- * If, for example, you want to enable publish audio privilege for 10 minutes, set pubAudioPrivilegeExpire as 600(seconds).
370
+ * If, for example, you want to enable publish audio privilege for 10 minutes, set pubAudioPrivilegeExpire
371
+ * as 600(seconds). This value must not exceed the token expiration value; otherwise, the privilege is
372
+ * limited by the token expiration time.
315
373
  * @param pubVideoPrivilegeExpire represented by the number of seconds elapsed since now.
316
- * If, for example, you want to enable publish video privilege for 10 minutes, set pubVideoPrivilegeExpire as 600(seconds).
374
+ * If, for example, you want to enable publish video privilege for 10 minutes, set pubVideoPrivilegeExpire
375
+ * as 600(seconds). This value must not exceed the token expiration value; otherwise, the privilege is
376
+ * limited by the token expiration time.
317
377
  * @param pubDataStreamPrivilegeExpire represented by the number of seconds elapsed since now.
318
- * If, for example, you want to enable publish data stream privilege for 10 minutes, set pubDataStreamPrivilegeExpire as 600(seconds).
378
+ * If, for example, you want to enable publish data stream privilege for 10 minutes, set
379
+ * pubDataStreamPrivilegeExpire as 600(seconds). This value must not exceed the token expiration value;
380
+ * otherwise, the privilege is limited by the token expiration time.
319
381
  * @return The RTC Token.
320
382
  */
321
383
  export function BuildTokenWithUserAccountAndPrivilege(
@@ -344,8 +406,13 @@ export namespace RtcTokenBuilder {
344
406
  * @param {*} role See #userRole.
345
407
  * - Role.PUBLISHER; RECOMMENDED. Use this role for a voice/video call or a live broadcast.
346
408
  * - 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.
347
- * @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)
348
- * @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).
409
+ * @param {*} tokenExpire represented by the number of seconds elapsed since now. If, for example, you
410
+ * want to access the Agora Service within 10 minutes after the token is generated, set tokenExpire as
411
+ * 600(seconds). This is the whole token expiration. The whole token is invalid after this time, even if a
412
+ * privilege expiration time is later.
413
+ * @param {*} privilegeExpire represented by the number of seconds elapsed since now. If, for example, you
414
+ * want to enable your privilege for 10 minutes, set privilegeExpire as 600(seconds). This value must not
415
+ * exceed the token expiration value; otherwise, the privilege is limited by the token expiration time.
349
416
  * @return The RTC and RTM Token.
350
417
  */
351
418
  export function buildTokenWithRtm(
@@ -357,6 +424,150 @@ export namespace RtcTokenBuilder {
357
424
  tokenExpire: number,
358
425
  privilegeExpire: number
359
426
  ): string
427
+
428
+ /**
429
+ * Build an RTC and RTM token with account.
430
+ * @param {*} appId The App ID issued to you by Agora.
431
+ * @param {*} appCertificate Certificate of the application that you registered in the Agora Dashboard.
432
+ * @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:
433
+ * - The 26 lowercase English letters: a to z.
434
+ * - The 26 uppercase English letters: A to Z.
435
+ * - The 10 digits: 0 to 9.
436
+ * - The space.
437
+ * - "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", " {", "}", "|", "~", ",".
438
+ * @param {*} rtcAccount The RTC user's account, max length is 255 Bytes.
439
+ * @param {*} rtcRole See #userRole.
440
+ * - Role.PUBLISHER; RECOMMENDED. Use this role for a voice/video call or a live broadcast.
441
+ * - 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.
442
+ * @param {*} rtcTokenExpire represented by the number of seconds elapsed since now. If, for example, you
443
+ * want to access the Agora Service within 10 minutes after the token is generated, set rtcTokenExpire as
444
+ * 600(seconds). This is the whole token expiration. The whole token is invalid after this time, even if a
445
+ * privilege expiration time is later.
446
+ * @param {*} joinChannelPrivilegeExpire represented by the number of seconds elapsed since now.
447
+ * If, for example, you want to join channel and expect stay in the channel for 10 minutes, set
448
+ * joinChannelPrivilegeExpire as 600(seconds). This value must not exceed the token expiration value;
449
+ * otherwise, the privilege is limited by the token expiration time.
450
+ * @param {*} pubAudioPrivilegeExpire represented by the number of seconds elapsed since now.
451
+ * If, for example, you want to enable publish audio privilege for 10 minutes, set pubAudioPrivilegeExpire
452
+ * as 600(seconds). This value must not exceed the token expiration value; otherwise, the privilege is
453
+ * limited by the token expiration time.
454
+ * @param {*} pubVideoPrivilegeExpire represented by the number of seconds elapsed since now.
455
+ * If, for example, you want to enable publish video privilege for 10 minutes, set pubVideoPrivilegeExpire
456
+ * as 600(seconds). This value must not exceed the token expiration value; otherwise, the privilege is
457
+ * limited by the token expiration time.
458
+ * @param {*} pubDataStreamPrivilegeExpire represented by the number of seconds elapsed since now.
459
+ * If, for example, you want to enable publish data stream privilege for 10 minutes, set
460
+ * pubDataStreamPrivilegeExpire as 600(seconds). This value must not exceed the token expiration value;
461
+ * otherwise, the privilege is limited by the token expiration time.
462
+ * @param rtmUserId: The RTM user's account, max length is 255 Bytes.
463
+ * @param rtmTokenExpire: represented by the number of seconds elapsed since now. If, for example,
464
+ * you want to access the Agora Service within 10 minutes after the token is generated, set rtmTokenExpire
465
+ * as 600(seconds). This value must not exceed the RTC token expiration value; otherwise, the RTM login
466
+ * privilege is limited by the token expiration time.
467
+ * * @return The RTC and RTM Token.
468
+ */
469
+ export function buildTokenWithRtm2(
470
+ appId: string,
471
+ appCertificate: string,
472
+ channelName: string,
473
+ rtcAccount: string | number,
474
+ rtcRole: number,
475
+ rtcTokenExpire: number,
476
+ joinChannelPrivilegeExpire: number,
477
+ pubAudioPrivilegeExpire: number,
478
+ pubVideoPrivilegeExpire: number,
479
+ pubDataStreamPrivilegeExpire: number,
480
+ rtmUserId: string | number,
481
+ rtmTokenExpire: number
482
+ ): string
483
+ }
484
+
485
+ export namespace ConvoAITokenBuilder {
486
+ /**
487
+ * Builds a Token007 that carries RTC, RTM, and ConvoAI services.
488
+ * @param appId The App ID issued to you by Agora.
489
+ * @param appCertificate Certificate of the application that you registered in the Agora Dashboard.
490
+ * @param channelName The unique channel name for the AgoraRTC session in the string format.
491
+ * @param rtcAccount The RTC user's account, max length is 255 bytes.
492
+ * @param rtcRole RtcRole.PUBLISHER for a broadcaster or RtcRole.SUBSCRIBER for an audience member.
493
+ * @param rtcTokenExpire Represented by the number of seconds elapsed since now. This is the whole token
494
+ * expiration. The whole token is invalid after this time, even if a privilege expiration time is later.
495
+ * @param joinChannelPrivilegeExpire Represented by the number of seconds elapsed since now. This value
496
+ * must not exceed the token expiration value; otherwise, the privilege is limited by the token expiration
497
+ * time.
498
+ * @param pubAudioPrivilegeExpire Represented by the number of seconds elapsed since now. This value must
499
+ * not exceed the token expiration value; otherwise, the privilege is limited by the token expiration
500
+ * time.
501
+ * @param pubVideoPrivilegeExpire Represented by the number of seconds elapsed since now. This value must
502
+ * not exceed the token expiration value; otherwise, the privilege is limited by the token expiration
503
+ * time.
504
+ * @param pubDataStreamPrivilegeExpire Represented by the number of seconds elapsed since now. This value
505
+ * must not exceed the token expiration value; otherwise, the privilege is limited by the token expiration
506
+ * time.
507
+ * @param rtmUserId The RTM user's account, max length is 255 bytes.
508
+ * @param rtmTokenExpire Represented by the number of seconds elapsed since now. This value must not
509
+ * exceed the RTC token expiration value; otherwise, the RTM login privilege is limited by the token
510
+ * expiration time.
511
+ * @return The RTC, RTM, and ConvoAI token.
512
+ */
513
+ export function buildToken(
514
+ appId: string,
515
+ appCertificate: string,
516
+ channelName: string,
517
+ rtcAccount: string | number,
518
+ rtcRole: number,
519
+ rtcTokenExpire: number,
520
+ joinChannelPrivilegeExpire: number,
521
+ pubAudioPrivilegeExpire: number,
522
+ pubVideoPrivilegeExpire: number,
523
+ pubDataStreamPrivilegeExpire: number,
524
+ rtmUserId: string | number,
525
+ rtmTokenExpire: number
526
+ ): string
527
+ }
528
+
529
+ export namespace SttTokenBuilder {
530
+ /**
531
+ * Builds a Token007 that carries RTC, RTM, and STT services.
532
+ * @param appId The App ID issued to you by Agora.
533
+ * @param appCertificate Certificate of the application that you registered in the Agora Dashboard.
534
+ * @param channelName The unique channel name for the AgoraRTC session in the string format.
535
+ * @param rtcAccount The RTC user's account, max length is 255 bytes.
536
+ * @param rtcRole RtcRole.PUBLISHER for a broadcaster or RtcRole.SUBSCRIBER for an audience member.
537
+ * @param rtcTokenExpire Represented by the number of seconds elapsed since now. This is the whole token
538
+ * expiration. The whole token is invalid after this time, even if a privilege expiration time is later.
539
+ * @param joinChannelPrivilegeExpire Represented by the number of seconds elapsed since now. This value
540
+ * must not exceed the token expiration value; otherwise, the privilege is limited by the token expiration
541
+ * time.
542
+ * @param pubAudioPrivilegeExpire Represented by the number of seconds elapsed since now. This value must
543
+ * not exceed the token expiration value; otherwise, the privilege is limited by the token expiration
544
+ * time.
545
+ * @param pubVideoPrivilegeExpire Represented by the number of seconds elapsed since now. This value must
546
+ * not exceed the token expiration value; otherwise, the privilege is limited by the token expiration
547
+ * time.
548
+ * @param pubDataStreamPrivilegeExpire Represented by the number of seconds elapsed since now. This value
549
+ * must not exceed the token expiration value; otherwise, the privilege is limited by the token expiration
550
+ * time.
551
+ * @param rtmUserId The RTM user's account, max length is 255 bytes.
552
+ * @param rtmTokenExpire Represented by the number of seconds elapsed since now. This value must not
553
+ * exceed the RTC token expiration value; otherwise, the RTM login privilege is limited by the token
554
+ * expiration time.
555
+ * @return The RTC, RTM, and STT token.
556
+ */
557
+ export function buildToken(
558
+ appId: string,
559
+ appCertificate: string,
560
+ channelName: string,
561
+ rtcAccount: string | number,
562
+ rtcRole: number,
563
+ rtcTokenExpire: number,
564
+ joinChannelPrivilegeExpire: number,
565
+ pubAudioPrivilegeExpire: number,
566
+ pubVideoPrivilegeExpire: number,
567
+ pubDataStreamPrivilegeExpire: number,
568
+ rtmUserId: string | number,
569
+ rtmTokenExpire: number
570
+ ): string
360
571
  }
361
572
 
362
573
  export namespace RtmTokenBuilder {
@@ -369,8 +580,31 @@ export namespace RtmTokenBuilder {
369
580
  * the Agora Dashboard. See Get an App Certificate.
370
581
  * @param userId The user's account, max length is 64 Bytes.
371
582
  * @param expire represented by the number of seconds elapsed since now. If, for example, you want to access the
372
- * Agora Service within 10 minutes after the token is generated, set expire as 600(seconds).
583
+ * Agora Service within 10 minutes after the token is generated, set expire as 600(seconds). This value is
584
+ * the whole token expiration and the service privilege expiration. The whole token is invalid after this
585
+ * time.
373
586
  * @return The RTM token.
374
587
  */
375
588
  export function buildToken(appId: string, appCertificate: string, userId: string | number, expire: number): string
589
+
590
+ /**
591
+ * Build an RTM2 token with resource-level permissions.
592
+ *
593
+ * This special interface requires Agora assistance for proper usage.
594
+ *
595
+ * @param appId The App ID issued to you by Agora.
596
+ * @param appCertificate Certificate of the application registered in the Agora Dashboard.
597
+ * @param userId The user's account, max length is 64 bytes.
598
+ * @param permissions The RTM2 resource-level permissions.
599
+ * @param expire The number of seconds from now before the token expires. This value is the whole token
600
+ * expiration and the service privilege expiration. The whole token is invalid after this time.
601
+ * @return The RTM2 token.
602
+ */
603
+ export function buildTokenWithPermissions(
604
+ appId: string,
605
+ appCertificate: string,
606
+ userId: string | number,
607
+ permissions: Rtm2Permissions,
608
+ expire: number
609
+ ): string
376
610
  }
package/index.js CHANGED
@@ -1,9 +1,12 @@
1
1
  module.exports = {
2
2
  ApaasTokenBuilder: require('./src/ApaasTokenBuilder').ApaasTokenBuilder,
3
3
  ChatTokenBuilder: require('./src/ChatTokenBuilder').ChatTokenBuilder,
4
+ ConvoAITokenBuilder: require('./src/ConvoAITokenBuilder').ConvoAITokenBuilder,
4
5
  EducationTokenBuilder: require('./src/EducationTokenBuilder').EducationTokenBuilder,
5
6
  FpaTokenBuilder: require('./src/FpaTokenBuilder').FpaTokenBuilder,
6
7
  RtcRole: require('./src/RtcTokenBuilder2').Role,
7
8
  RtcTokenBuilder: require('./src/RtcTokenBuilder2').RtcTokenBuilder,
8
- RtmTokenBuilder: require('./src/RtmTokenBuilder2').RtmTokenBuilder
9
+ RtmTokenBuilder: require('./src/RtmTokenBuilder2').RtmTokenBuilder,
10
+ Rtm2Permissions: require('./src/AccessToken2').Rtm2Permissions,
11
+ SttTokenBuilder: require('./src/SttTokenBuilder').SttTokenBuilder
9
12
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agora-token",
3
- "version": "2.0.4",
3
+ "version": "2.0.6",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/AgoraIO/Tools/tree/master/DynamicKey/AgoraDynamicKey/nodejs",
6
6
  "main": "index.js",
@@ -1,26 +1,36 @@
1
- const { AccessToken2, ServiceRtc } = require("../src/AccessToken2");
2
- const RtcRole = require("../src/RtcTokenBuilder").Role;
1
+ const { AccessToken2, ServiceRtc } = require('../src/AccessToken2')
2
+ const RtcRole = require('../src/RtcTokenBuilder2').Role
3
3
 
4
4
  // Need to set environment variable AGORA_APP_ID
5
- const appId = process.env.AGORA_APP_ID;
5
+ const appId = process.env.AGORA_APP_ID
6
6
  // Need to set environment variable AGORA_APP_CERTIFICATE
7
- const appCertificate = process.env.AGORA_APP_CERTIFICATE;
7
+ const appCertificate = process.env.AGORA_APP_CERTIFICATE
8
8
 
9
- const channelName = "7d72365eb983485397e3e3f9d460bdda";
10
- const uid = 2882341273;
11
- const account = "2882341273";
12
- const role = RtcRole.PUBLISHER;
13
- const expirationTimeInSeconds = 3600;
14
- const currentTimestamp = Math.floor(Date.now() / 1000);
9
+ const channelName = '7d72365eb983485397e3e3f9d460bdda'
10
+ const uid = 2882341273
11
+ // const account = '2882341273'
12
+ const role = RtcRole.PUBLISHER
13
+ const tokenExpirationInSecond = 3600
14
+ const joinChannelPrivilegeExpireInSeconds = 3600
15
+ const pubAudioPrivilegeExpireInSeconds = 3600
16
+ const pubVideoPrivilegeExpireInSeconds = 3600
17
+ const pubDataStreamPrivilegeExpireInSeconds = 3600
15
18
 
16
- console.log("App Id:", appId);
17
- console.log("App Certificate:", appCertificate);
18
- if (appId == undefined || appId == "" || appCertificate == undefined || appCertificate == "") {
19
- console.log("Need to set environment variable AGORA_APP_ID and AGORA_APP_CERTIFICATE");
20
- process.exit(1);
19
+ console.log('App Id:', appId)
20
+ console.log('App Certificate:', appCertificate)
21
+ if (appId == undefined || appId == '' || appCertificate == undefined || appCertificate == '') {
22
+ console.log('Need to set environment variable AGORA_APP_ID and AGORA_APP_CERTIFICATE')
23
+ process.exit(1)
21
24
  }
22
25
 
23
- let token = new AccessToken2(appId, appCertificate, currentTimestamp, expirationTimeInSeconds);
24
- let rtc_service = new ServiceRtc(channelName, uid);
25
- token.add_service(rtc_service);
26
- console.log("Token: ", token.build());
26
+ let token = new AccessToken2(appId, appCertificate, 0, tokenExpirationInSecond)
27
+ let serviceRtc = new ServiceRtc(channelName, uid)
28
+ serviceRtc.add_privilege(ServiceRtc.kPrivilegeJoinChannel, joinChannelPrivilegeExpireInSeconds)
29
+ if (role == RtcRole.PUBLISHER) {
30
+ serviceRtc.add_privilege(ServiceRtc.kPrivilegePublishAudioStream, pubAudioPrivilegeExpireInSeconds)
31
+ serviceRtc.add_privilege(ServiceRtc.kPrivilegePublishVideoStream, pubVideoPrivilegeExpireInSeconds)
32
+ serviceRtc.add_privilege(ServiceRtc.kPrivilegePublishDataStream, pubDataStreamPrivilegeExpireInSeconds)
33
+ }
34
+ token.add_service(serviceRtc)
35
+
36
+ console.log('Token: ', token.build())
@@ -0,0 +1,36 @@
1
+ const { ConvoAITokenBuilder, RtcRole } = require('..')
2
+
3
+ const appId = process.env.AGORA_APP_ID
4
+ const appCertificate = process.env.AGORA_APP_CERTIFICATE
5
+ const channelName = '7d72365eb983485397e3e3f9d460bdda'
6
+ const rtcAccount = '2882341273'
7
+ const rtcRole = RtcRole.PUBLISHER
8
+ const rtcTokenExpire = 3600
9
+ const joinChannelPrivilegeExpire = 3600
10
+ const pubAudioPrivilegeExpire = 3600
11
+ const pubVideoPrivilegeExpire = 3600
12
+ const pubDataStreamPrivilegeExpire = 3600
13
+ const rtmUserId = '2882341273'
14
+ const rtmTokenExpire = 3600
15
+
16
+ console.log('App Id:', appId)
17
+ if (!appId || !appCertificate) {
18
+ console.log('Need to set environment variable AGORA_APP_ID and AGORA_APP_CERTIFICATE')
19
+ process.exit(0)
20
+ }
21
+
22
+ const token = ConvoAITokenBuilder.buildToken(
23
+ appId,
24
+ appCertificate,
25
+ channelName,
26
+ rtcAccount,
27
+ rtcRole,
28
+ rtcTokenExpire,
29
+ joinChannelPrivilegeExpire,
30
+ pubAudioPrivilegeExpire,
31
+ pubVideoPrivilegeExpire,
32
+ pubDataStreamPrivilegeExpire,
33
+ rtmUserId,
34
+ rtmTokenExpire
35
+ )
36
+ console.log('ConvoAI token:', token)
@@ -84,3 +84,19 @@ const tokenWithRtm = RtcTokenBuilder.buildTokenWithRtm(
84
84
  privilegeExpirationInSecond
85
85
  )
86
86
  console.log('Token with RTM:', tokenWithRtm)
87
+
88
+ const tokenWithRtm2 = RtcTokenBuilder.buildTokenWithRtm2(
89
+ appId,
90
+ appCertificate,
91
+ channelName,
92
+ account,
93
+ role,
94
+ tokenExpirationInSecond,
95
+ joinChannelPrivilegeExpireInSeconds,
96
+ pubAudioPrivilegeExpireInSeconds,
97
+ pubVideoPrivilegeExpireInSeconds,
98
+ pubDataStreamPrivilegeExpireInSeconds,
99
+ account,
100
+ tokenExpirationInSecond
101
+ )
102
+ console.log('Token with RTM:', tokenWithRtm2)
@@ -0,0 +1,36 @@
1
+ const { SttTokenBuilder, RtcRole } = require('..')
2
+
3
+ const appId = process.env.AGORA_APP_ID
4
+ const appCertificate = process.env.AGORA_APP_CERTIFICATE
5
+ const channelName = '7d72365eb983485397e3e3f9d460bdda'
6
+ const rtcAccount = '2882341273'
7
+ const rtcRole = RtcRole.PUBLISHER
8
+ const rtcTokenExpire = 3600
9
+ const joinChannelPrivilegeExpire = 3600
10
+ const pubAudioPrivilegeExpire = 3600
11
+ const pubVideoPrivilegeExpire = 3600
12
+ const pubDataStreamPrivilegeExpire = 3600
13
+ const rtmUserId = '2882341273'
14
+ const rtmTokenExpire = 3600
15
+
16
+ console.log('App Id:', appId)
17
+ if (!appId || !appCertificate) {
18
+ console.log('Need to set environment variable AGORA_APP_ID and AGORA_APP_CERTIFICATE')
19
+ process.exit(0)
20
+ }
21
+
22
+ const token = SttTokenBuilder.buildToken(
23
+ appId,
24
+ appCertificate,
25
+ channelName,
26
+ rtcAccount,
27
+ rtcRole,
28
+ rtcTokenExpire,
29
+ joinChannelPrivilegeExpire,
30
+ pubAudioPrivilegeExpire,
31
+ pubVideoPrivilegeExpire,
32
+ pubDataStreamPrivilegeExpire,
33
+ rtmUserId,
34
+ rtmTokenExpire
35
+ )
36
+ console.log('STT token:', token)