protected IObservable <Beacon> Scan() { // TODO: switch to background scan this.beaconScanner = this.beaconScanner ?? this.adapter .Scan() .Where(x => Beacon.IsIBeaconPacket(x.AdvertisementData?.ManufacturerData)) .Select(x => Beacon.Parse(x.AdvertisementData.ManufacturerData, x.Rssi)) .Publish() .RefCount(); return(this.beaconScanner); }
IObservable <Beacon> Scan() { // TODO: switch to background scan this.beaconScanner = this.beaconScanner ?? Observable .Create <Beacon>(ob => this.adapter .Scan() .Subscribe(sr => { var md = sr.AdvertisementData?.ManufacturerData; if (md != null && Beacon.IsIBeaconPacket(md)) { var beacon = Beacon.Parse(md, sr.Rssi); ob.OnNext(beacon); } }) ) .Publish() .RefCount(); return(this.beaconScanner); }