Skip to content

Commit b23addf

Browse files
authored
Merge pull request #3 from libp2p/rust-server
Rust server
2 parents 394169c + a40fa93 commit b23addf

File tree

12 files changed

+4477
-146
lines changed

12 files changed

+4477
-146
lines changed

package-lock.json

Lines changed: 124 additions & 125 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"lint": "next lint"
88
},
99
"dependencies": {
10-
"@chainsafe/libp2p-gossipsub": "^6.2.0",
10+
"@chainsafe/libp2p-gossipsub": "github:maschad/js-libp2p-gossipsub#fix/add-mesh-peers-to-sub",
1111
"@chainsafe/libp2p-noise": "^11.0.0",
1212
"@chainsafe/libp2p-yamux": "^3.0.5",
1313
"@headlessui/react": "^1.7.13",

packages/frontend/src/components/chat.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export default function ChatContainer() {
1616
// Effect hook to subscribe to pubsub events and update the message state hook
1717
useEffect(() => {
1818
const messageCB = (message: CustomEvent<Message>) => {
19+
console.log("gossipsub console log", message)
1920
const { topic, data } = message.detail
2021
const msg = new TextDecoder().decode(data)
2122
console.log(`${topic}: ${msg}`)
@@ -35,10 +36,14 @@ export default function ChatContainer() {
3536
const sendMessage = useCallback(async () => {
3637
if (input === '') return
3738

39+
console.log('peers in gossip:', libp2p.pubsub.getSubscribers(CHAT_TOPIC).toString())
40+
3841
const res = await libp2p.pubsub.publish(
3942
CHAT_TOPIC,
4043
new TextEncoder().encode(input),
4144
)
45+
console.log('sent message to: ', res.recipients.map((peerId) => peerId.toString()))
46+
4247
setMessages([...messages, { msg: input, from: 'me' }])
4348
setInput('')
4449
}, [input, messages, setInput, libp2p])
@@ -74,7 +79,7 @@ export default function ChatContainer() {
7479
<div className="lg:col-span-3 lg:block">
7580
<div className="w-full">
7681
<div className="relative flex items-center p-3 border-b border-gray-300">
77-
{/* disable
82+
{/* disable
7883
<img
7984
className="object-cover w-10 h-10 rounded-full"
8085
src="https://github.com/achingbrain.png"
@@ -92,9 +97,8 @@ export default function ChatContainer() {
9297
{messages.map(({ msg, from }, idx) => (
9398
<li
9499
key={idx}
95-
className={`flex ${
96-
from === 'me' ? 'justify-end' : 'justify-start'
97-
}`}
100+
className={`flex ${from === 'me' ? 'justify-end' : 'justify-start'
101+
}`}
98102
>
99103
<div className="relative max-w-xl px-4 py-2 text-gray-700 rounded shadow">
100104
<span className="block">{msg}</span>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const CHAT_TOPIC = 'universal-connectivity'
1+
export const CHAT_TOPIC = "universal-connectivity"
22

33
// export const DEFAULT_APP_PEER = '12D3KooWBdmLJjhpgJ9KZgLM3f894ff9xyBfPvPjFNn7MKJpyrC2'
44
export const DEFAULT_APP_PEER = '12D3KooWRBy97UB99e3J6hiPesre1MZeuNQvfan4gBziswrRJsNK'

0 commit comments

Comments
 (0)