Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sync): set device name with random string at the end #121

Merged
merged 4 commits into from
May 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/frontend/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ export function addPeerListener(handler: PeerHandler): Subscription {
};
}

export function syncJoin() {
api.get("sync/join?name=Mapeo%20Mobile");
export function syncJoin(name) {
api.get(`sync/join?name=${name}`)
}

export function syncLeave() {
Expand Down
13 changes: 11 additions & 2 deletions src/frontend/screens/SyncModal/SyncView.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ const Header = ({ onClosePress }: HeaderProps) => (
</View>
);

const WifiBar = ({ onPress, ssid }) => (
const WifiBar = ({ onPress, ssid, deviceName }) => (
<TouchableNativeFeedback onPress={onPress}>
<View style={styles.wifiBar}>
<WifiIcon />
<Text style={styles.wifiBarText}>
<Text style={styles.bold}>Wi-Fi:</Text> {ssid}
</Text>
<Text style={styles.deviceName}>{deviceName}</Text>
</View>
</TouchableNativeFeedback>
);
Expand Down Expand Up @@ -72,6 +73,7 @@ type Props = {
onClosePress: () => void,
onSyncPress: (peerId: string) => void,
onWifiPress: () => void,
deviceName: string,
peers: Array<Peer>,
ssid: null | string
};
Expand All @@ -81,6 +83,7 @@ const SyncView = ({
onSyncPress,
peers,
ssid,
deviceName,
onWifiPress
}: Props) => (
<ScrollView
Expand All @@ -90,7 +93,7 @@ const SyncView = ({
<Header onClosePress={onClosePress} />
{ssid ? (
<>
<WifiBar onPress={onWifiPress} ssid={ssid} />
<WifiBar onPress={onWifiPress} ssid={ssid} deviceName={deviceName} />
{peers.length ? (
<PeerList peers={peers} onSyncPress={onSyncPress} />
) : (
Expand Down Expand Up @@ -186,6 +189,12 @@ const styles = StyleSheet.create({
color: "white",
paddingLeft: 10
},
deviceName: {
fontWeight: "bold",
textAlign: "right",
color: "white",
flex: 1
},
bold: {
fontWeight: "700"
},
Expand Down
10 changes: 9 additions & 1 deletion src/frontend/screens/SyncModal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ type State = {
ssid: null | string
};

const deviceName: string =
"Android " +
Math.floor(Math.random() * 1e9)
.toString(36)
.slice(0, 4)
.toUpperCase();

class SyncModal extends React.Component<Props, State> {
// Assume wifi is turned on at first (better UX)
state = { serverPeers: [], syncErrors: new Map(), ssid: null };
Expand All @@ -44,7 +51,7 @@ class SyncModal extends React.Component<Props, State> {

componentDidMount() {
// When the modal opens, start announcing this device as available for sync
syncJoin();
syncJoin(deviceName);
this._opened = Date.now();
// Subscribe to peer updates
this._subscriptions.push(addPeerListener(this.updatePeers));
Expand Down Expand Up @@ -157,6 +164,7 @@ class SyncModal extends React.Component<Props, State> {
const peers = this.getDerivedPeerState();
return (
<SyncView
deviceName={deviceName}
peers={peers}
ssid={this.state.ssid}
onClosePress={() => navigation.pop()}
Expand Down