Show peers immediately on discovery, before DataChannel opens

Emit peer_connected + peer_status(connecting) as soon as a PeerConn is
created, so peers appear in the sidebar even if ICE is still negotiating
or ultimately fails. The alias updates in-place once the DataChannel hello
arrives with the real nick.

Fixes: mobile/CGNAT peers being completely invisible when STUN hole
punching fails — they now show with a connecting/failed dot instead of
not appearing at all.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Fredrik Johansson
2026-06-25 20:54:47 +02:00
parent fb14ca82af
commit c4032417ae
2 changed files with 15 additions and 1 deletions

View File

@@ -707,6 +707,7 @@ export class BrowserAdapter {
const peer = new PeerConn(this.identity, this.sig!, pid,
(ev, data) => this._onPeerEvent(ev, data), this.identity.nick, this.sharedFiles)
this.peers.set(pid, peer)
this._emitDiscovered(pid)
await peer.startOffer()
}
@@ -716,6 +717,7 @@ export class BrowserAdapter {
if (!peer || peer.pc.connectionState === 'failed' || peer.pc.connectionState === 'closed') {
peer = new PeerConn(this.identity, this.sig!, from,
(ev, data) => this._onPeerEvent(ev, data), this.identity.nick, this.sharedFiles)
this._emitDiscovered(from)
this.peers.set(from, peer)
}
await peer.onBox(box)
@@ -810,6 +812,18 @@ export class BrowserAdapter {
}
}
private _emitDiscovered(pid: string) {
this.emit({
type: 'peer_connected',
peer: { id: pid, alias: pid.slice(0, 8), public_key: pid, created_at: new Date().toISOString() },
})
this.emit({
type: 'peer_status',
peer_id: pid as unknown as import('../types').PeerID,
conn_state: 'connecting',
})
}
setSharedFiles(files: Map<string, File>) {
this.sharedFiles = files
this.peers.forEach(p => { p.share = files })

View File

@@ -235,7 +235,7 @@ export const useWaste = create<WasteState>((set, get) => ({
if (msg.peer) {
set(s => ({
connectedPeers: s.connectedPeers.some(p => p.id === msg.peer!.id)
? s.connectedPeers
? s.connectedPeers.map(p => p.id === msg.peer!.id ? { ...p, ...msg.peer } : p)
: [...s.connectedPeers, msg.peer!],
}))
}