@d4l/react-native-wear-connectivity
Version:
Establish a two-way connection with wearOS
39 lines • 2.25 kB
JavaScript
import { Platform } from 'react-native';
import { WearConnectivity } from './index';
import { LIBRARY_NAME, IOS_NOT_SUPPORTED_WARNING } from './constants';
const UNHANDLED_CALLBACK = 'The capability function was called without a callback function. ';
const UNHANDLED_CALLBACK_REPLY = 'The callback function was invoked with the capability: ';
const UNHANDLED_CALLBACK_ERROR = 'The callback function was invoked with the error: ';
const defaultReplyCb = reply => {
console.log(UNHANDLED_CALLBACK + UNHANDLED_CALLBACK_REPLY, reply);
};
const defaultErrCb = err => {
console.warn(UNHANDLED_CALLBACK + UNHANDLED_CALLBACK_ERROR, err);
};
const getReachableNodes = (cb, errCb) => {
const callbackWithDefault = cb ?? defaultReplyCb;
const errCbWithDefault = errCb ?? defaultErrCb;
return WearConnectivity.getReachableNodes(callbackWithDefault, errCbWithDefault);
};
const getCapableAndReachableNodes = (capability, cb, errCb) => {
const callbackWithDefault = cb ?? defaultReplyCb;
const errCbWithDefault = errCb ?? defaultErrCb;
return WearConnectivity.getCapableAndReachableNodes(capability, callbackWithDefault, errCbWithDefault);
};
const getNonCapableAndReachableNodes = (capability, cb, errCb) => {
const callbackWithDefault = cb ?? defaultReplyCb;
const errCbWithDefault = errCb ?? defaultErrCb;
return WearConnectivity.getNonCapableAndReachableNodes(capability, callbackWithDefault, errCbWithDefault);
};
const nodesMock = () => console.warn(LIBRARY_NAME + 'nodes' + IOS_NOT_SUPPORTED_WARNING);
const nodesWithCapabilityMock = () => console.warn(LIBRARY_NAME + 'capability' + IOS_NOT_SUPPORTED_WARNING);
let getReachableNodesExport = nodesMock;
let getCapableAndReachableNodesExport = nodesWithCapabilityMock;
let getNonCapableAndReachableNodesExport = nodesWithCapabilityMock;
if (Platform.OS !== 'ios') {
getReachableNodesExport = getReachableNodes;
getCapableAndReachableNodesExport = getCapableAndReachableNodes;
getNonCapableAndReachableNodesExport = getNonCapableAndReachableNodes;
}
export { getReachableNodesExport as getReachableNodes, getCapableAndReachableNodesExport as getCapableAndReachableNodes, getNonCapableAndReachableNodesExport as getNonCapableAndReachableNodes };
//# sourceMappingURL=capability.js.map