Verified Commit dc8b690b authored by staltz's avatar staltz

UI: remove staged BT peer once the peer is connected

parent f8923168
......@@ -55,6 +55,23 @@ export type ThreadAndExtras = {
errorReason?: 'blocked' | 'missing' | 'unknown';
};
export type BTPeer = {remoteAddress: string; id: string; displayName: string};
function btPeerToStagedPeerMetadata(p: BTPeer): StagedPeerMetadata {
return {
key:
`bt:${p.remoteAddress.split(':').join('')}` +
'~' +
`shs:${p.id.replace(/^\@/, '')}`,
source: 'bt',
note: p.displayName,
};
}
function btPeerNotYetConnected(btp: BTPeer, connecteds: Array<PeerMetadata>) {
return connecteds.findIndex(p => p.key === btp.id) === -1;
}
export type StagedPeerMetadata = {
key: string;
source: 'local' | 'dht' | 'pub' | 'bt';
......@@ -270,22 +287,21 @@ export class SSBSource {
)
.startWith([]);
const bluetooth$: Stream<Array<StagedPeerMetadata>> = xsFromPullStream(
const bluetoothNearby$: Stream<Array<BTPeer>> = xsFromPullStream(
api.sbot.pull.nearbyBluetoothPeers[0](1000),
).map((result: any) =>
result.discovered.map(
(data: any) =>
({
key:
`bt:${data.remoteAddress.split(':').join('')}` +
'~' +
`shs:${data.id.replace(/^\@/, '')}`,
source: 'bt',
note: data.displayName,
} as StagedPeerMetadata),
),
).map((result: any) => result.discovered);
const bluetoothConnected$ = this.peers$.map(peers =>
peers.filter(p => (p.source as any) === 'bt'),
);
const bluetooth$ = xs
.combine(bluetoothNearby$, bluetoothConnected$)
.map(([nearbys, connecteds]) =>
nearbys.filter(btPeer => btPeerNotYetConnected(btPeer, connecteds)),
)
.map(btPeers => btPeers.map(btPeerToStagedPeerMetadata));
return xs.combine(bluetooth$, hosting$, claiming$);
})
.flatten()
......
......@@ -19,7 +19,7 @@ export default function ssb(actions: Actions) {
invite => ({type: 'dhtInvite.remove', invite} as Req),
),
actions.bluetoothSearch$.mapTo(
{type: 'searchBluetooth', interval: 60e3} as Req,
{type: 'searchBluetooth', interval: 20e3} as Req,
),
actions.openStagedPeer$
.filter(peer => peer.source === 'bt')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment