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:
@@ -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 })
|
||||
|
||||
Reference in New Issue
Block a user