agora-token 2.0.2 → 2.0.4
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/README.md +14 -0
- package/eslint.config.mjs +8 -0
- package/index.d.ts +255 -140
- package/index.js +8 -7
- package/package.json +23 -18
- package/sample/AccessToken2Sample.js +20 -12
- 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 +73 -15
- package/sample/RtcTokenBuilderSample.js +21 -16
- package/sample/RtmTokenBuilder2Sample.js +14 -3
- package/sample/RtmTokenBuilderSample.js +20 -11
- package/sample.js +1 -1
- 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 +138 -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
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
const md5 = require('md5')
|
|
2
|
+
|
|
1
3
|
const AccessToken = require('../src/AccessToken2').AccessToken2
|
|
2
|
-
const
|
|
3
|
-
const ServiceRtm = require('../src/AccessToken2').ServiceRtm
|
|
4
|
+
const ServiceApaas = require('../src/AccessToken2').ServiceApaas
|
|
4
5
|
const ServiceChat = require('../src/AccessToken2').ServiceChat
|
|
5
|
-
const
|
|
6
|
-
|
|
6
|
+
const ServiceRtm = require('../src/AccessToken2').ServiceRtm
|
|
7
7
|
|
|
8
8
|
class EducationTokenBuilder {
|
|
9
9
|
/**
|
|
@@ -14,17 +14,17 @@ class EducationTokenBuilder {
|
|
|
14
14
|
* the Agora Dashboard. See Get an App Certificate.
|
|
15
15
|
* @param roomUuid The room's id, must be unique.
|
|
16
16
|
* @param userUuid The user's id, must be unique.
|
|
17
|
-
* @param role The user's role
|
|
17
|
+
* @param role The user's role.
|
|
18
18
|
* @param expire represented by the number of seconds elapsed since now. If, for example, you want to access the
|
|
19
|
-
* Agora Service within 10 minutes after the token is generated, set
|
|
20
|
-
* @return The
|
|
19
|
+
* Agora Service within 10 minutes after the token is generated, set expire as 600(seconds).
|
|
20
|
+
* @return The user room token.
|
|
21
21
|
*/
|
|
22
22
|
static buildRoomUserToken(appId, appCertificate, roomUuid, userUuid, role, expire) {
|
|
23
23
|
let accessToken = new AccessToken(appId, appCertificate, 0, expire)
|
|
24
24
|
|
|
25
25
|
let chatUserId = md5(userUuid)
|
|
26
|
-
let
|
|
27
|
-
accessToken.add_service(
|
|
26
|
+
let apaasService = new ServiceApaas(roomUuid, userUuid, role)
|
|
27
|
+
accessToken.add_service(apaasService)
|
|
28
28
|
|
|
29
29
|
let rtmService = new ServiceRtm(userUuid)
|
|
30
30
|
rtmService.add_privilege(ServiceRtm.kPrivilegeLogin, expire)
|
|
@@ -38,40 +38,40 @@ class EducationTokenBuilder {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
|
-
* build user
|
|
41
|
+
* build user token
|
|
42
42
|
* @param appId The App ID issued to you by Agora. Apply for a new App ID from
|
|
43
43
|
* Agora Dashboard if it is missing from your kit. See Get an App ID.
|
|
44
44
|
* @param appCertificate Certificate of the application that you registered in
|
|
45
45
|
* the Agora Dashboard. See Get an App Certificate.
|
|
46
46
|
* @param userUuid The user's id, must be unique.
|
|
47
47
|
* @param expire represented by the number of seconds elapsed since now. If, for example, you want to access the
|
|
48
|
-
* Agora Service within 10 minutes after the token is generated, set
|
|
49
|
-
* @return The
|
|
48
|
+
* Agora Service within 10 minutes after the token is generated, set expire as 600(seconds).
|
|
49
|
+
* @return The user token.
|
|
50
50
|
*/
|
|
51
51
|
static buildUserToken(appId, appCertificate, userUuid, expire) {
|
|
52
52
|
let accessToken = new AccessToken(appId, appCertificate, 0, expire)
|
|
53
|
-
let
|
|
54
|
-
|
|
55
|
-
accessToken.add_service(
|
|
53
|
+
let apaasService = new ServiceApaas('', userUuid)
|
|
54
|
+
apaasService.add_privilege(ServiceApaas.PRIVILEGE_USER, expire)
|
|
55
|
+
accessToken.add_service(apaasService)
|
|
56
56
|
|
|
57
57
|
return accessToken.build()
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
/**
|
|
61
|
-
* build app
|
|
61
|
+
* build app token
|
|
62
62
|
* @param appId The App ID issued to you by Agora. Apply for a new App ID from
|
|
63
63
|
* Agora Dashboard if it is missing from your kit. See Get an App ID.
|
|
64
64
|
* @param appCertificate Certificate of the application that you registered in
|
|
65
65
|
* the Agora Dashboard. See Get an App Certificate.
|
|
66
66
|
* @param expire represented by the number of seconds elapsed since now. If, for example, you want to access the
|
|
67
|
-
* Agora Service within 10 minutes after the token is generated, set
|
|
68
|
-
* @return The
|
|
67
|
+
* Agora Service within 10 minutes after the token is generated, set expire as 600(seconds).
|
|
68
|
+
* @return The app token.
|
|
69
69
|
*/
|
|
70
70
|
static buildAppToken(appId, appCertificate, expire) {
|
|
71
71
|
let accessToken = new AccessToken(appId, appCertificate, 0, expire)
|
|
72
|
-
let
|
|
73
|
-
|
|
74
|
-
accessToken.add_service(
|
|
72
|
+
let apaasService = new ServiceApaas()
|
|
73
|
+
apaasService.add_privilege(ServiceApaas.PRIVILEGE_APP, expire)
|
|
74
|
+
accessToken.add_service(apaasService)
|
|
75
75
|
|
|
76
76
|
return accessToken.build()
|
|
77
77
|
}
|
package/src/RtcTokenBuilder.js
CHANGED
|
@@ -5,11 +5,11 @@ const Role = {
|
|
|
5
5
|
// DEPRECATED. Role::ATTENDEE has the same privileges as Role.PUBLISHER.
|
|
6
6
|
ATTENDEE: 0,
|
|
7
7
|
|
|
8
|
-
// RECOMMENDED. Use this role for a voice/video call or a live broadcast, if your scenario does not require authentication for [
|
|
8
|
+
// RECOMMENDED. Use this role for a voice/video call or a live broadcast, if your scenario does not require authentication for [Co-host](https://docs.agora.io/en/video-calling/get-started/authentication-workflow?#co-host-token-authentication).
|
|
9
9
|
PUBLISHER: 1,
|
|
10
10
|
|
|
11
|
-
/* Only use this role if your scenario require authentication for [
|
|
12
|
-
* @note In order for this role to take effect, please contact our support team to enable authentication for
|
|
11
|
+
/* Only use this role if your scenario require authentication for [Co-host](https://docs.agora.io/en/video-calling/get-started/authentication-workflow?#co-host-token-authentication).
|
|
12
|
+
* @note 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.
|
|
13
13
|
*/
|
|
14
14
|
SUBSCRIBER: 2,
|
|
15
15
|
|
|
@@ -18,58 +18,55 @@ const Role = {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
class RtcTokenBuilder {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
*/
|
|
21
|
+
/**
|
|
22
|
+
* Builds an RTC token using an Integer uid.
|
|
23
|
+
* @param {*} appID The App ID issued to you by Agora.
|
|
24
|
+
* @param {*} appCertificate Certificate of the application that you registered in the Agora Dashboard.
|
|
25
|
+
* @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:
|
|
26
|
+
* - The 26 lowercase English letters: a to z.
|
|
27
|
+
* - The 26 uppercase English letters: A to Z.
|
|
28
|
+
* - The 10 digits: 0 to 9.
|
|
29
|
+
* - The space.
|
|
30
|
+
* - "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", " {", "}", "|", "~", ",".
|
|
31
|
+
* @param {*} uid User ID. A 32-bit unsigned integer with a value ranging from 1 to (2^32-1).
|
|
32
|
+
* @param {*} role See #userRole.
|
|
33
|
+
* - Role.PUBLISHER; RECOMMENDED. Use this role for a voice/video call or a live broadcast.
|
|
34
|
+
* - 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.
|
|
35
|
+
* @param {*} privilegeExpiredTs represented by the number of seconds elapsed since 1/1/1970. If, for example, you want to access the Agora Service within 10 minutes after the token is generated, set expireTimestamp as the current timestamp + 600 (seconds).
|
|
36
|
+
* @return The new Token.
|
|
37
|
+
*/
|
|
39
38
|
static buildTokenWithUid(appID, appCertificate, channelName, uid, role, privilegeExpiredTs) {
|
|
40
39
|
return this.buildTokenWithAccount(appID, appCertificate, channelName, uid, role, privilegeExpiredTs)
|
|
41
40
|
}
|
|
42
41
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Builds an RTC token with account.
|
|
44
|
+
* @param {*} appID The App ID issued to you by Agora.
|
|
45
|
+
* @param {*} appCertificate Certificate of the application that you registered in the Agora Dashboard.
|
|
46
|
+
* @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:
|
|
47
|
+
* - The 26 lowercase English letters: a to z.
|
|
48
|
+
* - The 26 uppercase English letters: A to Z.
|
|
49
|
+
* - The 10 digits: 0 to 9.
|
|
50
|
+
* - The space.
|
|
51
|
+
* - "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", " {", "}", "|", "~", ",".
|
|
52
|
+
* @param {*} account The user account.
|
|
53
|
+
* @param {*} role See #userRole.
|
|
54
|
+
* - Role.PUBLISHER; RECOMMENDED. Use this role for a voice/video call or a live broadcast.
|
|
55
|
+
* - 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.
|
|
56
|
+
* @param {*} privilegeExpiredTs represented by the number of seconds elapsed since 1/1/1970. If, for example, you want to access the Agora Service within 10 minutes after the token is generated, set expireTimestamp as the current timestamp + 600 (seconds).
|
|
57
|
+
* @return The new Token.
|
|
58
|
+
*/
|
|
60
59
|
static buildTokenWithAccount(appID, appCertificate, channelName, account, role, privilegeExpiredTs) {
|
|
61
60
|
this.key = new AccessToken(appID, appCertificate, channelName, account)
|
|
62
61
|
this.key.addPriviledge(Priviledges.kJoinChannel, privilegeExpiredTs)
|
|
63
|
-
if (role == Role.ATTENDEE ||
|
|
64
|
-
role == Role.PUBLISHER ||
|
|
65
|
-
role == Role.ADMIN) {
|
|
62
|
+
if (role == Role.ATTENDEE || role == Role.PUBLISHER || role == Role.ADMIN) {
|
|
66
63
|
this.key.addPriviledge(Priviledges.kPublishAudioStream, privilegeExpiredTs)
|
|
67
64
|
this.key.addPriviledge(Priviledges.kPublishVideoStream, privilegeExpiredTs)
|
|
68
65
|
this.key.addPriviledge(Priviledges.kPublishDataStream, privilegeExpiredTs)
|
|
69
66
|
}
|
|
70
|
-
return this.key.build()
|
|
67
|
+
return this.key.build()
|
|
71
68
|
}
|
|
72
69
|
}
|
|
73
70
|
|
|
74
|
-
module.exports.RtcTokenBuilder = RtcTokenBuilder
|
|
75
|
-
module.exports.Role = Role
|
|
71
|
+
module.exports.RtcTokenBuilder = RtcTokenBuilder
|
|
72
|
+
module.exports.Role = Role
|
package/src/RtcTokenBuilder2.js
CHANGED
|
@@ -1,12 +1,24 @@
|
|
|
1
1
|
const AccessToken = require('../src/AccessToken2').AccessToken2
|
|
2
2
|
const ServiceRtc = require('../src/AccessToken2').ServiceRtc
|
|
3
|
+
const ServiceRtm = require('../src/AccessToken2').ServiceRtm
|
|
3
4
|
|
|
4
5
|
const Role = {
|
|
5
|
-
|
|
6
|
+
/**
|
|
7
|
+
* RECOMMENDED. Use this role for a voice/video call or a live broadcast, if
|
|
8
|
+
* your scenario does not require authentication for
|
|
9
|
+
* [Co-host](https://docs.agora.io/en/video-calling/get-started/authentication-workflow?#co-host-token-authentication).
|
|
10
|
+
*/
|
|
6
11
|
PUBLISHER: 1,
|
|
7
12
|
|
|
8
|
-
|
|
9
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Only use this role if your scenario require authentication for
|
|
15
|
+
* [Co-host](https://docs.agora.io/en/video-calling/get-started/authentication-workflow?#co-host-token-authentication).
|
|
16
|
+
*
|
|
17
|
+
* @note In order for this role to take effect, please contact our support team
|
|
18
|
+
* to enable authentication for Hosting-in for you. Otherwise, Role_Subscriber
|
|
19
|
+
* still has the same privileges as Role_Publisher.
|
|
20
|
+
*/
|
|
21
|
+
SUBSCRIBER: 2
|
|
10
22
|
}
|
|
11
23
|
|
|
12
24
|
class RtcTokenBuilder {
|
|
@@ -23,16 +35,25 @@ class RtcTokenBuilder {
|
|
|
23
35
|
* @param {*} uid User ID. A 32-bit unsigned integer with a value ranging from 1 to (2^32-1).
|
|
24
36
|
* @param {*} role See #userRole.
|
|
25
37
|
* - Role.PUBLISHER; RECOMMENDED. Use this role for a voice/video call or a live broadcast.
|
|
26
|
-
* - Role.SUBSCRIBER: ONLY use this role if your live-broadcast scenario requires authentication for [
|
|
27
|
-
* @param {*}
|
|
28
|
-
* @param {*}
|
|
38
|
+
* - Role.SUBSCRIBER: ONLY use this role if your live-broadcast scenario requires authentication for [Co-host](https://docs.agora.io/en/video-calling/get-started/authentication-workflow?#co-host-token-authentication). In order for this role to take effect, please contact our support team to enable authentication for Co-host for you. Otherwise, Role_Subscriber still has the same privileges as Role_Publisher.
|
|
39
|
+
* @param {*} tokenExpire epresented by the number of seconds elapsed since now. If, for example, you want to access the Agora Service within 10 minutes after the token is generated, set tokenExpire as 600(seconds)
|
|
40
|
+
* @param {*} privilegeExpire represented by the number of seconds elapsed since now. If, for example, you want to enable your privilege for 10 minutes, set privilegeExpire as 600(seconds).
|
|
41
|
+
* @return The RTC Token.
|
|
29
42
|
*/
|
|
30
|
-
static buildTokenWithUid(appId, appCertificate, channelName, uid, role,
|
|
31
|
-
return this.buildTokenWithUserAccount(
|
|
43
|
+
static buildTokenWithUid(appId, appCertificate, channelName, uid, role, tokenExpire, privilegeExpire = 0) {
|
|
44
|
+
return this.buildTokenWithUserAccount(
|
|
45
|
+
appId,
|
|
46
|
+
appCertificate,
|
|
47
|
+
channelName,
|
|
48
|
+
uid,
|
|
49
|
+
role,
|
|
50
|
+
tokenExpire,
|
|
51
|
+
privilegeExpire
|
|
52
|
+
)
|
|
32
53
|
}
|
|
33
54
|
|
|
34
55
|
/**
|
|
35
|
-
* Builds an RTC token
|
|
56
|
+
* Builds an RTC token with account.
|
|
36
57
|
* @param {*} appId The App ID issued to you by Agora.
|
|
37
58
|
* @param {*} appCertificate Certificate of the application that you registered in the Agora Dashboard.
|
|
38
59
|
* @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:
|
|
@@ -44,20 +65,28 @@ class RtcTokenBuilder {
|
|
|
44
65
|
* @param {*} account The user account.
|
|
45
66
|
* @param {*} role See #userRole.
|
|
46
67
|
* - Role.PUBLISHER; RECOMMENDED. Use this role for a voice/video call or a live broadcast.
|
|
47
|
-
* - Role.SUBSCRIBER: ONLY use this role if your live-broadcast scenario requires authentication for [
|
|
48
|
-
* @param {*}
|
|
49
|
-
* @param {*}
|
|
50
|
-
* @return The
|
|
68
|
+
* - Role.SUBSCRIBER: ONLY use this role if your live-broadcast scenario requires authentication for [Co-host](https://docs.agora.io/en/video-calling/get-started/authentication-workflow?#co-host-token-authentication). In order for this role to take effect, please contact our support team to enable authentication for Co-host for you. Otherwise, Role_Subscriber still has the same privileges as Role_Publisher.
|
|
69
|
+
* @param {*} tokenExpire epresented by the number of seconds elapsed since now. If, for example, you want to access the Agora Service within 10 minutes after the token is generated, set tokenExpire as 600(seconds)
|
|
70
|
+
* @param {*} privilegeExpire represented by the number of seconds elapsed since now. If, for example, you want to enable your privilege for 10 minutes, set privilegeExpire as 600(seconds).
|
|
71
|
+
* @return The RTC Token.
|
|
51
72
|
*/
|
|
52
|
-
static buildTokenWithUserAccount(
|
|
53
|
-
|
|
73
|
+
static buildTokenWithUserAccount(
|
|
74
|
+
appId,
|
|
75
|
+
appCertificate,
|
|
76
|
+
channelName,
|
|
77
|
+
account,
|
|
78
|
+
role,
|
|
79
|
+
tokenExpire,
|
|
80
|
+
privilegeExpire = 0
|
|
81
|
+
) {
|
|
82
|
+
let token = new AccessToken(appId, appCertificate, 0, tokenExpire)
|
|
54
83
|
|
|
55
84
|
let serviceRtc = new ServiceRtc(channelName, account)
|
|
56
|
-
serviceRtc.add_privilege(ServiceRtc.kPrivilegeJoinChannel,
|
|
85
|
+
serviceRtc.add_privilege(ServiceRtc.kPrivilegeJoinChannel, privilegeExpire)
|
|
57
86
|
if (role == Role.PUBLISHER) {
|
|
58
|
-
serviceRtc.add_privilege(ServiceRtc.kPrivilegePublishAudioStream,
|
|
59
|
-
serviceRtc.add_privilege(ServiceRtc.kPrivilegePublishVideoStream,
|
|
60
|
-
serviceRtc.add_privilege(ServiceRtc.kPrivilegePublishDataStream,
|
|
87
|
+
serviceRtc.add_privilege(ServiceRtc.kPrivilegePublishAudioStream, privilegeExpire)
|
|
88
|
+
serviceRtc.add_privilege(ServiceRtc.kPrivilegePublishVideoStream, privilegeExpire)
|
|
89
|
+
serviceRtc.add_privilege(ServiceRtc.kPrivilegePublishDataStream, privilegeExpire)
|
|
61
90
|
}
|
|
62
91
|
token.add_service(serviceRtc)
|
|
63
92
|
|
|
@@ -99,29 +128,39 @@ class RtcTokenBuilder {
|
|
|
99
128
|
* - "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", " {", "}", "|", "~", ",".
|
|
100
129
|
* @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.
|
|
101
130
|
* @param tokenExpire represented by the number of seconds elapsed since now. If, for example, you want to access the
|
|
102
|
-
* Agora Service within 10 minutes after the token is generated, set
|
|
103
|
-
* @param joinChannelPrivilegeExpire
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
* current timestamp plus 600 seconds, the token expires in 10 minutes. If you do not want to enable this privilege,
|
|
113
|
-
* set pubVideoPrivilegeExpire as the current Unix timestamp.
|
|
114
|
-
* @param pubDataStreamPrivilegeExpire The Unix timestamp when the privilege for publishing data streams expires, represented
|
|
115
|
-
* by the sum of the current timestamp plus the valid time period of the token. For example, if you set pubDataStreamPrivilegeExpire as the
|
|
116
|
-
* current timestamp plus 600 seconds, the token expires in 10 minutes. If you do not want to enable this privilege,
|
|
117
|
-
* set pubDataStreamPrivilegeExpire as the current Unix timestamp.
|
|
118
|
-
* @return The new Token
|
|
131
|
+
* Agora Service within 10 minutes after the token is generated, set tokenExpire as 600(seconds).
|
|
132
|
+
* @param joinChannelPrivilegeExpire represented by the number of seconds elapsed since now.
|
|
133
|
+
* If, for example, you want to join channel and expect stay in the channel for 10 minutes, set joinChannelPrivilegeExpire as 600(seconds).
|
|
134
|
+
* @param pubAudioPrivilegeExpire represented by the number of seconds elapsed since now.
|
|
135
|
+
* If, for example, you want to enable publish audio privilege for 10 minutes, set pubAudioPrivilegeExpire as 600(seconds).
|
|
136
|
+
* @param pubVideoPrivilegeExpire represented by the number of seconds elapsed since now.
|
|
137
|
+
* If, for example, you want to enable publish video privilege for 10 minutes, set pubVideoPrivilegeExpire as 600(seconds).
|
|
138
|
+
* @param pubDataStreamPrivilegeExpire represented by the number of seconds elapsed since now.
|
|
139
|
+
* If, for example, you want to enable publish data stream privilege for 10 minutes, set pubDataStreamPrivilegeExpire as 600(seconds).
|
|
140
|
+
* @return The RTC Token
|
|
119
141
|
*/
|
|
120
|
-
static buildTokenWithUidAndPrivilege(
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
142
|
+
static buildTokenWithUidAndPrivilege(
|
|
143
|
+
appId,
|
|
144
|
+
appCertificate,
|
|
145
|
+
channelName,
|
|
146
|
+
uid,
|
|
147
|
+
tokenExpire,
|
|
148
|
+
joinChannelPrivilegeExpire,
|
|
149
|
+
pubAudioPrivilegeExpire,
|
|
150
|
+
pubVideoPrivilegeExpire,
|
|
151
|
+
pubDataStreamPrivilegeExpire
|
|
152
|
+
) {
|
|
153
|
+
return this.BuildTokenWithUserAccountAndPrivilege(
|
|
154
|
+
appId,
|
|
155
|
+
appCertificate,
|
|
156
|
+
channelName,
|
|
157
|
+
uid,
|
|
158
|
+
tokenExpire,
|
|
159
|
+
joinChannelPrivilegeExpire,
|
|
160
|
+
pubAudioPrivilegeExpire,
|
|
161
|
+
pubVideoPrivilegeExpire,
|
|
162
|
+
pubDataStreamPrivilegeExpire
|
|
163
|
+
)
|
|
125
164
|
}
|
|
126
165
|
|
|
127
166
|
/**
|
|
@@ -159,27 +198,28 @@ class RtcTokenBuilder {
|
|
|
159
198
|
* - "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", " {", "}", "|", "~", ",".
|
|
160
199
|
* @param userAccount The user account.
|
|
161
200
|
* @param tokenExpire represented by the number of seconds elapsed since now. If, for example, you want to access the
|
|
162
|
-
* Agora Service within 10 minutes after the token is generated, set
|
|
163
|
-
* @param joinChannelPrivilegeExpire
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
* current timestamp plus 600 seconds, the token expires in 10 minutes. If you do not want to enable this privilege,
|
|
173
|
-
* set pubVideoPrivilegeExpire as the current Unix timestamp.
|
|
174
|
-
* @param pubDataStreamPrivilegeExpire The Unix timestamp when the privilege for publishing data streams expires, represented
|
|
175
|
-
* by the sum of the current timestamp plus the valid time period of the token. For example, if you set pubDataStreamPrivilegeExpire as the
|
|
176
|
-
* current timestamp plus 600 seconds, the token expires in 10 minutes. If you do not want to enable this privilege,
|
|
177
|
-
* set pubDataStreamPrivilegeExpire as the current Unix timestamp.
|
|
178
|
-
* @return The new Token.
|
|
201
|
+
* Agora Service within 10 minutes after the token is generated, set tokenExpire as 600(seconds).
|
|
202
|
+
* @param joinChannelPrivilegeExpire represented by the number of seconds elapsed since now.
|
|
203
|
+
* If, for example, you want to join channel and expect stay in the channel for 10 minutes, set joinChannelPrivilegeExpire as 600(seconds).
|
|
204
|
+
* @param pubAudioPrivilegeExpire represented by the number of seconds elapsed since now.
|
|
205
|
+
* If, for example, you want to enable publish audio privilege for 10 minutes, set pubAudioPrivilegeExpire as 600(seconds).
|
|
206
|
+
* @param pubVideoPrivilegeExpire represented by the number of seconds elapsed since now.
|
|
207
|
+
* If, for example, you want to enable publish video privilege for 10 minutes, set pubVideoPrivilegeExpire as 600(seconds).
|
|
208
|
+
* @param pubDataStreamPrivilegeExpire represented by the number of seconds elapsed since now.
|
|
209
|
+
* If, for example, you want to enable publish data stream privilege for 10 minutes, set pubDataStreamPrivilegeExpire as 600(seconds).
|
|
210
|
+
* @return The RTC Token.
|
|
179
211
|
*/
|
|
180
|
-
static BuildTokenWithUserAccountAndPrivilege(
|
|
181
|
-
|
|
182
|
-
|
|
212
|
+
static BuildTokenWithUserAccountAndPrivilege(
|
|
213
|
+
appId,
|
|
214
|
+
appCertificate,
|
|
215
|
+
channelName,
|
|
216
|
+
account,
|
|
217
|
+
tokenExpire,
|
|
218
|
+
joinChannelPrivilegeExpire,
|
|
219
|
+
pubAudioPrivilegeExpire,
|
|
220
|
+
pubVideoPrivilegeExpire,
|
|
221
|
+
pubDataStreamPrivilegeExpire
|
|
222
|
+
) {
|
|
183
223
|
let token = new AccessToken(appId, appCertificate, 0, tokenExpire)
|
|
184
224
|
|
|
185
225
|
let serviceRtc = new ServiceRtc(channelName, account)
|
|
@@ -191,6 +231,43 @@ class RtcTokenBuilder {
|
|
|
191
231
|
|
|
192
232
|
return token.build()
|
|
193
233
|
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Build an RTC and RTM token with account.
|
|
237
|
+
* @param {*} appId The App ID issued to you by Agora.
|
|
238
|
+
* @param {*} appCertificate Certificate of the application that you registered in the Agora Dashboard.
|
|
239
|
+
* @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:
|
|
240
|
+
* - The 26 lowercase English letters: a to z.
|
|
241
|
+
* - The 26 uppercase English letters: A to Z.
|
|
242
|
+
* - The 10 digits: 0 to 9.
|
|
243
|
+
* - The space.
|
|
244
|
+
* - "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", " {", "}", "|", "~", ",".
|
|
245
|
+
* @param {*} account The user account.
|
|
246
|
+
* @param {*} role See #userRole.
|
|
247
|
+
* - Role.PUBLISHER; RECOMMENDED. Use this role for a voice/video call or a live broadcast.
|
|
248
|
+
* - Role.SUBSCRIBER: ONLY use this role if your live-broadcast scenario requires authentication for [Co-host](https://docs.agora.io/en/video-calling/get-started/authentication-workflow?#co-host-token-authentication). In order for this role to take effect, please contact our support team to enable authentication for Co-host for you. Otherwise, Role_Subscriber still has the same privileges as Role_Publisher.
|
|
249
|
+
* @param {*} tokenExpire epresented by the number of seconds elapsed since now. If, for example, you want to access the Agora Service within 10 minutes after the token is generated, set tokenExpire as 600(seconds)
|
|
250
|
+
* @param {*} privilegeExpire represented by the number of seconds elapsed since now. If, for example, you want to enable your privilege for 10 minutes, set privilegeExpire as 600(seconds).
|
|
251
|
+
* @return The RTC and RTM Token.
|
|
252
|
+
*/
|
|
253
|
+
static buildTokenWithRtm(appId, appCertificate, channelName, account, role, tokenExpire, privilegeExpire = 0) {
|
|
254
|
+
let token = new AccessToken(appId, appCertificate, 0, tokenExpire)
|
|
255
|
+
|
|
256
|
+
let serviceRtc = new ServiceRtc(channelName, account)
|
|
257
|
+
serviceRtc.add_privilege(ServiceRtc.kPrivilegeJoinChannel, privilegeExpire)
|
|
258
|
+
if (role == Role.PUBLISHER) {
|
|
259
|
+
serviceRtc.add_privilege(ServiceRtc.kPrivilegePublishAudioStream, privilegeExpire)
|
|
260
|
+
serviceRtc.add_privilege(ServiceRtc.kPrivilegePublishVideoStream, privilegeExpire)
|
|
261
|
+
serviceRtc.add_privilege(ServiceRtc.kPrivilegePublishDataStream, privilegeExpire)
|
|
262
|
+
}
|
|
263
|
+
token.add_service(serviceRtc)
|
|
264
|
+
|
|
265
|
+
let serviceRtm = new ServiceRtm(account)
|
|
266
|
+
serviceRtm.add_privilege(ServiceRtm.kPrivilegeLogin, tokenExpire)
|
|
267
|
+
token.add_service(serviceRtm)
|
|
268
|
+
|
|
269
|
+
return token.build()
|
|
270
|
+
}
|
|
194
271
|
}
|
|
195
272
|
|
|
196
273
|
module.exports.RtcTokenBuilder = RtcTokenBuilder
|
package/src/RtmTokenBuilder2.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const AccessToken = require(
|
|
2
|
-
const ServiceRtm = require(
|
|
1
|
+
const AccessToken = require('../src/AccessToken2').AccessToken2
|
|
2
|
+
const ServiceRtm = require('../src/AccessToken2').ServiceRtm
|
|
3
3
|
|
|
4
4
|
class RtmTokenBuilder {
|
|
5
5
|
/**
|
|
@@ -11,18 +11,18 @@ class RtmTokenBuilder {
|
|
|
11
11
|
* the Agora Dashboard. See Get an App Certificate.
|
|
12
12
|
* @param userId The user's account, max length is 64 Bytes.
|
|
13
13
|
* @param expire represented by the number of seconds elapsed since now. If, for example, you want to access the
|
|
14
|
-
* Agora Service within 10 minutes after the token is generated, set
|
|
14
|
+
* Agora Service within 10 minutes after the token is generated, set expire as 600(seconds).
|
|
15
15
|
* @return The RTM token.
|
|
16
16
|
*/
|
|
17
17
|
static buildToken(appId, appCertificate, userId, expire) {
|
|
18
|
-
let token = new AccessToken(appId, appCertificate, null, expire)
|
|
18
|
+
let token = new AccessToken(appId, appCertificate, null, expire)
|
|
19
19
|
|
|
20
|
-
let serviceRtm = new ServiceRtm(userId)
|
|
21
|
-
serviceRtm.add_privilege(ServiceRtm.kPrivilegeLogin, expire)
|
|
22
|
-
token.add_service(serviceRtm)
|
|
20
|
+
let serviceRtm = new ServiceRtm(userId)
|
|
21
|
+
serviceRtm.add_privilege(ServiceRtm.kPrivilegeLogin, expire)
|
|
22
|
+
token.add_service(serviceRtm)
|
|
23
23
|
|
|
24
|
-
return token.build()
|
|
24
|
+
return token.build()
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
module.exports.RtmTokenBuilder = RtmTokenBuilder
|
|
28
|
+
module.exports.RtmTokenBuilder = RtmTokenBuilder
|