Skip to content

Commit

Permalink
Merge pull request #3 from libp2p/rust-server
Browse files Browse the repository at this point in the history
Rust server
  • Loading branch information
p-shahi authored Mar 29, 2023
2 parents 394169c + a40fa93 commit b23addf
Show file tree
Hide file tree
Showing 12 changed files with 4,477 additions and 146 deletions.
249 changes: 124 additions & 125 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"lint": "next lint"
},
"dependencies": {
"@chainsafe/libp2p-gossipsub": "^6.2.0",
"@chainsafe/libp2p-gossipsub": "github:maschad/js-libp2p-gossipsub#fix/add-mesh-peers-to-sub",
"@chainsafe/libp2p-noise": "^11.0.0",
"@chainsafe/libp2p-yamux": "^3.0.5",
"@headlessui/react": "^1.7.13",
Expand Down
12 changes: 8 additions & 4 deletions packages/frontend/src/components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default function ChatContainer() {
// Effect hook to subscribe to pubsub events and update the message state hook
useEffect(() => {
const messageCB = (message: CustomEvent<Message>) => {
console.log("gossipsub console log", message)
const { topic, data } = message.detail
const msg = new TextDecoder().decode(data)
console.log(`${topic}: ${msg}`)
Expand All @@ -35,10 +36,14 @@ export default function ChatContainer() {
const sendMessage = useCallback(async () => {
if (input === '') return

console.log('peers in gossip:', libp2p.pubsub.getSubscribers(CHAT_TOPIC).toString())

const res = await libp2p.pubsub.publish(
CHAT_TOPIC,
new TextEncoder().encode(input),
)
console.log('sent message to: ', res.recipients.map((peerId) => peerId.toString()))

setMessages([...messages, { msg: input, from: 'me' }])
setInput('')
}, [input, messages, setInput, libp2p])
Expand Down Expand Up @@ -74,7 +79,7 @@ export default function ChatContainer() {
<div className="lg:col-span-3 lg:block">
<div className="w-full">
<div className="relative flex items-center p-3 border-b border-gray-300">
{/* disable
{/* disable
<img
className="object-cover w-10 h-10 rounded-full"
src="https://github.com/achingbrain.png"
Expand All @@ -92,9 +97,8 @@ export default function ChatContainer() {
{messages.map(({ msg, from }, idx) => (
<li
key={idx}
className={`flex ${
from === 'me' ? 'justify-end' : 'justify-start'
}`}
className={`flex ${from === 'me' ? 'justify-end' : 'justify-start'
}`}
>
<div className="relative max-w-xl px-4 py-2 text-gray-700 rounded shadow">
<span className="block">{msg}</span>
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const CHAT_TOPIC = 'universal-connectivity'
export const CHAT_TOPIC = "universal-connectivity"

// export const DEFAULT_APP_PEER = '12D3KooWBdmLJjhpgJ9KZgLM3f894ff9xyBfPvPjFNn7MKJpyrC2'
export const DEFAULT_APP_PEER = '12D3KooWRBy97UB99e3J6hiPesre1MZeuNQvfan4gBziswrRJsNK'
Loading

1 comment on commit b23addf

@vercel
Copy link

@vercel vercel bot commented on b23addf Mar 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.