alexkendall / react-native-bluetooth-cross-platform

Cross-Platform Bluetooth & WiFi React Native Module. Powered by underdark http://underdark.io/.
179 stars 35 forks source link

can't see discovers devices #41

Open aboozaid opened 6 years ago

aboozaid commented 6 years ago

First I have made a simple app to test this library I have two buttons one the first to advertise to make that first mobile shows to another and so the second for another device to discover (I still didn't know the idea I'm just testing) so the problem is nothing happens 👎 (I can't be able to see anything either advertise nor discover device)

This my simple code below: ` export default class App extends Component {

constructor() {

super();

this.ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});

const peers = [];

this.state = {

  peers,

  dataSource: this.ds.cloneWithRows(peers),

}

} getNearbyPeers(peers) {

BluetoothCP.getNearbyPeers((peers) => {

  this.setState({peers, dataSource: this.ds.cloneWithRows(peers)})

  alert(JSON.stringify(peers));

});

} render() {

return (

  <View style={styles.container}>
    <Button
      onPress={() => { BluetoothCP.advertise() }}
      title={"Connect to Device"}
    />
    <Button
      onPress={() => { BluetoothCP.browse() }}
      title={"check Devices"}
    />
    <TouchableHighlight onPress = {(peers) => this.getNearbyPeers()}>
      <Text>Find networks</Text>
    </TouchableHighlight>
    <ListView dataSource = {this.state.dataSource}
      renderRow = {(data) => {
        <View>
          <Text>{data.id}</Text>
        </View>
      }}
    />
  </View>

);

} }

aboozaid commented 6 years ago

@iotashan @Friendly-Robot @thibmaek if anyone could help

azanli commented 6 years ago

Have you tried registering the event listeners? Sometimes devices aren't detected again after they disconnect. For me personally, I used both advertise-browse at the same time so broadcasting and detecting would happen near simultaneously. Maybe try that. With the available event listeners and especially the 'receivedMessage' listener, a whole flow of coordinations can be set up so that advertisers would not know about browsers that aren't advertising and vice versa. Hope that helps!

I also recommend looking at the source code in the android/ios folders for a fuller comprehension of what's going on. It's actually pretty straight forward. Im leaving the country tonight so might not be able to reply. Best of luck!

qayyummdnoor commented 5 years ago

Does anyone solve this? i get empty array instead. @assemmohamedali @Friendly-Robot