agora-token 2.0.3 → 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.
@@ -1,9 +1,9 @@
1
+ const md5 = require('md5')
2
+
1
3
  const AccessToken = require('../src/AccessToken2').AccessToken2
2
- const ServiceEducation = require('../src/AccessToken2').ServiceEducation
3
- const ServiceRtm = require('../src/AccessToken2').ServiceRtm
4
+ const ServiceApaas = require('../src/AccessToken2').ServiceApaas
4
5
  const ServiceChat = require('../src/AccessToken2').ServiceChat
5
- const md5 = require("md5")
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, such as 0(invisible), 1(teacher), 2(student), 3(assistant), 4(observer) etc.
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 expireTimestamp as 600(seconds).
20
- * @return The education user room token.
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 eduService = new ServiceEducation(roomUuid, userUuid, role)
27
- accessToken.add_service(eduService)
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 individual token
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 expireTimestamp as 600(seconds).
49
- * @return The education user token.
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 eduService = new ServiceEducation("", userUuid)
54
- eduService.add_privilege(ServiceEducation.PRIVILEGE_USER, expire)
55
- accessToken.add_service(eduService)
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 global token
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 expireTimestamp as 600(seconds).
68
- * @return The education global token.
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 eduService = new ServiceEducation()
73
- eduService.add_privilege(ServiceEducation.PRIVILEGE_APP, expire)
74
- accessToken.add_service(eduService)
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
  }
@@ -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 [Hosting-in](https://docs.agora.io/en/Agora%20Platform/terms?platform=All%20Platforms#hosting-in).
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 [Hosting-in](https://docs.agora.io/en/Agora%20Platform/terms?platform=All%20Platforms#hosting-in).
12
- * @note 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.
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
- * Builds an RTC token using an Integer uid.
24
- * @param {*} appID The App ID issued to you by Agora.
25
- * @param {*} appCertificate Certificate of the application that you registered in the Agora Dashboard.
26
- * @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:
27
- * - The 26 lowercase English letters: a to z.
28
- * - The 26 uppercase English letters: A to Z.
29
- * - The 10 digits: 0 to 9.
30
- * - The space.
31
- * - "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", " {", "}", "|", "~", ",".
32
- * @param {*} uid User ID. A 32-bit unsigned integer with a value ranging from 1 to (2^32-1).
33
- * @param {*} role See #userRole.
34
- * - Role.PUBLISHER; RECOMMENDED. Use this role for a voice/video call or a live broadcast.
35
- * - 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.
36
- * @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).
37
- * @return The new Token.
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
- * Builds an RTC token using an Integer uid.
45
- * @param {*} appID The App ID issued to you by Agora.
46
- * @param {*} appCertificate Certificate of the application that you registered in the Agora Dashboard.
47
- * @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:
48
- * - The 26 lowercase English letters: a to z.
49
- * - The 26 uppercase English letters: A to Z.
50
- * - The 10 digits: 0 to 9.
51
- * - The space.
52
- * - "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", " {", "}", "|", "~", ",".
53
- * @param {*} account The user account.
54
- * @param {*} role See #userRole.
55
- * - Role.PUBLISHER; RECOMMENDED. Use this role for a voice/video call or a live broadcast.
56
- * - 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.
57
- * @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).
58
- * @return The new Token.
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
@@ -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
- // for live broadcaster
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
- // default, for live audience
9
- SUBSCRIBER: 2,
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 [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.
27
- * @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)
28
- * @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.
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, token_expire, privilege_expire = 0) {
31
- return this.buildTokenWithUserAccount(appId, appCertificate, channelName, uid, role, token_expire, privilege_expire)
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 using an Integer uid.
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 [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.
48
- * @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)
49
- * @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).
50
- * @return The new Token.
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(appId, appCertificate, channelName, account, role, token_expire, privilege_expire = 0) {
53
- let token = new AccessToken(appId, appCertificate, 0, token_expire)
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, privilege_expire)
85
+ serviceRtc.add_privilege(ServiceRtc.kPrivilegeJoinChannel, privilegeExpire)
57
86
  if (role == Role.PUBLISHER) {
58
- serviceRtc.add_privilege(ServiceRtc.kPrivilegePublishAudioStream, privilege_expire)
59
- serviceRtc.add_privilege(ServiceRtc.kPrivilegePublishVideoStream, privilege_expire)
60
- serviceRtc.add_privilege(ServiceRtc.kPrivilegePublishDataStream, privilege_expire)
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 token_expire as 600(seconds).
103
- * @param joinChannelPrivilegeExpire The Unix timestamp when the privilege for joining the channel expires, represented
104
- * by the sum of the current timestamp plus the valid time period of the token. For example, if you set joinChannelPrivilegeExpire as the
105
- * current timestamp plus 600 seconds, the token expires in 10 minutes.
106
- * @param pubAudioPrivilegeExpire The Unix timestamp when the privilege for publishing audio expires, represented
107
- * by the sum of the current timestamp plus the valid time period of the token. For example, if you set pubAudioPrivilegeExpire as the
108
- * current timestamp plus 600 seconds, the token expires in 10 minutes. If you do not want to enable this privilege,
109
- * set pubAudioPrivilegeExpire as the current Unix timestamp.
110
- * @param pubVideoPrivilegeExpire The Unix timestamp when the privilege for publishing video expires, represented
111
- * by the sum of the current timestamp plus the valid time period of the token. For example, if you set pubVideoPrivilegeExpire as the
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(appId, appCertificate, channelName, uid,
121
- tokenExpire, joinChannelPrivilegeExpire, pubAudioPrivilegeExpire,
122
- pubVideoPrivilegeExpire, pubDataStreamPrivilegeExpire) {
123
- return this.BuildTokenWithUserAccountAndPrivilege(appId, appCertificate, channelName, uid,
124
- tokenExpire, joinChannelPrivilegeExpire, pubAudioPrivilegeExpire, pubVideoPrivilegeExpire, pubDataStreamPrivilegeExpire)
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 token_expire as 600(seconds).
163
- * @param joinChannelPrivilegeExpire The Unix timestamp when the privilege for joining the channel expires, represented
164
- * by the sum of the current timestamp plus the valid time period of the token. For example, if you set joinChannelPrivilegeExpire as the
165
- * current timestamp plus 600 seconds, the token expires in 10 minutes.
166
- * @param pubAudioPrivilegeExpire The Unix timestamp when the privilege for publishing audio expires, represented
167
- * by the sum of the current timestamp plus the valid time period of the token. For example, if you set pubAudioPrivilegeExpire as the
168
- * current timestamp plus 600 seconds, the token expires in 10 minutes. If you do not want to enable this privilege,
169
- * set pubAudioPrivilegeExpire as the current Unix timestamp.
170
- * @param pubVideoPrivilegeExpire The Unix timestamp when the privilege for publishing video expires, represented
171
- * by the sum of the current timestamp plus the valid time period of the token. For example, if you set pubVideoPrivilegeExpire as the
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(appId, appCertificate, channelName, account,
181
- tokenExpire, joinChannelPrivilegeExpire, pubAudioPrivilegeExpire,
182
- pubVideoPrivilegeExpire, pubDataStreamPrivilegeExpire) {
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
@@ -1,5 +1,5 @@
1
- const AccessToken = require("../src/AccessToken2").AccessToken2;
2
- const ServiceRtm = require("../src/AccessToken2").ServiceRtm;
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 expireTimestamp as 600(seconds).
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