connectBluetoothDevice(params: Object)

Requires:
DeviceKit≥3.1.0@ray-js/ray≥0.8.0
Platforms:
iOSAndroid
import { device } from '@ray-js/ray';

const { connectBluetoothDevice } = device;

// Promise usage
try {
  const res = await connectBluetoothDevice({ ...params });
  console.log(res);
} catch (err) {
  console.log(err.errorMsg);
}

Description

Aggregated Bluetooth connection API; supports ble, ble in dual-mode, beacon, mesh, and mesh single-live-wire connections.

Parameters

PropertyTypeRequiredDefaultDescriptionDeviceKit Since
devIdstringYes-Device ID-
timeoutMillisnumberNo15000Connection timeout Unit: milliseconds-
souceTypenumberNo0Source type If it's an automatic connection from a panel, pass 1; otherwise the default is 0 for a manual connection-
connectTypenumberNo0Bluetooth connection mode (default: 0) 0: Gateway and app. Default mode; effective if either the local or gateway path is available. 1: App only. Only checks whether the device is locally online and whether the local connection succeeds. 2: Gateway only. Only checks whether the gateway is online and whether the gateway connection succeeds.v3.1.2
complete() => voidNo-Completion callback (executed on both success and failure)-
success() => voidNo-Callback on successful API call-
fail(params: Object) => voidNo-Failure callback-
fail callback parameters
PropertyTypeDescription
errorMsgstringError message
errorCodestring | numberError code
Error extension

Return Value

None

Examples

import { device } from '@ray-js/ray'

device.connectBluetoothDevice({
  devId: "xx",
  timeoutMillis: 15000,
  souceType: 0,
  connectType: 0,
  success: data => {
    console.log(data);
  },
  fail: error => {
    console.error(error);
  },
});