https://github.com/dodoinblue/ionic-native-bluetoothle
Ionic Native wrapper for cordova-plugin-bluetoothle
https://github.com/dodoinblue/ionic-native-bluetoothle
ble bluetooth ionic
Last synced: about 1 month ago
JSON representation
Ionic Native wrapper for cordova-plugin-bluetoothle
- Host: GitHub
- URL: https://github.com/dodoinblue/ionic-native-bluetoothle
- Owner: dodoinblue
- License: other
- Created: 2018-03-14T06:00:51.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-05-07T19:32:49.000Z (about 7 years ago)
- Last Synced: 2025-02-12T21:47:12.938Z (over 1 year ago)
- Topics: ble, bluetooth, ionic
- Language: TypeScript
- Homepage:
- Size: 6.04 MB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Cordova Bluetoothle Ionic Native Wrapper
This is a Ionic Native wrapper for [cordova-plugin-bluetoothle](https://github.com/randdusing/cordova-plugin-bluetoothle).
## Installation
Run following command to install this wrapper in your project.
```bash
npm install ionic-native-bluetoothle --save
```
You also need to install the bluetoothle cordova plugin.
```bash
cordova plugin add cordova-plugin-bluetoothle
```
## Documentation
See [cordova-plugin-bluetoothle](https://github.com/randdusing/cordova-plugin-bluetoothle) for API details.
Also see the demo here: https://github.com/dodoinblue/bluetoothle-demo
### Basic Usage
To use a plugin, import and add the plugin provider to your `@NgModule`, and then inject it where you wish to use it.
```typescript
// app.module.ts
import { BluetoothLe } from 'ionic-native-bluetoothle';
...
@NgModule({
...
providers: [
...
BluetoothLe
...
]
...
})
export class AppModule { }
```
```typescript
import { BluetoothLe } from 'ionic-native-bluetoothle';
import { Platform } from 'ionic-angular';
import { NgZone } from '@angular/core';
@Component({ ... })
export class MyComponent {
constructor(private ble: BluetoothLe, private platform: Platform) {
platform.ready().then(() => {
this.ble.initialize().take(1).subscribe(result => {
console.log(`bluetooth status: ${result.status}`)
})
});
}
}
```
### Mocking and Browser Development
Basic mocking for development in browser is provided. To use the basic mocking class, first import both real and mock class in your `src/app/app.module.ts` file
```typescript
import { BluetoothLe } from 'ionic-native-bluetoothle';
import { BluetoothLeMock } from 'ionic-native-bluetoothle/mocks/BluetoothLeMock';
```
And override previous `BluetoothLe` class in `providers` section in `src/app/app.module.ts`
```typescript
providers: [
{ provide: BluetoothLe, useClass: BluetoothLeMock }
]
```
If you'd like to modify the Mock behavior, extend it to your own class, and replace `BluetoothLeMock` in the previous steps with your class. Example:
```typescript
// YourBleMock.ts
import { BluetoothLeMock } from 'ionic-native-bluetoothle/mocks/BluetoothLeMock';
export class YourBleMock extends BluetoothLeMock {
}
// app.module.ts
import { BluetoothLe } from 'ionic-native-bluetoothle';
import { YourBleMock } from 'path/to/YourBleMock.ts';
...
providers: [
{ provide: BluetoothLe, useClass: YourBleMock }
]
```
# Credits
This plugin is based on:
* https://github.com/randdusing/cordova-plugin-bluetoothle
* https://github.com/ionic-team/ionic-native