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.
- package/eslint.config.mjs +8 -0
- package/index.d.ts +296 -138
- package/index.js +8 -7
- package/package.json +23 -20
- package/sample/AccessToken2Sample.js +32 -14
- package/sample/ApaasTokenSample.js +27 -0
- package/sample/ChatTokenBuilderSample.js +16 -5
- package/sample/EducationTokenSample.js +33 -20
- package/sample/FpaTokenBuilderSample.js +14 -5
- package/sample/RtcTokenBuilder2Sample.js +89 -15
- package/sample/RtcTokenBuilderSample.js +21 -16
- package/sample/RtmTokenBuilder2Sample.js +14 -3
- package/sample/RtmTokenBuilderSample.js +20 -11
- package/src/AccessToken2.js +38 -30
- package/src/ApaasTokenBuilder.js +80 -0
- package/src/ChatTokenBuilder.js +17 -18
- package/src/EducationTokenBuilder.js +21 -21
- package/src/RtcTokenBuilder.js +41 -44
- package/src/RtcTokenBuilder2.js +198 -61
- package/src/RtmTokenBuilder2.js +9 -9
- package/test/AccessToken2Test.js +111 -105
- package/test/ApaasTokenBuilderTest.js +45 -0
- package/test/EducationTokenBuilderTest.js +35 -35
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 [
|
|
23
|
-
* @param {*}
|
|
24
|
-
* @param {*}
|
|
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
|
-
|
|
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
|
|
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 [
|
|
42
|
-
* @param {*}
|
|
43
|
-
* @param {*}
|
|
44
|
-
* @return The
|
|
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
|
-
|
|
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
|
|
84
|
-
* @param joinChannelPrivilegeExpire
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
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(
|
|
102
|
-
|
|
103
|
-
|
|
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
|
|
141
|
-
* @param joinChannelPrivilegeExpire
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
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
|
-
|
|
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
|
-
*
|
|
183
|
-
* @param appId
|
|
184
|
-
*
|
|
185
|
-
* @param
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
* @
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
*
|
|
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
|
-
|
|
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
|
|
225
|
-
* @param appId
|
|
226
|
-
*
|
|
227
|
-
* @param
|
|
228
|
-
*
|
|
229
|
-
*
|
|
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
|
|
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
|
|
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
|
|
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
|
|
258
|
-
* @return The
|
|
415
|
+
* Agora Service within 10 minutes after the token is generated, set expire as 600(seconds).
|
|
416
|
+
* @return The RTM token.
|
|
259
417
|
*/
|
|
260
|
-
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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/
|
|
1
|
+
const { AccessToken2, ServiceRtc } = require('../src/AccessToken2')
|
|
2
|
+
const RtcRole = require('../src/RtcTokenBuilder2').Role
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
const
|
|
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
|
|
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
|
-
|
|
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(
|
|
16
|
-
let
|
|
17
|
-
|
|
18
|
-
|
|
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())
|