Verified Commit 308fa032 authored by staltz's avatar staltz

WIP UI work (show bluetooth staged peers)

parent 98a2ccf6
......@@ -57,8 +57,9 @@ export type ThreadAndExtras = {
export type StagedPeerMetadata = {
key: string;
source: 'local' | 'dht' | 'pub';
source: 'local' | 'dht' | 'pub' | 'bluetooth';
role?: 'client' | 'server';
note?: string;
};
function mutateMsgWithLiveExtras(api: any) {
......@@ -269,16 +270,26 @@ export class SSBSource {
)
.startWith([]);
const bluetooth$: Stream<any> = xsFromPullStream(
const bluetooth$: Stream<Array<StagedPeerMetadata>> = xsFromPullStream(
api.sbot.pull.nearbyBluetoothPeers[0](1000),
).map((result: any) =>
result.discovered.map((data: any) => ({
key: data.remoteAddress,
source: 'bluetooth',
note: data.displayName,
})),
);
bluetooth$.subscribe({next: x => console.warn(JSON.stringify(x))});
return xs.combine(hosting$, claiming$);
return xs.combine(bluetooth$, hosting$, claiming$);
})
.flatten()
.map(([hosting, claiming]) => hosting.concat(claiming));
.map(([bluetooth, hosting, claiming]) => [
...bluetooth,
...hosting,
...claiming,
]);
}
public thread$(rootMsgId: MsgId): Stream<ThreadAndExtras> {
......
......@@ -18,7 +18,7 @@ import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import {Palette} from '../../../global-styles/palette';
import {Dimensions} from '../../../global-styles/dimens';
import {Typography} from '../../../global-styles/typography';
import {StagedPeer} from './model';
import {StagedPeerMetadata as StagedPeer} from '../../../drivers/ssb';
export const styles = StyleSheet.create({
container: {
......@@ -69,6 +69,7 @@ export const styles = StyleSheet.create({
});
function peerModeIcon(peer: StagedPeer): string {
if (peer.source === 'bluetooth') return 'bluetooth';
if (peer.source === 'local') return 'wifi';
if (peer.source === 'dht') return 'account-network';
if (peer.source === 'pub') return 'server-network';
......@@ -76,6 +77,7 @@ function peerModeIcon(peer: StagedPeer): string {
}
function peerModeDescription(peer: StagedPeer): string {
if (peer.source === 'bluetooth') return 'Bluetooth';
if (peer.source === 'local') return 'Local network';
if (peer.source === 'dht' && peer.role === 'client')
return 'Internet P2P: looking for online friend...';
......
......@@ -6,14 +6,15 @@
import {Stream} from 'xstream';
import {Command} from 'cycle-native-asyncstorage';
import {State, StagedPeer} from './model';
import {StagedPeerMetadata} from '../../../drivers/ssb';
import {State} from './model';
import dropRepeats from 'xstream/extra/dropRepeats';
function isDhtInviteWithNote(invite: StagedPeer) {
function isDhtInviteWithNote(invite: StagedPeerMetadata) {
return !!invite.note && invite.source === 'dht';
}
export function noteStorageKeyFor(invite: StagedPeer) {
export function noteStorageKeyFor(invite: StagedPeerMetadata) {
return `dhtInviteNote:${invite.key}`;
}
......
......@@ -8,7 +8,8 @@ import {Stream} from 'xstream';
import {ReactSource} from '@cycle/react';
import {FeedId} from 'ssb-typescript';
import {NavSource} from 'cycle-native-navigation';
import {State, StagedPeer} from './model';
import {StagedPeerMetadata as StagedPeer} from '../../../drivers/ssb';
import {State} from './model';
import sample from 'xstream-sample';
export default function intent(
......
......@@ -8,16 +8,15 @@ import xs, {Stream} from 'xstream';
import concat from 'xstream/extra/concat';
import {PeerMetadata, FeedId} from 'ssb-typescript';
import {Reducer} from '@cycle/state';
import {SSBSource, StagedPeerMetadata} from '../../../drivers/ssb';
import {
SSBSource,
StagedPeerMetadata as StagedPeer,
} from '../../../drivers/ssb';
import {NetworkSource} from '../../../drivers/network';
import {noteStorageKeyFor} from './asyncstorage';
import dropRepeats from 'xstream/extra/dropRepeats';
import {AsyncStorageSource} from 'cycle-native-asyncstorage';
export type StagedPeer = StagedPeerMetadata & {
note?: string;
};
export type State = {
selfFeedId: FeedId;
lanEnabled: boolean;
......@@ -126,7 +125,7 @@ export default function model(
})
.flatten()
.map(
([rawStagedPeers, notes]: [StagedPeerMetadata[], [string, string][]]) =>
([rawStagedPeers, notes]: [StagedPeer[], [string, string][]]) =>
function setPeersReducer(prev: State): State {
const stagedPeers = rawStagedPeers.map(p => {
const kv = notes.find(_kv => _kv[0].endsWith(p.key) && !!_kv[1]);
......
......@@ -88,7 +88,8 @@ function ConnectivityModes(state: State) {
function Body(state: State) {
const {lanEnabled, internetEnabled, peers, stagedPeers} = state;
if (!lanEnabled && !internetEnabled) {
const bluetoothEnabled = true;
if (!bluetoothEnabled && !lanEnabled && !internetEnabled) {
return h(EmptySection, {
style: styles.emptySection,
image: require('../../../../../images/noun-lantern.png'),
......
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