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')
|
const peerId = b4a.toString(conn.remotePublicKey, 'hex')
|
||||||
this.peers.set(peerId, conn)
|
this.peers.set(peerId, conn)
|
||||||
const ch = attachGossipMesh(this, 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)
|
const attachCh = attachDriveMesh(this, conn, () => this._attachmentProvider)
|
||||||
this._attachChannels.set(peerId, attachCh)
|
if (attachCh) this._attachChannels.set(peerId, attachCh)
|
||||||
if (this._voiceMediaHub) {
|
if (this._voiceMediaHub) {
|
||||||
const voiceCh = attachVoiceMesh(this, conn, this._voiceMediaHub)
|
const voiceCh = attachVoiceMesh(this, conn, this._voiceMediaHub)
|
||||||
if (voiceCh) this._voiceChannels.set(peerId, voiceCh)
|
if (voiceCh) this._voiceChannels.set(peerId, voiceCh)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ const Protomux = require('protomux')
|
|||||||
const b4a = require('b4a')
|
const b4a = require('b4a')
|
||||||
const c = require('compact-encoding')
|
const c = require('compact-encoding')
|
||||||
const { RPC, encodeRpc, decodeRpc } = require('pearcord-shared')
|
const { RPC, encodeRpc, decodeRpc } = require('pearcord-shared')
|
||||||
|
const { openWireChannel } = require('pearcord-drive/mux-wire')
|
||||||
|
|
||||||
const GOSSIP_PROTOCOL = 'pearcord-gossip-v1'
|
const GOSSIP_PROTOCOL = 'pearcord-gossip-v1'
|
||||||
|
|
||||||
@@ -11,12 +12,9 @@ const rpcPayload = c.json
|
|||||||
|
|
||||||
function attachGossipMesh (guild, conn) {
|
function attachGossipMesh (guild, conn) {
|
||||||
const mux = Protomux.from(conn)
|
const mux = Protomux.from(conn)
|
||||||
const channel = mux.createChannel({
|
return openWireChannel(mux, {
|
||||||
protocol: GOSSIP_PROTOCOL,
|
protocol: GOSSIP_PROTOCOL,
|
||||||
onopen () {
|
ondata (buf) {
|
||||||
channel.open()
|
|
||||||
},
|
|
||||||
onmessage (buf) {
|
|
||||||
let packet
|
let packet
|
||||||
try {
|
try {
|
||||||
packet = decodeRpc(buf)
|
packet = decodeRpc(buf)
|
||||||
@@ -27,18 +25,17 @@ function attachGossipMesh (guild, conn) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return channel
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function broadcastGossip (guild, method, payload) {
|
async function broadcastGossip (guild, method, payload) {
|
||||||
const buf = encodeRpc(method, b4a.from(JSON.stringify(payload)))
|
const buf = encodeRpc(method, b4a.from(JSON.stringify(payload)))
|
||||||
const channels = [...guild._channels.values()]
|
const sessions = [...guild._channels.values()]
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
channels.map(async (ch) => {
|
sessions.map(async (session) => {
|
||||||
try {
|
try {
|
||||||
const ok = await ch.fullyOpened().catch(() => false)
|
const ok = await session.fullyOpened().catch(() => false)
|
||||||
if (!ok) return
|
if (!ok) return
|
||||||
ch.send(buf)
|
session.send(buf)
|
||||||
} catch {
|
} catch {
|
||||||
// peer gone
|
// 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