Verified Commit 9a0ac4aa authored by staltz's avatar staltz

UI work to show staged BT peers that can be followed-then-connected

parent 633f57a7
......@@ -69,6 +69,7 @@ export const styles = StyleSheet.create({
});
function peerModeIcon(source: PeerMetadata['source']): string {
if ((source as any) === 'bt') return 'bluetooth';
if (source === 'local') return 'wifi';
if ((source as any) === 'dht') return 'account-network';
if (source === 'pub') return 'server-network';
......@@ -76,6 +77,7 @@ function peerModeIcon(source: PeerMetadata['source']): string {
}
function peerModeTitle(source: PeerMetadata['source']): string {
if ((source as any) === 'bt') return 'Bluetooth';
if (source === 'local') return 'Local network';
if ((source as any) === 'dht') return 'Internet P2P';
if (source === 'pub') return 'Internet server';
......
......@@ -57,7 +57,7 @@ export type ThreadAndExtras = {
export type StagedPeerMetadata = {
key: string;
source: 'local' | 'dht' | 'pub' | 'bluetooth';
source: 'local' | 'dht' | 'pub' | 'bt';
role?: 'client' | 'server';
note?: string;
};
......@@ -273,14 +273,17 @@ export class SSBSource {
const bluetooth$: Stream<Array<StagedPeerMetadata>> = 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: 'bluetooth',
note: data.displayName,
})),
result.discovered.map(
(data: any) =>
({
key:
`bt:${data.remoteAddress.split(':').join('')}` +
'~' +
`shs:${data.id.replace(/^\@/, '')}`,
source: 'bt',
note: data.displayName,
} as StagedPeerMetadata),
),
);
return xs.combine(bluetooth$, hosting$, claiming$);
......@@ -511,6 +514,17 @@ export function ssbDriver(sink: Stream<Req>): SSBSource {
if (req.type === 'connectBluetooth') {
api.sbot.async.gossipConnect[0](req.address, (err: any) => {
if (err) console.error(err.message || err);
const friendId = '@' + req.address.split('shs:')[1];
api.sbot.async.publish[0](
{
type: 'contact',
contact: friendId,
following: true,
},
(err2: any) => {
if (err2) console.error(err2.message || err2);
},
);
});
}
if (req.type === 'dhtInvite.accept') {
......
......@@ -69,7 +69,7 @@ export const styles = StyleSheet.create({
});
function peerModeIcon(peer: StagedPeer): string {
if (peer.source === 'bluetooth') return 'bluetooth';
if (peer.source === 'bt') return 'bluetooth';
if (peer.source === 'local') return 'wifi';
if (peer.source === 'dht') return 'account-network';
if (peer.source === 'pub') return 'server-network';
......@@ -77,7 +77,7 @@ function peerModeIcon(peer: StagedPeer): string {
}
function peerModeDescription(peer: StagedPeer): string {
if (peer.source === 'bluetooth') return 'Bluetooth';
if (peer.source === 'bt') return 'Bluetooth';
if (peer.source === 'local') return 'Local network';
if (peer.source === 'dht' && peer.role === 'client')
return 'Internet P2P: looking for online friend...';
......
......@@ -22,7 +22,7 @@ export default function ssb(actions: Actions) {
{type: 'searchBluetooth', interval: 60e3} as Req,
),
actions.openStagedPeer$
.filter(peer => peer.source === 'bluetooth')
.filter(peer => peer.source === 'bt')
.map(peer => ({type: 'connectBluetooth', address: peer.key} as Req)),
);
}
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