fix(guild): protomux v3 gossip wire via pearcord-drive/mux-wire
Gossip mesh now uses c.buffer addMessage + wire.send so live P2P message sync works in Bare (test:gossip-live). Only store mesh sessions when createChannel succeeds; same pattern for attach/voice/screen channels. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -644,9 +644,9 @@ class PearcordGuild extends EventEmitter {
|
||||
const peerId = b4a.toString(conn.remotePublicKey, 'hex')
|
||||
this.peers.set(peerId, conn)
|
||||
const ch = attachGossipMesh(this, conn)
|
||||
this._channels.set(peerId, ch)
|
||||
if (ch) this._channels.set(peerId, ch)
|
||||
const attachCh = attachDriveMesh(this, conn, () => this._attachmentProvider)
|
||||
this._attachChannels.set(peerId, attachCh)
|
||||
if (attachCh) this._attachChannels.set(peerId, attachCh)
|
||||
if (this._voiceMediaHub) {
|
||||
const voiceCh = attachVoiceMesh(this, conn, this._voiceMediaHub)
|
||||
if (voiceCh) this._voiceChannels.set(peerId, voiceCh)
|
||||
|
||||
@@ -4,6 +4,7 @@ const Protomux = require('protomux')
|
||||
const b4a = require('b4a')
|
||||
const c = require('compact-encoding')
|
||||
const { RPC, encodeRpc, decodeRpc } = require('pearcord-shared')
|
||||
const { openWireChannel } = require('pearcord-drive/mux-wire')
|
||||
|
||||
const GOSSIP_PROTOCOL = 'pearcord-gossip-v1'
|
||||
|
||||
@@ -11,12 +12,9 @@ const rpcPayload = c.json
|
||||
|
||||
function attachGossipMesh (guild, conn) {
|
||||
const mux = Protomux.from(conn)
|
||||
const channel = mux.createChannel({
|
||||
return openWireChannel(mux, {
|
||||
protocol: GOSSIP_PROTOCOL,
|
||||
onopen () {
|
||||
channel.open()
|
||||
},
|
||||
onmessage (buf) {
|
||||
ondata (buf) {
|
||||
let packet
|
||||
try {
|
||||
packet = decodeRpc(buf)
|
||||
@@ -27,18 +25,17 @@ function attachGossipMesh (guild, conn) {
|
||||
}
|
||||
}
|
||||
})
|
||||
return channel
|
||||
}
|
||||
|
||||
async function broadcastGossip (guild, method, payload) {
|
||||
const buf = encodeRpc(method, b4a.from(JSON.stringify(payload)))
|
||||
const channels = [...guild._channels.values()]
|
||||
const sessions = [...guild._channels.values()]
|
||||
await Promise.all(
|
||||
channels.map(async (ch) => {
|
||||
sessions.map(async (session) => {
|
||||
try {
|
||||
const ok = await ch.fullyOpened().catch(() => false)
|
||||
const ok = await session.fullyOpened().catch(() => false)
|
||||
if (!ok) return
|
||||
ch.send(buf)
|
||||
session.send(buf)
|
||||
} catch {
|
||||
// peer gone
|
||||
}
|
||||
@@ -46,4 +43,4 @@ async function broadcastGossip (guild, method, payload) {
|
||||
)
|
||||
}
|
||||
|
||||
module.exports = { attachGossipMesh, broadcastGossip, GOSSIP_PROTOCOL }
|
||||
module.exports = { attachGossipMesh, broadcastGossip, GOSSIP_PROTOCOL, rpcPayload }
|
||||
|
||||
Reference in New Issue
Block a user