theta-ble-client-react-native
Version:
This library provides a way to control RICOH THETA using
135 lines (128 loc) • 4.68 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.BluetoothControlCommand = void 0;
var _thetaService = require("./theta-service");
var _values = require("./values");
var ThetaBleClient = _interopRequireWildcard(require("../native"));
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
/* eslint no-useless-catch: 0 */
/**
* Bluetooth Control Command Service
*
* Service: 0F291746-0C80-4726-87A7-3C501FD3B4B6
*/
class BluetoothControlCommand extends _thetaService.ThetaService {
constructor(device) {
super();
this.service = _values.BleServiceEnum.BLUETOOTH_CONTROL_COMMAND;
this.device = device;
}
setNotifyScan(callback) {
const notifyCallBack = callback != null ? event => {
if (event.params != null) {
callback(event.params);
}
} : undefined;
this.device.notifyList.set('NOTIFICATION_SCANNED_BLUETOOTH_PERIPHERAL_DEVICE', notifyCallBack);
}
setCompletedScan(callback) {
const notifyCallBack = callback != null ? event => {
if (event.params != null) {
this.device.notifyList.delete('NOTIFICATION_SCANNED_BLUETOOTH_PERIPHERAL_DEVICE');
this.device.notifyList.delete('SCAN_BLUETOOTH_PERIPHERAL_DEVICE');
callback(event.params);
}
} : undefined;
this.device.notifyList.set('SCAN_BLUETOOTH_PERIPHERAL_DEVICE', notifyCallBack);
if (!notifyCallBack) {
this.setNotifyScan();
}
}
/**
* Scanning for peripheral device
*
* Scan characteristic: 03F423B3-A71F-4D70-A4BC-437C3137AFCD
* Notify characteristic: 7B058429-DF5C-4454-88A2-C81086131C30
*
* @param timeout Timeout of scanning
* @return Scanned peripheral device list.
*/
async scanPeripheralDevice(timeout) {
try {
await this.scanPeripheralDeviceStop();
return await ThetaBleClient.nativeBluetoothControlCommandScanPeripheralDevice(this.device.id, timeout);
} catch (error) {
throw error;
}
}
/**
* Scanning start for peripheral device
*
* onCompleted is called in a timeout.
*
* Scan characteristic: 03F423B3-A71F-4D70-A4BC-437C3137AFCD
* Notify characteristic: 7B058429-DF5C-4454-88A2-C81086131C30
*
* @param timeout Timeout of scanning
* @param onNotify Notification of discovery of peripheral device
* @param onCompleted Notification of scan completion
*/
async scanPeripheralDeviceStart(timeout, onNotify, onCompleted) {
try {
await this.scanPeripheralDeviceStop();
this.setNotifyScan(onNotify);
this.setCompletedScan(onCompleted);
return await ThetaBleClient.nativeBluetoothControlCommandScanPeripheralDeviceStart(this.device.id, timeout);
} catch (error) {
this.setNotifyScan();
this.setCompletedScan();
throw error;
}
}
/**
* Scanning stop for peripheral device
*
* Notify characteristic: 7B058429-DF5C-4454-88A2-C81086131C30
*/
async scanPeripheralDeviceStop() {
try {
this.setNotifyScan();
await ThetaBleClient.nativeBluetoothControlCommandScanPeripheralDeviceStop(this.device.id);
this.setCompletedScan();
} catch (error) {
throw error;
}
}
/**
* Connect to peripheral device
*
* Characteristic: 1FA3E524-BAD5-4F75-808B-94487A4B9024
*
* @param macAddress MAC address of peripheral device
*/
async connectPeripheralDevice(peripheralDevice) {
try {
return await ThetaBleClient.nativeBluetoothControlCommandConnectPeripheralDevice(this.device.id, peripheralDevice.macAddress);
} catch (error) {
throw error;
}
}
/**
* Unsubscribe from peripheral device
*
* Characteristic: 61A37C82-D635-43B9-A973-5857EFE64094
*
* @param peripheralDevice Peripheral device
*/
async deletePeripheralDevice(peripheralDevice) {
try {
return await ThetaBleClient.nativeBluetoothControlCommandDeletePeripheralDevice(this.device.id, peripheralDevice.macAddress);
} catch (error) {
throw error;
}
}
}
exports.BluetoothControlCommand = BluetoothControlCommand;
//# sourceMappingURL=bluetooth-control-command.js.map