Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jinglescode/nostr-chat-plugin
A chat room React component that uses NOSTR protocol for messaging.
https://github.com/jinglescode/nostr-chat-plugin
nostr
Last synced: 25 days ago
JSON representation
A chat room React component that uses NOSTR protocol for messaging.
- Host: GitHub
- URL: https://github.com/jinglescode/nostr-chat-plugin
- Owner: jinglescode
- License: apache-2.0
- Created: 2024-10-14T15:12:40.000Z (2 months ago)
- Default Branch: main
- Last Pushed: 2024-10-16T07:10:56.000Z (2 months ago)
- Last Synced: 2024-11-26T23:35:18.057Z (28 days ago)
- Topics: nostr
- Language: TypeScript
- Homepage: https://jingles.dev/
- Size: 9.77 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Nostr Chat Provider
A chat room React component that uses NOSTR protocol for messaging.
### Usage
Install the package using npm:
```bash
npm install @jinglescode/nostr-chat-plugin
```In your `_app.tsx` file, import `NostrChatProvider` and wrap your component with it:
```typescript
import { NostrChatProvider } from "@jinglescode/nostr-chat-plugin";export default function App({ Component, pageProps }: AppProps) {
return (
);
}
```To use the chat component, import `useNostrChat`:
```typescript
import { useNostrChat } from "@jinglescode/nostr-chat-plugin";const { subscribeRoom, publishMessage, messages, generateNsec, setUser } =
useNostrChat();
```### API
First, depending if your user has a nostr key, if not, you can generate one:
```typescript
const {
nsec: string;
pubkey: string;
} = generateNsec();
```For users that already have a nostr key, you can set it:
```typescript
setUser({
nsec: nsec,
pubkey: pubkey,
});
```Then, when user enters a page with chat, you can subscribe to a room ID:
```typescript
subscribeRoom("room-id-here");
```Doing so will populate and listen for new `messages` from the room.
When the connected user wants to send a message, they can publish a message to the room:
```typescript
publishMessage("message here");
```