Calls / React Native
Calls React Native v1
Calls React Native
Calls
React Native
Home
/
Calls
/
React Native
/
Direct call

Retrieve call history

Sendbird server automatically stores information about calls. For ended calls, you can retrieve information such as user IDs of callees and callers, call history, and the end results.


Retrieve a call information

To retrieve information on local or remote users, use directCall.localUser and directCall.remoteUser properties.


Retrieve call history

To retrieve information calls such as call history of a user, use the DirectCallLogListQuery instance. You can use parameters like myRole and endResults to specify your search.

import { DirectCallEndResult, DirectCallLogListQuery, SendbirdCalls } from '@sendbird/calls-react-native';

const useCallHistory = () => {
 const [history, setHistory] = useState<DirectCallLog[]>([]);
 const query = useRef<DirectCallLogListQuery>();

 useEffect(() => {
   const effect = async () => {
     query.current = await SendbirdCalls.createDirectCallLogListQuery({
       myRole: 'ALL',
       endResults: [
         DirectCallEndResult.COMPLETED,
         DirectCallEndResult.CANCELED,
         DirectCallEndResult.DECLINED,
         DirectCallEndResult.DIAL_FAILED,
         DirectCallEndResult.ACCEPT_FAILED,
       ],
       limit: 20,
     });

     const data = await query.current.next();
     setHistory(data);
   };

   effect();

   return () => {
     query.current.release();
   };
 }, []);

 return {
   next: async () => {
     if (query.hasNext) {
       const data = await query.current.next();
       setHistory((prev) => prev.concat(...data));
     }
   },
   history,
 };
};