@jinglescode/nostr-chat-plugin
Advanced tools
Comparing version 0.0.8 to 0.0.9
@@ -174,3 +174,2 @@ import { jsx } from 'react/jsx-runtime'; | ||
messages: messages, | ||
subscribe: subscribe, | ||
setMessages: setMessages, | ||
@@ -182,2 +181,3 @@ user: user, | ||
generateNsec: generateNsec, | ||
subscribe: subscribe, | ||
}); }, [ | ||
@@ -187,3 +187,2 @@ subscribeRoom, | ||
messages, | ||
subscribe, | ||
setMessages, | ||
@@ -195,2 +194,3 @@ user, | ||
generateNsec, | ||
subscribe, | ||
]); | ||
@@ -197,0 +197,0 @@ return (jsx(NostrChatContext.Provider, { value: memoedValue, children: children })); |
@@ -5,3 +5,3 @@ import { ReactNode } from "react"; | ||
children: ReactNode; | ||
relay: string; | ||
relay?: string; | ||
}) => import("react/jsx-runtime").JSX.Element; | ||
@@ -8,0 +8,0 @@ export declare const useNostrChat: () => { |
{ | ||
"name": "@jinglescode/nostr-chat-plugin", | ||
"version": "0.0.8", | ||
"description": "React chatroom component powered by NOSTR.", | ||
"version": "0.0.9", | ||
"description": "A chat room React component that uses NOSTR protocol for messaging.", | ||
"author": "jinglescode", | ||
@@ -6,0 +6,0 @@ "license": "Apache-2.0", |
{ | ||
"name": "@jinglescode/nostr-chat-plugin", | ||
"version": "0.0.8", | ||
"description": "React chatroom component powered by NOSTR.", | ||
"version": "0.0.9", | ||
"description": "A chat room React component that uses NOSTR protocol for messaging.", | ||
"author": "jinglescode", | ||
@@ -6,0 +6,0 @@ "license": "Apache-2.0", |
@@ -1,1 +0,68 @@ | ||
# nostr-chat-plugin | ||
# 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 ( | ||
<NostrChatProvider> | ||
<Component {...pageProps} /> | ||
</NostrChatProvider> | ||
); | ||
} | ||
``` | ||
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"); | ||
``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
48856
69