Skip to content

Commit c57dc9f

Browse files
author
wesleytong
committed
node usersig 翻译
1 parent 2d504a6 commit c57dc9f

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

README_EN.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## npm integration
2+
```shell
3+
npm i tls-sig-api-v2
4+
```
5+
6+
## source code integration
7+
Just place the file `TLSSigAPIv2.js` in the desired path.
8+
9+
## interface call
10+
```javascript
11+
var TLSSigAPIv2 = require('tls-sig-api-v2');
12+
// var TLSSigAPIv2 = require('./TLSSigAPIv2'); // 源码集成需要使用相对路径
13+
14+
var api = new TLSSigAPIv2.Api(1400000000, "5bd2850fff3ecb11d7c805251c51ee463a25727bddc2385f3fa8bfee1bb93b5e");
15+
var sig = api.genSig("xiaojun", 86400*180);
16+
console.log(sig);
17+
```

TLSSigAPIv2.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,20 @@ Api.prototype._hmacsha256 = function (identifier, currTime, expire, base64UserBu
7171
* @param roomstr 字符串房间号
7272
* @return userbuf {string} 返回的userbuf
7373
*/
74+
75+
/**
76+
* User-defined userbuf is used for the encrypted string of TRTC service entry permission
77+
* @brief generate userbuf
78+
* @param account username
79+
* @param dwSdkappid sdkappid
80+
* @param dwAuthID digital room number
81+
* @param dwExpTime Expiration time: The expiration time of the encrypted string of this permission. Expiration time = now+dwExpTime
82+
* @param dwPrivilegeMap User permissions, 255 means all permissions
83+
* @param dwAccountType User type, default is 0
84+
* @param roomStr String room number
85+
* @return userbuf string returned userbuf
86+
*/
87+
7488
Api.prototype._genUserbuf = function (account, dwAuthID, dwExpTime,
7589
dwPrivilegeMap, dwAccountType, roomstr) {
7690

@@ -175,6 +189,14 @@ Api.prototype.genSig = function (userid, expire, userBuf) {
175189
* @param userid - 用户id,限制长度为32字节,只允许包含大小写英文字母(a-zA-Z)、数字(0-9)及下划线和连词符。
176190
* @param expire - UserSig 票据的过期时间,单位是秒,比如 86400 代表生成的 UserSig 票据在一天后就无法再使用了。
177191
*/
192+
193+
/**
194+
* Function: Used to issue UserSig that is required by the TRTC and IM services.
195+
*
196+
* Parameter description:
197+
* @param userid - User ID. The value can be up to 32 bytes in length and contain letters (a-z and A-Z), digits (0-9), underscores (_), and hyphens (-).
198+
* @param expire - UserSig expiration time, in seconds. For example, 86400 indicates that the generated UserSig will expire one day after being generated.
199+
*/
178200
Api.prototype.genUserSig = function (userid, expire) {
179201
return this.genSig(userid, expire, null);
180202
};
@@ -203,6 +225,32 @@ Api.prototype.genUserSig = function (userid, expire) {
203225
* - privilegeMap == 1111 1111 == 255 代表该 userid 在该 roomid 房间内的所有功能权限。
204226
* - privilegeMap == 0010 1010 == 42 代表该 userid 拥有加入房间和接收音视频数据的权限,但不具备其他权限。
205227
*/
228+
229+
/**
230+
* Function:
231+
* Used to issue PrivateMapKey that is optional for room entry.
232+
* PrivateMapKey must be used together with UserSig but with more powerful permission control capabilities.
233+
* - UserSig can only control whether a UserID has permission to use the TRTC service. As long as the UserSig is correct, the user with the corresponding UserID can enter or leave any room.
234+
* - PrivateMapKey specifies more stringent permissions for a UserID, including whether the UserID can be used to enter a specific room and perform audio/video upstreaming in the room.
235+
* To enable stringent PrivateMapKey permission bit verification, you need to enable permission key in TRTC console > Application Management > Application Info.
236+
*
237+
* Parameter description:
238+
* userid - User ID. The value can be up to 32 bytes in length and contain letters (a-z and A-Z), digits (0-9), underscores (_), and hyphens (-).
239+
* roomid - ID of the room to which the specified UserID can enter.
240+
* expire - PrivateMapKey expiration time, in seconds. For example, 86400 indicates that the generated PrivateMapKey will expire one day after being generated.
241+
* privilegeMap - Permission bits. Eight bits in the same byte are used as the permission switches of eight specific features:
242+
* - Bit 1: 0000 0001 = 1, permission for room creation
243+
* - Bit 2: 0000 0010 = 2, permission for room entry
244+
* - Bit 3: 0000 0100 = 4, permission for audio sending
245+
* - Bit 4: 0000 1000 = 8, permission for audio receiving
246+
* - Bit 5: 0001 0000 = 16, permission for video sending
247+
* - Bit 6: 0010 0000 = 32, permission for video receiving
248+
* - Bit 7: 0100 0000 = 64, permission for substream video sending (screen sharing)
249+
* - Bit 8: 1000 0000 = 200, permission for substream video receiving (screen sharing)
250+
* - privilegeMap == 1111 1111 == 255: Indicates that the UserID has all feature permissions of the room specified by roomid.
251+
* - privilegeMap == 0010 1010 == 42: Indicates that the UserID has only the permissions to enter the room and receive audio/video data.
252+
*/
253+
206254
Api.prototype.genPrivateMapKey = function (userid, expire, roomid, privilegeMap) {
207255
var userBuf = this._genUserbuf(userid, roomid, expire, privilegeMap, 0, null);
208256
return this.genSig(userid, expire, userBuf);
@@ -232,6 +280,31 @@ Api.prototype.genPrivateMapKey = function (userid, expire, roomid, privilegeMap)
232280
* - privilegeMap == 1111 1111 == 255 代表该 userid 在该房间内的所有功能权限。
233281
* - privilegeMap == 0010 1010 == 42 代表该 userid 拥有加入房间和接收音视频数据的权限,但不具备其他权限。
234282
*/
283+
284+
/**
285+
* Function:
286+
* Used to issue PrivateMapKey that is optional for room entry.
287+
* PrivateMapKey must be used together with UserSig but with more powerful permission control capabilities.
288+
* - UserSig can only control whether a UserID has permission to use the TRTC service. As long as the UserSig is correct, the user with the corresponding UserID can enter or leave any room.
289+
* - PrivateMapKey specifies more stringent permissions for a UserID, including whether the UserID can be used to enter a specific room and perform audio/video upstreaming in the room.
290+
* To enable stringent PrivateMapKey permission bit verification, you need to enable permission key in TRTC console > Application Management > Application Info.
291+
*
292+
* Parameter description:
293+
* @param userid - User ID. The value can be up to 32 bytes in length and contain letters (a-z and A-Z), digits (0-9), underscores (_), and hyphens (-).
294+
* @param roomstr - ID of the room to which the specified UserID can enter.
295+
* @param expire - PrivateMapKey expiration time, in seconds. For example, 86400 indicates that the generated PrivateMapKey will expire one day after being generated.
296+
* @param privilegeMap - Permission bits. Eight bits in the same byte are used as the permission switches of eight specific features:
297+
* - Bit 1: 0000 0001 = 1, permission for room creation
298+
* - Bit 2: 0000 0010 = 2, permission for room entry
299+
* - Bit 3: 0000 0100 = 4, permission for audio sending
300+
* - Bit 4: 0000 1000 = 8, permission for audio receiving
301+
* - Bit 5: 0001 0000 = 16, permission for video sending
302+
* - Bit 6: 0010 0000 = 32, permission for video receiving
303+
* - Bit 7: 0100 0000 = 64, permission for substream video sending (screen sharing)
304+
* - Bit 8: 1000 0000 = 200, permission for substream video receiving (screen sharing)
305+
* - privilegeMap == 1111 1111 == 255: Indicates that the UserID has all feature permissions of the room specified by roomid.
306+
* - privilegeMap == 0010 1010 == 42: Indicates that the UserID has only the permissions to enter the room and receive audio/video data.
307+
*/
235308
Api.prototype.genPrivateMapKeyWithStringRoomID = function (userid, expire, roomstr, privilegeMap) {
236309
var userBuf = this._genUserbuf(userid, 0, expire, privilegeMap, 0, roomstr);
237310
return this.genSig(userid, expire, userBuf);

0 commit comments

Comments
 (0)