@nitra/zebra 6.1.6 → 6.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,6 +12,9 @@
12
12
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
13
13
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
14
14
 
15
+ <!-- Wi-Fi info (SSID) on Android 13+ -->
16
+ <uses-permission android:name="android.permission.NEARBY_WIFI_DEVICES" />
17
+
15
18
  <!-- Feature declarations -->
16
19
  <uses-feature android:name="android.hardware.bluetooth_le" android:required="true" />
17
20
  <uses-feature android:name="android.hardware.bluetooth" android:required="true" />
@@ -44,6 +44,11 @@ import java.util.concurrent.Executors;
44
44
  import java.util.concurrent.Future;
45
45
  import java.util.concurrent.TimeUnit;
46
46
  import java.util.concurrent.TimeoutException;
47
+ import android.net.ConnectivityManager;
48
+ import android.net.Network;
49
+ import android.net.NetworkCapabilities;
50
+ import android.net.wifi.WifiInfo;
51
+ import android.net.wifi.WifiManager;
47
52
 
48
53
  @CapacitorPlugin(name = "ZebraPrinter", permissions = {
49
54
  @Permission(alias = "bluetooth", strings = {
@@ -52,7 +57,8 @@ import java.util.concurrent.TimeoutException;
52
57
  Manifest.permission.BLUETOOTH_CONNECT,
53
58
  Manifest.permission.BLUETOOTH_SCAN,
54
59
  Manifest.permission.ACCESS_FINE_LOCATION,
55
- Manifest.permission.ACCESS_COARSE_LOCATION
60
+ Manifest.permission.ACCESS_COARSE_LOCATION,
61
+ Manifest.permission.NEARBY_WIFI_DEVICES
56
62
  })
57
63
  })
58
64
  public class ZebraPrinter extends Plugin {
@@ -176,6 +182,7 @@ public class ZebraPrinter extends Plugin {
176
182
  permissionsToRequest.add(Manifest.permission.BLUETOOTH_ADMIN);
177
183
  permissionsToRequest.add(Manifest.permission.ACCESS_FINE_LOCATION);
178
184
  permissionsToRequest.add(Manifest.permission.ACCESS_COARSE_LOCATION);
185
+ permissionsToRequest.add(Manifest.permission.NEARBY_WIFI_DEVICES);
179
186
 
180
187
  // Add Android 12+ Bluetooth permissions
181
188
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
@@ -1342,4 +1349,70 @@ public class ZebraPrinter extends Plugin {
1342
1349
  result.put("connected", false);
1343
1350
  call.resolve(result);
1344
1351
  }
1352
+
1353
+ @PluginMethod
1354
+ public void getNetworkInfo(PluginCall call) {
1355
+ JSObject result = new JSObject();
1356
+ result.put("supported", true);
1357
+
1358
+ String type = "unknown";
1359
+ String ip = null;
1360
+ String ssid = null;
1361
+
1362
+ try {
1363
+ WifiManager wifiManager = (WifiManager) getContext().getApplicationContext().getSystemService(Context.WIFI_SERVICE);
1364
+ ConnectivityManager connectivityManager = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
1365
+
1366
+ if (wifiManager != null) {
1367
+ WifiInfo info = wifiManager.getConnectionInfo();
1368
+ if (info != null && info.getNetworkId() != -1) {
1369
+ int ipInt = info.getIpAddress();
1370
+ if (ipInt != 0) {
1371
+ ip = intToIp(ipInt);
1372
+ }
1373
+ ssid = info.getSSID();
1374
+ if (ssid != null) {
1375
+ ssid = ssid.replace("\"", "");
1376
+ if ("<unknown ssid>".equalsIgnoreCase(ssid)) {
1377
+ ssid = null;
1378
+ }
1379
+ }
1380
+ type = "wifi";
1381
+ }
1382
+ }
1383
+
1384
+ if ("unknown".equals(type) && connectivityManager != null) {
1385
+ Network activeNetwork = connectivityManager.getActiveNetwork();
1386
+ if (activeNetwork != null) {
1387
+ NetworkCapabilities caps = connectivityManager.getNetworkCapabilities(activeNetwork);
1388
+ if (caps != null && caps.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) {
1389
+ type = "cell";
1390
+ }
1391
+ }
1392
+ }
1393
+ } catch (Exception e) {
1394
+ Log.w(TAG, "⚠️ getNetworkInfo failed: " + e.getMessage());
1395
+ result.put("error", e.getMessage());
1396
+ }
1397
+
1398
+ result.put("type", type);
1399
+ if (ip != null) {
1400
+ result.put("ip", ip);
1401
+ }
1402
+ if (ssid != null) {
1403
+ result.put("ssid", ssid);
1404
+ }
1405
+
1406
+ call.resolve(result);
1407
+ }
1408
+
1409
+ private String intToIp(int ip) {
1410
+ return String.format(
1411
+ "%d.%d.%d.%d",
1412
+ (ip & 0xff),
1413
+ (ip >> 8 & 0xff),
1414
+ (ip >> 16 & 0xff),
1415
+ (ip >> 24 & 0xff)
1416
+ );
1417
+ }
1345
1418
  }
package/dist/plugin.js CHANGED
@@ -421,6 +421,38 @@ class ZebraPrinterWeb extends WebPlugin {
421
421
  connected: false,
422
422
  };
423
423
  }
424
+
425
+ /**
426
+ * Get device network info (web not supported directly)
427
+ * @returns {Promise<{supported: boolean, type: string, error?: string, ip?: string, ssid?: string}>} Network info proxied via printer-server if available
428
+ */
429
+ async getNetworkInfo() {
430
+ const serviceOk = await this._checkService();
431
+ if (!serviceOk) {
432
+ return {
433
+ supported: false,
434
+ type: 'unknown',
435
+ error: 'Printer service not available for network info',
436
+ };
437
+ }
438
+
439
+ const result = await this._fetch('/network-info', { method: 'GET' });
440
+
441
+ if (result && result.success) {
442
+ return {
443
+ supported: true,
444
+ type: result.type || 'unknown',
445
+ ip: result.ip,
446
+ ssid: result.ssid,
447
+ };
448
+ }
449
+
450
+ return {
451
+ supported: false,
452
+ type: 'unknown',
453
+ error: result?.error || 'Network info not available',
454
+ };
455
+ }
424
456
  }
425
457
 
426
458
  const ZebraPrinter = registerPlugin('ZebraPrinter', {
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sources":["../src/web/index.js","../src/index.js"],"sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\n/**\n * ZebraPrinterWeb - Web implementation for development\n *\n * Uses local printer-server.js (TCP/IP) so developers can\n * test the printer in the browser.\n *\n * Production (iOS) uses the native BLE implementation.\n */\n/**\n * @typedef {import('../definitions').EchoOptions} EchoOptions\n * @typedef {import('../definitions').EchoResult} EchoResult\n * @typedef {import('../definitions').PrintTextOptions} PrintTextOptions\n * @typedef {import('../definitions').PrintResult} PrintResult\n * @typedef {import('../definitions').PrinterStatus} PrinterStatus\n * @typedef {import('../definitions').PrinterStatusResult} PrinterStatusResult\n * @typedef {import('../definitions').ScanResult} ScanResult\n * @typedef {import('../definitions').ConnectOptions} ConnectOptions\n * @typedef {import('../definitions').ConnectResult} ConnectResult\n * @typedef {import('../definitions').DisconnectResult} DisconnectResult\n * @typedef {import('../definitions').PermissionResult} PermissionResult\n */\n\nconst API_BASE = '/api/printer';\n\nexport class ZebraPrinterWeb extends WebPlugin {\n constructor() {\n super();\n this.connectedPrinter = null;\n this.serviceAvailable = null;\n this.defaultSubnet = this._getDefaultSubnet();\n }\n\n /**\n * Check if printer-server is reachable\n * @returns {Promise<boolean>} True if reachable\n */\n async _checkService() {\n if (this.serviceAvailable !== null) {\n return this.serviceAvailable;\n }\n\n try {\n const response = await fetch(`${API_BASE}/status`, {\n method: 'GET',\n headers: { 'Content-Type': 'application/json' },\n });\n const data = await response.json();\n this.serviceAvailable = data.success === true;\n return this.serviceAvailable;\n } catch (error) {\n console.warn('ZebraPrinter: service check failed', error);\n this.serviceAvailable = false;\n return false;\n }\n }\n\n /**\n * Fetch wrapper with error handling\n * @param {string} endpoint - API route\n * @param {RequestInit} [options] - Fetch configuration\n * @returns {Promise<any>} Response JSON\n */\n async _fetch(endpoint, options = {}) {\n try {\n const response = await fetch(`${API_BASE}${endpoint}`, {\n headers: { 'Content-Type': 'application/json' },\n ...options,\n });\n return await response.json();\n } catch (error) {\n console.warn(`ZebraPrinter Web: ${endpoint} failed -`, error.message);\n return {\n success: false,\n error:\n 'Printer service is not available. Ensure Vite dev server runs with printer-server plugin.',\n serviceUnavailable: true,\n };\n }\n }\n\n /**\n * Derive default subnet from host IP, if possible\n * @returns {string} Example: \"192.168.1\" or \"10.0.0\"\n */\n _getDefaultSubnet() {\n if (typeof window === 'undefined') return '192.168.1';\n const host = window.location.hostname;\n const ipMatch = host.match(\n /^(10|172\\.(1[6-9]|2[0-9]|3[0-1])|192\\.168)\\.(\\d+)\\.(\\d+)$/\n );\n if (ipMatch) {\n return `${ipMatch[1]}.${ipMatch[3]}`;\n }\n return '192.168.1';\n }\n\n /**\n * Wrap plain text into a basic ZPL label unless it already looks like ZPL\n * @param {string} text - Input text or ZPL\n * @returns {string} ZPL payload\n */\n _wrapTextIfNeeded(text) {\n const isZplLike =\n typeof text === 'string' &&\n /\\^XA/i.test(text) &&\n (/\\^XZ/i.test(text) || /\\^JUS/i.test(text));\n if (isZplLike) {\n return text;\n }\n\n const safeText = String(text ?? '').replaceAll(/\\r?\\n/g, String.raw`\\&`);\n return [\n '^XA',\n '^CI28',\n '^FO50,50',\n '^A0N,30,30',\n `^FD${safeText}^FS`,\n '^XZ',\n ].join('\\n');\n }\n\n /**\n * Echo a value\n * @param {EchoOptions} options - Input data\n * @returns {Promise<EchoResult & {platform: string, serviceAvailable: boolean}>} Echo result with platform info\n */\n async echo(options) {\n console.log('ZebraPrinter: echo called with options:', options);\n const serviceOk = await this._checkService();\n return {\n value: options.value,\n platform: 'web',\n serviceAvailable: serviceOk,\n };\n }\n\n /**\n * Check if required permissions are granted\n * @returns {Promise<PermissionResult>} Permission status\n */\n async checkPermissions() {\n const serviceOk = await this._checkService();\n const hasNavigator = typeof navigator !== 'undefined';\n const bleSupported = hasNavigator && navigator.bluetooth !== undefined;\n\n if (!serviceOk) {\n console.warn('ZebraPrinter: printer-server not available');\n return {\n hasPermissions: false,\n missingPermissions: ['printer-server'],\n bluetoothSupported: bleSupported,\n bleSupported: bleSupported,\n webMode: true,\n serviceAvailable: false,\n };\n }\n\n return {\n hasPermissions: true,\n missingPermissions: [],\n bluetoothSupported: bleSupported,\n bleSupported: bleSupported,\n webMode: true,\n serviceAvailable: true,\n };\n }\n\n /**\n * Request required permissions\n * @returns {Promise<PermissionResult>} Permission status\n */\n async requestPermissions() {\n // Not needed on web - just check service\n return await this.checkPermissions();\n }\n\n /**\n * Print text to the connected printer\n * @param {PrintTextOptions} options - Parameters with ZPL text\n * @returns {Promise<PrintResult>} Print result\n */\n async printText(options) {\n const { text } = options || {};\n\n if (!text) {\n return {\n success: false,\n message: 'No text provided for printing',\n error: 'Missing text parameter',\n };\n }\n\n const zplPayload = this._wrapTextIfNeeded(text);\n\n const result = await this._fetch('/print', {\n method: 'POST',\n body: JSON.stringify({\n zpl: zplPayload,\n ip: this.connectedPrinter?.ip,\n }),\n });\n\n if (result.success) {\n return {\n success: true,\n message: 'Print successful',\n zpl: `${zplPayload.slice(0, 100)}...`,\n bytes: zplPayload.length,\n };\n }\n\n return {\n success: false,\n message: result.error || 'Print failed',\n error: result.error,\n };\n }\n\n /**\n * Get printer status\n * @returns {Promise<PrinterStatus>} Printer status\n */\n async getStatus() {\n if (!this.connectedPrinter) {\n return {\n connected: false,\n status: 'disconnected',\n };\n }\n\n const result = await this._fetch('/check', {\n method: 'POST',\n body: JSON.stringify({ ip: this.connectedPrinter.ip }),\n });\n\n return {\n connected: result.reachable === true,\n status: result.reachable ? 'connected' : 'disconnected',\n printerAddress: this.connectedPrinter.ip,\n printerType: 'network',\n };\n }\n\n /**\n * Check printer status with ZPL command\n * @returns {Promise<PrinterStatusResult>} Status request result\n */\n async checkPrinterStatus() {\n if (!this.connectedPrinter) {\n return {\n success: false,\n message: 'No printer connected',\n error: 'Not connected',\n };\n }\n\n // On web we send ~HS command\n const result = await this._fetch('/print', {\n method: 'POST',\n body: JSON.stringify({\n zpl: '~HS',\n ip: this.connectedPrinter.ip,\n }),\n });\n\n return {\n success: result.success,\n message: result.success ? 'Status command sent' : result.error,\n command: '~HS',\n };\n }\n\n /**\n * Scan for available printers\n * @param {{subnet?: string}} [options] - Custom subnet (e.g., \"192.168.0\")\n * @returns {Promise<ScanResult>} List of found printers\n */\n async scanForPrinters(options = {}) {\n const serviceOk = await this._checkService();\n\n if (!serviceOk) {\n return {\n success: false,\n error:\n 'Printer service is not available. Add printer-server.js and vite-plugin-zebra-printer.js to your project.',\n printers: [],\n count: 0,\n };\n }\n\n const subnet = options.subnet || this.defaultSubnet || '192.168.1';\n\n // Scan the network (can be slow)\n const result = await this._fetch(\n `/scan?subnet=${encodeURIComponent(subnet)}`\n );\n\n if (result.success) {\n return {\n success: true,\n printers: (result.printers || []).map((p) => ({\n name: p.name || `Zebra @ ${p.ip}`,\n address: p.ip || p.address,\n type: 'network',\n paired: false,\n })),\n count: result.printers?.length || 0,\n };\n }\n\n return {\n success: false,\n error: result.error || 'Scan failed',\n printers: [],\n count: 0,\n };\n }\n\n /**\n * Connect to a printer\n * @param {ConnectOptions} options - Connection parameters\n * @returns {Promise<ConnectResult>} Connection result\n */\n async connect(options) {\n const { address, type } = options || {};\n\n if (!address) {\n return {\n success: false,\n connected: false,\n error: 'Printer address (IP) not provided',\n };\n }\n\n // On web we support only network connections\n if (type === 'bluetooth') {\n return {\n success: false,\n connected: false,\n error:\n 'Bluetooth is not available on web. Use IP address or test in the iOS app.',\n };\n }\n\n const result = await this._fetch('/connect', {\n method: 'POST',\n body: JSON.stringify({ ip: address }),\n });\n\n if (result.success) {\n this.connectedPrinter = {\n ip: address,\n name: result.printer?.name || `Zebra @ ${address}`,\n type: 'network',\n };\n\n return {\n success: true,\n connected: true,\n address,\n type: 'network',\n message: 'Connected to printer',\n };\n }\n\n return {\n success: false,\n connected: false,\n error: result.error || 'Connection failed',\n };\n }\n\n /**\n * Connect to printer by MAC address (web - redirect to IP)\n * @param {ConnectOptions} options - Connection parameters\n * @returns {Promise<ConnectResult>} Connection result\n */\n async connectByAddress(options) {\n console.warn('ZebraPrinter Web: connectByAddress - use IP address on web');\n return await this.connect(options);\n }\n\n /**\n * Check device by address\n * @param {ConnectOptions} options - Parameters with address\n * @returns {Promise<ConnectResult>} Reachability info\n */\n async checkDeviceByAddress(options) {\n const { address } = options || {};\n\n if (!address) {\n return {\n success: false,\n error: 'Address not provided',\n };\n }\n\n const result = await this._fetch('/check', {\n method: 'POST',\n body: JSON.stringify({ ip: address }),\n });\n\n return {\n success: true,\n reachable: result.reachable,\n address,\n };\n }\n\n /**\n * Disconnect from the printer\n * @returns {Promise<DisconnectResult>} Disconnect result\n */\n async disconnect() {\n this.connectedPrinter = null;\n await Promise.resolve();\n return {\n success: true,\n connected: false,\n };\n }\n}\n","import { registerPlugin } from '@capacitor/core';\n\nimport { ZebraPrinterWeb } from './web';\n\nconst ZebraPrinter = registerPlugin('ZebraPrinter', {\n web: () => new ZebraPrinterWeb(),\n // iOS and Android plugins will be auto-discovered via the Capacitor config\n});\n\nexport { ZebraPrinter };\n"],"names":[],"mappings":";;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,MAAM,QAAQ,GAAG,cAAc;;AAExB,MAAM,eAAe,SAAS,SAAS,CAAC;AAC/C,EAAE,WAAW,GAAG;AAChB,IAAI,KAAK,EAAE;AACX,IAAI,IAAI,CAAC,gBAAgB,GAAG,IAAI;AAChC,IAAI,IAAI,CAAC,gBAAgB,GAAG,IAAI;AAChC,IAAI,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,iBAAiB,EAAE;AACjD,EAAE;;AAEF;AACA;AACA;AACA;AACA,EAAE,MAAM,aAAa,GAAG;AACxB,IAAI,IAAI,IAAI,CAAC,gBAAgB,KAAK,IAAI,EAAE;AACxC,MAAM,OAAO,IAAI,CAAC,gBAAgB;AAClC,IAAI;;AAEJ,IAAI,IAAI;AACR,MAAM,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE;AACzD,QAAQ,MAAM,EAAE,KAAK;AACrB,QAAQ,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;AACvD,OAAO,CAAC;AACR,MAAM,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE;AACxC,MAAM,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,OAAO,KAAK,IAAI;AACn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AAC,OAAO,CAAC;AACtC,EAAE;;AAEF;AACA;AACA;AACA;AACA;AACA,EAAE,MAAM,oBAAoB,CAAC,OAAO,EAAE;AACtC,IAAI,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,IAAI,EAAE;;AAErC,IAAI,IAAI,CAAC,OAAO,EAAE;AAClB,MAAM,OAAO;AACb,QAAQ,OAAO,EAAE,KAAK;AACtB,QAAQ,KAAK,EAAE,sBAAsB;AACrC,OAAO;AACP,IAAI;;AAEJ,IAAI,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE;AAC/C,MAAM,MAAM,EAAE,MAAM;AACpB,MAAM,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC;AAC3C,KAAK,CAAC;;AAEN,IAAI,OAAO;AACX,MAAM,OAAO,EAAE,IAAI;AACnB,MAAM,SAAS,EAAE,MAAM,CAAC,SAAS;AACjC,MAAM,OAAO;AACb,KAAK;AACL,EAAE;;AAEF;AACA;AACA;AACA;AACA,EAAE,MAAM,UAAU,GAAG;AACrB,IAAI,IAAI,CAAC,gBAAgB,GAAG,IAAI;AAChC,IAAI,MAAM,OAAO,CAAC,OAAO,EAAE;AAC3B,IAAI,OAAO;AACX,MAAM,OAAO,EAAE,IAAI;AACnB,MAAM,SAAS,EAAE,KAAK;AACtB,KAAK;AACL,EAAE;AACF;;ACnaK,MAAC,YAAY,GAAG,cAAc,CAAC,cAAc,EAAE;AACpD,EAAE,GAAG,EAAE,MAAM,IAAI,eAAe,EAAE;AAClC;AACA,CAAC;;;;"}
1
+ {"version":3,"file":"plugin.js","sources":["../src/web/index.js","../src/index.js"],"sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\n/**\n * ZebraPrinterWeb - Web implementation for development\n *\n * Uses local printer-server.js (TCP/IP) so developers can\n * test the printer in the browser.\n *\n * Production (iOS) uses the native BLE implementation.\n */\n/**\n * @typedef {import('../definitions').EchoOptions} EchoOptions\n * @typedef {import('../definitions').EchoResult} EchoResult\n * @typedef {import('../definitions').PrintTextOptions} PrintTextOptions\n * @typedef {import('../definitions').PrintResult} PrintResult\n * @typedef {import('../definitions').PrinterStatus} PrinterStatus\n * @typedef {import('../definitions').PrinterStatusResult} PrinterStatusResult\n * @typedef {import('../definitions').ScanResult} ScanResult\n * @typedef {import('../definitions').ConnectOptions} ConnectOptions\n * @typedef {import('../definitions').ConnectResult} ConnectResult\n * @typedef {import('../definitions').DisconnectResult} DisconnectResult\n * @typedef {import('../definitions').PermissionResult} PermissionResult\n */\n\nconst API_BASE = '/api/printer';\n\nexport class ZebraPrinterWeb extends WebPlugin {\n constructor() {\n super();\n this.connectedPrinter = null;\n this.serviceAvailable = null;\n this.defaultSubnet = this._getDefaultSubnet();\n }\n\n /**\n * Check if printer-server is reachable\n * @returns {Promise<boolean>} True if reachable\n */\n async _checkService() {\n if (this.serviceAvailable !== null) {\n return this.serviceAvailable;\n }\n\n try {\n const response = await fetch(`${API_BASE}/status`, {\n method: 'GET',\n headers: { 'Content-Type': 'application/json' },\n });\n const data = await response.json();\n this.serviceAvailable = data.success === true;\n return this.serviceAvailable;\n } catch (error) {\n console.warn('ZebraPrinter: service check failed', error);\n this.serviceAvailable = false;\n return false;\n }\n }\n\n /**\n * Fetch wrapper with error handling\n * @param {string} endpoint - API route\n * @param {RequestInit} [options] - Fetch configuration\n * @returns {Promise<any>} Response JSON\n */\n async _fetch(endpoint, options = {}) {\n try {\n const response = await fetch(`${API_BASE}${endpoint}`, {\n headers: { 'Content-Type': 'application/json' },\n ...options,\n });\n return await response.json();\n } catch (error) {\n console.warn(`ZebraPrinter Web: ${endpoint} failed -`, error.message);\n return {\n success: false,\n error:\n 'Printer service is not available. Ensure Vite dev server runs with printer-server plugin.',\n serviceUnavailable: true,\n };\n }\n }\n\n /**\n * Derive default subnet from host IP, if possible\n * @returns {string} Example: \"192.168.1\" or \"10.0.0\"\n */\n _getDefaultSubnet() {\n if (typeof window === 'undefined') return '192.168.1';\n const host = window.location.hostname;\n const ipMatch = host.match(\n /^(10|172\\.(1[6-9]|2[0-9]|3[0-1])|192\\.168)\\.(\\d+)\\.(\\d+)$/\n );\n if (ipMatch) {\n return `${ipMatch[1]}.${ipMatch[3]}`;\n }\n return '192.168.1';\n }\n\n /**\n * Wrap plain text into a basic ZPL label unless it already looks like ZPL\n * @param {string} text - Input text or ZPL\n * @returns {string} ZPL payload\n */\n _wrapTextIfNeeded(text) {\n const isZplLike =\n typeof text === 'string' &&\n /\\^XA/i.test(text) &&\n (/\\^XZ/i.test(text) || /\\^JUS/i.test(text));\n if (isZplLike) {\n return text;\n }\n\n const safeText = String(text ?? '').replaceAll(/\\r?\\n/g, String.raw`\\&`);\n return [\n '^XA',\n '^CI28',\n '^FO50,50',\n '^A0N,30,30',\n `^FD${safeText}^FS`,\n '^XZ',\n ].join('\\n');\n }\n\n /**\n * Echo a value\n * @param {EchoOptions} options - Input data\n * @returns {Promise<EchoResult & {platform: string, serviceAvailable: boolean}>} Echo result with platform info\n */\n async echo(options) {\n console.log('ZebraPrinter: echo called with options:', options);\n const serviceOk = await this._checkService();\n return {\n value: options.value,\n platform: 'web',\n serviceAvailable: serviceOk,\n };\n }\n\n /**\n * Check if required permissions are granted\n * @returns {Promise<PermissionResult>} Permission status\n */\n async checkPermissions() {\n const serviceOk = await this._checkService();\n const hasNavigator = typeof navigator !== 'undefined';\n const bleSupported = hasNavigator && navigator.bluetooth !== undefined;\n\n if (!serviceOk) {\n console.warn('ZebraPrinter: printer-server not available');\n return {\n hasPermissions: false,\n missingPermissions: ['printer-server'],\n bluetoothSupported: bleSupported,\n bleSupported: bleSupported,\n webMode: true,\n serviceAvailable: false,\n };\n }\n\n return {\n hasPermissions: true,\n missingPermissions: [],\n bluetoothSupported: bleSupported,\n bleSupported: bleSupported,\n webMode: true,\n serviceAvailable: true,\n };\n }\n\n /**\n * Request required permissions\n * @returns {Promise<PermissionResult>} Permission status\n */\n async requestPermissions() {\n // Not needed on web - just check service\n return await this.checkPermissions();\n }\n\n /**\n * Print text to the connected printer\n * @param {PrintTextOptions} options - Parameters with ZPL text\n * @returns {Promise<PrintResult>} Print result\n */\n async printText(options) {\n const { text } = options || {};\n\n if (!text) {\n return {\n success: false,\n message: 'No text provided for printing',\n error: 'Missing text parameter',\n };\n }\n\n const zplPayload = this._wrapTextIfNeeded(text);\n\n const result = await this._fetch('/print', {\n method: 'POST',\n body: JSON.stringify({\n zpl: zplPayload,\n ip: this.connectedPrinter?.ip,\n }),\n });\n\n if (result.success) {\n return {\n success: true,\n message: 'Print successful',\n zpl: `${zplPayload.slice(0, 100)}...`,\n bytes: zplPayload.length,\n };\n }\n\n return {\n success: false,\n message: result.error || 'Print failed',\n error: result.error,\n };\n }\n\n /**\n * Get printer status\n * @returns {Promise<PrinterStatus>} Printer status\n */\n async getStatus() {\n if (!this.connectedPrinter) {\n return {\n connected: false,\n status: 'disconnected',\n };\n }\n\n const result = await this._fetch('/check', {\n method: 'POST',\n body: JSON.stringify({ ip: this.connectedPrinter.ip }),\n });\n\n return {\n connected: result.reachable === true,\n status: result.reachable ? 'connected' : 'disconnected',\n printerAddress: this.connectedPrinter.ip,\n printerType: 'network',\n };\n }\n\n /**\n * Check printer status with ZPL command\n * @returns {Promise<PrinterStatusResult>} Status request result\n */\n async checkPrinterStatus() {\n if (!this.connectedPrinter) {\n return {\n success: false,\n message: 'No printer connected',\n error: 'Not connected',\n };\n }\n\n // On web we send ~HS command\n const result = await this._fetch('/print', {\n method: 'POST',\n body: JSON.stringify({\n zpl: '~HS',\n ip: this.connectedPrinter.ip,\n }),\n });\n\n return {\n success: result.success,\n message: result.success ? 'Status command sent' : result.error,\n command: '~HS',\n };\n }\n\n /**\n * Scan for available printers\n * @param {{subnet?: string}} [options] - Custom subnet (e.g., \"192.168.0\")\n * @returns {Promise<ScanResult>} List of found printers\n */\n async scanForPrinters(options = {}) {\n const serviceOk = await this._checkService();\n\n if (!serviceOk) {\n return {\n success: false,\n error:\n 'Printer service is not available. Add printer-server.js and vite-plugin-zebra-printer.js to your project.',\n printers: [],\n count: 0,\n };\n }\n\n const subnet = options.subnet || this.defaultSubnet || '192.168.1';\n\n // Scan the network (can be slow)\n const result = await this._fetch(\n `/scan?subnet=${encodeURIComponent(subnet)}`\n );\n\n if (result.success) {\n return {\n success: true,\n printers: (result.printers || []).map((p) => ({\n name: p.name || `Zebra @ ${p.ip}`,\n address: p.ip || p.address,\n type: 'network',\n paired: false,\n })),\n count: result.printers?.length || 0,\n };\n }\n\n return {\n success: false,\n error: result.error || 'Scan failed',\n printers: [],\n count: 0,\n };\n }\n\n /**\n * Connect to a printer\n * @param {ConnectOptions} options - Connection parameters\n * @returns {Promise<ConnectResult>} Connection result\n */\n async connect(options) {\n const { address, type } = options || {};\n\n if (!address) {\n return {\n success: false,\n connected: false,\n error: 'Printer address (IP) not provided',\n };\n }\n\n // On web we support only network connections\n if (type === 'bluetooth') {\n return {\n success: false,\n connected: false,\n error:\n 'Bluetooth is not available on web. Use IP address or test in the iOS app.',\n };\n }\n\n const result = await this._fetch('/connect', {\n method: 'POST',\n body: JSON.stringify({ ip: address }),\n });\n\n if (result.success) {\n this.connectedPrinter = {\n ip: address,\n name: result.printer?.name || `Zebra @ ${address}`,\n type: 'network',\n };\n\n return {\n success: true,\n connected: true,\n address,\n type: 'network',\n message: 'Connected to printer',\n };\n }\n\n return {\n success: false,\n connected: false,\n error: result.error || 'Connection failed',\n };\n }\n\n /**\n * Connect to printer by MAC address (web - redirect to IP)\n * @param {ConnectOptions} options - Connection parameters\n * @returns {Promise<ConnectResult>} Connection result\n */\n async connectByAddress(options) {\n console.warn('ZebraPrinter Web: connectByAddress - use IP address on web');\n return await this.connect(options);\n }\n\n /**\n * Check device by address\n * @param {ConnectOptions} options - Parameters with address\n * @returns {Promise<ConnectResult>} Reachability info\n */\n async checkDeviceByAddress(options) {\n const { address } = options || {};\n\n if (!address) {\n return {\n success: false,\n error: 'Address not provided',\n };\n }\n\n const result = await this._fetch('/check', {\n method: 'POST',\n body: JSON.stringify({ ip: address }),\n });\n\n return {\n success: true,\n reachable: result.reachable,\n address,\n };\n }\n\n /**\n * Disconnect from the printer\n * @returns {Promise<DisconnectResult>} Disconnect result\n */\n async disconnect() {\n this.connectedPrinter = null;\n await Promise.resolve();\n return {\n success: true,\n connected: false,\n };\n }\n\n /**\n * Get device network info (web not supported directly)\n * @returns {Promise<{supported: boolean, type: string, error?: string, ip?: string, ssid?: string}>} Network info proxied via printer-server if available\n */\n async getNetworkInfo() {\n const serviceOk = await this._checkService();\n if (!serviceOk) {\n return {\n supported: false,\n type: 'unknown',\n error: 'Printer service not available for network info',\n };\n }\n\n const result = await this._fetch('/network-info', { method: 'GET' });\n\n if (result && result.success) {\n return {\n supported: true,\n type: result.type || 'unknown',\n ip: result.ip,\n ssid: result.ssid,\n };\n }\n\n return {\n supported: false,\n type: 'unknown',\n error: result?.error || 'Network info not available',\n };\n }\n}\n","import { registerPlugin } from '@capacitor/core';\n\nimport { ZebraPrinterWeb } from './web';\n\nconst ZebraPrinter = registerPlugin('ZebraPrinter', {\n web: () => new ZebraPrinterWeb(),\n // iOS and Android plugins will be auto-discovered via the Capacitor config\n});\n\nexport { ZebraPrinter };\n"],"names":[],"mappings":";;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,MAAM,QAAQ,GAAG,cAAc;;AAExB,MAAM,eAAe,SAAS,SAAS,CAAC;AAC/C,EAAE,WAAW,GAAG;AAChB,IAAI,KAAK,EAAE;AACX,IAAI,IAAI,CAAC,gBAAgB,GAAG,IAAI;AAChC,IAAI,IAAI,CAAC,gBAAgB,GAAG,IAAI;AAChC,IAAI,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,iBAAiB,EAAE;AACjD,EAAE;;AAEF;AACA;AACA;AACA;AACA,EAAE,MAAM,aAAa,GAAG;AACxB,IAAI,IAAI,IAA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O;AACX,MAAM,OAAO,EAAE,IAAI;AACnB,MAAM,SAAS,EAAE,KAAK;AACtB,KAAK;AACL,EAAE;;AAEF;AACA;AACA;AACA;AACA,EAAE,MAAM,cAAc,GAAG;AACzB,IAAI,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,aAAa,EAAE;AAChD,IAAI,IAAI,CAAC,SAAS,EAAE;AACpB,MAAM,OAAO;AACb,QAAQ,SAAS,EAAE,KAAK;AACxB,QAAQ,IAAI,EAAE,SAAS;AACvB,QAAQ,KAAK,EAAE,gDAAgD;AAC/D,OAAO;AACP,IAAI;;AAEJ,IAAI,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,eAAe,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;;AAExE,IAAI,IAAI,MAAM,IAAI,MAAM,CAAC,OAAO,EAAE;AAClC,MAAM,OAAO;AACb,QAAQ,SAAS,EAAE,IAAI;AACvB,QAAQ,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,SAAS;AACtC,QAAQ,EAAE,EAAE,MAAM,CAAC,EAAE;AACrB,QAAQ,IAAI,EAAE,MAAM,CAAC,IAAI;AACzB,OAAO;AACP,IAAI;;AAEJ,IAAI,OAAO;AACX,MAAM,SAAS,EAAE,KAAK;AACtB,MAAM,IAAI,EAAE,SAAS;AACrB,MAAM,KAAK,EAAE,MAAM,EAAE,KAAK,IAAI,4BAA4B;AAC1D,KAAK;AACL,EAAE;AACF;;ACncK,MAAC,YAAY,GAAG,cAAc,CAAC,cAAc,EAAE;AACpD,EAAE,GAAG,EAAE,MAAM,IAAI,eAAe,EAAE;AAClC;AACA,CAAC;;;;"}
@@ -1,6 +1,7 @@
1
1
  import Foundation
2
2
  import Capacitor
3
3
  import CoreBluetooth
4
+ import SystemConfiguration
4
5
 
5
6
  @objc(ZebraPrinterPlugin)
6
7
  public class ZebraPrinterPlugin: CAPPlugin, CBCentralManagerDelegate, CBPeripheralDelegate {
@@ -363,6 +364,22 @@ public class ZebraPrinterPlugin: CAPPlugin, CBCentralManagerDelegate, CBPeripher
363
364
  "connected": false
364
365
  ])
365
366
  }
367
+
368
+ // MARK: - Network Info (iOS)
369
+ @objc func getNetworkInfo(_ call: CAPPluginCall) {
370
+ let (ip, ssid) = getWiFiInfo()
371
+ var result: [String: Any] = [
372
+ "supported": true,
373
+ "type": ip == nil ? "unknown" : "wifi"
374
+ ]
375
+ if let ip = ip {
376
+ result["ip"] = ip
377
+ }
378
+ if let ssid = ssid {
379
+ result["ssid"] = ssid
380
+ }
381
+ call.resolve(result)
382
+ }
366
383
 
367
384
  // MARK: - Helper Methods
368
385
  private func sendDataToPrinter(_ data: Data) -> Bool {
@@ -400,5 +417,49 @@ public class ZebraPrinterPlugin: CAPPlugin, CBCentralManagerDelegate, CBPeripher
400
417
 
401
418
  return true
402
419
  }
420
+
421
+ private func getWiFiInfo() -> (String?, String?) {
422
+ var address: String?
423
+ var ssid: String?
424
+
425
+ // IP address from en0
426
+ var ifaddr: UnsafeMutablePointer<ifaddrs>?
427
+ if getifaddrs(&ifaddr) == 0 {
428
+ var ptr = ifaddr
429
+ while ptr != nil {
430
+ defer { ptr = ptr?.pointee.ifa_next }
431
+ guard let interface = ptr?.pointee else { continue }
432
+ let name = String(cString: interface.ifa_name)
433
+ let addrFamily = interface.ifa_addr.pointee.sa_family
434
+ if name == "en0", addrFamily == UInt8(AF_INET) {
435
+ var hostname = [CChar](repeating: 0, count: Int(NI_MAXHOST))
436
+ var addr = interface.ifa_addr.pointee
437
+ let res = getnameinfo(&addr,
438
+ socklen_t(interface.ifa_addr.pointee.sa_len),
439
+ &hostname,
440
+ socklen_t(hostname.count),
441
+ nil,
442
+ socklen_t(0),
443
+ NI_NUMERICHOST)
444
+ if res == 0 {
445
+ address = String(cString: hostname)
446
+ }
447
+ }
448
+ }
449
+ freeifaddrs(ifaddr)
450
+ }
451
+
452
+ // SSID (best effort; may be nil without entitlements/permissions)
453
+ if let interfaces = CNCopySupportedInterfaces() as? [String] {
454
+ for interface in interfaces {
455
+ if let dict = CNCopyCurrentNetworkInfo(interface as CFString) as NSDictionary? {
456
+ ssid = dict[kCNNetworkInfoKeySSID as String] as? String
457
+ break
458
+ }
459
+ }
460
+ }
461
+
462
+ return (address, ssid)
463
+ }
403
464
  }
404
465
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nitra/zebra",
3
- "version": "6.1.6",
3
+ "version": "6.1.8",
4
4
  "description": "Nitra capacitor components",
5
5
  "main": "dist/plugin.js",
6
6
  "module": "dist/plugin.js",