📖 Core API Reference
Complete API documentation for @xhub-chat/core package.
Main Classes
XHubChatClient
The main client class that provides all chat functionality.
Constructor
createClient(opts: ICreateClientOpts): XHubChatClient
Parameters:
interface ICreateClientOpts {
baseUrl: string; // Server URL
accessToken: string; // Authentication token
userId: string; // User ID
store?: IStoreOpts; // Storage configuration
sync?: ISyncOpts; // Sync configuration
timelineSupport?: boolean;
cryptoEnabled?: boolean;
}
Methods
Connection
startClient(opts?: IStartClientOpts): Promise<void>- Start the clientstopClient(): Promise<void>- Stop the clientdestroy(): Promise<void>- Destroy and cleanup
Rooms
getRoom(roomId: string): Room | null- Get room by IDgetRooms(): Room[]- Get all roomsjoinRoom(roomId: string): Promise<void>- Join a roomleaveRoom(roomId: string): Promise<void>- Leave a room
Messaging
sendTextMessage(roomId: string, text: string): Promise<void>- Send text messagesendMessage(roomId: string, content: any): Promise<void>- Send custom messageresendEvent(event: Event): Promise<void>- Resend failed event
Reels
paginateReels(opts?: { limit?: number }): Promise<void>- Load more reels from feedcanPaginateReels(): boolean- Check if more reels availableclearReelCache(): void- Clear reels cachefetchMyReels(filter?: MyReelsFilter): Promise<MyReelsResponse>- Fetch user's own reels
Events
on(event: string, handler: Function): void- Register event listeneroff(event: string, handler: Function): void- Remove event listeneronce(event: string, handler: Function): void- One-time event listener
Reels API
fetchMyReels
Fetch the current user's own reels with filtering and pagination.
Signature:
fetchMyReels(filter?: MyReelsFilter): Promise<MyReelsResponse>
Parameters:
interface MyReelsFilter {
approving_status?: 'approved' | 'rejected' | 'pending';
privacy?: number;
sort?: string;
sorted?: 'asc' | 'desc';
cursor?: string;
limit?: number; // default: 10
}
Returns:
interface MyReelsResponse {
reels: ReelData[];
nextCursor: string | null;
hasMore: boolean;
}
Example:
// Fetch approved reels
const { reels, nextCursor, hasMore } = await client.fetchMyReels({
approving_status: 'approved',
limit: 20,
});
// Load next page
if (hasMore && nextCursor) {
const nextPage = await client.fetchMyReels({
cursor: nextCursor,
limit: 20,
});
}
See Also:
- My Reels Guide - Complete guide with examples
- useMyReels Hook - React hook wrapper