agora-token 2.0.0
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 +36 -0
- package/index.d.ts +232 -0
- package/index.js +7 -0
- package/package.json +19 -0
- package/sample/AccessToken2Sample.js +18 -0
- package/sample/EducationTokenSample.js +21 -0
- package/sample/FpaTokenBuilderSample.js +7 -0
- package/sample/README.md +12 -0
- package/sample/RtcTokenBuilder2Sample.js +28 -0
- package/sample/RtcTokenBuilderSample.js +25 -0
- package/sample/RtmTokenBuilder2Sample.js +8 -0
- package/sample/RtmTokenBuilderSample.js +14 -0
- package/sample.js +46 -0
- package/server/DemoServer.js +66 -0
- package/server/README.md +26 -0
- package/server/package-lock.json +242 -0
- package/server/package.json +14 -0
- package/src/AccessToken.js +237 -0
- package/src/AccessToken2.js +414 -0
- package/src/DynamicKey5.js +173 -0
- package/src/EducationTokenBuilder.js +80 -0
- package/src/FpaTokenBuilder.js +24 -0
- package/src/RtcTokenBuilder.js +75 -0
- package/src/RtcTokenBuilder2.js +197 -0
- package/src/RtmTokenBuilder.js +31 -0
- package/src/RtmTokenBuilder2.js +28 -0
- package/src/SignalingToken.js +29 -0
- package/test/AccessToken2Test.js +110 -0
- package/test/AccessTokenTest.js +77 -0
- package/test/DynamicKeyTest.js +47 -0
- package/test/EducationTokenBuilderTest.js +45 -0
- package/test/FpaTokenBuilderTest.js +22 -0
- package/test/RtcTokenBuilder2Test.js +140 -0
- package/test/RtmTokenBuilder2Test.js +24 -0
- package/test/RtmTokenBuilderTest.js +24 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
const AccessToken = require('../src/AccessToken').AccessToken
|
|
2
|
+
const Priviledges = require('../src/AccessToken').priviledges
|
|
3
|
+
|
|
4
|
+
const Role = {
|
|
5
|
+
// DEPRECATED. Role::ATTENDEE has the same privileges as Role.PUBLISHER.
|
|
6
|
+
ATTENDEE: 0,
|
|
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).
|
|
9
|
+
PUBLISHER: 1,
|
|
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.
|
|
13
|
+
*/
|
|
14
|
+
SUBSCRIBER: 2,
|
|
15
|
+
|
|
16
|
+
// DEPRECATED. Role.ADMIN has the same privileges as Role.PUBLISHER.
|
|
17
|
+
ADMIN: 101
|
|
18
|
+
}
|
|
19
|
+
|
|
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
|
+
*/
|
|
39
|
+
static buildTokenWithUid(appID, appCertificate, channelName, uid, role, privilegeExpiredTs) {
|
|
40
|
+
return this.buildTokenWithAccount(appID, appCertificate, channelName, uid, role, privilegeExpiredTs)
|
|
41
|
+
}
|
|
42
|
+
|
|
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
|
+
*/
|
|
60
|
+
static buildTokenWithAccount(appID, appCertificate, channelName, account, role, privilegeExpiredTs) {
|
|
61
|
+
this.key = new AccessToken(appID, appCertificate, channelName, account)
|
|
62
|
+
this.key.addPriviledge(Priviledges.kJoinChannel, privilegeExpiredTs)
|
|
63
|
+
if (role == Role.ATTENDEE ||
|
|
64
|
+
role == Role.PUBLISHER ||
|
|
65
|
+
role == Role.ADMIN) {
|
|
66
|
+
this.key.addPriviledge(Priviledges.kPublishAudioStream, privilegeExpiredTs)
|
|
67
|
+
this.key.addPriviledge(Priviledges.kPublishVideoStream, privilegeExpiredTs)
|
|
68
|
+
this.key.addPriviledge(Priviledges.kPublishDataStream, privilegeExpiredTs)
|
|
69
|
+
}
|
|
70
|
+
return this.key.build();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
module.exports.RtcTokenBuilder = RtcTokenBuilder;
|
|
75
|
+
module.exports.Role = Role;
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
const AccessToken = require('../src/AccessToken2').AccessToken2
|
|
2
|
+
const ServiceRtc = require('../src/AccessToken2').ServiceRtc
|
|
3
|
+
|
|
4
|
+
const Role = {
|
|
5
|
+
// for live broadcaster
|
|
6
|
+
PUBLISHER: 1,
|
|
7
|
+
|
|
8
|
+
// default, for live audience
|
|
9
|
+
SUBSCRIBER: 2,
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
class RtcTokenBuilder {
|
|
13
|
+
/**
|
|
14
|
+
* Builds an RTC token using an Integer uid.
|
|
15
|
+
* @param {*} appId The App ID issued to you by Agora.
|
|
16
|
+
* @param {*} appCertificate Certificate of the application that you registered in the Agora Dashboard.
|
|
17
|
+
* @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:
|
|
18
|
+
* - The 26 lowercase English letters: a to z.
|
|
19
|
+
* - The 26 uppercase English letters: A to Z.
|
|
20
|
+
* - The 10 digits: 0 to 9.
|
|
21
|
+
* - The space.
|
|
22
|
+
* - "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", " {", "}", "|", "~", ",".
|
|
23
|
+
* @param {*} uid User ID. A 32-bit unsigned integer with a value ranging from 1 to (2^32-1).
|
|
24
|
+
* @param {*} role See #userRole.
|
|
25
|
+
* - 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.
|
|
29
|
+
*/
|
|
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)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Builds an RTC token using an Integer uid.
|
|
36
|
+
* @param {*} appId The App ID issued to you by Agora.
|
|
37
|
+
* @param {*} appCertificate Certificate of the application that you registered in the Agora Dashboard.
|
|
38
|
+
* @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:
|
|
39
|
+
* - The 26 lowercase English letters: a to z.
|
|
40
|
+
* - The 26 uppercase English letters: A to Z.
|
|
41
|
+
* - The 10 digits: 0 to 9.
|
|
42
|
+
* - The space.
|
|
43
|
+
* - "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", " {", "}", "|", "~", ",".
|
|
44
|
+
* @param {*} account The user account.
|
|
45
|
+
* @param {*} role See #userRole.
|
|
46
|
+
* - 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.
|
|
51
|
+
*/
|
|
52
|
+
static buildTokenWithUserAccount(appId, appCertificate, channelName, account, role, token_expire, privilege_expire = 0) {
|
|
53
|
+
let token = new AccessToken(appId, appCertificate, 0, token_expire)
|
|
54
|
+
|
|
55
|
+
let serviceRtc = new ServiceRtc(channelName, account)
|
|
56
|
+
serviceRtc.add_privilege(ServiceRtc.kPrivilegeJoinChannel, privilege_expire)
|
|
57
|
+
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)
|
|
61
|
+
}
|
|
62
|
+
token.add_service(serviceRtc)
|
|
63
|
+
|
|
64
|
+
return token.build()
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Generates an RTC token with the specified privilege.
|
|
69
|
+
*
|
|
70
|
+
* This method supports generating a token with the following privileges:
|
|
71
|
+
* - Joining an RTC channel.
|
|
72
|
+
* - Publishing audio in an RTC channel.
|
|
73
|
+
* - Publishing video in an RTC channel.
|
|
74
|
+
* - Publishing data streams in an RTC channel.
|
|
75
|
+
*
|
|
76
|
+
* The privileges for publishing audio, video, and data streams in an RTC channel apply only if you have
|
|
77
|
+
* enabled co-host authentication.
|
|
78
|
+
*
|
|
79
|
+
* A user can have multiple privileges. Each privilege is valid for a maximum of 24 hours.
|
|
80
|
+
* The SDK triggers the onTokenPrivilegeWillExpire and onRequestToken callbacks when the token is about to expire
|
|
81
|
+
* or has expired. The callbacks do not report the specific privilege affected, and you need to maintain
|
|
82
|
+
* the respective timestamp for each privilege in your app logic. After receiving the callback, you need
|
|
83
|
+
* to generate a new token, and then call renewToken to pass the new token to the SDK, or call joinChannel to re-join
|
|
84
|
+
* the channel.
|
|
85
|
+
*
|
|
86
|
+
* @note
|
|
87
|
+
* Agora recommends setting a reasonable timestamp for each privilege according to your scenario.
|
|
88
|
+
* Suppose the expiration timestamp for joining the channel is set earlier than that for publishing audio.
|
|
89
|
+
* When the token for joining the channel expires, the user is immediately kicked off the RTC channel
|
|
90
|
+
* and cannot publish any audio stream, even though the timestamp for publishing audio has not expired.
|
|
91
|
+
*
|
|
92
|
+
* @param appId The App ID of your Agora project.
|
|
93
|
+
* @param appCertificate The App Certificate of your Agora project.
|
|
94
|
+
* @param channelName The unique channel name for the Agora RTC session in string format. The string length must be less than 64 bytes. The channel name may contain the following characters:
|
|
95
|
+
* - All lowercase English letters: a to z.
|
|
96
|
+
* - All uppercase English letters: A to Z.
|
|
97
|
+
* - All numeric characters: 0 to 9.
|
|
98
|
+
* - The space character.
|
|
99
|
+
* - "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", " {", "}", "|", "~", ",".
|
|
100
|
+
* @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
|
+
* @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
|
|
119
|
+
*/
|
|
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)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Generates an RTC token with the specified privilege.
|
|
129
|
+
*
|
|
130
|
+
* This method supports generating a token with the following privileges:
|
|
131
|
+
* - Joining an RTC channel.
|
|
132
|
+
* - Publishing audio in an RTC channel.
|
|
133
|
+
* - Publishing video in an RTC channel.
|
|
134
|
+
* - Publishing data streams in an RTC channel.
|
|
135
|
+
*
|
|
136
|
+
* The privileges for publishing audio, video, and data streams in an RTC channel apply only if you have
|
|
137
|
+
* enabled co-host authentication.
|
|
138
|
+
*
|
|
139
|
+
* A user can have multiple privileges. Each privilege is valid for a maximum of 24 hours.
|
|
140
|
+
* The SDK triggers the onTokenPrivilegeWillExpire and onRequestToken callbacks when the token is about to expire
|
|
141
|
+
* or has expired. The callbacks do not report the specific privilege affected, and you need to maintain
|
|
142
|
+
* the respective timestamp for each privilege in your app logic. After receiving the callback, you need
|
|
143
|
+
* to generate a new token, and then call renewToken to pass the new token to the SDK, or call joinChannel to re-join
|
|
144
|
+
* the channel.
|
|
145
|
+
*
|
|
146
|
+
* @note
|
|
147
|
+
* Agora recommends setting a reasonable timestamp for each privilege according to your scenario.
|
|
148
|
+
* Suppose the expiration timestamp for joining the channel is set earlier than that for publishing audio.
|
|
149
|
+
* When the token for joining the channel expires, the user is immediately kicked off the RTC channel
|
|
150
|
+
* and cannot publish any audio stream, even though the timestamp for publishing audio has not expired.
|
|
151
|
+
*
|
|
152
|
+
* @param appId The App ID of your Agora project.
|
|
153
|
+
* @param appCertificate The App Certificate of your Agora project.
|
|
154
|
+
* @param channelName The unique channel name for the Agora RTC session in string format. The string length must be less than 64 bytes. The channel name may contain the following characters:
|
|
155
|
+
* - All lowercase English letters: a to z.
|
|
156
|
+
* - All uppercase English letters: A to Z.
|
|
157
|
+
* - All numeric characters: 0 to 9.
|
|
158
|
+
* - The space character.
|
|
159
|
+
* - "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", " {", "}", "|", "~", ",".
|
|
160
|
+
* @param userAccount The user account.
|
|
161
|
+
* @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.
|
|
179
|
+
*/
|
|
180
|
+
static BuildTokenWithUserAccountAndPrivilege(appId, appCertificate, channelName, account,
|
|
181
|
+
tokenExpire, joinChannelPrivilegeExpire, pubAudioPrivilegeExpire,
|
|
182
|
+
pubVideoPrivilegeExpire, pubDataStreamPrivilegeExpire) {
|
|
183
|
+
let token = new AccessToken(appId, appCertificate, 0, tokenExpire)
|
|
184
|
+
|
|
185
|
+
let serviceRtc = new ServiceRtc(channelName, account)
|
|
186
|
+
serviceRtc.add_privilege(ServiceRtc.kPrivilegeJoinChannel, joinChannelPrivilegeExpire)
|
|
187
|
+
serviceRtc.add_privilege(ServiceRtc.kPrivilegePublishAudioStream, pubAudioPrivilegeExpire)
|
|
188
|
+
serviceRtc.add_privilege(ServiceRtc.kPrivilegePublishVideoStream, pubVideoPrivilegeExpire)
|
|
189
|
+
serviceRtc.add_privilege(ServiceRtc.kPrivilegePublishDataStream, pubDataStreamPrivilegeExpire)
|
|
190
|
+
token.add_service(serviceRtc)
|
|
191
|
+
|
|
192
|
+
return token.build()
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
module.exports.RtcTokenBuilder = RtcTokenBuilder
|
|
197
|
+
module.exports.Role = Role
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const AccessToken = require("../src/AccessToken").AccessToken
|
|
2
|
+
const Priviledges = require('../src/AccessToken').priviledges
|
|
3
|
+
|
|
4
|
+
const Role = {
|
|
5
|
+
Rtm_User: 1
|
|
6
|
+
}
|
|
7
|
+
class RtmTokenBuilder {
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @param {*} appID: The App ID issued to you by Agora. Apply for a new App ID from
|
|
11
|
+
* Agora Dashboard if it is missing from your kit. See Get an App ID.
|
|
12
|
+
* @param {*} appCertificate: Certificate of the application that you registered in
|
|
13
|
+
* the Agora Dashboard. See Get an App Certificate.
|
|
14
|
+
* @param {*} account: The user account.
|
|
15
|
+
* @param {*} role : Role_Publisher = 1: A broadcaster (host) in a live-broadcast profile.
|
|
16
|
+
* Role_Subscriber = 2: (Default) A audience in a live-broadcast profile.
|
|
17
|
+
* @param {*} privilegeExpiredTs : represented by the number of seconds elapsed since
|
|
18
|
+
* 1/1/1970. If, for example, you want to access the
|
|
19
|
+
* Agora Service within 10 minutes after the token is
|
|
20
|
+
* generated, set expireTimestamp as the current
|
|
21
|
+
* @return token
|
|
22
|
+
*/
|
|
23
|
+
static buildToken (appID, appCertificate, account, role, privilegeExpiredTs) {
|
|
24
|
+
const key = new AccessToken(appID, appCertificate, account, "")
|
|
25
|
+
key.addPriviledge(Priviledges.kRtmLogin, privilegeExpiredTs)
|
|
26
|
+
return key.build()
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
module.exports.RtmTokenBuilder = RtmTokenBuilder
|
|
31
|
+
module.exports.Role = Role
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const AccessToken = require("../src/AccessToken2").AccessToken2;
|
|
2
|
+
const ServiceRtm = require("../src/AccessToken2").ServiceRtm;
|
|
3
|
+
|
|
4
|
+
class RtmTokenBuilder {
|
|
5
|
+
/**
|
|
6
|
+
* Build the RTM token.
|
|
7
|
+
*
|
|
8
|
+
* @param appId The App ID issued to you by Agora. Apply for a new App ID from
|
|
9
|
+
* Agora Dashboard if it is missing from your kit. See Get an App ID.
|
|
10
|
+
* @param appCertificate Certificate of the application that you registered in
|
|
11
|
+
* the Agora Dashboard. See Get an App Certificate.
|
|
12
|
+
* @param userId The user's account, max length is 64 Bytes.
|
|
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).
|
|
15
|
+
* @return The RTM token.
|
|
16
|
+
*/
|
|
17
|
+
static buildToken(appId, appCertificate, userId, expire) {
|
|
18
|
+
let token = new AccessToken(appId, appCertificate, null, expire);
|
|
19
|
+
|
|
20
|
+
let serviceRtm = new ServiceRtm(userId);
|
|
21
|
+
serviceRtm.add_privilege(ServiceRtm.kPrivilegeLogin, expire);
|
|
22
|
+
token.add_service(serviceRtm);
|
|
23
|
+
|
|
24
|
+
return token.build();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
module.exports.RtmTokenBuilder = RtmTokenBuilder;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const md5 = require("md5");
|
|
2
|
+
|
|
3
|
+
var SignalingToken = {}
|
|
4
|
+
|
|
5
|
+
SignalingToken.get = function(appid, appcertificate, account, validTimeInSeconds){
|
|
6
|
+
var expiredTime = parseInt(new Date().getTime() / 1000)+ validTimeInSeconds;
|
|
7
|
+
var token_items = [];
|
|
8
|
+
|
|
9
|
+
//append SDK VERSION
|
|
10
|
+
token_items.push("1");
|
|
11
|
+
|
|
12
|
+
//append appid
|
|
13
|
+
token_items.push(appid);
|
|
14
|
+
|
|
15
|
+
//expired time
|
|
16
|
+
token_items.push(expiredTime);
|
|
17
|
+
|
|
18
|
+
//md5 account + appid + appcertificate + expiredtime
|
|
19
|
+
token_items.push(md5(account + appid + appcertificate + expiredTime));
|
|
20
|
+
|
|
21
|
+
return token_items.join(":");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
//convenience function to get token valid within 1 day
|
|
25
|
+
SignalingToken.get1DayToken = function(appid, appcertificate, account){
|
|
26
|
+
return SignalingToken.get(appid, appcertificate, account, 3600 * 24);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
module.exports = SignalingToken;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* run this test with command:
|
|
3
|
+
* nodeunit AccessTokenTest.js
|
|
4
|
+
* see https://github.com/caolan/nodeunit
|
|
5
|
+
*/
|
|
6
|
+
const {AccessToken2, ServiceRtc, ServiceRtm, ServiceChat} = require('../src/AccessToken2')
|
|
7
|
+
|
|
8
|
+
var appID = "970CA35de60c44645bbae8a215061b33";
|
|
9
|
+
var appCertificate = "5CFd2fd1755d40ecb72977518be15d3b";
|
|
10
|
+
var channel = "7d72365eb983485397e3e3f9d460bdda";
|
|
11
|
+
var uid = 2882341273;
|
|
12
|
+
var uidStr = "2882341273"
|
|
13
|
+
var ts = 1111111;
|
|
14
|
+
var expire = 600;
|
|
15
|
+
var salt = 1;
|
|
16
|
+
var user_id = "test_user"
|
|
17
|
+
|
|
18
|
+
exports.AccessToken_Test = function (test) {
|
|
19
|
+
var expected = "007eJxTYBBbsMMnKq7p9Hf/HcIX5kce9b518kCiQgSr5Zrp4X1Tu6UUGCzNDZwdjU1TUs0Mkk1MzExMk5ISUy0SjQxNDcwMk4yN3b8IMEQwMTAwMoAwBIL4CgzmKeZGxmamqUmWFsYmFqbGluapxqnGaZYpJmYGSSkpiVwMRhYWRsYmhkbmxgDCaiTj";
|
|
20
|
+
|
|
21
|
+
var token = new AccessToken2(appID, appCertificate, ts, expire);
|
|
22
|
+
token.salt = salt;
|
|
23
|
+
let rtc_service = new ServiceRtc(channel, uid)
|
|
24
|
+
rtc_service.add_privilege(ServiceRtc.kPrivilegeJoinChannel, expire)
|
|
25
|
+
token.add_service(rtc_service)
|
|
26
|
+
|
|
27
|
+
var actual = token.build();
|
|
28
|
+
test.equal(expected, actual);
|
|
29
|
+
test.done();
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// test uid = 0
|
|
33
|
+
exports.AccessToken_Test2 = function (test) {
|
|
34
|
+
var expected = "007eJxTYLhzZP08Lxa1Pg57+TcXb/3cZ3wi4V6kbpbOog0G2dOYk20UGCzNDZwdjU1TUs0Mkk1MzExMk5ISUy0SjQxNDcwMk4yN3b8IMEQwMTAwMoAwBIL4CgzmKeZGxmamqUmWFsYmFqbGluapxqnGaZYpJmYGSSkpiQwMADacImo=";
|
|
35
|
+
|
|
36
|
+
var token = new AccessToken2(appID, appCertificate, ts, expire);
|
|
37
|
+
token.salt = salt;
|
|
38
|
+
let rtc_service = new ServiceRtc(channel, 0)
|
|
39
|
+
rtc_service.add_privilege(ServiceRtc.kPrivilegeJoinChannel, expire)
|
|
40
|
+
token.add_service(rtc_service)
|
|
41
|
+
|
|
42
|
+
var actual = token.build();
|
|
43
|
+
test.equal(expected, actual);
|
|
44
|
+
test.done();
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// test service rtc account
|
|
48
|
+
exports.AccessToken_Test3 = function (test) {
|
|
49
|
+
var expected = "007eJxTYBBbsMMnKq7p9Hf/HcIX5kce9b518kCiQgSr5Zrp4X1Tu6UUGCzNDZwdjU1TUs0Mkk1MzExMk5ISUy0SjQxNDcwMk4yN3b8IMEQwMTAwMoAwBIL4CgzmKeZGxmamqUmWFsYmFqbGluapxqnGaZYpJmYGSSkpiVwMRhYWRsYmhkbmxgDCaiTj";
|
|
50
|
+
|
|
51
|
+
var token = new AccessToken2(appID, appCertificate, ts, expire);
|
|
52
|
+
token.salt = salt;
|
|
53
|
+
let rtc_service = new ServiceRtc(channel, `${uid}`)
|
|
54
|
+
rtc_service.add_privilege(ServiceRtc.kPrivilegeJoinChannel, expire)
|
|
55
|
+
token.add_service(rtc_service)
|
|
56
|
+
|
|
57
|
+
var actual = token.build();
|
|
58
|
+
test.equal(expected, actual);
|
|
59
|
+
test.done();
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// test service multi service
|
|
63
|
+
exports.AccessToken_Test4 = function (test) {
|
|
64
|
+
var expected = "007eJxTYOAQsrQ5s3TfH+1tvy8zZZ46EpCc0V43JXdGd2jS8porKo4KDJbmBs6OxqYpqWYGySYmZiamSUmJqRaJRoamBmaGScbG7l8EGCKYGBgYGRgYmIAkCxCD+ExgkhlMsoBJBQbzFHMjYzPT1CRLC2MTC1NjS/NU41TjNMsUEzODpJSURC4GIwsLI2MTQyNzY5BZEJM4GUpSi0viS4tTiwAipyp4";
|
|
65
|
+
|
|
66
|
+
var token = new AccessToken2(appID, appCertificate, ts, expire);
|
|
67
|
+
token.salt = salt;
|
|
68
|
+
let rtc_service = new ServiceRtc(channel, uid)
|
|
69
|
+
rtc_service.add_privilege(ServiceRtc.kPrivilegeJoinChannel, expire)
|
|
70
|
+
rtc_service.add_privilege(ServiceRtc.kPrivilegePublishAudioStream, expire)
|
|
71
|
+
rtc_service.add_privilege(ServiceRtc.kPrivilegePublishVideoStream, expire)
|
|
72
|
+
rtc_service.add_privilege(ServiceRtc.kPrivilegePublishDataStream, expire)
|
|
73
|
+
token.add_service(rtc_service)
|
|
74
|
+
|
|
75
|
+
let rtm_service = new ServiceRtm(user_id)
|
|
76
|
+
rtm_service.add_privilege(ServiceRtm.kPrivilegeLogin, expire)
|
|
77
|
+
token.add_service(rtm_service)
|
|
78
|
+
|
|
79
|
+
var actual = token.build();
|
|
80
|
+
test.equal(expected, actual);
|
|
81
|
+
test.done();
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
exports.AccessToken_Test_buildChatUserToken = function (test) {
|
|
85
|
+
var expected = "007eJxTYNAIsnbS3v/A5t2TC6feR15r+6cq8bqAvfaW+tk/Vzz+p6xTYLA0N3B2NDZNSTUzSDYxMTMxTUpKTLVINDI0NTAzTDI2dv8iwBDBxMDAyADCrEDMCOZzMRhZWBgZmxgamRsDAB+lHrg="
|
|
86
|
+
|
|
87
|
+
var token = new AccessToken2(appID, appCertificate, ts, expire)
|
|
88
|
+
token.salt = salt
|
|
89
|
+
let chat_service = new ServiceChat(uidStr)
|
|
90
|
+
chat_service.add_privilege(ServiceChat.kPrivilegeUser, expire)
|
|
91
|
+
token.add_service(chat_service)
|
|
92
|
+
|
|
93
|
+
var actual = token.build()
|
|
94
|
+
test.equal(expected, actual)
|
|
95
|
+
test.done()
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
exports.AccessToken_Test_buildChatAppToken = function (test) {
|
|
99
|
+
var expected = "007eJxTYNDNaz3snC8huEfHWdz6s98qltq4zqy9fl99Uh0FDvy6F6DAYGlu4OxobJqSamaQbGJiZmKalJSYapFoZGhqYGaYZGzs/kWAIYKJgYGRAYRZgZgJzGdgAACt8hhr"
|
|
100
|
+
|
|
101
|
+
var token = new AccessToken2(appID, appCertificate, ts, expire)
|
|
102
|
+
token.salt = salt
|
|
103
|
+
let chat_service = new ServiceChat()
|
|
104
|
+
chat_service.add_privilege(ServiceChat.kPrivilegeApp, expire)
|
|
105
|
+
token.add_service(chat_service)
|
|
106
|
+
|
|
107
|
+
var actual = token.build()
|
|
108
|
+
test.equal(expected, actual)
|
|
109
|
+
test.done()
|
|
110
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* run this test with command:
|
|
3
|
+
* nodeunit AccessTokenTest.js
|
|
4
|
+
* see https://github.com/caolan/nodeunit
|
|
5
|
+
*/
|
|
6
|
+
const AccessToken = require("../src/AccessToken").AccessToken;
|
|
7
|
+
const Priviledges = require("../src/AccessToken").priviledges;
|
|
8
|
+
|
|
9
|
+
const appID = "970CA35de60c44645bbae8a215061b33";
|
|
10
|
+
const appCertificate = "5CFd2fd1755d40ecb72977518be15d3b";
|
|
11
|
+
const channel = "7d72365eb983485397e3e3f9d460bdda";
|
|
12
|
+
const uid = 2882341273;
|
|
13
|
+
const salt = 1;
|
|
14
|
+
const ts = 1111111;
|
|
15
|
+
const expireTimestamp = 1446455471;
|
|
16
|
+
|
|
17
|
+
exports.AccessToken_Test = function (test) {
|
|
18
|
+
const expected = "006970CA35de60c44645bbae8a215061b33IACV0fZUBw+72cVoL9eyGGh3Q6Poi8bgjwVLnyKSJyOXR7dIfRBXoFHlEAABAAAAR/QQAAEAAQCvKDdW";
|
|
19
|
+
|
|
20
|
+
const key = new AccessToken(appID, appCertificate, channel, uid);
|
|
21
|
+
key.salt = salt;
|
|
22
|
+
key.ts = ts;
|
|
23
|
+
key.messages[Priviledges.kJoinChannel] = expireTimestamp;
|
|
24
|
+
|
|
25
|
+
const actual = key.build();
|
|
26
|
+
test.equal(expected, actual);
|
|
27
|
+
test.done();
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// test uid = 0
|
|
31
|
+
exports.AccessToken_Test2 = function (test) {
|
|
32
|
+
const expected = "006970CA35de60c44645bbae8a215061b33IACw1o7htY6ISdNRtku3p9tjTPi0jCKf9t49UHJhzCmL6bdIfRAAAAAAEAABAAAAR/QQAAEAAQCvKDdW";
|
|
33
|
+
|
|
34
|
+
const uid_zero = 0;
|
|
35
|
+
const key = new AccessToken(appID, appCertificate, channel, uid_zero);
|
|
36
|
+
key.salt = salt;
|
|
37
|
+
key.ts = ts;
|
|
38
|
+
key.messages[Priviledges.kJoinChannel] = expireTimestamp;
|
|
39
|
+
|
|
40
|
+
const actual = key.build();
|
|
41
|
+
test.equal(expected, actual);
|
|
42
|
+
test.done();
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const RtcRole = require("../src/RtcTokenBuilder").Role;
|
|
46
|
+
|
|
47
|
+
exports.RtcTokenBuilder_Test = function (test) {
|
|
48
|
+
const appID = "970CA35de60c44645bbae8a215061b33";
|
|
49
|
+
const certificate = "5CFd2fd1755d40ecb72977518be15d3b";
|
|
50
|
+
const expected =
|
|
51
|
+
"006970CA35de60c44645bbae8a215061b33IACMv3I+fsRSejxy6luEwzA/1t/zbEHWfJCJ5m8ssFP/fLdIfRBXoFHlIgABAAAAR/QQAAQAAQCvKDdWAgCvKDdWAwCvKDdWBACvKDdW";
|
|
52
|
+
|
|
53
|
+
const channelName = "7d72365eb983485397e3e3f9d460bdda";
|
|
54
|
+
|
|
55
|
+
const uid = 2882341273;
|
|
56
|
+
|
|
57
|
+
const salt = 1;
|
|
58
|
+
|
|
59
|
+
const ts = 1111111;
|
|
60
|
+
|
|
61
|
+
const privilegeExpiredsTs = 1446455471;
|
|
62
|
+
|
|
63
|
+
const role = RtcRole.PUBLISHER;
|
|
64
|
+
|
|
65
|
+
const key = new AccessToken(appID, certificate, channelName, uid);
|
|
66
|
+
key.addPriviledge(Priviledges.kJoinChannel, privilegeExpiredsTs);
|
|
67
|
+
key.salt = salt;
|
|
68
|
+
key.ts = ts;
|
|
69
|
+
if (role == RtcRole.PUBLISHER || role == RtcRole.SUBSCRIBER || role == RtcRole.ADMIN) {
|
|
70
|
+
key.addPriviledge(Priviledges.kPublishAudioStream, privilegeExpiredsTs);
|
|
71
|
+
key.addPriviledge(Priviledges.kPublishVideoStream, privilegeExpiredsTs);
|
|
72
|
+
key.addPriviledge(Priviledges.kPublishDataStream, privilegeExpiredsTs);
|
|
73
|
+
}
|
|
74
|
+
const actual = key.build();
|
|
75
|
+
test.equal(expected, actual);
|
|
76
|
+
test.done();
|
|
77
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* run this test with command:
|
|
3
|
+
* nodeunit DynamicKeyTest.js
|
|
4
|
+
* see https://github.com/caolan/nodeunit
|
|
5
|
+
*/
|
|
6
|
+
var DynamicKey5 = require('../src/DynamicKey5');
|
|
7
|
+
|
|
8
|
+
var appID = "970ca35de60c44645bbae8a215061b33";
|
|
9
|
+
var appCertificate = "5cfd2fd1755d40ecb72977518be15d3b";
|
|
10
|
+
var channel = "7d72365eb983485397e3e3f9d460bdda";
|
|
11
|
+
var ts = 1446455472;
|
|
12
|
+
var r = 58964981;
|
|
13
|
+
//var uid=999;
|
|
14
|
+
var uid=2882341273;
|
|
15
|
+
var expiredTs=1446455471;
|
|
16
|
+
|
|
17
|
+
exports.PublicSharingKey5_Test = function(test) {
|
|
18
|
+
var expected = "005AwAoADc0QTk5RTVEQjI4MDk0NUI0NzUwNTk0MUFDMjM4MDU2NzIwREY3QjAQAJcMo13mDERkW7roohUGGzOwKDdW9buDA68oN1YAAA==";
|
|
19
|
+
var actual = DynamicKey5.generatePublicSharingKey(appID, appCertificate, channel, ts, r, uid, expiredTs);
|
|
20
|
+
test.equal(expected, actual);
|
|
21
|
+
test.done();
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
exports.RecordingKey5_Test = function(test) {
|
|
25
|
+
var expected = "005AgAoADkyOUM5RTQ2MTg3QTAyMkJBQUIyNkI3QkYwMTg0MzhDNjc1Q0ZFMUEQAJcMo13mDERkW7roohUGGzOwKDdW9buDA68oN1YAAA==";
|
|
26
|
+
var result = DynamicKey5.generateRecordingKey(appID, appCertificate, channel, ts, r, uid, expiredTs);
|
|
27
|
+
test.equal(expected, result);
|
|
28
|
+
test.done();
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
exports.MediaChannelKey5_Test = function(test) {
|
|
32
|
+
var expected = "005AQAoAEJERTJDRDdFNkZDNkU0ODYxNkYxQTYwOUVFNTM1M0U5ODNCQjFDNDQQAJcMo13mDERkW7roohUGGzOwKDdW9buDA68oN1YAAA==";
|
|
33
|
+
var result = DynamicKey5.generateMediaChannelKey(appID, appCertificate, channel, ts, r, uid, expiredTs);
|
|
34
|
+
test.equal(expected, result);
|
|
35
|
+
test.done();
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
exports.InChannelPermission5_Test = function(test) {
|
|
39
|
+
var noUpload = "005BAAoADgyNEQxNDE4M0FGRDkyOEQ4REFFMUU1OTg5NTg2MzA3MTEyNjRGNzQQAJcMo13mDERkW7roohUGGzOwKDdW9buDA68oN1YBAAEAAQAw";
|
|
40
|
+
var generatedNoUpload = DynamicKey5.generateInChannelPermissionKey(appID, appCertificate, channel, ts, r, uid, expiredTs, DynamicKey5.noUpload);
|
|
41
|
+
test.equal(noUpload, generatedNoUpload);
|
|
42
|
+
|
|
43
|
+
var audioVideoUpload = "005BAAoADJERDA3QThENTE2NzJGNjQwMzY5NTFBNzE0QkI5NTc0N0Q1QjZGQjMQAJcMo13mDERkW7roohUGGzOwKDdW9buDA68oN1YBAAEAAQAz";
|
|
44
|
+
var generatedAudioVideoUpload = DynamicKey5.generateInChannelPermissionKey(appID, appCertificate, channel, ts, r, uid, expiredTs, DynamicKey5.audioVideoUpload);
|
|
45
|
+
test.equal(audioVideoUpload, generatedAudioVideoUpload);
|
|
46
|
+
test.done();
|
|
47
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* run this test with command:
|
|
3
|
+
* nodeunit test/EducationTokenBuilderTest.js
|
|
4
|
+
* see https://github.com/caolan/nodeunit
|
|
5
|
+
*/
|
|
6
|
+
const EduTokenBuilder = require('../src/EducationTokenBuilder').EducationTokenBuilder
|
|
7
|
+
const {AccessToken2, kEducationServiceType} = require('../src/AccessToken2')
|
|
8
|
+
const appId = "970CA35de60c44645bbae8a215061b33"
|
|
9
|
+
const appCertificate = "5CFd2fd1755d40ecb72977518be15d3b"
|
|
10
|
+
const expire = 600
|
|
11
|
+
const roomUuid = "123";
|
|
12
|
+
const userUuid = "2882341273";
|
|
13
|
+
const role = 1;
|
|
14
|
+
|
|
15
|
+
exports.BuildRoomUserToken_Test = function (test) {
|
|
16
|
+
let accessToken = new AccessToken2('', '', 0, 0)
|
|
17
|
+
let token = EduTokenBuilder.buildRoomUserToken(appId, appCertificate, roomUuid, userUuid, role, expire)
|
|
18
|
+
accessToken.from_string(token)
|
|
19
|
+
test.equal(appId, accessToken.appId)
|
|
20
|
+
test.equal(expire, accessToken.expire)
|
|
21
|
+
test.equal(roomUuid, accessToken.services[kEducationServiceType].__room_uuid)
|
|
22
|
+
test.equal(userUuid, accessToken.services[kEducationServiceType].__user_uuid)
|
|
23
|
+
test.equal(role, accessToken.services[kEducationServiceType].__role)
|
|
24
|
+
test.done()
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
exports.BuildUserToken_Test = function (test) {
|
|
28
|
+
let accessToken = new AccessToken2('', '', 0, 0)
|
|
29
|
+
let token = EduTokenBuilder.buildUserToken(appId, appCertificate, userUuid, expire)
|
|
30
|
+
accessToken.from_string(token)
|
|
31
|
+
|
|
32
|
+
test.equal(appId, accessToken.appId)
|
|
33
|
+
test.equal(expire, accessToken.expire)
|
|
34
|
+
test.equal(userUuid, accessToken.services[kEducationServiceType].__user_uuid)
|
|
35
|
+
test.done()
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
exports.BuildAppToken_Test = function (test) {
|
|
39
|
+
let accessToken = new AccessToken2('', '', 0, 0)
|
|
40
|
+
let token = EduTokenBuilder.buildAppToken(appId, appCertificate, expire)
|
|
41
|
+
accessToken.from_string(token)
|
|
42
|
+
test.equal(appId, accessToken.appId)
|
|
43
|
+
test.equal(expire, accessToken.expire)
|
|
44
|
+
test.done()
|
|
45
|
+
}
|