@centimoo/capacitor-tcp-printer
v1.0.0
Published
Native TCP printer plugin for Capacitor using Apple Network.framework. Enables raw socket printing (ESC/POS) to LAN printers on iOS.
Maintainers
Readme
@centimoo/capacitor-tcp-printer
Native TCP printer plugin for Capacitor using Apple Network.framework. Enables raw socket printing (ESC/POS) to LAN printers on iOS.
Install
npm install @centimoo/capacitor-tcp-printer
npx cap syncAPI
TCP Socket Plugin interface for Capacitor Provides methods for TCP socket communication
connect(...)
connect(options: ConnectOptions) => Promise<ConnectResult>Connects to a TCP server
| Param | Type | Description |
| ------------- | --------------------------------------------------------- | ------------------------------------------------ |
| options | ConnectOptions | Connection options including IP address and port |
Returns: Promise<ConnectResult>
send(...)
send(options: SendOptions) => Promise<void>Sends data to a connected TCP server
| Param | Type | Description |
| ------------- | --------------------------------------------------- | --------------------------------------------------- |
| options | SendOptions | Send options including client ID, data and encoding |
read(...)
read(options: ReadOptions) => Promise<ReadResult>Reads data from a connected TCP server
| Param | Type | Description |
| ------------- | --------------------------------------------------- | ------------------------------------------------------------- |
| options | ReadOptions | Read options including client ID, expected length and timeout |
Returns: Promise<ReadResult>
disconnect(...)
disconnect(options: DisconnectOptions) => Promise<DisconnectResult>Disconnects from a TCP server
| Param | Type | Description |
| ------------- | --------------------------------------------------------------- | --------------------------------- |
| options | DisconnectOptions | Disconnect options with client ID |
Returns: Promise<DisconnectResult>
Interfaces
ConnectResult
Result of a successful connection
| Prop | Type | Description |
| ------------ | ------------------- | ---------------------------------------------------- |
| client | number | Client ID that can be used for subsequent operations |
ConnectOptions
Options for connecting to a TCP server
| Prop | Type | Description | Default |
| --------------- | ------------------- | -------------------------------------- | ----------------- |
| ipAddress | string | IP address of the server to connect to | |
| port | number | Port number of the TCP server | 9100 |
SendOptions
Options for sending data to a TCP server
| Prop | Type | Description | Default |
| -------------- | ----------------------------------------------------- | -------------------------------------- | ------------------------------ |
| client | number | Client ID from a previous connect call | |
| data | number[] | Data string to send to the server | |
| encoding | DataEncoding | Encoding type for the data | DataEncoding.UTF8 |
ReadResult
Result of a read operation
| Prop | Type | Description |
| -------------- | ----------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
| result | string | Data read from the server Can be UTF-8 string, Base64 encoded string, or Hex string depending on the encoding option |
| encoding | DataEncoding | The encoding of the returned result |
ReadOptions
Options for reading data from a TCP server
| Prop | Type | Description | Default |
| --------------- | ----------------------------------------------------- | -------------------------------------- | ------------------------------ |
| client | number | Client ID from a previous connect call | |
| expectLen | number | Expected number of bytes to read | |
| timeout | number | Read timeout in seconds | 10 |
| encoding | DataEncoding | Preferred encoding for returned data | DataEncoding.UTF8 |
DisconnectResult
Result of a disconnect operation
| Prop | Type | Description |
| ------------ | ------------------- | ------------------------------- |
| client | number | Client ID that was disconnected |
DisconnectOptions
Options for disconnecting from a TCP server
| Prop | Type | Description |
| ------------ | ------------------- | -------------------------------------- |
| client | number | Client ID from a previous connect call |
Enums
DataEncoding
| Members | Value | Description |
| ------------ | --------------------- | ------------------- |
| UTF8 | 'utf8' | UTF-8 text encoding |
| BASE64 | 'base64' | Base64 encoded data |
| HEX | 'hex' | Hexadecimal string |
