GiftState is a dedicated module within AtomicXCore that manages gift interactions in live streaming rooms. This module enables you to implement a robust gift system in your live streaming application, supporting flexible monetization and enhanced audience engagement.Gift Panel | Barrage Gift | Full-Screen Gift |
![]() | ![]() | ![]() |
GiftState instance and set up listeners to handle gift events and gift list changes.useGiftState(liveID) to retrieve the GiftState instance for the current live room.addGiftListener to subscribe to the onReceiveGift event.usableGifts list to update your UI.import { useEffect } from 'react';import { useGiftState } from 'react-native-tuikit-atomic-x/lib/module/atomic-x/state/GiftState';// Get GiftState instance by liveIDconst { addGiftListener, removeGiftListener, usableGifts } = useGiftState(liveID);useEffect(() => {const onReceiveGift = (event) => {const gift = JSON.parse(event.gift);const sender = JSON.parse(event.sender);console.log('Gift received', gift, 'Sender', sender);// Handle gift logic here, e.g., play SVGA gifts, show popups for other formats};addGiftListener('onReceiveGift', onReceiveGift);return () => {removeGiftListener('onReceiveGift', onReceiveGift);};}, []);// Listen for real-time changes in usableGifts to drive UI updatesuseEffect(() => {console.log(usableGifts);}, [usableGifts]);
GiftCategory Parameter DescriptionParameter | Type | Description |
categoryID | string | Unique identifier for the gift category. |
name | string | Display name of the gift category. |
desc | string | Description of the gift category. |
extensionInfo | Record<string: string> | Extension info fields. |
giftList | [string] | Array of Gift objects in this category. |
Gift Parameter DescriptionParameter | Type | Description |
giftID | string | Unique identifier for the gift. |
name | string | Display name of the gift. |
desc | string | Description of the gift. |
iconURL | string | Gift icon URL. |
resourceURL | string | Gift AR animation resource URL. |
level | number | Gift level. |
coins | number | Gift price. |
extensionInfo | Record<string: string> | Extension info fields. |
refreshUsableGifts method to retrieve the gift list from your server.refreshUsableGifts at the appropriate time (such as when the page loads).onSuccess and onError to track API results.usableGifts list is automatically available via the listener from Step 2.import { useEffect } from 'react';import { useGiftState } from 'react-native-tuikit-atomic-x/lib/module/atomic-x/state/GiftState';// Get GiftState instance by liveIDconst { refreshUsableGifts } = useGiftState(liveID);useEffect(() => {refreshUsableGifts({liveID: liveID, // Current live room liveIDonSuccess: () => {console.log('Gift list fetched successfully');// State reactive data will update automatically on success},onError: (error) => {console.log('Failed to fetch gift list', error);},});}, []);
sendGift API.giftID and count from the UI.sendGift API.onError callback. UI updates (animations, live comments) should be handled via the onReceiveGift event.import { useGiftState } from 'react-native-tuikit-atomic-x/lib/module/atomic-x/state/GiftState';// Get GiftState instance by liveIDconst { sendGift } = useGiftState(liveID);// User sends a gift (function receives giftID as parameter)const handleSendGift = (giftID) => {sendGift({liveID: liveID, // Current live room liveIDgiftID: giftID,count: 1,onSuccess: () => {console.log(`Gift ${giftID} sent successfully`);},onError: (error) => {console.log('Failed to send gift', error);},});};
sendGift API ParametersParameter Name | Type | Description |
liveID | string | The current live room's liveID. |
giftID | string | Unique identifier of the gift. |
count | number | Quantity to send. |
onSuccess | Function | Callback for successful send. |
onError | Function | Callback for failed send. |
GiftState are tightly coupled with your business backend. This section provides guidance on creating a dynamic, engaging gift system by combining server configuration and client-side implementation.LiveKit server REST API to manage gift information, categories, and multi-language support. See the Gift Configuration Guide.refreshUsableGifts to retrieve configuration data.List<GiftCategory> to populate the gift panel.
Interface Category | Interface | Request Example |
Gift Management | Add Gift Information | |
| Delete Gift Information | |
| Query Gift Information | |
Gift Category Management | Add Gift Category Information | |
| Delete Specific Gift Category Information | |
| Get Specific Gift Category Information | |
Gift Relationship Management | Add Relationship between a Specific Gift Category and Gift | |
| Delete Relationship between a Specific Gift Category and Gift | |
| Get Gift Relationships under a Specific Gift Category | |
Gift Multi-language Management | Add Gift Multi-language Information | |
| Delete Specific Gift Multi-language Information | |
| Get Gift Multi-language Information | |
| Add Gift Category Multi-language Information | |
| Delete Specific Gift Category Multi-language Information | |
| Get Gift Category Multi-language Information | |
sendGift.onReceiveGift event; if failed, the completion callback of sendGift receives an error.
API | Description | Request Example |
Callback Configuration > Pre-Gift Send Callback | Your backend uses this callback to validate and allow gift sending. |
AtomicXCore includes an SVGA animation player for gift AR effects. Integrate it as follows.addGiftListener to subscribe to the onReceiveGift event.onReceiveGift event is received, check if gift.resourceURL points to an SVGA file. If so, pass gift.resourceURL to SVGAAnimationView to play the animation.import { useEffect, useRef, useState } from 'react';import { useGiftState } from 'react-native-tuikit-atomic-x/lib/module/atomic-x/state/GiftState';import { SVGAAnimationView } from 'react-native-tuikit-atomic-x/lib/module/components/SVGAAnimationView';// Get GiftState instance by liveIDconst { addGiftListener, removeGiftListener } = useGiftState(liveID);const svgaRef = useRef(null);const [showSVGA, setShowSVGA] = useState(false);useEffect(() => {const onReceiveGift = (event) => {const gift = JSON.parse(event.gift);if (gift.resourceURL) {setShowSVGA(true);setTimeout(() => {svgaRef.current?.startAnimation(gift.resourceURL);}, 100);}};addGiftListener('onReceiveGift', onReceiveGift);return () => {removeGiftListener('onReceiveGift', onReceiveGift);};}, []);// Add full-screen SVGA playback layer in JSX{showSVGA ? (<SVGAAnimationViewref={svgaRef}style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0 }}onFinished={() => setShowSVGA(false)}/>) : null}
addGiftListener to subscribe to the onReceiveGift event.useBarrageState(liveID) to retrieve the instance for the current room.textContent (e.g., "[sender.userName] sent [gift.name]").barrageState.appendLocalTip(message: giftTip) to add the message to the local list.import { useEffect } from 'react';import { useGiftState } from 'react-native-tuikit-atomic-x/lib/module/atomic-x/state/GiftState';import { useBarrageState } from 'react-native-tuikit-atomic-x/lib/module/atomic-x/state/BarrageState';// Get GiftState instance by liveIDconst { addGiftListener, removeGiftListener } = useGiftState(liveID);// Get BarrageState instance by liveIDconst { appendLocalTip } = useBarrageState(liveID);useEffect(() => {const onReceiveGift = (event) => {const gift = JSON.parse(event.gift);const sender = JSON.parse(event.sender);console.log('Gift received', gift, 'Sender', sender);appendLocalTip({liveID: liveID, // Current live room liveIDmessage: {textContent: `${sender.userName || sender.userID} sent ${gift.name || gift.giftID}`,sender: {userID: sender.userID || '',userName: sender.userName || '',avatarURL: sender.avatarURL || '',},messageType: 0,sequence: Math.floor(Date.now() / 1000),timestampInSecond: Math.floor(Date.now() / 1000),liveID: liveID,},onSuccess: () => {},onError: (error) => {console.log('Failed to insert gift live comment:', error);},});};addGiftListener('onReceiveGift', onReceiveGift);return () => {removeGiftListener('onReceiveGift', onReceiveGift);};}, []);
State | Feature Description | API Documentation |
GiftState | Gift interaction: fetch gift list, send/receive gifts, listen for gift events (including sender and gift details). | |
BarrageState | Live comments: send text/custom comments, maintain comment list, real-time state updates. |
GiftState is empty. What should I do?refreshUsableGifts() to fetch the gift list from your business backend. Gift data must be configured via your backend's REST API.GiftState provides the setLanguage(language: string) method. Call this before refreshUsableGifts, passing the target language code (such as "en" or "zh-CN"). The server will return gift names and descriptions in the specified language.onReceiveGift event is broadcast to all room members, including the sender. If you trigger UI updates both in the onSuccess callback of sendGift and in the onReceiveGift event handler, you'll see duplicated effects.onReceiveGift event handler. Use the onError callback of sendGift to notify users of failures (such as "Send failed" or "Insufficient balance").AtomicXCore connects to your backend via callback. When the client calls sendGift, your backend completes the deduction and returns the result to the AtomicXCore backend, which then decides whether to broadcast the gift event.onReceiveGift event) are not affected by mute or message frequency control and are reliably delivered.Was this page helpful?
You can also Contact sales or Submit a Ticket for help.
Help us improve! Rate your documentation experience in 5 mins.
Feedback