The Interactive Gift Component is a virtual gift interaction platform designed to add more fun to users' social experiences. With this component, users can send virtual gifts to their favorite live streamers to express their appreciation, love, and support. The Interactive Gift Component supports settings for gift materials, balance display, normal gift playback and full-screen gift playback, recharge button, etc. The feature of interactive gifts has been implemented in TUILiveKit through Chat.
Use Instructions
Gift Effect
Gift Display Panel
Normal Gift Playback Effect
Full-Screen Gift Playback Effect
Gift System
Gift System Architecture Diagram
Gift System Sequence Diagram
Non-persistent connection requests from the client are sent to its own business server, involving gift billing logic.
1. After billing, the sender directly sees that XXX sent a gift to XXX (to ensure the sender sees their own sent gift. When the message volume is large, it may trigger an abandonment strategy).
2. After the fees are settled, call GiftListView.sendGift to send the gift message.
Feature Customization
Customizable Gifts Backend Logic
If you need custom backend services for gifts, please refer to the following path for modifications.
giftcloudserver// Self Definition gift backend service directory
├── GiftCloudServer.java // Default implementation class, interacts with the gift backend, responsible for balance verification, settlement, statistics, etc. Clients are advised to implement their custom version
└── IGiftCloudServer.java // Gift backend service interface
├── CloudServerConfig.swift // Service Layer Data Source for Gift Component
├── GiftCloudServer.swift // Default implementation class, interacting with the gift backend, responsible for verifying balance, settlement, statistics, etc. Custom implementation is recommended for clients
└── IGiftCloudServer.swift // Gift backend service interface
Custom Gift Panel View
If you need a custom gift panel view, please refer to the following path for modifications.
The client implements the logic of giftCloudServer.queryGiftInfoList to get a custom gift list List<TUIGift>, and sets the gift list via GiftListView.setGiftList.
The animationUrl of the gift requires an SVGA animation.
Clients need to implement the logic of giftCloudServer.sendGift. The main process is to first connect to the client’s business server for balance verification. After verification, the server performs billing and records the consumption. Finally, it calls back the result to the client. Upon receiving the successful callback, the client sends the gift message through GiftListView's sendGift and updates the gift balance via setBalance.
Customizable loading and playing of gift animations
giftCacheService.request(withURL: url){ error, fileUrl in
if error ==0{
DispatchQueue.main.async{
giftPlayView.playGiftAnimation(playUrl: fileUrl)
}
}
}
}
Note:
Clients need to implement the logic of giftCacheService.request. After successfully loading the animation, get the fileUrl (String type) and play the gift animation through TUIGiftPlayView's playGiftAnimation.
Key code
Quick Integration
The gift component mainly provides 2 APIs:
TUIGiftListView: Gift Panel, presents the gift list, sends gifts, and recharges.
TUIGiftPlayView: Panel for playing gifts, automatically listens to gift messages.
Set gift materials
The gift panel component TUIGiftListView provides the setGiftList interface, which can be used to set gift materials.
The Interactive Gift Component supports setting your own gift media. If animationUrl is empty, the gift playback effect is standard, and the content played is the image linked by imageUrl; if animationUrl is not empty, the playback effect is full-screen, and the content played is the corresponding svga animation.
Gift Sending and Receiving
Send Gift
Implement the callback TUIGiftListView delegate TUIGiftListViewDelegate in onSendGift:giftListView:gift:giftCount to get the gift count and gift information. After pre-processing, you can call the TUIGiftListView's sendGift function for the actual gift sending.
If you need to get the callback information of receiving gifts, you can implement the onReceiveGift callback in the TUIGiftPlayViewListener of TUIGiftPlayView.
If you need to obtain callback information for receiving gifts, you can implement the TUIGiftPlayView delegate TUIGiftPlayViewDelegate function giftPlayView:onReceiveGift:gift:giftCount:sender:receiver.
You need to actively invoke the playGiftAnimation method of TUIGiftPlayView when you receive onPlayGiftAnimation callback from the TUIGiftPlayViewListener of TUIGiftPlayView.
It is required to actively call TUIGiftPlayView 's playGiftAnimation to play the animation. The appropriate time to call is upon receiving the TUIGiftPlayViewDelegate's giftPlayView:onPlayGiftAnimation callback.
The gift panel component TUIGiftListView provides the setBalance interface, which can be used to set the balance value displayed on the gift panel.
Android
iOS
giftListView.setBalance(xxx);
giftListView.setBalance(xxx);
Recharge
Android
iOS
Implementing the onRecharge callback in the OnGiftListener of TUIGiftListView can be used to receive the click event of the recharge button thrown by the gift display panel. Here, you can connect to your own recharge system.
Implement the delegate TUIGiftListViewDelegate in TUIGiftListView, the onRecharge:view callback can be used to receive the recharge button click event thrown by the gift display panel, where you can integrate your own recharge system.
Gift balance is a virtual currency concept, not real money.
The gift recharge logic is implemented externally. Customers can integrate their own recharge systems. After recharging, the gift balance is updated.
Billing Statistics
Android
iOS
Implement the onSendGift callback in the OnGiftListener of TUIGiftListView, connect to the customer's own business server, complete the balance verification, gift billing, and consumption statistics, and then call the sendGift of TUIGiftListView to send the gift message.
//... Here, connect to the customer's own business server to complete balance verification, gift billing, consumption statistics, etc
TUIGiftUser receiver =newTUIGiftUser();
//...Here set the gift recipient information
giftListView.sendGift(gift, giftCount, receiver);
}
Implement the TUIGiftListView delegate TUIGiftListViewDelegate callback onSendGift:view:giftModel:giftCount to connect to the customer's own business server. After completing balance verification, gift billing, and consumption statistics, call TUIGiftListView's sendGift to send the gift message.