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

Why does stopAdvertising() and stopBrowsing() call initTransport()? #39

Closed azanli closed 5 years ago

azanli commented 6 years ago
    @ReactMethod
    public void stopAdvertising() {
        if(this.type == User.PeerType.ADVERTISER_BROWSER) {
            this.type = User.PeerType.BROWSER;
            this.networkCommunicator.initTransport("WIFI-BT", this.type);
            return;
        }
        this.type = User.PeerType.OFFLINE;
        this.networkCommunicator.stopTransport();
    }
    @ReactMethod
    public void stopBrowsing() {
        if(this.type == User.PeerType.ADVERTISER_BROWSER) {
            this.type = User.PeerType.ADVERISER;
            this.networkCommunicator.initTransport("WIFI-BT", this.type);
            return;
        }
        this.type = User.PeerType.OFFLINE;
        this.networkCommunicator.stopTransport();
    }

NetworkManager in iOS does the same thing. I cannot wrap my head around the reason behind this. As I am calling advertise() with "WIFI-BT" as the default argument, I assume that this.type == User.Peertype.ADVERTISER_BROWSER so my application never stops broadcasting. Please correct me if I'm wrong then, but wouldn't the condition in those functions before stopTransport() essentially prevent the very thing the user wants to stop from stopping? Why do those stop functions appear to start instead? Someone please explain, I am denying my logic because this appears to be there for a purpose..