agora-token 2.0.3 → 2.0.5

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,8 @@
1
+ import globals from 'globals'
2
+ import pluginJs from '@eslint/js'
3
+
4
+ export default [
5
+ { files: ['**/*.js'], languageOptions: { sourceType: 'commonjs' } },
6
+ { languageOptions: { globals: globals.node } },
7
+ pluginJs.configs.recommended
8
+ ]
package/index.d.ts CHANGED
@@ -1,11 +1,163 @@
1
+ export namespace ApaasTokenBuilder {
2
+ /**
3
+ * build user room token
4
+ * @param appId The App ID issued to you by Agora. Apply for a new App ID from
5
+ * Agora Dashboard if it is missing from your kit. See Get an App ID.
6
+ * @param appCertificate Certificate of the application that you registered in
7
+ * the Agora Dashboard. See Get an App Certificate.
8
+ * @param roomUuid The room's id, must be unique.
9
+ * @param userUuid The user's id, must be unique.
10
+ * @param role The user's role.
11
+ * @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).
13
+ * @return The user room token.
14
+ */
15
+ export function buildRoomUserToken(
16
+ appId: string,
17
+ appCertificate: string,
18
+ roomUuid: string,
19
+ userUuid: string | number,
20
+ role: number,
21
+ expire: number
22
+ ): string
23
+
24
+ /**
25
+ * build user token
26
+ * @param appId The App ID issued to you by Agora. Apply for a new App ID from
27
+ * Agora Dashboard if it is missing from your kit. See Get an App ID.
28
+ * @param appCertificate Certificate of the application that you registered in
29
+ * the Agora Dashboard. See Get an App Certificate.
30
+ * @param userUuid The user's id, must be unique.
31
+ * @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).
33
+ * @return The user token.
34
+ */
35
+ export function buildUserToken(
36
+ appId: string,
37
+ appCertificate: string,
38
+ userUuid: string | number,
39
+ expire: number
40
+ ): string
41
+
42
+ /**
43
+ * build app token
44
+ * @param appId The App ID issued to you by Agora. Apply for a new App ID from
45
+ * Agora Dashboard if it is missing from your kit. See Get an App ID.
46
+ * @param appCertificate Certificate of the application that you registered in
47
+ * the Agora Dashboard. See Get an App Certificate.
48
+ * @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).
50
+ * @return The app token.
51
+ */
52
+ export function buildAppToken(appId: string, appCertificate: string, expire: number): string
53
+ }
54
+
55
+ export namespace ChatTokenBuilder {
56
+ /**
57
+ * Build the Chat user token.
58
+ *
59
+ * @param appId The App ID issued to you by Agora. Apply for a new App ID from
60
+ * Agora Dashboard if it is missing from your kit. See Get an App ID.
61
+ * @param appCertificate Certificate of the application that you registered in
62
+ * the Agora Dashboard. See Get an App Certificate.
63
+ * @param userUuid The user's id, must be unique.
64
+ * @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).
66
+ * @return The chat user token.
67
+ */
68
+ export function buildUserToken(
69
+ appId: string,
70
+ appCertificate: string,
71
+ userId: string | number,
72
+ expire: number
73
+ ): string
74
+
75
+ /**
76
+ * Build the Chat App token.
77
+ *
78
+ * @param appId The App ID issued to you by Agora. Apply for a new App ID from
79
+ * Agora Dashboard if it is missing from your kit. See Get an App ID.
80
+ * @param appCertificate Certificate of the application that you registered in
81
+ * the Agora Dashboard. See Get an App Certificate.
82
+ * @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).
84
+ * @return The chat App token.
85
+ */
86
+ export function buildAppToken(appId: string, appCertificate: string, expire: number): string
87
+ }
88
+
89
+ export namespace EducationTokenBuilder {
90
+ /**
91
+ * build user room token
92
+ * @param appId The App ID issued to you by Agora. Apply for a new App ID from
93
+ * Agora Dashboard if it is missing from your kit. See Get an App ID.
94
+ * @param appCertificate Certificate of the application that you registered in
95
+ * the Agora Dashboard. See Get an App Certificate.
96
+ * @param roomUuid The room's id, must be unique.
97
+ * @param userUuid The user's id, must be unique.
98
+ * @param role The user's role.
99
+ * @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).
101
+ * @return The user room token.
102
+ */
103
+ export function buildRoomUserToken(
104
+ appId: string,
105
+ appCertificate: string,
106
+ roomUuid: string,
107
+ userUuid: string | number,
108
+ role: number,
109
+ expire: number
110
+ ): string
111
+
112
+ /**
113
+ * build user token
114
+ * @param appId The App ID issued to you by Agora. Apply for a new App ID from
115
+ * Agora Dashboard if it is missing from your kit. See Get an App ID.
116
+ * @param appCertificate Certificate of the application that you registered in
117
+ * the Agora Dashboard. See Get an App Certificate.
118
+ * @param userUuid The user's id, must be unique.
119
+ * @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).
121
+ * @return The user token.
122
+ */
123
+ export function buildUserToken(
124
+ appId: string,
125
+ appCertificate: string,
126
+ userUuid: string | number,
127
+ expire: number
128
+ ): string
129
+
130
+ /**
131
+ * build app token
132
+ * @param appId The App ID issued to you by Agora. Apply for a new App ID from
133
+ * Agora Dashboard if it is missing from your kit. See Get an App ID.
134
+ * @param appCertificate Certificate of the application that you registered in
135
+ * the Agora Dashboard. See Get an App Certificate.
136
+ * @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).
138
+ * @return The app token.
139
+ */
140
+ export function buildAppToken(appId: string, appCertificate: string, expire: number): string
141
+ }
142
+
143
+ export namespace FpaTokenBuilder {
144
+ /**
145
+ * Build the FPA token.
146
+ * @param appId The App ID issued to you by Agora. Apply for a new App ID from
147
+ * Agora Dashboard if it is missing from your kit. See Get an App ID.
148
+ * @param appCertificate Certificate of the application that you registered in
149
+ * the Agora Dashboard. See Get an App Certificate.
150
+ * @return The FPA token.
151
+ */
152
+ export function buildToken(appId: string, appCertificate: string): string
153
+ }
1
154
 
2
155
  export namespace RtcRole {
3
- export const PUBLISHER: number;
4
- export const SUBSCRIBER: number;
156
+ export const PUBLISHER: number
157
+ export const SUBSCRIBER: number
5
158
  }
6
159
 
7
160
  export namespace RtcTokenBuilder {
8
-
9
161
  /**
10
162
  * Builds an RTC token using an Integer uid.
11
163
  * @param {*} appId The App ID issued to you by Agora.
@@ -19,14 +171,23 @@ export namespace RtcTokenBuilder {
19
171
  * @param {*} uid User ID. A 32-bit unsigned integer with a value ranging from 1 to (2^32-1).
20
172
  * @param {*} role See #userRole.
21
173
  * - Role.PUBLISHER; RECOMMENDED. Use this role for a voice/video call or a live broadcast.
22
- * - Role.SUBSCRIBER: ONLY use this role if your live-broadcast scenario requires authentication for [Hosting-in](https://docs.agora.io/en/Agora%20Platform/terms?platform=All%20Platforms#hosting-in). In order for this role to take effect, please contact our support team to enable authentication for Hosting-in for you. Otherwise, Role_Subscriber still has the same privileges as Role_Publisher.
23
- * @param {*} token_expire 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 token_expire as 600(seconds)
24
- * @param {*} privilege_expire represented by the number of seconds elapsed since now. If, for example, you want to enable your privilege for 10 minutes, set privilege_expire as 600(seconds). * @return The new Token.
174
+ * - 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).
177
+ * @return The RTC Token.
25
178
  */
26
- export function buildTokenWithUid(appId: string, appCertificate: string, channelName: string, uid: string | number, role: number, token_expire: number, privilege_expire: number): string;
179
+ export function buildTokenWithUid(
180
+ appId: string,
181
+ appCertificate: string,
182
+ channelName: string,
183
+ uid: string | number,
184
+ role: number,
185
+ tokenExpire: number,
186
+ privilegeExpire: number
187
+ ): string
27
188
 
28
189
  /**
29
- * Builds an RTC token using an Integer uid.
190
+ * Builds an RTC token with account.
30
191
  * @param {*} appId The App ID issued to you by Agora.
31
192
  * @param {*} appCertificate Certificate of the application that you registered in the Agora Dashboard.
32
193
  * @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:
@@ -38,14 +199,22 @@ export namespace RtcTokenBuilder {
38
199
  * @param {*} account The user account.
39
200
  * @param {*} role See #userRole.
40
201
  * - Role.PUBLISHER; RECOMMENDED. Use this role for a voice/video call or a live broadcast.
41
- * - Role.SUBSCRIBER: ONLY use this role if your live-broadcast scenario requires authentication for [Hosting-in](https://docs.agora.io/en/Agora%20Platform/terms?platform=All%20Platforms#hosting-in). In order for this role to take effect, please contact our support team to enable authentication for Hosting-in for you. Otherwise, Role_Subscriber still has the same privileges as Role_Publisher.
42
- * @param {*} token_expire 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 token_expire as 600(seconds)
43
- * @param {*} privilege_expire represented by the number of seconds elapsed since now. If, for example, you want to enable your privilege for 10 minutes, set privilege_expire as 600(seconds).
44
- * @return The new Token.
202
+ * - 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).
205
+ * @return The RTC Token.
45
206
  */
46
- export function buildTokenWithUserAccount(appId: string, appCertificate: string, channelName: string, account: string | number, role: number, token_expire: number, privilege_expire: number): string;
207
+ export function buildTokenWithUserAccount(
208
+ appId: string,
209
+ appCertificate: string,
210
+ channelName: string,
211
+ account: string | number,
212
+ role: number,
213
+ tokenExpire: number,
214
+ privilegeExpire: number
215
+ ): string
47
216
 
48
- /**
217
+ /**
49
218
  * Generates an RTC token with the specified privilege.
50
219
  *
51
220
  * This method supports generating a token with the following privileges:
@@ -80,27 +249,28 @@ export namespace RtcTokenBuilder {
80
249
  * - "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", " {", "}", "|", "~", ",".
81
250
  * @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.
82
251
  * @param tokenExpire 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 token_expire as 600(seconds).
84
- * @param joinChannelPrivilegeExpire The Unix timestamp when the privilege for joining the channel expires, represented
85
- * by the sum of the current timestamp plus the valid time period of the token. For example, if you set joinChannelPrivilegeExpire as the
86
- * current timestamp plus 600 seconds, the token expires in 10 minutes.
87
- * @param pubAudioPrivilegeExpire The Unix timestamp when the privilege for publishing audio expires, represented
88
- * by the sum of the current timestamp plus the valid time period of the token. For example, if you set pubAudioPrivilegeExpire as the
89
- * current timestamp plus 600 seconds, the token expires in 10 minutes. If you do not want to enable this privilege,
90
- * set pubAudioPrivilegeExpire as the current Unix timestamp.
91
- * @param pubVideoPrivilegeExpire The Unix timestamp when the privilege for publishing video expires, represented
92
- * by the sum of the current timestamp plus the valid time period of the token. For example, if you set pubVideoPrivilegeExpire as the
93
- * current timestamp plus 600 seconds, the token expires in 10 minutes. If you do not want to enable this privilege,
94
- * set pubVideoPrivilegeExpire as the current Unix timestamp.
95
- * @param pubDataStreamPrivilegeExpire The Unix timestamp when the privilege for publishing data streams expires, represented
96
- * by the sum of the current timestamp plus the valid time period of the token. For example, if you set pubDataStreamPrivilegeExpire as the
97
- * current timestamp plus 600 seconds, the token expires in 10 minutes. If you do not want to enable this privilege,
98
- * set pubDataStreamPrivilegeExpire as the current Unix timestamp.
99
- * @return The new Token
252
+ * Agora Service within 10 minutes after the token is generated, set tokenExpire as 600(seconds).
253
+ * @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).
255
+ * @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).
257
+ * @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).
259
+ * @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).
261
+ * @return The RTC Token
100
262
  */
101
- export function buildTokenWithUidAndPrivilege(appId: string, appCertificate: string, channelName: string, uid: string | number,
102
- tokenExpire: number, joinChannelPrivilegeExpire: number, pubAudioPrivilegeExpire: number,
103
- pubVideoPrivilegeExpire: number, pubDataStreamPrivilegeExpire: number): string;
263
+ export function buildTokenWithUidAndPrivilege(
264
+ appId: string,
265
+ appCertificate: string,
266
+ channelName: string,
267
+ uid: string | number,
268
+ tokenExpire: number,
269
+ joinChannelPrivilegeExpire: number,
270
+ pubAudioPrivilegeExpire: number,
271
+ pubVideoPrivilegeExpire: number,
272
+ pubDataStreamPrivilegeExpire: number
273
+ ): string
104
274
 
105
275
  /**
106
276
  * Generates an RTC token with the specified privilege.
@@ -137,125 +307,113 @@ export namespace RtcTokenBuilder {
137
307
  * - "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", " {", "}", "|", "~", ",".
138
308
  * @param userAccount The user account.
139
309
  * @param tokenExpire represented by the number of seconds elapsed since now. If, for example, you want to access the
140
- * Agora Service within 10 minutes after the token is generated, set token_expire as 600(seconds).
141
- * @param joinChannelPrivilegeExpire The Unix timestamp when the privilege for joining the channel expires, represented
142
- * by the sum of the current timestamp plus the valid time period of the token. For example, if you set joinChannelPrivilegeExpire as the
143
- * current timestamp plus 600 seconds, the token expires in 10 minutes.
144
- * @param pubAudioPrivilegeExpire The Unix timestamp when the privilege for publishing audio expires, represented
145
- * by the sum of the current timestamp plus the valid time period of the token. For example, if you set pubAudioPrivilegeExpire as the
146
- * current timestamp plus 600 seconds, the token expires in 10 minutes. If you do not want to enable this privilege,
147
- * set pubAudioPrivilegeExpire as the current Unix timestamp.
148
- * @param pubVideoPrivilegeExpire The Unix timestamp when the privilege for publishing video expires, represented
149
- * by the sum of the current timestamp plus the valid time period of the token. For example, if you set pubVideoPrivilegeExpire as the
150
- * current timestamp plus 600 seconds, the token expires in 10 minutes. If you do not want to enable this privilege,
151
- * set pubVideoPrivilegeExpire as the current Unix timestamp.
152
- * @param pubDataStreamPrivilegeExpire The Unix timestamp when the privilege for publishing data streams expires, represented
153
- * by the sum of the current timestamp plus the valid time period of the token. For example, if you set pubDataStreamPrivilegeExpire as the
154
- * current timestamp plus 600 seconds, the token expires in 10 minutes. If you do not want to enable this privilege,
155
- * set pubDataStreamPrivilegeExpire as the current Unix timestamp.
156
- * @return The new Token.
157
- */
158
- export function BuildTokenWithUserAccountAndPrivilege(appId: string, appCertificate: string, channelName: string, account: string | number,
159
- tokenExpire: number, joinChannelPrivilegeExpire: number, pubAudioPrivilegeExpire: number,
160
- pubVideoPrivilegeExpire: number, pubDataStreamPrivilegeExpire: number): string;
161
- }
162
-
163
- export namespace RtmTokenBuilder {
164
-
165
- /**
166
- * Build the RTM token.
167
- *
168
- * @param appId The App ID issued to you by Agora. Apply for a new App ID from
169
- * Agora Dashboard if it is missing from your kit. See Get an App ID.
170
- * @param appCertificate Certificate of the application that you registered in
171
- * the Agora Dashboard. See Get an App Certificate.
172
- * @param userId The user's account, max length is 64 Bytes.
173
- * @param expire represented by the number of seconds elapsed since now. If, for example, you want to access the
174
- * Agora Service within 10 minutes after the token is generated, set expireTimestamp as 600(seconds).
175
- * @return The RTM token.
310
+ * Agora Service within 10 minutes after the token is generated, set tokenExpire as 600(seconds).
311
+ * @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).
313
+ * @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).
315
+ * @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).
317
+ * @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).
319
+ * @return The RTC Token.
176
320
  */
177
- export function buildToken(appId: string, appCertificate: string, userId: string | number, expire: number): string;
178
- }
321
+ export function BuildTokenWithUserAccountAndPrivilege(
322
+ appId: string,
323
+ appCertificate: string,
324
+ channelName: string,
325
+ account: string | number,
326
+ tokenExpire: number,
327
+ joinChannelPrivilegeExpire: number,
328
+ pubAudioPrivilegeExpire: number,
329
+ pubVideoPrivilegeExpire: number,
330
+ pubDataStreamPrivilegeExpire: number
331
+ ): string
179
332
 
180
- export namespace EducationTokenBuilder {
181
333
  /**
182
- * build user room token
183
- * @param appId The App ID issued to you by Agora. Apply for a new App ID from
184
- * Agora Dashboard if it is missing from your kit. See Get an App ID.
185
- * @param appCertificate Certificate of the application that you registered in
186
- * the Agora Dashboard. See Get an App Certificate.
187
- * @param roomUuid The room's id, must be unique.
188
- * @param userUuid The user's id, must be unique.
189
- * @param role The user's role, such as 0(invisible), 1(teacher), 2(student), 3(assistant), 4(observer) etc.
190
- * @param expire represented by the number of seconds elapsed since now. If, for example, you want to access the
191
- * Agora Service within 10 minutes after the token is generated, set expireTimestamp as 600(seconds).
192
- * @return The education user room token.
193
- */
194
- export function buildRoomUserToken(appId: string, appCertificate: string, roomUuid: string, userUuid: string | number, role: number, expire: number): string;
195
-
196
- /**
197
- * build user individual token
198
- * @param appId The App ID issued to you by Agora. Apply for a new App ID from
199
- * Agora Dashboard if it is missing from your kit. See Get an App ID.
200
- * @param appCertificate Certificate of the application that you registered in
201
- * the Agora Dashboard. See Get an App Certificate.
202
- * @param userUuid The user's id, must be unique.
203
- * @param expire represented by the number of seconds elapsed since now. If, for example, you want to access the
204
- * Agora Service within 10 minutes after the token is generated, set expireTimestamp as 600(seconds).
205
- * @return The education user token.
206
- */
207
- export function buildUserToken(appId: string, appCertificate: string, userUuid: string | number, expire: number): string;
208
-
209
- /**
210
- * build app global token
211
- * @param appId The App ID issued to you by Agora. Apply for a new App ID from
212
- * Agora Dashboard if it is missing from your kit. See Get an App ID.
213
- * @param appCertificate Certificate of the application that you registered in
214
- * the Agora Dashboard. See Get an App Certificate.
215
- * @param expire represented by the number of seconds elapsed since now. If, for example, you want to access the
216
- * Agora Service within 10 minutes after the token is generated, set expireTimestamp as 600(seconds).
217
- * @return The education global token.
334
+ * Build an RTC and RTM token with account.
335
+ * @param {*} appId The App ID issued to you by Agora.
336
+ * @param {*} appCertificate Certificate of the application that you registered in the Agora Dashboard.
337
+ * @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:
338
+ * - The 26 lowercase English letters: a to z.
339
+ * - The 26 uppercase English letters: A to Z.
340
+ * - The 10 digits: 0 to 9.
341
+ * - The space.
342
+ * - "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", " {", "}", "|", "~", ",".
343
+ * @param {*} account The user account.
344
+ * @param {*} role See #userRole.
345
+ * - Role.PUBLISHER; RECOMMENDED. Use this role for a voice/video call or a live broadcast.
346
+ * - 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).
349
+ * @return The RTC and RTM Token.
218
350
  */
219
- export function buildAppToken(appId: string, appCertificate: string, expire: number): string;
220
- }
351
+ export function buildTokenWithRtm(
352
+ appId: string,
353
+ appCertificate: string,
354
+ channelName: string,
355
+ account: string | number,
356
+ role: number,
357
+ tokenExpire: number,
358
+ privilegeExpire: number
359
+ ): string
221
360
 
222
- export namespace FpaTokenBuilder {
223
361
  /**
224
- * Build the FPA token.
225
- * @param appId The App ID issued to you by Agora. Apply for a new App ID from
226
- * Agora Dashboard if it is missing from your kit. See Get an App ID.
227
- * @param appCertificate Certificate of the application that you registered in
228
- * the Agora Dashboard. See Get an App Certificate.
229
- * @return The FPA token.
362
+ * Build an RTC and RTM token with account.
363
+ * @param {*} appId The App ID issued to you by Agora.
364
+ * @param {*} appCertificate Certificate of the application that you registered in the Agora Dashboard.
365
+ * @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:
366
+ * - The 26 lowercase English letters: a to z.
367
+ * - The 26 uppercase English letters: A to Z.
368
+ * - The 10 digits: 0 to 9.
369
+ * - The space.
370
+ * - "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", " {", "}", "|", "~", ",".
371
+ * @param {*} rtcAccount The RTC user's account, max length is 255 Bytes.
372
+ * @param {*} rtcRole See #userRole.
373
+ * - Role.PUBLISHER; RECOMMENDED. Use this role for a voice/video call or a live broadcast.
374
+ * - 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.
375
+ * @param {*} rtcTokenExpire 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)
376
+ * @param {*} joinChannelPrivilegeExpire represented by the number of seconds elapsed since now.
377
+ * If, for example, you want to join channel and expect stay in the channel for 10 minutes, set joinChannelPrivilegeExpire as 600(seconds).
378
+ * @param {*} pubAudioPrivilegeExpire represented by the number of seconds elapsed since now.
379
+ * If, for example, you want to enable publish audio privilege for 10 minutes, set pubAudioPrivilegeExpire as 600(seconds).
380
+ * @param {*} pubVideoPrivilegeExpire represented by the number of seconds elapsed since now.
381
+ * If, for example, you want to enable publish video privilege for 10 minutes, set pubVideoPrivilegeExpire as 600(seconds).
382
+ * @param {*} pubDataStreamPrivilegeExpire represented by the number of seconds elapsed since now.
383
+ * If, for example, you want to enable publish data stream privilege for 10 minutes, set pubDataStreamPrivilegeExpire as 600(seconds).
384
+ * @param rtmUserId: The RTM user's account, max length is 255 Bytes.
385
+ * @param rtmTokenExpire: represented by the number of seconds elapsed since now. If, for example,
386
+ * you want to access the Agora Service within 10 minutes after the token is generated, set rtmTokenExpire as 600(seconds).
387
+ * * @return The RTC and RTM Token.
230
388
  */
231
- export function buildToken(appId: string, appCertificate: string): string;
389
+ export function buildTokenWithRtm2(
390
+ appId: string,
391
+ appCertificate: string,
392
+ channelName: string,
393
+ rtcAccount: string | number,
394
+ rtcRole: number,
395
+ rtcTokenExpire: number,
396
+ joinChannelPrivilegeExpire: number,
397
+ pubAudioPrivilegeExpire: number,
398
+ pubVideoPrivilegeExpire: number,
399
+ pubDataStreamPrivilegeExpire: number,
400
+ rtmUserId: string | number,
401
+ rtmTokenExpire: number
402
+ ): string
232
403
  }
233
404
 
234
- export namespace ChatTokenBuilder {
235
- /**
236
- * Build the Chat user token.
237
- *
238
- * @param appId The App ID issued to you by Agora. Apply for a new App ID from
239
- * Agora Dashboard if it is missing from your kit. See Get an App ID.
240
- * @param appCertificate Certificate of the application that you registered in
241
- * the Agora Dashboard. See Get an App Certificate.
242
- * @param userUuid The user's id, must be unique.
243
- * @param expire represented by the number of seconds elapsed since now. If, for example, you want to access the
244
- * Agora Service within 10 minutes after the token is generated, set expireTimestamp as 600(seconds).
245
- * @return The chat user token.
246
- */
247
- export function buildUserToken(appId: string, appCertificate: string, userId: string | number, expire: number): string;
248
-
405
+ export namespace RtmTokenBuilder {
249
406
  /**
250
- * Build the Chat App token.
407
+ * Build the RTM token.
251
408
  *
252
409
  * @param appId The App ID issued to you by Agora. Apply for a new App ID from
253
410
  * Agora Dashboard if it is missing from your kit. See Get an App ID.
254
411
  * @param appCertificate Certificate of the application that you registered in
255
412
  * the Agora Dashboard. See Get an App Certificate.
413
+ * @param userId The user's account, max length is 64 Bytes.
256
414
  * @param expire represented by the number of seconds elapsed since now. If, for example, you want to access the
257
- * Agora Service within 10 minutes after the token is generated, set expireTimestamp as 600(seconds).
258
- * @return The chat App token.
415
+ * Agora Service within 10 minutes after the token is generated, set expire as 600(seconds).
416
+ * @return The RTM token.
259
417
  */
260
- export function buildAppToken(appId: string, appCertificate: string, expire: number): string;
418
+ export function buildToken(appId: string, appCertificate: string, userId: string | number, expire: number): string
261
419
  }
package/index.js CHANGED
@@ -1,8 +1,9 @@
1
1
  module.exports = {
2
- RtcTokenBuilder: require('./src/RtcTokenBuilder2').RtcTokenBuilder,
3
- RtcRole: require('./src/RtcTokenBuilder2').Role,
4
- RtmTokenBuilder: require('./src/RtmTokenBuilder2').RtmTokenBuilder,
5
- EducationTokenBuilder: require('./src/EducationTokenBuilder').EducationTokenBuilder,
6
- FpaTokenBuilder: require('./src/FpaTokenBuilder').FpaTokenBuilder,
7
- ChatTokenBuilder: require('./src/ChatTokenBuilder').ChatTokenBuilder
8
- };
2
+ ApaasTokenBuilder: require('./src/ApaasTokenBuilder').ApaasTokenBuilder,
3
+ ChatTokenBuilder: require('./src/ChatTokenBuilder').ChatTokenBuilder,
4
+ EducationTokenBuilder: require('./src/EducationTokenBuilder').EducationTokenBuilder,
5
+ FpaTokenBuilder: require('./src/FpaTokenBuilder').FpaTokenBuilder,
6
+ RtcRole: require('./src/RtcTokenBuilder2').Role,
7
+ RtcTokenBuilder: require('./src/RtcTokenBuilder2').RtcTokenBuilder,
8
+ RtmTokenBuilder: require('./src/RtmTokenBuilder2').RtmTokenBuilder
9
+ }
package/package.json CHANGED
@@ -1,21 +1,24 @@
1
1
  {
2
- "name": "agora-token",
3
- "version": "2.0.3",
4
- "description": "",
5
- "homepage": "https://github.com/AgoraIO/Tools/tree/master/DynamicKey/AgoraDynamicKey/nodejs",
6
- "main": "index.js",
7
- "scripts": {
8
- "test": "nodeunit test/*.js"
9
- },
10
- "types": "index.d.ts",
11
- "author": "",
12
- "license": "ISC",
13
- "dependencies": {
14
- "crc-32": "^1.2.0",
15
- "cuint": "0.2.2",
16
- "md5": "^2.3.0"
17
- },
18
- "devDependencies": {
19
- "nodeunit": "^0.11.3"
20
- }
21
- }
2
+ "name": "agora-token",
3
+ "version": "2.0.5",
4
+ "description": "",
5
+ "homepage": "https://github.com/AgoraIO/Tools/tree/master/DynamicKey/AgoraDynamicKey/nodejs",
6
+ "main": "index.js",
7
+ "scripts": {
8
+ "test": "nodeunit test/*.js"
9
+ },
10
+ "types": "index.d.ts",
11
+ "author": "",
12
+ "license": "ISC",
13
+ "dependencies": {
14
+ "crc-32": "^1.2.0",
15
+ "cuint": "0.2.2",
16
+ "md5": "^2.3.0"
17
+ },
18
+ "devDependencies": {
19
+ "@eslint/js": "^9.8.0",
20
+ "eslint": "^9.8.0",
21
+ "globals": "^15.8.0",
22
+ "nodeunit": "^0.11.3"
23
+ }
24
+ }
@@ -1,18 +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
- const appID = '970CA35de60c44645bbae8a215061b33';
5
- const appCertificate = '5CFd2fd1755d40ecb72977518be15d3b';
6
- const channelName = '7d72365eb983485397e3e3f9d460bdda';
7
- const uid = 2882341273;
8
- const account = "2882341273";
9
- const role = RtcRole.PUBLISHER;
4
+ // Need to set environment variable AGORA_APP_ID
5
+ const appId = process.env.AGORA_APP_ID
6
+ // Need to set environment variable AGORA_APP_CERTIFICATE
7
+ const appCertificate = process.env.AGORA_APP_CERTIFICATE
10
8
 
11
- const expirationTimeInSeconds = 3600
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
12
18
 
13
- const currentTimestamp = Math.floor(Date.now() / 1000)
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)
24
+ }
14
25
 
15
- let token = new AccessToken2(appID, appCertificate, currentTimestamp, expirationTimeInSeconds)
16
- let rtc_service = new ServiceRtc(channelName, uid)
17
- token.add_service(rtc_service)
18
- console.log(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())