UNPKG

9.74 kBJavaScriptView Raw
1"use strict";
2var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6 return c > 3 && r && Object.defineProperty(target, key, r), r;
7};
8var plugin_1 = require('./plugin');
9/**
10 * @name Bluetooth Serial
11 * @description This plugin enables serial communication over Bluetooth. It was written for communicating between Android or iOS and an Arduino.
12 * @usage
13 * ```typescript
14 * import { BluetoothSerial } from 'ionic-native';
15 *
16 *
17 * // Write a string
18 * BluetoothSerial.write("hello world").then(success, failure);
19 *
20 * // Array of int or bytes
21 * BluetoothSerial.write([186, 220, 222]).then(success, failure);
22 *
23 * // Typed Array
24 * var data = new Uint8Array(4);
25 * data[0] = 0x41;
26 * data[1] = 0x42;
27 * data[2] = 0x43;
28 * data[3] = 0x44;
29 * BluetoothSerial.write(data).then(success, failure);
30 *
31 * // Array Buffer
32 * BluetoothSerial.write(data.buffer).then(success, failure);
33 * ```
34 */
35var BluetoothSerial = (function () {
36 function BluetoothSerial() {
37 }
38 /**
39 * Connect to a Bluetooth device
40 * @param {string} macAddress_or_uuid Identifier of the remote device
41 * @returns {Observable<any>} Subscribe to connect, unsubscribe to disconnect.
42 */
43 BluetoothSerial.connect = function (macAddress_or_uuid) { return; };
44 /**
45 * Connect insecurely to a Bluetooth device
46 * @param {string} macAddress Identifier of the remote device
47 * @returns {Observable<any>} Subscribe to connect, unsubscribe to disconnect.
48 */
49 BluetoothSerial.connectInsecure = function (macAddress) { return; };
50 /**
51 * Disconnect from the connected device
52 * @returns {Promise<any>}
53 */
54 BluetoothSerial.disconnect = function () { return; };
55 /**
56 * Writes data to the serial port
57 * @param {any} data ArrayBuffer of data
58 * @returns {Promise<any>} returns a promise when data has been written
59 */
60 BluetoothSerial.write = function (data) { return; };
61 /**
62 * Gets the number of bytes of data available
63 * @returns {Promise<any>} returns a promise that contains the available bytes
64 */
65 BluetoothSerial.available = function () { return; };
66 /**
67 * Reads data from the buffer
68 * @returns {Promise<any>} returns a promise with data from the buffer
69 */
70 BluetoothSerial.read = function () { return; };
71 /**
72 * Reads data from the buffer until it reaches a delimiter
73 * @param {string} delimiter string that you want to search until
74 * @returns {Promise<any>} returns a promise
75 */
76 BluetoothSerial.readUntil = function (delimiter) { return; };
77 /**
78 * Subscribe to be notified when data is received
79 * @param {string} delimiter the string you want to watch for
80 * @returns {Observable<any>} returns an observable.
81 */
82 BluetoothSerial.subscribe = function (delimiter) { return; };
83 /**
84 * Subscribe to be notified when data is received
85 * @returns {Observable<any>} returns an observable
86 */
87 BluetoothSerial.subscribeRawData = function () { return; };
88 /**
89 * Clears data in buffer
90 * @returns {Promise<any>} returns a promise when completed
91 */
92 BluetoothSerial.clear = function () { return; };
93 /**
94 * Lists bonded devices
95 * @returns {Promise<any>} returns a promise
96 */
97 BluetoothSerial.list = function () { return; };
98 /**
99 * Reports if bluetooth is enabled
100 * @returns {Promise<any>} returns a promise
101 */
102 BluetoothSerial.isEnabled = function () { return; };
103 /**
104 * Reports the connection status
105 * @returns {Promise<any>} returns a promise
106 */
107 BluetoothSerial.isConnected = function () { return; };
108 /**
109 * Reads the RSSI from the connected peripheral
110 * @returns {Promise<any>} returns a promise
111 */
112 BluetoothSerial.readRSSI = function () { return; };
113 /**
114 * Show the Bluetooth settings on the device
115 * @returns {Promise<any>} returns a promise
116 */
117 BluetoothSerial.showBluetoothSettings = function () { return; };
118 /**
119 * Enable Bluetooth on the device
120 * @returns {Promise<any>} returns a promise
121 */
122 BluetoothSerial.enable = function () { return; };
123 /**
124 * Discover unpaired devices
125 * @returns {Promise<any>} returns a promise
126 */
127 BluetoothSerial.discoverUnpaired = function () { return; };
128 /**
129 * Subscribe to be notified on Bluetooth device discovery. Discovery process must be initiated with the `discoverUnpaired` function.
130 * @returns {Observable<any>} Returns an observable
131 */
132 BluetoothSerial.setDeviceDiscoveredListener = function () { return; };
133 /**
134 * Sets the human readable device name that is broadcasted to other devices
135 * @param {string} newName Desired name of device
136 */
137 BluetoothSerial.setName = function (newName) { };
138 /**
139 * Makes the device discoverable by other devices
140 * @param {number} discoverableDuration Desired number of seconds device should be discoverable for
141 */
142 BluetoothSerial.setDiscoverable = function (discoverableDuration) { };
143 __decorate([
144 plugin_1.Cordova({
145 platforms: ['Android', 'iOS', 'Windows Phone'],
146 observable: true,
147 clearFunction: 'disconnect'
148 })
149 ], BluetoothSerial, "connect", null);
150 __decorate([
151 plugin_1.Cordova({
152 platforms: ['Android'],
153 observable: true,
154 clearFunction: 'disconnect'
155 })
156 ], BluetoothSerial, "connectInsecure", null);
157 __decorate([
158 plugin_1.Cordova()
159 ], BluetoothSerial, "disconnect", null);
160 __decorate([
161 plugin_1.Cordova({
162 platforms: ['Android', 'iOS', 'Windows Phone']
163 })
164 ], BluetoothSerial, "write", null);
165 __decorate([
166 plugin_1.Cordova({
167 platforms: ['Android', 'iOS', 'Windows Phone']
168 })
169 ], BluetoothSerial, "available", null);
170 __decorate([
171 plugin_1.Cordova({
172 platforms: ['Android', 'iOS', 'Windows Phone']
173 })
174 ], BluetoothSerial, "read", null);
175 __decorate([
176 plugin_1.Cordova({
177 platforms: ['Android', 'iOS', 'Windows Phone']
178 })
179 ], BluetoothSerial, "readUntil", null);
180 __decorate([
181 plugin_1.Cordova({
182 platforms: ['Android', 'iOS', 'Windows Phone'],
183 observable: true,
184 clearFunction: 'unsubscribe'
185 })
186 ], BluetoothSerial, "subscribe", null);
187 __decorate([
188 plugin_1.Cordova({
189 platforms: ['Android', 'iOS', 'Windows Phone'],
190 observable: true,
191 clearFunction: 'unsubscribeRawData'
192 })
193 ], BluetoothSerial, "subscribeRawData", null);
194 __decorate([
195 plugin_1.Cordova({
196 platforms: ['Android', 'iOS', 'Windows Phone']
197 })
198 ], BluetoothSerial, "clear", null);
199 __decorate([
200 plugin_1.Cordova({
201 platforms: ['Android', 'iOS', 'Windows Phone']
202 })
203 ], BluetoothSerial, "list", null);
204 __decorate([
205 plugin_1.Cordova({
206 platforms: ['Android', 'iOS', 'Windows Phone']
207 })
208 ], BluetoothSerial, "isEnabled", null);
209 __decorate([
210 plugin_1.Cordova({
211 platforms: ['Android', 'iOS', 'Windows Phone']
212 })
213 ], BluetoothSerial, "isConnected", null);
214 __decorate([
215 plugin_1.Cordova({
216 platforms: ['Android', 'iOS', 'Windows Phone']
217 })
218 ], BluetoothSerial, "readRSSI", null);
219 __decorate([
220 plugin_1.Cordova({
221 platforms: ['Android', 'iOS', 'Windows Phone']
222 })
223 ], BluetoothSerial, "showBluetoothSettings", null);
224 __decorate([
225 plugin_1.Cordova({
226 platforms: ['Android', 'iOS', 'Windows Phone']
227 })
228 ], BluetoothSerial, "enable", null);
229 __decorate([
230 plugin_1.Cordova({
231 platforms: ['Android', 'iOS', 'Windows Phone']
232 })
233 ], BluetoothSerial, "discoverUnpaired", null);
234 __decorate([
235 plugin_1.Cordova({
236 platforms: ['Android', 'iOS', 'Windows Phone'],
237 observable: true,
238 clearFunction: 'clearDeviceDiscoveredListener'
239 })
240 ], BluetoothSerial, "setDeviceDiscoveredListener", null);
241 __decorate([
242 plugin_1.Cordova({
243 platforms: ['Android'],
244 sync: true
245 })
246 ], BluetoothSerial, "setName", null);
247 __decorate([
248 plugin_1.Cordova({
249 platforms: ['Android'],
250 sync: true
251 })
252 ], BluetoothSerial, "setDiscoverable", null);
253 BluetoothSerial = __decorate([
254 plugin_1.Plugin({
255 pluginName: 'BluetoothSerial',
256 repo: 'https://github.com/don/BluetoothSerial',
257 plugin: 'cordova-plugin-bluetooth-serial',
258 pluginRef: 'bluetoothSerial',
259 platforms: ['Android', 'iOS', 'Windows Phone', 'Browser']
260 })
261 ], BluetoothSerial);
262 return BluetoothSerial;
263}());
264exports.BluetoothSerial = BluetoothSerial;
265//# sourceMappingURL=bluetoothserial.js.map
\No newline at end of file