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:
@@ -11,6 +11,7 @@ const {
|
|||||||
const { attachGossipMesh, broadcastGossip } = require('./mesh')
|
const { attachGossipMesh, broadcastGossip } = require('./mesh')
|
||||||
const { attachDriveMesh, requestAttachmentFromPeers } = require('pearcord-drive/attach-mesh')
|
const { attachDriveMesh, requestAttachmentFromPeers } = require('pearcord-drive/attach-mesh')
|
||||||
const { attachVoiceMesh, broadcastVoiceMedia } = require('pearcord-voice-media')
|
const { attachVoiceMesh, broadcastVoiceMedia } = require('pearcord-voice-media')
|
||||||
|
const { attachScreenMesh, broadcastScreenMedia } = require('pearcord-screen-share')
|
||||||
|
|
||||||
class PearcordGuild extends EventEmitter {
|
class PearcordGuild extends EventEmitter {
|
||||||
constructor (opts = {}) {
|
constructor (opts = {}) {
|
||||||
@@ -24,15 +25,21 @@ class PearcordGuild extends EventEmitter {
|
|||||||
this._channels = new Map()
|
this._channels = new Map()
|
||||||
this._attachChannels = new Map()
|
this._attachChannels = new Map()
|
||||||
this._voiceChannels = new Map()
|
this._voiceChannels = new Map()
|
||||||
|
this._screenChannels = new Map()
|
||||||
this._meshHandler = null
|
this._meshHandler = null
|
||||||
this._attachmentProvider = null
|
this._attachmentProvider = null
|
||||||
this._voiceMediaHub = null
|
this._voiceMediaHub = null
|
||||||
|
this._screenShareHub = null
|
||||||
}
|
}
|
||||||
|
|
||||||
setVoiceMediaHub (hub) {
|
setVoiceMediaHub (hub) {
|
||||||
this._voiceMediaHub = hub || null
|
this._voiceMediaHub = hub || null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setScreenShareHub (hub) {
|
||||||
|
this._screenShareHub = hub || null
|
||||||
|
}
|
||||||
|
|
||||||
setAttachmentProvider (fn) {
|
setAttachmentProvider (fn) {
|
||||||
this._attachmentProvider = fn
|
this._attachmentProvider = fn
|
||||||
}
|
}
|
||||||
@@ -355,6 +362,9 @@ class PearcordGuild extends EventEmitter {
|
|||||||
if (method === RPC.AUTOMOD_CONFIG_UPDATE) {
|
if (method === RPC.AUTOMOD_CONFIG_UPDATE) {
|
||||||
this.emit('automod-config', payload)
|
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). */
|
/** Deterministic gossip injection for Bare smokes (no live mesh). */
|
||||||
@@ -494,6 +504,14 @@ class PearcordGuild extends EventEmitter {
|
|||||||
broadcastGossip(this, RPC.AUTOMOD_CONFIG_UPDATE, payload)
|
broadcastGossip(this, RPC.AUTOMOD_CONFIG_UPDATE, payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gossipScreenShare (payload) {
|
||||||
|
broadcastGossip(this, RPC.SCREEN_SHARE_UPDATE, payload)
|
||||||
|
}
|
||||||
|
|
||||||
|
sendScreenMedia (msg) {
|
||||||
|
broadcastScreenMedia(this, msg)
|
||||||
|
}
|
||||||
|
|
||||||
gossipPresence (payload) {
|
gossipPresence (payload) {
|
||||||
broadcastGossip(this, RPC.PRESENCE_UPDATE, payload)
|
broadcastGossip(this, RPC.PRESENCE_UPDATE, payload)
|
||||||
}
|
}
|
||||||
@@ -517,12 +535,17 @@ class PearcordGuild extends EventEmitter {
|
|||||||
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)
|
||||||
}
|
}
|
||||||
|
if (this._screenShareHub) {
|
||||||
|
const screenCh = attachScreenMesh(this, conn, this._screenShareHub)
|
||||||
|
if (screenCh) this._screenChannels.set(peerId, screenCh)
|
||||||
|
}
|
||||||
this.emit('peer', { peerId, type: 'join' })
|
this.emit('peer', { peerId, type: 'join' })
|
||||||
conn.on('close', () => {
|
conn.on('close', () => {
|
||||||
this.peers.delete(peerId)
|
this.peers.delete(peerId)
|
||||||
this._channels.delete(peerId)
|
this._channels.delete(peerId)
|
||||||
this._attachChannels.delete(peerId)
|
this._attachChannels.delete(peerId)
|
||||||
this._voiceChannels.delete(peerId)
|
this._voiceChannels.delete(peerId)
|
||||||
|
this._screenChannels.delete(peerId)
|
||||||
this.emit('peer', { peerId, type: 'leave' })
|
this.emit('peer', { peerId, type: 'leave' })
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -536,6 +559,7 @@ class PearcordGuild extends EventEmitter {
|
|||||||
this._channels.clear()
|
this._channels.clear()
|
||||||
this._attachChannels.clear()
|
this._attachChannels.clear()
|
||||||
this._voiceChannels.clear()
|
this._voiceChannels.clear()
|
||||||
|
this._screenChannels.clear()
|
||||||
if (this.guild?.topic) {
|
if (this.guild?.topic) {
|
||||||
await this.swarm.leave(topicToBuffer(this.guild.topic)).catch(() => {})
|
await this.swarm.leave(topicToBuffer(this.guild.topic)).catch(() => {})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
"pearcord-shared": "file:../pearcord-shared",
|
"pearcord-shared": "file:../pearcord-shared",
|
||||||
"pearcord-drive": "file:../pearcord-drive",
|
"pearcord-drive": "file:../pearcord-drive",
|
||||||
"pearcord-voice-media": "file:../pearcord-voice-media",
|
"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",
|
"hyperswarm": "^4.8.0",
|
||||||
"protomux": "^3.0.0",
|
"protomux": "^3.0.0",
|
||||||
"compact-encoding": "^2.0.0"
|
"compact-encoding": "^2.0.0"
|
||||||
|
|||||||
Reference in New Issue
Block a user