User Information
This document primarily provides the API description for user information provided by 用户模块(user).
1. Viewer Details
Interface: UserInfoDetail
| Property Name | Description | Type |
|---|---|---|
userId |
User ID | string |
nick |
Viewer Nickname | string |
pic |
Viewer Avatar | string |
actor |
Viewer Title | string |
openId |
WeChat OpenID | string |
unionId |
WeChat UnionId | string |
authType |
User Authorization Method | AuthType |
label |
Tags | Object |
2. Get Current User Info
Used to get the detailed information of the current user.
Returns
undefinedif viewing conditions are not authorized or no user info was passed when creating the SDK.
API Method: getUserInfo(): undefined | UserInfoDetail
Return Value Description: User info, type undefined | UserInfoDetail
Example:
const userInfo = watchCore.user.getUserInfo();
console.log('用户信息', userInfo);
3. Check if User is a Special User Type
The user module provides an API to determine if the user identity is a built-in special user identity, such as lecturer, admin, teaching assistant, etc.
API Method: isSpecialUserType(userType: unknown, actor?: string): boolean
Parameter Description:
- userType: User identity, type
unknown, required - actor: User title, type
string, optional
Return Value Description: Whether it is a special identity
Example:
import { ChatUserType } from '@polyv/live-watch-sdk';
console.log(watchCore.user.isSpecialUserType(ChatUserType.Teacher)); // true
console.log(watchCore.user.isSpecialUserType(ChatUserType.Manager)); // true
console.log(watchCore.user.isSpecialUserType(ChatUserType.Guest)); // true
console.log(watchCore.user.isSpecialUserType(ChatUserType.Student)); // false
console.log(watchCore.user.isSpecialUserType(ChatUserType.Viewer)); // false
console.log(watchCore.user.isSpecialUserType(ChatUserType.Dummy)); // false
console.log(watchCore.user.isSpecialUserType(ChatUserType.Dummy, '观众')); // false
4. Get Current User's userId
Used to get the current user's userId. The default userId is a timestamp string. Notes on userId:
- After WeChat authorization in a WeChat environment, the user's WeChat
openidis used as the userId. - After whitelist authorization, the entered membership code is used as the userId (higher priority than WeChat authorization).
Returns
undefinedif viewing conditions are not authorized or no user info was passed when creating the SDK.
API Method: getUserId(): undefined | string
Return Value Description: User userId, type undefined | string
Example:
const userId = watchCore.user.getUserId();
console.log('用户 userId', userId);
5. Get Current User Nickname
Used to get the current user's nickname.
Returns
undefinedif viewing conditions are not authorized or no user info was passed when creating the SDK.
API Method: getUserNick(): undefined | string
Return Value Description: User nickname, type undefined | string
Example:
const nickname = watchCore.user.getUserNick();
console.log('用户昵称', nickname);
6. Modify Current User Nickname
Used for viewers to modify their nickname a second time.
- Listen for nickname modification completion via the UserEvents.CurrentUserSetNick event.
- Listen for nickname setting failure via the UserEvents.SetNickError event.
API Method: updateUserNick(nickname: string): void
Parameter Description:
- nickname: New nickname, type
string, required
Example:
watchCore.user.eventEmitter.on(UserEvents.CurrentUserSetNick, () => {
toast.success('修改昵称成功');
});
watchCore.user.eventEmitter.on(UserEvents.SetNickError, (data) => {
toast.error('修改昵称失败:' + data.message);
});
watchCore.user.updateUserNick('新的用户昵称');
7. Get Current User Avatar URL
Used to get the current user's avatar URL. The viewing page SDK provides the constant DEFAULT_VIEWER_AVATAR for the default viewer avatar.
Returns
undefinedif viewing conditions are not authorized or no user info was passed when creating the SDK.
API Method: getUserAvatar(): undefined | string
Return Value Description: User avatar URL, type undefined | string
Example:
import { DEFAULT_VIEWER_AVATAR } from '@polyv/live-watch-sdk';
const userAvatar = watchCore.user.getUserAvatar();
console.log('用户头像', userAvatar);
console.log('默认头像', DEFAULT_VIEWER_AVATAR);
8. Get Current User's WeChat OpenID
Used to get the current user's WeChat OpenID. Only returned after (non-)silent WeChat authorization.
API Method: getUserOpenId(): undefined | string
Return Value Description: WeChat OpenID, type undefined | string
Example:
const openId = watchCore.user.getUserOpenId();
console.log('openId', openId);
9. Get Current User's WeChat UnionId
Used to get the current user's WeChat UnionId. Only returned after (non-)silent WeChat authorization.
API Method: getUserUnionId(): undefined | string
Return Value Description: WeChat UnionId, type undefined | string
Example:
const unionId = watchCore.user.getUserUnionId();
console.log('unionId', unionId);
10. Get Current User's Title
API Method: getUserActor(): undefined | string
Supported from version v0.11.0
Return Value Description: User title, type undefined | string
Example:
const actor = watchCore.user.getUserActor();
console.log('actor', actor);
11. Get Tags Related to the Current User
API Method: getUserLabels(): undefined | Object
Supported from version v2.18.0
Return Value Description: User title
const labels = watchCore.user.getUserLabels();
console.log('labels', labels);
```, type `undefined | Object`
<a id="classmethoddoc_plvusermodule_needhideuseractor"></a>
## 12. Whether to Hide User Title
**API Method:** `needHideUserActor(): boolean`
> Supported from version v1.2.0
<a id="classmethoddoc_plvusermodule_getuserauthtype"></a>
## 13. Get Current User's Authorization Method
Used to get the current user's authorization method. Returns AuthType.None if not authorized.
**API Method:** `getUserAuthType(): AuthType`
**Return Value Description:** Authorization method, type `AuthType`
**Example:**
```js
const authType = watchCore.user.getUserAuthType();
console.log('当前用户的授权方式', authType);
14. Whether Phone Number Real-Name Authentication is Required
API Method: needRealNameAuth(): Promise<boolean>
Supported from version v0.8.0
Return Value Description: Whether authentication is required, type Promise<boolean>
Example:
const needAuth = watchCore.user.needRealNameAuth();
if (needAuth) {
console.log('需要认证,显示认证弹层');
}
15. Save Real-Name Authentication Information
API Method: saveRealNameData(option: SaveRealNameOptions): Promise<RealNameResult>
Supported from version v0.8.0
Parameter Description:
- option: Option parameter, type
SaveRealNameOptions, required. Detailed type description is as follows:
| Parameter Name | Description | Type | Required | Default Value |
|---|---|---|---|---|
areaCode |
Phone Area Code | string |
Yes | - |
phoneNumber |
Phone Number | string |
Yes | - |
smsCode |
SMS Verification Code | string |
Yes | - |
Return Value Description: Type Promise<RealNameResult>
16. Get Current Viewer's Cloud Seat Information
API Method: getUserSeatInfo(): undefined | ViewerSeatInfo
Supported from version v0.10.0
Return Value Description: Type undefined | ViewerSeatInfo
17. Get Current Viewer's Follower Information
API Method: getUserSaleInfo(): ViewerSaleInfo
Supported from version v1.1.0
Return Value Description: User follower information, type ViewerSaleInfo. Detailed type description is as follows:
| Property Name | Description | Type |
|---|---|---|
saleId |
Follower ID | undefined | string |
18. Get Invite Watch Inviter/Distributor ID
API Method: getInviteWatchSaleId(): null | string
Supported from version v2.0.0
Return Value Description: Type null | string
19. Get the inviteWatchSaleId of the Superior Inviter for Invite Watch
API Method: getInviteWatchInviteSalesId(): null | string
Supported from version v2.2.0
Return Value Description: Type null | string
