@cappitolian/http-local-server 0.0.8 → 0.0.10

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.
package/dist/plugin.js CHANGED
@@ -2,25 +2,78 @@ var capacitorHttpLocalServer = (function (exports, core) {
2
2
  'use strict';
3
3
 
4
4
  /**
5
- * Registramos el plugin.
6
- * El nombre 'HttpLocalServer' debe coincidir con el @CapacitorPlugin en Java
7
- * y el @objc(HttpLocalServerPlugin) en Swift.
5
+ * Plugin de servidor HTTP local para Android e iOS.
6
+ *
7
+ * Permite crear un servidor HTTP en el dispositivo que puede recibir
8
+ * peticiones desde otros dispositivos en la misma red.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * import { HttpLocalServer } from '@cappitolian/http-local-server';
13
+ *
14
+ * // Iniciar servidor
15
+ * const { ip, port } = await HttpLocalServer.connect();
16
+ * console.log(`Servidor en http://${ip}:${port}`);
17
+ *
18
+ * // Escuchar peticiones
19
+ * await HttpLocalServer.addListener('onRequest', async (data) => {
20
+ * console.log('Petición recibida:', data);
21
+ *
22
+ * // Procesar y responder
23
+ * await HttpLocalServer.sendResponse({
24
+ * requestId: data.requestId,
25
+ * body: JSON.stringify({ success: true })
26
+ * });
27
+ * });
28
+ * ```
8
29
  */
9
30
  const HttpLocalServer = core.registerPlugin('HttpLocalServer', {
10
31
  web: () => Promise.resolve().then(function () { return web; }).then(m => new m.HttpLocalServerWeb()),
11
32
  });
12
33
 
34
+ /**
35
+ * Implementación web del plugin HttpLocalServer.
36
+ * Proporciona funcionalidad mock para desarrollo en navegador.
37
+ */
13
38
  class HttpLocalServerWeb extends core.WebPlugin {
39
+ constructor() {
40
+ super(...arguments);
41
+ this.isRunning = false;
42
+ }
14
43
  async connect() {
15
- console.warn('HttpLocalServer: El servidor nativo no se puede iniciar en el navegador.');
16
- // Devolvemos un valor por defecto para no romper la ejecución en web
17
- return { ip: '127.0.0.1', port: 8080 };
44
+ if (this.isRunning) {
45
+ console.warn('HttpLocalServer: El servidor ya está ejecutándose (Mock).');
46
+ return { ip: '127.0.0.1', port: 8080 };
47
+ }
48
+ console.warn('HttpLocalServer: El servidor nativo no está disponible en navegador. ' +
49
+ 'Retornando valores mock para desarrollo.');
50
+ this.isRunning = true;
51
+ return {
52
+ ip: '127.0.0.1',
53
+ port: 8080
54
+ };
18
55
  }
19
56
  async disconnect() {
57
+ if (!this.isRunning) {
58
+ console.log('HttpLocalServer: El servidor ya está detenido (Mock).');
59
+ return;
60
+ }
20
61
  console.log('HttpLocalServer: Servidor detenido (Mock).');
62
+ this.isRunning = false;
21
63
  }
22
64
  async sendResponse(options) {
23
- console.log('HttpLocalServer: Respuesta mock enviada al requestId:', options.requestId);
65
+ if (!this.isRunning) {
66
+ console.warn('HttpLocalServer: El servidor no está ejecutándose (Mock).');
67
+ return;
68
+ }
69
+ const { requestId, body } = options;
70
+ if (!requestId) {
71
+ throw new Error('Missing requestId');
72
+ }
73
+ if (!body) {
74
+ throw new Error('Missing body');
75
+ }
76
+ console.log(`HttpLocalServer: Respuesta mock enviada para requestId: ${requestId}`, '\nBody:', body.substring(0, 100) + (body.length > 100 ? '...' : ''));
24
77
  }
25
78
  }
26
79
 
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\n/**\n * Registramos el plugin.\n * El nombre 'HttpLocalServer' debe coincidir con el @CapacitorPlugin en Java\n * y el @objc(HttpLocalServerPlugin) en Swift.\n */\nconst HttpLocalServer = registerPlugin('HttpLocalServer', {\n web: () => import('./web').then(m => new m.HttpLocalServerWeb()),\n});\n// Exportamos las interfaces para que el usuario pueda tipar sus variables\nexport * from './definitions';\n// Exportamos el objeto del plugin\nexport { HttpLocalServer };\n// Exportación por defecto opcional para mayor compatibilidad\nexport default HttpLocalServer;\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class HttpLocalServerWeb extends WebPlugin {\n async connect() {\n console.warn('HttpLocalServer: El servidor nativo no se puede iniciar en el navegador.');\n // Devolvemos un valor por defecto para no romper la ejecución en web\n return { ip: '127.0.0.1', port: 8080 };\n }\n async disconnect() {\n console.log('HttpLocalServer: Servidor detenido (Mock).');\n }\n async sendResponse(options) {\n console.log('HttpLocalServer: Respuesta mock enviada al requestId:', options.requestId);\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;IACA;IACA;IACA;IACA;IACA;AACK,UAAC,eAAe,GAAGA,mBAAc,CAAC,iBAAiB,EAAE;IAC1D,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,kBAAkB,EAAE,CAAC;IACpE,CAAC;;ICPM,MAAM,kBAAkB,SAASC,cAAS,CAAC;IAClD,IAAI,MAAM,OAAO,GAAG;IACpB,QAAQ,OAAO,CAAC,IAAI,CAAC,0EAA0E,CAAC;IAChG;IACA,QAAQ,OAAO,EAAE,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,IAAI,EAAE;IAC9C,IAAI;IACJ,IAAI,MAAM,UAAU,GAAG;IACvB,QAAQ,OAAO,CAAC,GAAG,CAAC,4CAA4C,CAAC;IACjE,IAAI;IACJ,IAAI,MAAM,YAAY,CAAC,OAAO,EAAE;IAChC,QAAQ,OAAO,CAAC,GAAG,CAAC,uDAAuD,EAAE,OAAO,CAAC,SAAS,CAAC;IAC/F,IAAI;IACJ;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\n/**\n * Plugin de servidor HTTP local para Android e iOS.\n *\n * Permite crear un servidor HTTP en el dispositivo que puede recibir\n * peticiones desde otros dispositivos en la misma red.\n *\n * @example\n * ```typescript\n * import { HttpLocalServer } from '@cappitolian/http-local-server';\n *\n * // Iniciar servidor\n * const { ip, port } = await HttpLocalServer.connect();\n * console.log(`Servidor en http://${ip}:${port}`);\n *\n * // Escuchar peticiones\n * await HttpLocalServer.addListener('onRequest', async (data) => {\n * console.log('Petición recibida:', data);\n *\n * // Procesar y responder\n * await HttpLocalServer.sendResponse({\n * requestId: data.requestId,\n * body: JSON.stringify({ success: true })\n * });\n * });\n * ```\n */\nconst HttpLocalServer = registerPlugin('HttpLocalServer', {\n web: () => import('./web').then(m => new m.HttpLocalServerWeb()),\n});\nexport * from './definitions';\nexport { HttpLocalServer };\nexport default HttpLocalServer;\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\n/**\n * Implementación web del plugin HttpLocalServer.\n * Proporciona funcionalidad mock para desarrollo en navegador.\n */\nexport class HttpLocalServerWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.isRunning = false;\n }\n async connect() {\n if (this.isRunning) {\n console.warn('HttpLocalServer: El servidor ya está ejecutándose (Mock).');\n return { ip: '127.0.0.1', port: 8080 };\n }\n console.warn('HttpLocalServer: El servidor nativo no está disponible en navegador. ' +\n 'Retornando valores mock para desarrollo.');\n this.isRunning = true;\n return {\n ip: '127.0.0.1',\n port: 8080\n };\n }\n async disconnect() {\n if (!this.isRunning) {\n console.log('HttpLocalServer: El servidor ya está detenido (Mock).');\n return;\n }\n console.log('HttpLocalServer: Servidor detenido (Mock).');\n this.isRunning = false;\n }\n async sendResponse(options) {\n if (!this.isRunning) {\n console.warn('HttpLocalServer: El servidor no está ejecutándose (Mock).');\n return;\n }\n const { requestId, body } = options;\n if (!requestId) {\n throw new Error('Missing requestId');\n }\n if (!body) {\n throw new Error('Missing body');\n }\n console.log(`HttpLocalServer: Respuesta mock enviada para requestId: ${requestId}`, '\\nBody:', body.substring(0, 100) + (body.length > 100 ? '...' : ''));\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;I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AY;IACZ,QAAQ;IACR,QAAQ,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,OAAO;IAC3C,QAAQ,IAAI,CAAC,SAAS,EAAE;IACxB,YAAY,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC;IAChD,QAAQ;IACR,QAAQ,IAAI,CAAC,IAAI,EAAE;IACnB,YAAY,MAAM,IAAI,KAAK,CAAC,cAAc,CAAC;IAC3C,QAAQ;IACR,QAAQ,OAAO,CAAC,GAAG,CAAC,CAAC,wDAAwD,EAAE,SAAS,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,IAAI,IAAI,CAAC,MAAM,GAAG,GAAG,GAAG,KAAK,GAAG,EAAE,CAAC,CAAC;IACjK,IAAI;IACJ;;;;;;;;;;;;;;;;;;"}
@@ -27,6 +27,7 @@ public protocol HttpLocalServerDelegate: AnyObject {
27
27
 
28
28
  // MARK: - HttpLocalServer
29
29
  @objc public class HttpLocalServer: NSObject {
30
+
30
31
  // MARK: - Properties
31
32
  private var webServer: GCDWebServer?
32
33
  private weak var delegate: HttpLocalServerDelegate?
@@ -194,7 +195,8 @@ public protocol HttpLocalServerDelegate: AnyObject {
194
195
  "path": path
195
196
  ]
196
197
 
197
- if let body = body {
198
+ // Solo agregar si existen (consistente con TypeScript y Android)
199
+ if let body = body, !body.isEmpty {
198
200
  requestData["body"] = body
199
201
  }
200
202
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cappitolian/http-local-server",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "description": "Runs a local HTTP server on your device, accessible over LAN. Supports connect, disconnect, GET, and POST methods with IP and port discovery.",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",