UNPKG

@bitxenia/astrachat

Version:

Decentralized p2p real-time chat on IPFS

76 lines (68 loc) 2.47 kB
import { Blockstore } from 'interface-blockstore'; import { Datastore } from 'interface-datastore'; import { AstraDb } from '@bitxenia/astradb'; type ChatMessage = { id: string; parentId: string; sender: string; senderAlias: string; message: string; timestamp: number; }; type ChatMessageCallback = (message: ChatMessage) => void; declare class AstrachatNode implements Astrachat { chatSpace: string; alias: string; astraDb: AstraDb; constructor(chatSpace: string); init(init: AstrachatInit): Promise<void>; createChat(chatName: string, callback?: (message: ChatMessage) => void): Promise<void>; getMessages(chatName: string, onNewMessage?: ChatMessageCallback): Promise<ChatMessage[]>; sendMessage(chatName: string, text: string, parentId?: string): Promise<void>; getChatList(): Promise<string[]>; getUserId(): string; getLoginKey(): Promise<string>; getAlias(): string; setChatAlias(alias: string): void; getNodeMultiaddrs(): Promise<string[]>; } type LogLevel = "debug" | "info" | "warn" | "error"; interface AstrachatInit { chatSpace?: string; alias?: string; loginKey?: string; isCollaborator?: boolean; datastore?: Datastore; blockstore?: Blockstore; publicIp?: string; tcpPort?: number; webrtcDirectPort?: number; dataDir?: string; bootstrapProviderPeers?: string[]; logLevel?: LogLevel; /** * If true, the node will not connect to the network and will only work locally. * This is useful for testing purposes. * * @default false */ offlineMode?: boolean; } declare function createAstrachat(init: AstrachatInit): Promise<AstrachatNode>; interface Astrachat { createChat(chatName: string, onNewMessage?: ChatMessageCallback): Promise<void>; getMessages(chatName: string, onNewMessage?: ChatMessageCallback): Promise<ChatMessage[]>; sendMessage(chatName: string, text: string, parentId?: string): Promise<void>; getChatList(): Promise<string[]>; getUserId(): string; getLoginKey(): Promise<string>; getAlias(): string; setChatAlias(alias: string): void; /** * Retrieves the public multiaddresses of the astrachat node. * * This multiaddresses can be used as bootstrapProviderPeers from other nodes. */ getNodeMultiaddrs: () => Promise<string[]>; } export { type Astrachat, type AstrachatInit, type ChatMessage, createAstrachat };