@cappitolian/http-local-server-swifter 0.0.13 → 0.0.14

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.
@@ -1 +1 @@
1
- {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAO5C;;;;;GAKG;AACH,MAAM,OAAO,yBAA0B,SAAQ,SAAS;IAAxD;;QAEU,cAAS,GAAG,KAAK,CAAC;IAoD5B,CAAC;IAlDC,KAAK,CAAC,OAAO;QACX,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACnB,OAAO,CAAC,IAAI,CAAC,uEAAuE,CAAC,CAAC;YACtF,OAAO,EAAE,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;QACzC,CAAC;QAED,OAAO,CAAC,IAAI,CACV,yFAAyF;YACzF,4CAA4C;YAC5C,iEAAiE,CAClE,CAAC;QAEF,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QAEtB,OAAO;YACL,EAAE,EAAE,WAAW;YACf,IAAI,EAAE,IAAI;SACX,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,UAAU;QACd,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACpB,OAAO,CAAC,GAAG,CAAC,mEAAmE,CAAC,CAAC;YACjF,OAAO;QACT,CAAC;QAED,OAAO,CAAC,GAAG,CAAC,wDAAwD,CAAC,CAAC;QACtE,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,OAAgC;QACjD,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;QAClE,CAAC;QAED,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;QAEpC,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;QACvC,CAAC;QAED,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CAAC,cAAc,CAAC,CAAC;QAClC,CAAC;QAED,OAAO,CAAC,GAAG,CACT,kEAAkE,SAAS,EAAE,EAC7E,iBAAiB,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAC7E,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\nimport type {\n HttpLocalServerSwifterPlugin,\n HttpConnectResult,\n HttpSendResponseOptions\n } from './definitions';\n\n/**\n * Implementación web (mock) del plugin HttpLocalServerSwifter.\n * \n * Proporciona funcionalidad simulada para desarrollo en navegador.\n * El servidor real solo funciona en dispositivos iOS/Android nativos.\n */\nexport class HttpLocalServerSwifterWeb extends WebPlugin implements HttpLocalServerSwifterPlugin {\n\n private isRunning = false;\n\n async connect(): Promise<HttpConnectResult> {\n if (this.isRunning) {\n console.warn('[HttpLocalServerSwifter Web] El servidor ya está ejecutándose (Mock).');\n return { ip: '127.0.0.1', port: 8080 };\n }\n\n console.warn(\n '[HttpLocalServerSwifter Web] El servidor HTTP nativo no está disponible en navegador.\\n' +\n 'Retornando valores mock para desarrollo.\\n' +\n 'Para funcionalidad real, ejecuta en un dispositivo iOS/Android.'\n );\n\n this.isRunning = true;\n\n return {\n ip: '127.0.0.1',\n port: 8080\n };\n }\n\n async disconnect(): Promise<void> {\n if (!this.isRunning) {\n console.log('[HttpLocalServerSwifter Web] El servidor ya está detenido (Mock).');\n return;\n }\n\n console.log('[HttpLocalServerSwifter Web] Servidor detenido (Mock).');\n this.isRunning = false;\n }\n\n async sendResponse(options: HttpSendResponseOptions): Promise<void> {\n if (!this.isRunning) {\n throw new Error('Server is not running. Call connect() first.');\n }\n\n const { requestId, body } = options;\n\n if (!requestId) {\n throw new Error('Missing requestId');\n }\n\n if (!body) {\n throw new Error('Missing body');\n }\n\n console.log(\n `[HttpLocalServerSwifter Web] Mock response sent for requestId: ${requestId}`,\n '\\nBody preview:', body.substring(0, 100) + (body.length > 100 ? '...' : '')\n );\n }\n}"]}
1
+ {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAO5C,MAAM,OAAO,yBAA0B,SAAQ,SAAS;IAAxD;;QACU,cAAS,GAAG,KAAK,CAAC;IAuB5B,CAAC;IArBC,KAAK,CAAC,OAAO;QACX,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACtB,OAAO,CAAC,IAAI,CAAC,oEAAoE,CAAC,CAAC;QACnF,OAAO,EAAE,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IACzC,CAAC;IAED,KAAK,CAAC,UAAU;QACd,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;QACvB,OAAO,CAAC,GAAG,CAAC,mDAAmD,CAAC,CAAC;IACnE,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,OAAgC;QACjD,IAAI,CAAC,IAAI,CAAC,SAAS;YAAE,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;QAE3D,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;QAErD,OAAO,CAAC,GAAG,CACT,6CAA6C,EAC7C,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,GAAG,EAAE,OAAO,EAAE,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,EAAE,EAAE,UAAU,EAAE,IAAI,CAAC,MAAM,EAAE,CACtF,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\nimport type {\n HttpLocalServerSwifterPlugin,\n HttpConnectResult,\n HttpSendResponseOptions\n} from './definitions';\n\nexport class HttpLocalServerSwifterWeb extends WebPlugin implements HttpLocalServerSwifterPlugin {\n private isRunning = false;\n\n async connect(): Promise<HttpConnectResult> {\n this.isRunning = true;\n console.warn('[HttpLocalServerSwifter Web] Mock server started at 127.0.0.1:8080');\n return { ip: '127.0.0.1', port: 8080 };\n }\n\n async disconnect(): Promise<void> {\n this.isRunning = false;\n console.log('[HttpLocalServerSwifter Web] Mock server stopped.');\n }\n\n async sendResponse(options: HttpSendResponseOptions): Promise<void> {\n if (!this.isRunning) throw new Error('Server not running');\n\n const { requestId, body, status, headers } = options;\n\n console.log(\n `[HttpLocalServerSwifter Web] Mock Response:`,\n { requestId, status: status ?? 200, headers: headers ?? {}, bodyLength: body.length }\n );\n }\n}"]}
@@ -3,83 +3,35 @@
3
3
  var core = require('@capacitor/core');
4
4
 
5
5
  /**
6
- * Plugin de servidor HTTP local para Android e iOS.
7
- *
8
- * Permite crear un servidor HTTP en el dispositivo que puede recibir
9
- * peticiones desde otros dispositivos en la misma red local.
10
- *
11
- * @example
12
- * ```typescript
13
- * import { HttpLocalServerSwifter } from '@cappitolian/http-local-server-swifter';
14
- *
15
- * // Iniciar servidor
16
- * const { ip, port } = await HttpLocalServerSwifter.connect();
17
- * console.log(`Servidor en http://${ip}:${port}`);
18
- *
19
- * // Escuchar peticiones
20
- * await HttpLocalServerSwifter.addListener('onRequest', async (data) => {
21
- * console.log('Petición recibida:', data);
22
- *
23
- * // Procesar y responder
24
- * await HttpLocalServerSwifter.sendResponse({
25
- * requestId: data.requestId,
26
- * body: JSON.stringify({ success: true })
27
- * });
28
- * });
29
- *
30
- * // Detener servidor
31
- * await HttpLocalServerSwifter.disconnect();
32
- * ```
6
+ * Local HTTP server plugin for Android and iOS.
7
+ * * Allows creating an HTTP server on the device that can receive
8
+ * requests from other devices on the same local network or
9
+ * from the app's own WebView (fixing CORS issues).
33
10
  */
34
11
  const HttpLocalServerSwifter = core.registerPlugin('HttpLocalServerSwifter', {
12
+ // We point to the web mock for browser development
35
13
  web: () => Promise.resolve().then(function () { return web; }).then(m => new m.HttpLocalServerSwifterWeb()),
36
14
  });
37
15
 
38
- /**
39
- * Implementación web (mock) del plugin HttpLocalServerSwifter.
40
- *
41
- * Proporciona funcionalidad simulada para desarrollo en navegador.
42
- * El servidor real solo funciona en dispositivos iOS/Android nativos.
43
- */
44
16
  class HttpLocalServerSwifterWeb extends core.WebPlugin {
45
17
  constructor() {
46
18
  super(...arguments);
47
19
  this.isRunning = false;
48
20
  }
49
21
  async connect() {
50
- if (this.isRunning) {
51
- console.warn('[HttpLocalServerSwifter Web] El servidor ya está ejecutándose (Mock).');
52
- return { ip: '127.0.0.1', port: 8080 };
53
- }
54
- console.warn('[HttpLocalServerSwifter Web] El servidor HTTP nativo no está disponible en navegador.\n' +
55
- 'Retornando valores mock para desarrollo.\n' +
56
- 'Para funcionalidad real, ejecuta en un dispositivo iOS/Android.');
57
22
  this.isRunning = true;
58
- return {
59
- ip: '127.0.0.1',
60
- port: 8080
61
- };
23
+ console.warn('[HttpLocalServerSwifter Web] Mock server started at 127.0.0.1:8080');
24
+ return { ip: '127.0.0.1', port: 8080 };
62
25
  }
63
26
  async disconnect() {
64
- if (!this.isRunning) {
65
- console.log('[HttpLocalServerSwifter Web] El servidor ya está detenido (Mock).');
66
- return;
67
- }
68
- console.log('[HttpLocalServerSwifter Web] Servidor detenido (Mock).');
69
27
  this.isRunning = false;
28
+ console.log('[HttpLocalServerSwifter Web] Mock server stopped.');
70
29
  }
71
30
  async sendResponse(options) {
72
- if (!this.isRunning) {
73
- throw new Error('Server is not running. Call connect() first.');
74
- }
75
- const { requestId, body } = options;
76
- if (!requestId) {
77
- throw new Error('Missing requestId');
78
- }
79
- if (!body) {
80
- throw new Error('Missing body');
81
- }
82
- console.log(`[HttpLocalServerSwifter Web] Mock response sent for requestId: ${requestId}`, '\nBody preview:', body.substring(0, 100) + (body.length > 100 ? '...' : ''));
31
+ if (!this.isRunning)
32
+ throw new Error('Server not running');
33
+ const { requestId, body, status, headers } = options;
34
+ console.log(`[HttpLocalServerSwifter Web] Mock Response:`, { requestId, status: status !== null && status !== void 0 ? status : 200, headers: headers !== null && headers !== void 0 ? headers : {}, bodyLength: body.length });
83
35
  }
84
36
  }
85
37
 
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.cjs.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 local.\n *\n * @example\n * ```typescript\n * import { HttpLocalServerSwifter } from '@cappitolian/http-local-server-swifter';\n *\n * // Iniciar servidor\n * const { ip, port } = await HttpLocalServerSwifter.connect();\n * console.log(`Servidor en http://${ip}:${port}`);\n *\n * // Escuchar peticiones\n * await HttpLocalServerSwifter.addListener('onRequest', async (data) => {\n * console.log('Petición recibida:', data);\n *\n * // Procesar y responder\n * await HttpLocalServerSwifter.sendResponse({\n * requestId: data.requestId,\n * body: JSON.stringify({ success: true })\n * });\n * });\n *\n * // Detener servidor\n * await HttpLocalServerSwifter.disconnect();\n * ```\n */\nconst HttpLocalServerSwifter = registerPlugin('HttpLocalServerSwifter', {\n web: () => import('./web').then(m => new m.HttpLocalServerSwifterWeb()),\n});\nexport * from './definitions';\nexport { HttpLocalServerSwifter };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\n/**\n * Implementación web (mock) del plugin HttpLocalServerSwifter.\n *\n * Proporciona funcionalidad simulada para desarrollo en navegador.\n * El servidor real solo funciona en dispositivos iOS/Android nativos.\n */\nexport class HttpLocalServerSwifterWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.isRunning = false;\n }\n async connect() {\n if (this.isRunning) {\n console.warn('[HttpLocalServerSwifter Web] El servidor ya está ejecutándose (Mock).');\n return { ip: '127.0.0.1', port: 8080 };\n }\n console.warn('[HttpLocalServerSwifter Web] El servidor HTTP nativo no está disponible en navegador.\\n' +\n 'Retornando valores mock para desarrollo.\\n' +\n 'Para funcionalidad real, ejecuta en un dispositivo iOS/Android.');\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('[HttpLocalServerSwifter Web] El servidor ya está detenido (Mock).');\n return;\n }\n console.log('[HttpLocalServerSwifter Web] Servidor detenido (Mock).');\n this.isRunning = false;\n }\n async sendResponse(options) {\n if (!this.isRunning) {\n throw new Error('Server is not running. Call connect() first.');\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(`[HttpLocalServerSwifter Web] Mock response sent for requestId: ${requestId}`, '\\nBody preview:', body.substring(0, 100) + (body.length > 100 ? '...' : ''));\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACK,MAAC,sBAAsB,GAAGA,mBAAc,CAAC,wBAAwB,EAAE;AACxE,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,yBAAyB,EAAE,CAAC;AAC3E,CAAC;;AC/BD;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,yBAAyB,SAASC,cAAS,CAAC;AACzD,IAAI,WAAW,GAAG;AAClB,QAAQ,KAAK,CAAC,GAAG,SAAS,CAAC;AAC3B,QAAQ,IAAI,CAAC,SAAS,GAAG,KAAK;AAC9B,IAAI;AACJ,IAAI,MAAM,OAAO,GAAG;AACpB,QAAQ,IAAI,IAAI,CAAC,SAAS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AAG,GAAG,GAAG,KAAK,GAAG,EAAE,CAAC,CAAC;AAChL,IAAI;AACJ;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\n/**\n * Local HTTP server plugin for Android and iOS.\n * * Allows creating an HTTP server on the device that can receive\n * requests from other devices on the same local network or\n * from the app's own WebView (fixing CORS issues).\n */\nconst HttpLocalServerSwifter = registerPlugin('HttpLocalServerSwifter', {\n // We point to the web mock for browser development\n web: () => import('./web').then(m => new m.HttpLocalServerSwifterWeb()),\n});\n// Re-export everything from definitions so they are available to the app\nexport * from './definitions';\nexport { HttpLocalServerSwifter };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class HttpLocalServerSwifterWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.isRunning = false;\n }\n async connect() {\n this.isRunning = true;\n console.warn('[HttpLocalServerSwifter Web] Mock server started at 127.0.0.1:8080');\n return { ip: '127.0.0.1', port: 8080 };\n }\n async disconnect() {\n this.isRunning = false;\n console.log('[HttpLocalServerSwifter Web] Mock server stopped.');\n }\n async sendResponse(options) {\n if (!this.isRunning)\n throw new Error('Server not running');\n const { requestId, body, status, headers } = options;\n console.log(`[HttpLocalServerSwifter Web] Mock Response:`, { requestId, status: status !== null && status !== void 0 ? status : 200, headers: headers !== null && headers !== void 0 ? headers : {}, bodyLength: body.length });\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACA;AACA;AACA;AACA;AACA;AACA;AACK,MAAC,sBAAsB,GAAGA,mBAAc,CAAC,wBAAwB,EAAE;AACxE;AACA,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,yBAAyB,EAAE,CAAC;AAC3E,CAAC;;ACTM,MAAM,yBAAyB,SAASC,cAAS,CAAC;AACzD,IAAI,WAAW,GAAG;AAClB,QAAQ,KAAK,CAAC,GAAG,SAAS,CAAC;AAC3B,QAAQ,IAAI,CAAC,SAAS,GAAG,KAAK;AAC9B,IAAI;AACJ,IAAI,MAAM,OAAO,GAAG;AACpB,QAAQ,IAAI,CAAC,SAAS,GAAG,IAAI;AAC7B,QAAQ,OAAO,CAAC,IAAI,CAAC,oEAAoE,CAAC;AAC1F,QAAQ,OAAO,EAAE,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,IAAI,EAAE;AAC9C,IAAI;AACJ,IAAI,MAAM,UAAU,GAAG;AACvB,QAAQ,IAAI,CAAC,SAAS,GAAG,KAAK;AAC9B,QAAQ,OAAO,CAAC,GAAG,CAAC,mDAAmD,CAAC;AACxE,IAAI;AACJ,IAAI,MAAM,YAAY,CAAC,OAAO,EAAE;AAChC,QAAQ,IAAI,CAAC,IAAI,CAAC,SAAS;AAC3B,YAAY,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC;AACjD,QAAQ,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO;AAC5D,QAAQ,OAAO,CAAC,GAAG,CAAC,CAAC,2CAA2C,CAAC,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,IAAI,MAAM,KAAK,MAAM,GAAG,MAAM,GAAG,GAAG,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,MAAM,GAAG,OAAO,GAAG,EAAE,EAAE,UAAU,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC;AACvO,IAAI;AACJ;;;;;;;;;"}
package/dist/plugin.js CHANGED
@@ -2,83 +2,35 @@ var capacitorHttpLocalServerSwifter = (function (exports, core) {
2
2
  'use strict';
3
3
 
4
4
  /**
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 local.
9
- *
10
- * @example
11
- * ```typescript
12
- * import { HttpLocalServerSwifter } from '@cappitolian/http-local-server-swifter';
13
- *
14
- * // Iniciar servidor
15
- * const { ip, port } = await HttpLocalServerSwifter.connect();
16
- * console.log(`Servidor en http://${ip}:${port}`);
17
- *
18
- * // Escuchar peticiones
19
- * await HttpLocalServerSwifter.addListener('onRequest', async (data) => {
20
- * console.log('Petición recibida:', data);
21
- *
22
- * // Procesar y responder
23
- * await HttpLocalServerSwifter.sendResponse({
24
- * requestId: data.requestId,
25
- * body: JSON.stringify({ success: true })
26
- * });
27
- * });
28
- *
29
- * // Detener servidor
30
- * await HttpLocalServerSwifter.disconnect();
31
- * ```
5
+ * Local HTTP server plugin for Android and iOS.
6
+ * * Allows creating an HTTP server on the device that can receive
7
+ * requests from other devices on the same local network or
8
+ * from the app's own WebView (fixing CORS issues).
32
9
  */
33
10
  const HttpLocalServerSwifter = core.registerPlugin('HttpLocalServerSwifter', {
11
+ // We point to the web mock for browser development
34
12
  web: () => Promise.resolve().then(function () { return web; }).then(m => new m.HttpLocalServerSwifterWeb()),
35
13
  });
36
14
 
37
- /**
38
- * Implementación web (mock) del plugin HttpLocalServerSwifter.
39
- *
40
- * Proporciona funcionalidad simulada para desarrollo en navegador.
41
- * El servidor real solo funciona en dispositivos iOS/Android nativos.
42
- */
43
15
  class HttpLocalServerSwifterWeb extends core.WebPlugin {
44
16
  constructor() {
45
17
  super(...arguments);
46
18
  this.isRunning = false;
47
19
  }
48
20
  async connect() {
49
- if (this.isRunning) {
50
- console.warn('[HttpLocalServerSwifter Web] El servidor ya está ejecutándose (Mock).');
51
- return { ip: '127.0.0.1', port: 8080 };
52
- }
53
- console.warn('[HttpLocalServerSwifter Web] El servidor HTTP nativo no está disponible en navegador.\n' +
54
- 'Retornando valores mock para desarrollo.\n' +
55
- 'Para funcionalidad real, ejecuta en un dispositivo iOS/Android.');
56
21
  this.isRunning = true;
57
- return {
58
- ip: '127.0.0.1',
59
- port: 8080
60
- };
22
+ console.warn('[HttpLocalServerSwifter Web] Mock server started at 127.0.0.1:8080');
23
+ return { ip: '127.0.0.1', port: 8080 };
61
24
  }
62
25
  async disconnect() {
63
- if (!this.isRunning) {
64
- console.log('[HttpLocalServerSwifter Web] El servidor ya está detenido (Mock).');
65
- return;
66
- }
67
- console.log('[HttpLocalServerSwifter Web] Servidor detenido (Mock).');
68
26
  this.isRunning = false;
27
+ console.log('[HttpLocalServerSwifter Web] Mock server stopped.');
69
28
  }
70
29
  async sendResponse(options) {
71
- if (!this.isRunning) {
72
- throw new Error('Server is not running. Call connect() first.');
73
- }
74
- const { requestId, body } = options;
75
- if (!requestId) {
76
- throw new Error('Missing requestId');
77
- }
78
- if (!body) {
79
- throw new Error('Missing body');
80
- }
81
- console.log(`[HttpLocalServerSwifter Web] Mock response sent for requestId: ${requestId}`, '\nBody preview:', body.substring(0, 100) + (body.length > 100 ? '...' : ''));
30
+ if (!this.isRunning)
31
+ throw new Error('Server not running');
32
+ const { requestId, body, status, headers } = options;
33
+ console.log(`[HttpLocalServerSwifter Web] Mock Response:`, { requestId, status: status !== null && status !== void 0 ? status : 200, headers: headers !== null && headers !== void 0 ? headers : {}, bodyLength: body.length });
82
34
  }
83
35
  }
84
36
 
@@ -1 +1 @@
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 local.\n *\n * @example\n * ```typescript\n * import { HttpLocalServerSwifter } from '@cappitolian/http-local-server-swifter';\n *\n * // Iniciar servidor\n * const { ip, port } = await HttpLocalServerSwifter.connect();\n * console.log(`Servidor en http://${ip}:${port}`);\n *\n * // Escuchar peticiones\n * await HttpLocalServerSwifter.addListener('onRequest', async (data) => {\n * console.log('Petición recibida:', data);\n *\n * // Procesar y responder\n * await HttpLocalServerSwifter.sendResponse({\n * requestId: data.requestId,\n * body: JSON.stringify({ success: true })\n * });\n * });\n *\n * // Detener servidor\n * await HttpLocalServerSwifter.disconnect();\n * ```\n */\nconst HttpLocalServerSwifter = registerPlugin('HttpLocalServerSwifter', {\n web: () => import('./web').then(m => new m.HttpLocalServerSwifterWeb()),\n});\nexport * from './definitions';\nexport { HttpLocalServerSwifter };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\n/**\n * Implementación web (mock) del plugin HttpLocalServerSwifter.\n *\n * Proporciona funcionalidad simulada para desarrollo en navegador.\n * El servidor real solo funciona en dispositivos iOS/Android nativos.\n */\nexport class HttpLocalServerSwifterWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.isRunning = false;\n }\n async connect() {\n if (this.isRunning) {\n console.warn('[HttpLocalServerSwifter Web] El servidor ya está ejecutándose (Mock).');\n return { ip: '127.0.0.1', port: 8080 };\n }\n console.warn('[HttpLocalServerSwifter Web] El servidor HTTP nativo no está disponible en navegador.\\n' +\n 'Retornando valores mock para desarrollo.\\n' +\n 'Para funcionalidad real, ejecuta en un dispositivo iOS/Android.');\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('[HttpLocalServerSwifter Web] El servidor ya está detenido (Mock).');\n return;\n }\n console.log('[HttpLocalServerSwifter Web] Servidor detenido (Mock).');\n this.isRunning = false;\n }\n async sendResponse(options) {\n if (!this.isRunning) {\n throw new Error('Server is not running. Call connect() first.');\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(`[HttpLocalServerSwifter Web] Mock response sent for requestId: ${requestId}`, '\\nBody preview:', 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;IAC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Y,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC;IAC3E,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,+DAA+D,EAAE,SAAS,CAAC,CAAC,EAAE,iBAAiB,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,IAAI,IAAI,CAAC,MAAM,GAAG,GAAG,GAAG,KAAK,GAAG,EAAE,CAAC,CAAC;IAChL,IAAI;IACJ;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\n/**\n * Local HTTP server plugin for Android and iOS.\n * * Allows creating an HTTP server on the device that can receive\n * requests from other devices on the same local network or\n * from the app's own WebView (fixing CORS issues).\n */\nconst HttpLocalServerSwifter = registerPlugin('HttpLocalServerSwifter', {\n // We point to the web mock for browser development\n web: () => import('./web').then(m => new m.HttpLocalServerSwifterWeb()),\n});\n// Re-export everything from definitions so they are available to the app\nexport * from './definitions';\nexport { HttpLocalServerSwifter };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class HttpLocalServerSwifterWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.isRunning = false;\n }\n async connect() {\n this.isRunning = true;\n console.warn('[HttpLocalServerSwifter Web] Mock server started at 127.0.0.1:8080');\n return { ip: '127.0.0.1', port: 8080 };\n }\n async disconnect() {\n this.isRunning = false;\n console.log('[HttpLocalServerSwifter Web] Mock server stopped.');\n }\n async sendResponse(options) {\n if (!this.isRunning)\n throw new Error('Server not running');\n const { requestId, body, status, headers } = options;\n console.log(`[HttpLocalServerSwifter Web] Mock Response:`, { requestId, status: status !== null && status !== void 0 ? status : 200, headers: headers !== null && headers !== void 0 ? headers : {}, bodyLength: body.length });\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;IACA;IACA;IACA;IACA;IACA;IACA;AACK,UAAC,sBAAsB,GAAGA,mBAAc,CAAC,wBAAwB,EAAE;IACxE;IACA,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,yBAAyB,EAAE,CAAC;IAC3E,CAAC;;ICTM,MAAM,yBAAyB,SAASC,cAAS,CAAC;IACzD,IAAI,WAAW,GAAG;IAClB,QAAQ,KAAK,CAAC,GAAG,SAAS,CAAC;IAC3B,QAAQ,IAAI,CAAC,SAAS,GAAG,KAAK;IAC9B,IAAI;IACJ,IAAI,MAAM,OAAO,GAAG;IACpB,QAAQ,IAAI,CAAC,SAAS,GAAG,IAAI;IAC7B,QAAQ,OAAO,CAAC,IAAI,CAAC,oEAAoE,CAAC;IAC1F,QAAQ,OAAO,EAAE,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,IAAI,EAAE;IAC9C,IAAI;IACJ,IAAI,MAAM,UAAU,GAAG;IACvB,QAAQ,IAAI,CAAC,SAAS,GAAG,KAAK;IAC9B,QAAQ,OAAO,CAAC,GAAG,CAAC,mDAAmD,CAAC;IACxE,IAAI;IACJ,IAAI,MAAM,YAAY,CAAC,OAAO,EAAE;IAChC,QAAQ,IAAI,CAAC,IAAI,CAAC,SAAS;IAC3B,YAAY,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC;IACjD,QAAQ,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO;IAC5D,QAAQ,OAAO,CAAC,GAAG,CAAC,CAAC,2CAA2C,CAAC,EAAE,EAAE,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