Exemple #1
0
 public override IObservable <string> WhenNameUpdated()
 {
     return(BluetoothObservables
            .WhenDeviceNameChanged()
            .Where(x => x.Equals(this.native))
            .Select(x => this.Name));
 }
Exemple #2
0
        public override IObservable <AdapterStatus> WhenStatusChanged()
        {
            this.statusOb = this.statusOb ?? BluetoothObservables
                            .WhenAdapterStatusChanged()
                            .StartWith(this.Status)
                            .Select(x => this.Status)
                            .Replay(1)
                            .RefCount();

            return(this.statusOb);
        }
Exemple #3
0
        public IObservable <AdapterStatus> WhenStatusChanged()
        {
            this.statusOb = this.statusOb ?? Observable.Create <AdapterStatus>(ob =>
            {
                ob.OnNext(this.Status);
                var aob = BluetoothObservables
                          .WhenAdapterStatusChanged()
                          .Subscribe(_ => ob.OnNext(this.Status));

                return(aob.Dispose);
            })
                            .Replay(1)
                            .RefCount();

            return(this.statusOb);
        }
Exemple #4
0
        public override IObservable <bool> PairingRequest(string pin) => Observable.Create <bool>(ob =>
        {
            IDisposable requestOb = null;
            IDisposable istatusOb = null;

            if (this.PairingStatus == PairingStatus.Paired)
            {
                ob.Respond(true);
            }
            else
            {
                if (pin != null && Build.VERSION.SdkInt >= BuildVersionCodes.Kitkat)
                {
                    requestOb = BluetoothObservables
                                .WhenBondRequestReceived()
                                .Where(x => x.Equals(this.context.NativeDevice))
                                .Subscribe(x =>
                    {
                        var bytes = ConvertPinToBytes(pin);
                        x.SetPin(bytes);
                        x.SetPairingConfirmation(true);
                    },
                                           ob.OnError);
                }
                istatusOb = BluetoothObservables
                            .WhenBondStatusChanged()
                            .Where(x => x.Equals(this.context.NativeDevice) && x.BondState != Bond.Bonding)
                            .Subscribe(x => ob.Respond(x.BondState == Bond.Bonded)); // will complete here

                // execute
                if (!this.context.NativeDevice.CreateBond())
                {
                    ob.Respond(false);
                }
            }
            return(() =>
            {
                requestOb?.Dispose();
                istatusOb?.Dispose();
            });
        });
Exemple #5
0
 public override IObservable <string> WhenNameUpdated() => BluetoothObservables
 .WhenDeviceNameChanged()
 .Where(x => x.Equals(this.context.NativeDevice))
 .Select(x => this.Name);