### Start Example App Packager Source: https://github.com/tr3v3r/react-native-esc-pos-printer/blob/main/CONTRIBUTING.md Starts the Metro server for the example application, which is necessary for running the app on devices or simulators. ```sh yarn example start ``` -------------------------------- ### Start Metro Server (npm) Source: https://github.com/tr3v3r/react-native-esc-pos-printer/blob/main/package/example/README.md Use this command to start the Metro bundler when using npm. ```bash npm start ``` -------------------------------- ### Start Application on iOS (npm) Source: https://github.com/tr3v3r/react-native-esc-pos-printer/blob/main/package/example/README.md Run this command to start your iOS application using npm. ```bash npm run ios ``` -------------------------------- ### Start Application on Android (npm) Source: https://github.com/tr3v3r/react-native-esc-pos-printer/blob/main/package/example/README.md Run this command to start your Android application using npm. ```bash npm run android ``` -------------------------------- ### Start Application on iOS (Yarn) Source: https://github.com/tr3v3r/react-native-esc-pos-printer/blob/main/package/example/README.md Run this command to start your iOS application using Yarn. ```bash yarn ios ``` -------------------------------- ### Run Example App on iOS Source: https://github.com/tr3v3r/react-native-esc-pos-printer/blob/main/CONTRIBUTING.md Builds and runs the example application on an iOS simulator or device. ```sh yarn example ios ``` -------------------------------- ### Run Example App on Android Source: https://github.com/tr3v3r/react-native-esc-pos-printer/blob/main/CONTRIBUTING.md Builds and runs the example application on an Android device or emulator. ```sh yarn example android ``` -------------------------------- ### Start Metro Server (Yarn) Source: https://github.com/tr3v3r/react-native-esc-pos-printer/blob/main/package/example/README.md Use this command to start the Metro bundler when using Yarn. ```bash yarn start ``` -------------------------------- ### Start Application on Android (Yarn) Source: https://github.com/tr3v3r/react-native-esc-pos-printer/blob/main/package/example/README.md Run this command to start your Android application using Yarn. ```bash yarn android ``` -------------------------------- ### Install ESC/POS Printer for Expo Source: https://github.com/tr3v3r/react-native-esc-pos-printer/blob/main/README.md Install the library and prebuild for Expo projects. ```sh npx expo install react-native-esc-pos-printer npx expo prebuild ``` -------------------------------- ### start Source: https://github.com/tr3v3r/react-native-esc-pos-printer/blob/main/docs/discovery/PrintersDiscovery.md Starts searching for the specified device type. An event is generated for each device detected. By default, the search stops after 5 seconds, but this can be changed using the `timeout` parameter. ```APIDOC ## start ### Description Starts searching for the specified device type. An event is generated for each device detected. By default, the search stops after 5 seconds, but this can be changed using the `timeout` parameter. ### Method `start(params: DiscoveryStartParams): void` ### Parameters #### Path Parameters - **params** (DiscoveryStartParams) - Required - The search parameters. ### Example ```typescript PrintersDiscovery.start({ timeout: 2000, filterOption: { deviceModel: DiscoveryFilterOption.MODEL_ALL, }, }); ``` ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/tr3v3r/react-native-esc-pos-printer/blob/main/CONTRIBUTING.md Run this command in the root directory to install all dependencies for the monorepo using Yarn workspaces. ```sh yarn ``` -------------------------------- ### start Source: https://github.com/tr3v3r/react-native-esc-pos-printer/blob/main/docs/discovery/usePrintersDiscovery.md Starts searching for printers. The search automatically stops after a default timeout of 5 seconds, which can be customized using the `timeout` parameter. ```APIDOC ## start ### Description Starts searching for the specified device type. An event is generated for each device detected. By default, the search will be stopped after 5 seconds. To change this behavior, use the `timeout` parameter. ### Method `start(params?: DiscoveryStartParams): void` ### Parameters #### Parameters - **params** (`DiscoveryStartParams`) - Required - The search parameters, including optional `timeout` and `filterOption`. ### Request Example ```typescript const { start } = usePrintersDiscovery() start({ timeout: 2000, filterOption: { deviceModel: DiscoveryFilterOption.MODEL_ALL, }, }); ``` ``` -------------------------------- ### Add patch-package and postinstall-postinstall Source: https://github.com/tr3v3r/react-native-esc-pos-printer/blob/main/docs/flipperWorkaround.md Install necessary packages for patching dependencies. Refer to the patch-package documentation for more details. ```bash yarn add patch-package postinstall-postinstall ``` -------------------------------- ### Example IP Address Source: https://github.com/tr3v3r/react-native-esc-pos-printer/blob/main/docs/interfaces/deviceInfo.md Stores the IP address of the device. If it could not be acquired, a blank character is stored. ```string `TCP: "192.168.192.168"` ``` -------------------------------- ### Install React Native ESC/POS Printer Source: https://github.com/tr3v3r/react-native-esc-pos-printer/blob/main/README.md Install the library using Yarn for React Native projects. ```sh yarn add react-native-esc-pos-printer ``` -------------------------------- ### connect Source: https://github.com/tr3v3r/react-native-esc-pos-printer/blob/main/docs/printer/Printer.md Starts communication with the printer. It can optionally accept a timeout value. ```APIDOC ## connect ### Description Starts communication with the printer. ### Method `connect(timeout?: string): Promise` ### Parameters #### Query Parameters - **timeout** (string) - Optional - The timeout duration for the connection. ### Request Example ```typescript await printerInstance.connect(); ``` ``` -------------------------------- ### Install iOS Pods for Bare React Native Source: https://github.com/tr3v3r/react-native-esc-pos-printer/blob/main/docs/INSTALLATION.md Run this command in your iOS project directory to install necessary CocoaPods dependencies for bare React Native projects. ```sh pod install ``` -------------------------------- ### Connect to Printer Source: https://github.com/tr3v3r/react-native-esc-pos-printer/blob/main/docs/printer/Printer.md Starts communication with the printer. This method initiates the connection process. ```typescript await printerInstance.connect(); ``` -------------------------------- ### Example MAC Address Source: https://github.com/tr3v3r/react-native-esc-pos-printer/blob/main/docs/interfaces/deviceInfo.md Stores the MAC address of the device. If it could not be acquired, a blank character is stored. ```string `TCP: "12:34:56:78:56:78"` ``` -------------------------------- ### Example Device Name Source: https://github.com/tr3v3r/react-native-esc-pos-printer/blob/main/docs/interfaces/deviceInfo.md Stores the name set to the device. If it could not be acquired, a blank character or 'TM Printer' is stored. ```string `TM-T88V` ``` -------------------------------- ### connect Source: https://github.com/tr3v3r/react-native-esc-pos-printer/blob/main/docs/printer/connect.md Starts communication with the printer. This method establishes a connection and returns a Promise that resolves when communication is successfully initiated. ```APIDOC ## connect Starts communication with the printer. ### Parameters #### timeout *(optional)* - `number` Specifies the maximum time (in milliseconds) to wait for communication with the printer to be established. | **Value** | **Description** | **Default** | | --- | --- | --- | | 1000 to 300000 | Maximum wait time before an error is returned (in milliseconds). | 15000 | ### Returns `Promise` ### Errors | **Error status** | **Description** | | --- | --- | | ERR_PARAM | An invalid parameter was passed. | | ERR_CONNECT | Failed to open the device. | | ERR_TIMEOUT | Failed to communicate with the devices within the specified time. | | ERR_ILLEGAL | Tried to start communication with a printer with which communication had been already established. Tried to start communication with a printer during reconnection process. | | ERR_MEMORY | Necessary memory could not be allocated. | | ERR_FAILURE | An unknown error occurred. | | ERR_PROCESSING | Could not run the process. | | ERR_NOT_FOUND | The printer could not be found. | | ERR_IN_USE | The device was in use. | | ERR_TYPE_INVALID | The device type is different. | | ERR_RECOVERY_FAILURE | Failed to recover the printer. | ### Supplementary explanation Android: - When communication with the printer is no longer necessary, be sure to call disconnect to terminate it. - If you are using DHCP to assign the IP address of the printer, specify the MAC address or host name of the printer as the identifier. - When connecting through the USB, the identifiers that can be specified differ depending on the shape of the USB connector. When the identifier is omitted, Android OS connects with the USB device found first. When the Android terminal is set to the developer mode, you may not be able to connect through USB-A - Device Charging. - Devices other than printers are exclusively locked. - If error with status ERR_RECOVERY_FAILURE occurs, restart the printer. iOS: - When communication with the printer is no longer necessary, be sure to call disconnect to terminate it. - For TM-DT series, MAC address cannot be specified. - When connecting with the printer using Bluetooth, complete pairing before calling the connect command. - Depending on the project settings, Bluetooth communication may be disconnected if the application runs in the background. - If Bluetooth and USB are used simultaneously, priority is given to the USB. - Devices other than printers are exclusively locked. - If error with status ERR_RECOVERY_FAILURE occurs, restart the printer. - Since it takes time to send and receive a large amount of data with BLE connection, the following APIs not recommended be used. (addImage) ``` -------------------------------- ### Add postinstall script to package.json Source: https://github.com/tr3v3r/react-native-esc-pos-printer/blob/main/docs/flipperWorkaround.md Configure package.json to automatically run patch-package after installations. This ensures patches are applied consistently. ```json "scripts": { "postinstall": "patch-package" } ``` -------------------------------- ### Example Bluetooth Device Address Source: https://github.com/tr3v3r/react-native-esc-pos-printer/blob/main/docs/interfaces/deviceInfo.md Stores the Bluetooth device address. If it could not be acquired, a blank character is stored. ```string `BT: "00:22:15:7D:70:9C"` ``` -------------------------------- ### Printer.monitorPrinter() Source: https://github.com/tr3v3r/react-native-esc-pos-printer/blob/main/docs/printer/Printer.md Starts monitoring the printer status at a specified interval and provides a callback for status updates. ```APIDOC ## Printer.monitorPrinter() ### Description Starts monitoring the printer status. ### Method `Printer.monitorPrinter(printerInstance: Printer, listener: Listener, interval: number): () => void` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **printerInstance** (Printer) - Required - The printer instance to monitor. * **listener** (Listener) - Required - A callback function that receives the printer status. * **interval** (number) - Required - The interval in milliseconds to check the printer status. ### Request Example ```typescript const stop = Printer.monitorPrinter(printerInstance, (status) => { console.log(status); }, 5000); // call stop() to stop monitoring ``` ### Response #### Success Response (200) * **() => void** - A function to stop monitoring the printer. #### Response Example None ``` -------------------------------- ### Printer.addViewShot() Source: https://github.com/tr3v3r/react-native-esc-pos-printer/blob/main/docs/printer/Printer.md Prints an image captured from a React Native View. Requires 'react-native-view-shot' to be installed. ```APIDOC ## Printer.addViewShot() ### Description Prints image captured from React Native View. Requires `react-native-view-shot` to be installed. ### Method `Printer.addViewShot(printerInstance: Printer, params: AddViewShotParams): Promise` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **printerInstance** (Printer) - Required - The printer instance to use. * **params** (AddViewShotParams) - Required - Parameters for capturing and printing the view. * **viewNode** (React Native View Node) - Required - The reference to the React Native View to capture. ### Request Example ```typescript const ref = useRef(null); ... await Printer.addViewShot(printerInstance, { viewNode: ref.current, }); ... return ( Print me ); ``` ### Response #### Success Response (200) void #### Response Example None ``` -------------------------------- ### Start Printer Discovery Source: https://github.com/tr3v3r/react-native-esc-pos-printer/blob/main/docs/discovery/PrintersDiscovery.md Initiates a search for printers with a specified timeout and filter options. The search stops automatically after the timeout period. ```typescript PrintersDiscovery.start({ timeout: 2000, filterOption: { deviceModel: DiscoveryFilterOption.MODEL_ALL, }, }); ``` -------------------------------- ### Start Printer Discovery with Timeout and Filter Source: https://github.com/tr3v3r/react-native-esc-pos-printer/blob/main/docs/discovery/usePrintersDiscovery.md Initiates a search for printers with a specified timeout and filter options. The search will automatically stop after the given timeout in milliseconds. ```typescript const { start } = usePrintersDiscovery() start({ timeout: 2000, filterOption: { deviceModel: DiscoveryFilterOption.MODEL_ALL, }, }); ``` -------------------------------- ### Access Discovered Printers List Source: https://github.com/tr3v3r/react-native-esc-pos-printer/blob/main/docs/discovery/usePrintersDiscovery.md Starts the printer discovery process and logs the list of discovered printers. The 'printers' array is updated dynamically as new devices are found. ```typescript const { printers, start } = usePrintersDiscovery() start() console.log(printers) // will be update when every new printer is discovered ``` -------------------------------- ### Printer.monitorPrinter Source: https://github.com/tr3v3r/react-native-esc-pos-printer/blob/main/docs/printer/monitorPrinter.md Starts monitoring the printer status and provides updates via a listener function. It allows for custom intervals and internally utilizes connect, getStatus, and disconnect commands. ```APIDOC ## static Printer.monitorPrinter Starts monitoring the printer status. ### Parameters #### printerInstance - `Printer` Printer instance defined by calling `new Printer(...)`. #### listener - (status: [PrinterStatus](../interfaces/printerStatus.md)) => void Listener function that will be called with printer status. #### interval (optional) - `number` Interval in milliseconds. Default: 1000. ### Returns `() => void` ### Supplementary explanation - Internaly uses [connect](./connect.md), [getStatus](./getStatus.md) and [disconnect](./disconnect.md) commands. ``` -------------------------------- ### Get Printer Status Source: https://github.com/tr3v3r/react-native-esc-pos-printer/blob/main/docs/printer/Printer.md Acquires the current status information of the printer. ```typescript const printerStatus = await printerInstance.getStatus(); ``` -------------------------------- ### Initialize Printer with Bluetooth Target Source: https://github.com/tr3v3r/react-native-esc-pos-printer/blob/main/docs/printer/constructor.md Instantiates a new Printer object, specifying a Bluetooth device address as the connection target and the printer's model name. ```typescript const printer = new Printer({ target: "BT:00:22:15:7D:70:9C", deviceName: "TM-T88V", }) ``` -------------------------------- ### Printer Constructor Source: https://github.com/tr3v3r/react-native-esc-pos-printer/blob/main/docs/printer/constructor.md Initializes a new Printer instance. This constructor implements a singleton pattern, returning the same instance if the same target is provided. ```APIDOC ## Printer constructor Initializes the printer object. > [!NOTE] > Implements singletone pattern. Return the same instance if the same target is passed. ### Parameters #### target - `string` Specifies the method of connecting to the printer by a character string. The connection method varies according to the system configuration. Can be retrieved from the [discovery](../discovery/discovery.md). | **I/F** | **Connec-tion type** | **Identifier** | **Example** | | --- | --- | --- | --- | | Wi-Fi/Ethernet | "TCP" | - IP address in IPv4 format
- MAC address
- Host name | "TCP:192.168.192.168" | | Bluetooth | "BT" | BD address | "BT:00:22:15:7D:70:9C" | | USB | "USB" | - Device node
- USB Serial number
- Omitted | "USB:/dev/udev/*", "USB:00000000000000000", "USB:" | --- #### deviceName - `string` The name set to the device is stored. Example: `TM-T88V` --- #### lang - `enum PrinterModelLang` Specifies the language of the printer. | **Value** | **Description** | | --- | --- | | `PrinterConstants.MODEL_ANK` | ANK model | | `PrinterConstants.MODEL_CHINESE` | Simplified Chinese model | | `PrinterConstants.MODEL_TAIWAN` | Taiwan model | | `PrinterConstants.MODEL_KOREAN` | Korean model | | `PrinterConstants.MODEL_THAI` | Thai model | | `PrinterConstants.MODEL_SOUTHASIA` | South Asian model | Note: The default value is `PrinterConstants.MODEL_ANK`. ### Example ```typescript const printer = new Printer({ target: "BT:00:22:15:7D:70:9C", deviceName: "TM-T88V", }) ``` ``` -------------------------------- ### Get Printer Setting Source: https://github.com/tr3v3r/react-native-esc-pos-printer/blob/main/docs/printer/Printer.md Acquires the set value of a printer setting. The value is notified to a listener method. ```typescript const printerSetting = await printerInstance.getPrinterSetting(PrinterConstants.PRINTER_SETTING_PAPERWIDTH); ``` -------------------------------- ### Device Connection Targets Source: https://github.com/tr3v3r/react-native-esc-pos-printer/blob/main/docs/interfaces/deviceInfo.md Specifies various connection targets for different device types (TCP, Bluetooth, USB). Use these strings to establish a connection to the device. ```string "TCP:192.168.192.168" ``` ```string "BT:00:22:15:7D:70:9C" ``` ```string "USB:/dev/udev/*" ``` ```string "USB:000000000000000000" ``` ```string "TCP:192.168.192.168[local_printer]" ``` ```string "TCP:192.168.192.168[local_display]" ``` ```string "TCP:12:34:56:78:56:78" ``` -------------------------------- ### DiscoveryStartParams Source: https://github.com/tr3v3r/react-native-esc-pos-printer/blob/main/docs/interfaces/discoveryStartParams.md Parameters for initiating a discovery process. Allows configuration of search timeout, automatic stopping, and filtering. ```APIDOC ## DiscoveryStartParams ### Description An interface defining the parameters for starting a discovery process. It allows customization of the search duration, whether the search stops automatically, and filtering options. ### Parameters #### Optional Parameters - **timeout** (number) - Optional - The search timeout in milliseconds. The default value is 5000 ms. - **autoStop** (boolean) - Optional - If true, the search will stop automatically after the timeout. The default value is true. - **filterOption** (FilterOption) - Optional - The search filter options. See [FilterOption](./filterOption.md) for more details. ``` -------------------------------- ### Publish New Versions Source: https://github.com/tr3v3r/react-native-esc-pos-printer/blob/main/CONTRIBUTING.md Uses release-it to automate the process of publishing new versions to npm, including version bumping and tag creation. ```sh yarn release ``` -------------------------------- ### Print Image from React Native View Source: https://github.com/tr3v3r/react-native-esc-pos-printer/blob/main/docs/printer/Printer.md Prints an image captured from a React Native View component. Requires `react-native-view-shot` to be installed and configured. ```bash yarn add react-native-view-shot # For iOS, run: cd ios && pod install ``` ```typescript const ref = useRef(null); ... await Printer.addViewShot(printerInstance, { viewNode: ref.current, }); ... return ( Print me ); ``` -------------------------------- ### Printer.tryToConnectUntil Source: https://github.com/tr3v3r/react-native-esc-pos-printer/blob/main/docs/printer/tryToConnectUntil.md Attempts to establish a connection with the printer, retrying until the provided predicate function returns true based on the printer's status. This is useful for scenarios like waiting for a printer to recover from a connection loss. ```APIDOC ## static Printer.tryToConnectUntil Tries to connect to the printer until the condition is met. ### Parameters #### printerInstance - `Printer` Printer instance defined by calling `new Printer(...)`. #### predicate - `(status: [PrinterStatus](../interfaces/printerStatus.md)) => boolean` Predicate function that will be called with printer status. If returns `true` promise will be resolved and next steps will be executed. ### Returns `Promise` ### Supplementary explanation - Can be used to wait for printer to be ready based on its status. I.e. connection loss. - Internaly uses [connect](./connect.md), [getStatus](./getStatus.md) commands. ``` -------------------------------- ### Print Text to Discovered Printers Source: https://github.com/tr3v3r/react-native-esc-pos-printer/blob/main/README.md Instantiate a Printer, connect to it, add text and formatting commands, and send the data. Ensure to handle connection status and disconnect after printing. ```tsx import { Printer } from 'react-native-esc-pos-printer'; function App() { const { start, isDiscovering, printers } = usePrintersDiscovery(); useEffect(() => { start(); }, []); const print = () => { // printing on all discovered printers printers.forEach(printersData => { const printerInstance = new Printer({ target: printersData.target, deviceName: printersData.deviceName, }); const res = await printerInstance.addQueueTask(async () => { await Printer.tryToConnectUntil( printerInstance, (status) => status.online.statusCode === PrinterConstants.TRUE ); await printerInstance.addText('DUDE!'); await printerInstance.addFeedLine(); await printerInstance.addCut(); const result = await printerInstance.sendData(); await printerInstance.disconnect(); return result; }) }) } return