Follow Anchors
Description of the Feature
In live streaming scenarios, the Follow the host feature is an important interaction method. It allows viewers to choose to follow specific hosts, thus establishing long-term interaction and follow relationships on the live streaming platform. The TUILiveKit has implemented the Follow the host feature through Chat.
Follow feature allows users to choose other users they are interested in so that they can get the latest updates, posts, or event information promptly. You can provide personalized content recommendations based on the user's Follow list.
Fans feature refers to the status of a user being followed by others. When User A follows User B, A becomes a Fan of B.
Through the Follow and Fans features, social applications and websites can create an active and interconnected user network, promoting the dissemination of information and the building of communities.
Use Instructions
Note:
TUILiveKit's Follow the host feature relies on the Chat Follow & Fan APIs, so you need to activate the related Package bundles for Chat. For details, please refer to the Follow&Fan documentation.
Unfollowed Status | Followed Status | Broadcaster Info Panel |
| | |
Follow the host: You can click the
button in the live room information area at the top left corner of the live streaming interface to follow the hostUnfollow: You can click the
button in the live room information area at the top left corner of the live streaming interface to unfollow the hostView the host's fan count: You can click the live room information area at the top left corner of the live streaming interface to pop up the live room details panel, which will display the host's fan count.
Feature customization
If the current UI does not meet your needs, you can achieve your desired UI effects by modifying the source code. For easier UI customization, an introduction to the files related to the follow feature is provided here.
// File location:Android/tuilivekit/src/Main/java/com/trtc/uikit/livekit/common/uicomponent/
roominfo // Directory for implementing the live room information UI component├── RoomInfoDetailView.java // Specific implementation of the Live Room Information Details Panel View└── RoomInfoView.java // Specific implementation of the Live Room Information View. Clicking this view will show the Details Panel View
// File location:TUILiveKit/iOS/TUILiveKit/Sources/Component/LiveInfo/
LiveInfo // Implementation directory of Live Room Information UI Component├── LiveInfoView.swift // Detailed implementation of Live Room Information Panel View└── View└── LiveInfoPanelView.swift // Detailed implementation of Live Room Information View, clicking this view will display the detailed panel view
Key code
Follow anchor
// File location:Android/tuilivekit
/src/Main/java/com/trtc/uikit/livekit/service/impl/LiveServiceImpl.javaList<String> userIDList = new ArrayList<>();userIDList.add("userId");V2TIMManager.getFriendshipManager().followUser(userIDList,new V2TIMValueCallback<List<V2TIMFollowOperationResult>>() {@Overridepublic void onSuccess(List<V2TIMFollowOperationResult> results) {}@Overridepublic void onError(int code, String message) {}});
// File location:TUILiveKit/iOS/TUILiveKit/Sources/Component/LiveInfo/RoomInfoService
public func followUser(userId: String) {let userInfo = TUIUserInfo()userInfo.userId = userIdV2TIMManager.sharedInstance().followUser([userId]) { [weak self] followResultList inguard let self = self, let result = followResultList?.first else { return }if result.resultCode == 0, !self.state.followingList.contains(where: { $0.userId == userId }) {self.state.followingList.insert(userInfo)self.getFansNumber()}} fail: { code, message indebugPrint("[RoomInfo] followUser failed, error:\(code), message:\(String(describing: message))")}}
Unfollow anchor
// File location:Android/tuilivekit
/src/Main/java/com/trtc/uikit/livekit/service/impl/LiveServiceImpl.javaList<String> userIDList = new ArrayList<>();userIDList.add("userId");V2TIMManager.getFriendshipManager().unfollowUser(userIDList,new V2TIMValueCallback<List<V2TIMFollowOperationResult>>() {@Overridepublic void onSuccess(List<V2TIMFollowOperationResult> results) {}@Overridepublic void onError(int code, String message) {}});
// File location:TUILiveKit/iOS/TUILiveKit/Sources/Component/LiveInfo/RoomInfoService
public func unfollowUser(userId: String) {V2TIMManager.sharedInstance().unfollowUser([userId]) { [weak self] followResultList inguard let self = self, let result = followResultList?.first else { return }if result.resultCode == 0 {self.state.followingList = state.followingList.filter { $0.userId != userId}}} fail: { code, message indebugPrint("[RoomInfo] unfollowUser failed, error:\(code), message:\(String(describing: message))")}}
View anchor's follow status
// File location:Android/tuilivekit
/src/Main/java/com/trtc/uikit/livekit/service/impl/LiveServiceImpl.javaList<String> userIDList = new ArrayList<>();userIDList.add("userId");V2TIMManager.getFriendshipManager().checkFollowType(userIDList,new V2TIMValueCallback<List<V2TIMFollowTypeCheckResult>>() {@Overridepublic void onSuccess(List<V2TIMFollowTypeCheckResult> results) {}@Overridepublic void onError(int code, String message) {}});
// File location:TUILiveKit/iOS/TUILiveKit/Sources/Component/LiveInfo/RoomInfoService
public func isFollow(userId: String) {let userInfo = TUIUserInfo()userInfo.userId = userIdV2TIMManager.sharedInstance().checkFollowType([state.ownerId]) { [weak self] checkResultList inguard let self = self, let result = checkResultList?.first else { return }if result.followType == .FOLLOW_TYPE_IN_BOTH_FOLLOWERS_LIST || result.followType == .FOLLOW_TYPE_IN_MY_FOLLOWING_LIST {if !self.state.followingList.contains(where: { $0.userId == userId }) {self.state.followingList.insert(userInfo)}} else {self.state.followingList = state.followingList.filter { $0.userId != userId}}} fail: { code, message indebugPrint("[RoomInfo] isFollow failed, error:\(code), message:\(String(describing: message))")}}
Get number of followers
// File location:Android/tuilivekit
/src/Main/java/com/trtc/uikit/livekit/service/impl/LiveServiceImpl.javaList<String> userIDList = new ArrayList<>();userIDList.add("userId");V2TIMManager.getFriendshipManager().getUserFollowInfo(userIDList,new V2TIMValueCallback<List<V2TIMFollowInfo>>() {@Overridepublic void onSuccess(List<V2TIMFollowInfo> results) {}@Overridepublic void onError(int code, String message) {}});
// File location:TUILiveKit/iOS/TUILiveKit/Sources/Component/LiveInfo/RoomInfoService
public func getFansNumber() {V2TIMManager.sharedInstance().getUserFollowInfo([state.ownerId]) { [weak self] followInfoList inguard let self = self, let followInfo = followInfoList?.first else { return }self.state.fansNumber = Int(followInfo.followersCount)} fail: { code, message indebugPrint("[RoomInfo] getFansNumber failed, error:\(code), message:\(String(describing: message))")}}