The interactive barrage feature is a crucial real-time communication tool, supporting various interactive methods. Users can input emojis in the barrage to enhance the entertainment value of messages, making the interactive experience more enjoyable and vivid. Through this feature, the audience can engage in richer communication with anchors and other viewers during live streaming, boosting the overall sense of participation and fun. The TUILiveKit has already implemented the interactive barrage feature through Chat.
Use Instructions
Integration
The Barrage Component mainly provides 2 parts: Launch View (BarrageInputView) and Message List View (BarrageStreamView):
BarrageInputView: Click to pull up the input interface
BarrageStreamView: Used to display the barrage message list
In scenarios where barrage needs to be sent, create BarrageInputView. After clicking, you can pull up the input interface:
The red box on the left image is BarrageInputView. After clicking, the input panel pops up (red box on the right image)
Note:
1. Supports switching between System Keyboard and Emoji Keyboard.
2. To respect the copyright of emoji designs, the TUILiveKit project does not include large emoji elements. Before the official commercial launch, please replace them with your own designed or copyrighted emoji packs. The default Little Yellow Face Emoji Pack shown below is copyrighted by Tencent Cloud and can be licensed for a fee. If you need authorization, please submit a ticket to contact us.
In scenarios where barrage needs to be displayed, use BarrageStreamView to display barrage messages:
BarrageStreamView inserts special messages through the insertBarrages interface (different from the default chat messages).
LiveKit internally already has such a scenario. During the sending and receiving of gifts, a gift message is generated and inserted into the barrage message list. The effect is as follows:
It is very obvious that this message has a different style from the default chat message. It is implemented as follows:
First, rewrite BarrageItemTypeDelegate and add a new message format as 1, while the default message format remains 0. Invoke setItemTypeDelegate to update the agent.
The Barrage's extInfo is a Map, used for storing custom data.
Note:
The message format of the barrage component is 0 by default. LiveKit inserts a new message into the barrage when sending and receiving gift messages, with a message format of 1. Therefore, when using setItemTypeDelegate and setItemAdapter, please note to retain the original message formats 0 and 1, as well as their corresponding adapters (BarrageItemDefaultAdapter and GiftBarrageAdapter).
Sending and receiving barrage messages
Feature customization
Modify Message Style
If you are unsatisfied with the existing message format, you can customize the message format. Specific steps are as follows:
Create a new BarrageItemAdapter, such as called MyBarrageItemAdapter. The new style is relatively simple, containing only one text box with a font size of 20 and a font color of red. Example code as follows:
Comparison effect of message style 0 corresponding adapter before and after the overwrite is as follows:
Default styleBarrageItemDefaultAdapter
Custom style after coveringMyBarrageItemAdapter
Insert custom message
Default already supports 0 and 1 two types of message styles. If you want to insert a new style message, please use the new style type. Taking the addition of a new message format 2 as an example:
Please retain the original 0 and 1 two types of message styles.
For message style 2, implement the corresponding adapter. The new style is relatively simple, containing only one text box with a font size of 12, font color of yellow, and background color of gray. Complete BarrageItemStyle2Adapter example code as follows: