feat(guild): attach screen-share protomux mesh per peer connection

Wire pearcord-screen-share: SCREEN_SHARE_UPDATE gossip handler,
gossipScreenShare/sendScreenMedia, and pearcord-screen-v1 channels
alongside existing voice media channels.

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
Raven Scott
2026-05-21 22:03:15 -04:00
co-authored by Cursor
parent 36e4aceb14
commit 47fdaa641a
2 changed files with 25 additions and 0 deletions
+24
View File
@@ -11,6 +11,7 @@ const {
const { attachGossipMesh, broadcastGossip } = require('./mesh')
const { attachDriveMesh, requestAttachmentFromPeers } = require('pearcord-drive/attach-mesh')
const { attachVoiceMesh, broadcastVoiceMedia } = require('pearcord-voice-media')
const { attachScreenMesh, broadcastScreenMedia } = require('pearcord-screen-share')
class PearcordGuild extends EventEmitter {
constructor (opts = {}) {
@@ -24,15 +25,21 @@ class PearcordGuild extends EventEmitter {
this._channels = new Map()
this._attachChannels = new Map()
this._voiceChannels = new Map()
this._screenChannels = new Map()
this._meshHandler = null
this._attachmentProvider = null
this._voiceMediaHub = null
this._screenShareHub = null
}
setVoiceMediaHub (hub) {
this._voiceMediaHub = hub || null
}
setScreenShareHub (hub) {
this._screenShareHub = hub || null
}
setAttachmentProvider (fn) {
this._attachmentProvider = fn
}
@@ -355,6 +362,9 @@ class PearcordGuild extends EventEmitter {
if (method === RPC.AUTOMOD_CONFIG_UPDATE) {
this.emit('automod-config', payload)
}
if (method === RPC.SCREEN_SHARE_UPDATE) {
this.emit('screen-share', payload)
}
}
/** Deterministic gossip injection for Bare smokes (no live mesh). */
@@ -494,6 +504,14 @@ class PearcordGuild extends EventEmitter {
broadcastGossip(this, RPC.AUTOMOD_CONFIG_UPDATE, payload)
}
gossipScreenShare (payload) {
broadcastGossip(this, RPC.SCREEN_SHARE_UPDATE, payload)
}
sendScreenMedia (msg) {
broadcastScreenMedia(this, msg)
}
gossipPresence (payload) {
broadcastGossip(this, RPC.PRESENCE_UPDATE, payload)
}
@@ -517,12 +535,17 @@ class PearcordGuild extends EventEmitter {
const voiceCh = attachVoiceMesh(this, conn, this._voiceMediaHub)
if (voiceCh) this._voiceChannels.set(peerId, voiceCh)
}
if (this._screenShareHub) {
const screenCh = attachScreenMesh(this, conn, this._screenShareHub)
if (screenCh) this._screenChannels.set(peerId, screenCh)
}
this.emit('peer', { peerId, type: 'join' })
conn.on('close', () => {
this.peers.delete(peerId)
this._channels.delete(peerId)
this._attachChannels.delete(peerId)
this._voiceChannels.delete(peerId)
this._screenChannels.delete(peerId)
this.emit('peer', { peerId, type: 'leave' })
})
})
@@ -536,6 +559,7 @@ class PearcordGuild extends EventEmitter {
this._channels.clear()
this._attachChannels.clear()
this._voiceChannels.clear()
this._screenChannels.clear()
if (this.guild?.topic) {
await this.swarm.leave(topicToBuffer(this.guild.topic)).catch(() => {})
}
+1
View File
@@ -15,6 +15,7 @@
"pearcord-shared": "file:../pearcord-shared",
"pearcord-drive": "file:../pearcord-drive",
"pearcord-voice-media": "file:../pearcord-voice-media",
"pearcord-screen-share": "git+https://git.ssh.surf/pearcord/pearcord-screen-share.git#main",
"hyperswarm": "^4.8.0",
"protomux": "^3.0.0",
"compact-encoding": "^2.0.0"