diff --git a/src/NativeWearConnectivity.ts b/src/NativeWearConnectivity.ts index 43cb2c4..2581c40 100644 --- a/src/NativeWearConnectivity.ts +++ b/src/NativeWearConnectivity.ts @@ -5,14 +5,21 @@ type Payload = Record; type ReplyCallback = (reply: Payload) => void; type ErrorCallback = (err: Error) => void; +const UNHANDLED_CALLBACK = + 'The sendMessage function was called without a callback function. '; +const UNHANDLED_CALLBACK_REPLY = + 'The callback function was invoked with the payload: '; +const UNHANDLED_CALLBACK_ERROR = + 'The callback function was invoked with the error: '; + export const defaultReplyCb = (reply: Payload) => { - console.warn('Unhandled watch reply', reply); + console.log(UNHANDLED_CALLBACK + UNHANDLED_CALLBACK_REPLY, reply); }; export const defaultErrCb = (err: Error) => { - console.warn('Unhandled sendMessage error', err); + console.warn(UNHANDLED_CALLBACK + UNHANDLED_CALLBACK_ERROR, err); }; -export type SendMessageType = ( +export type SendMessage = ( message: Payload, cb: ReplyCallback, errCb: ErrorCallback @@ -20,7 +27,7 @@ export type SendMessageType = ( export interface Spec extends TurboModule { multiply(a: number, b: number): Promise; - sendMessage: SendMessageType; + sendMessage: SendMessage; } export default TurboModuleRegistry.getEnforcing('WearConnectivity'); diff --git a/src/index.tsx b/src/index.tsx index 5b43076..462cbd4 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,5 +1,5 @@ import { NativeModules, Platform } from 'react-native'; -import type { SendMessageType } from './NativeWearConnectivity'; +import type { SendMessage } from './NativeWearConnectivity'; import { defaultReplyCb, defaultErrCb } from './NativeWearConnectivity'; const LINKING_ERROR = @@ -30,7 +30,7 @@ export function multiply(a: number, b: number): Promise { return WearConnectivity.multiply(a, b); } -const sendMessage: SendMessageType = (message, cb, errCb) => { +const sendMessage: SendMessage = (message, cb, errCb) => { const callbackWithDefault = cb ?? defaultReplyCb; const errCbWithDefault = errCb ?? defaultErrCb; return WearConnectivity.sendMessage(