Skip to content

Commit

Permalink
fix: subscribe pref
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaohaodu committed Jun 9, 2024
1 parent a1d2683 commit 33dfa81
Show file tree
Hide file tree
Showing 5 changed files with 8,326 additions and 6,351 deletions.
10 changes: 9 additions & 1 deletion packages/web-chat-x-express/src/controllers/libp2p.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
import { Libp2p, createLibp2p } from "libp2p";
import { noise } from "@chainsafe/libp2p-noise";
import { yamux } from "@chainsafe/libp2p-yamux";
import { circuitRelayServer } from "@libp2p/circuit-relay-v2";
import {
circuitRelayServer,
circuitRelayTransport,
} from "@libp2p/circuit-relay-v2";
import { webSockets } from "@libp2p/websockets";
import * as filters from "@libp2p/websockets/filters";
import { identify } from "@libp2p/identify";
Expand Down Expand Up @@ -48,6 +51,11 @@ export default class Libp2pManager {
webSockets({
filter: filters.all,
}),
circuitRelayTransport({
//允许当前节点建立和接受中继连接
discoverRelays: 0, // 要找到多少个网络中继
reservationConcurrency: 1, // 一次要尝试保留多少个继电器的插槽
}),
],
connectionEncryption: [noise(), tls()],
streamMuxers: [yamux()],
Expand Down
10 changes: 6 additions & 4 deletions packages/web-chat-x-vue/src/classes/Libp2pManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class Libp2pManager {
},
}),
circuitRelayTransport({
discoverRelays: 1,
discoverRelays: 50,
}),
],
connectionEncryption: [noise()],
Expand Down Expand Up @@ -498,9 +498,11 @@ export class Libp2pManager {
for (const subscriber of subscribers) {
promiseAllArray.push(fallbackCall(channel, subscriber));
}
(this.libp2p!.services.pubsub as PubSub<GossipsubEvents>).subscribe(
`${channel.name}@${channel.id}`
);
if (!subscriberIds.includes(this.chatUser?.value.id!)) {
(this.libp2p!.services.pubsub as PubSub<GossipsubEvents>).subscribe(
`${channel.name}@${channel.id}`
);
}
}
}
Promise.all(promiseAllArray).then(() => {
Expand Down
1 change: 0 additions & 1 deletion packages/web-chat-x-vue/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ declare module 'vue' {
ElContainer: typeof import('element-plus/es')['ElContainer']
ElDialog: typeof import('element-plus/es')['ElDialog']
ElDivider: typeof import('element-plus/es')['ElDivider']
ElFooter: typeof import('element-plus/es')['ElFooter']
ElForm: typeof import('element-plus/es')['ElForm']
ElFormItem: typeof import('element-plus/es')['ElFormItem']
ElHeader: typeof import('element-plus/es')['ElHeader']
Expand Down
7 changes: 2 additions & 5 deletions packages/web-chat-x-vue/src/views/Channel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,9 @@
<p
class="text-left text-gray-600"
>
{{message.postUserId===currentUser.id? currentUser.name:libp2pManager.getSubscriber(message.postUserId)!.name }}
{{libp2pManager.getSubscriber(message.postUserId)!.name }}
<div
:class="[
'flex flex-col self-end',
message.postUserId===currentUser.id ? 'text-right' : 'text-left',
]"
class="flex flex-col self-end text-left"
>
<span class="text-gray-600" v-if="message.text">
{{ message.text }}
Expand Down
Loading

0 comments on commit 33dfa81

Please sign in to comment.