@cappitolian/http-local-server-swifter 0.0.1

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/docs.json ADDED
@@ -0,0 +1,312 @@
1
+ {
2
+ "api": {
3
+ "name": "HttpLocalServerSwifterPlugin",
4
+ "slug": "httplocalserverswifterplugin",
5
+ "docs": "Plugin para ejecutar un servidor HTTP local en dispositivos iOS y Android.\n\nPermite recibir peticiones HTTP desde otros dispositivos en la red local\ny responder desde JavaScript/TypeScript.",
6
+ "tags": [
7
+ {
8
+ "text": "0.1.0",
9
+ "name": "since"
10
+ }
11
+ ],
12
+ "methods": [
13
+ {
14
+ "name": "connect",
15
+ "signature": "() => Promise<HttpConnectResult>",
16
+ "parameters": [],
17
+ "returns": "Promise<HttpConnectResult>",
18
+ "tags": [
19
+ {
20
+ "name": "returns",
21
+ "text": "Promesa con la IP y puerto del servidor"
22
+ },
23
+ {
24
+ "name": "throws",
25
+ "text": "Error si el servidor no puede iniciarse (ej: puerto ocupado)"
26
+ },
27
+ {
28
+ "name": "example",
29
+ "text": "```typescript\nconst { ip, port } = await HttpLocalServerSwifter.connect();\nconsole.log(`Servidor corriendo en http://${ip}:${port}`);\n```"
30
+ },
31
+ {
32
+ "name": "since",
33
+ "text": "0.1.0"
34
+ }
35
+ ],
36
+ "docs": "Inicia el servidor HTTP local en el dispositivo.\n\nEl servidor escucha en todas las interfaces de red (0.0.0.0)\ny es accesible desde otros dispositivos en la misma red local.",
37
+ "complexTypes": [
38
+ "HttpConnectResult"
39
+ ],
40
+ "slug": "connect"
41
+ },
42
+ {
43
+ "name": "disconnect",
44
+ "signature": "() => Promise<void>",
45
+ "parameters": [],
46
+ "returns": "Promise<void>",
47
+ "tags": [
48
+ {
49
+ "name": "returns",
50
+ "text": "Promesa que se resuelve cuando el servidor se detiene"
51
+ },
52
+ {
53
+ "name": "example",
54
+ "text": "```typescript\nawait HttpLocalServerSwifter.disconnect();\nconsole.log('Servidor detenido');\n```"
55
+ },
56
+ {
57
+ "name": "since",
58
+ "text": "0.1.0"
59
+ }
60
+ ],
61
+ "docs": "Detiene el servidor HTTP local.\n\nCierra todas las conexiones activas y libera el puerto.\nLas peticiones pendientes recibirán un timeout.",
62
+ "complexTypes": [],
63
+ "slug": "disconnect"
64
+ },
65
+ {
66
+ "name": "sendResponse",
67
+ "signature": "(options: HttpSendResponseOptions) => Promise<void>",
68
+ "parameters": [
69
+ {
70
+ "name": "options",
71
+ "docs": "- Objeto con requestId y cuerpo de la respuesta",
72
+ "type": "HttpSendResponseOptions"
73
+ }
74
+ ],
75
+ "returns": "Promise<void>",
76
+ "tags": [
77
+ {
78
+ "name": "param",
79
+ "text": "options - Objeto con requestId y cuerpo de la respuesta"
80
+ },
81
+ {
82
+ "name": "returns",
83
+ "text": "Promesa que se resuelve cuando la respuesta se envía"
84
+ },
85
+ {
86
+ "name": "throws",
87
+ "text": "Error si faltan requestId o body"
88
+ },
89
+ {
90
+ "name": "example",
91
+ "text": "```typescript\nawait HttpLocalServerSwifter.sendResponse({\n requestId: '123-456-789',\n body: JSON.stringify({ status: 'ok', data: { id: 1 } })\n});\n```"
92
+ },
93
+ {
94
+ "name": "since",
95
+ "text": "0.1.0"
96
+ }
97
+ ],
98
+ "docs": "Envía una respuesta HTTP de vuelta al cliente.\n\nDebe llamarse con el `requestId` recibido en el evento 'onRequest'.\nSi no se llama dentro de 5 segundos, el cliente recibirá un timeout (408).",
99
+ "complexTypes": [
100
+ "HttpSendResponseOptions"
101
+ ],
102
+ "slug": "sendresponse"
103
+ },
104
+ {
105
+ "name": "addListener",
106
+ "signature": "(eventName: 'onRequest', listenerFunc: (data: HttpRequestData) => void | Promise<void>) => Promise<PluginListenerHandle>",
107
+ "parameters": [
108
+ {
109
+ "name": "eventName",
110
+ "docs": "- Debe ser 'onRequest'",
111
+ "type": "'onRequest'"
112
+ },
113
+ {
114
+ "name": "listenerFunc",
115
+ "docs": "- Callback que recibe los datos de la petición",
116
+ "type": "(data: HttpRequestData) => void | Promise<void>"
117
+ }
118
+ ],
119
+ "returns": "Promise<PluginListenerHandle>",
120
+ "tags": [
121
+ {
122
+ "name": "param",
123
+ "text": "eventName - Debe ser 'onRequest'"
124
+ },
125
+ {
126
+ "name": "param",
127
+ "text": "listenerFunc - Callback que recibe los datos de la petición"
128
+ },
129
+ {
130
+ "name": "returns",
131
+ "text": "Handle para remover el listener posteriormente"
132
+ },
133
+ {
134
+ "name": "example",
135
+ "text": "```typescript\nconst listener = await HttpLocalServerSwifter.addListener('onRequest', async (data) => {\n console.log(`${data.method} ${data.path}`);\n \n const response = {\n message: 'Hello from device',\n timestamp: Date.now()\n };\n \n await HttpLocalServerSwifter.sendResponse({\n requestId: data.requestId,\n body: JSON.stringify(response)\n });\n});\n\n// Remover listener cuando ya no sea necesario\nawait listener.remove();\n```"
136
+ },
137
+ {
138
+ "name": "since",
139
+ "text": "0.1.0"
140
+ }
141
+ ],
142
+ "docs": "Registra un listener para recibir peticiones HTTP entrantes.\n\nEste evento se dispara cada vez que el servidor recibe una petición.\nDebes responder usando `sendResponse()` con el mismo `requestId`.",
143
+ "complexTypes": [
144
+ "PluginListenerHandle",
145
+ "HttpRequestData"
146
+ ],
147
+ "slug": "addlisteneronrequest-"
148
+ },
149
+ {
150
+ "name": "removeAllListeners",
151
+ "signature": "() => Promise<void>",
152
+ "parameters": [],
153
+ "returns": "Promise<void>",
154
+ "tags": [
155
+ {
156
+ "name": "returns",
157
+ "text": "Promesa que se resuelve cuando se eliminan los listeners"
158
+ },
159
+ {
160
+ "name": "example",
161
+ "text": "```typescript\nawait HttpLocalServerSwifter.removeAllListeners();\n```"
162
+ },
163
+ {
164
+ "name": "since",
165
+ "text": "0.1.0"
166
+ }
167
+ ],
168
+ "docs": "Elimina todos los listeners del evento 'onRequest'.",
169
+ "complexTypes": [],
170
+ "slug": "removealllisteners"
171
+ }
172
+ ],
173
+ "properties": []
174
+ },
175
+ "interfaces": [
176
+ {
177
+ "name": "HttpConnectResult",
178
+ "slug": "httpconnectresult",
179
+ "docs": "Resultado de la conexión del servidor HTTP local",
180
+ "tags": [],
181
+ "methods": [],
182
+ "properties": [
183
+ {
184
+ "name": "ip",
185
+ "tags": [],
186
+ "docs": "Dirección IP del servidor (ej: \"192.168.1.100\")",
187
+ "complexTypes": [],
188
+ "type": "string"
189
+ },
190
+ {
191
+ "name": "port",
192
+ "tags": [],
193
+ "docs": "Puerto en el que escucha el servidor (típicamente 8080)",
194
+ "complexTypes": [],
195
+ "type": "number"
196
+ }
197
+ ]
198
+ },
199
+ {
200
+ "name": "HttpSendResponseOptions",
201
+ "slug": "httpsendresponseoptions",
202
+ "docs": "Opciones para enviar una respuesta HTTP",
203
+ "tags": [],
204
+ "methods": [],
205
+ "properties": [
206
+ {
207
+ "name": "requestId",
208
+ "tags": [],
209
+ "docs": "ID de la petición (recibido en el evento 'onRequest')",
210
+ "complexTypes": [],
211
+ "type": "string"
212
+ },
213
+ {
214
+ "name": "body",
215
+ "tags": [],
216
+ "docs": "Cuerpo de la respuesta. Típicamente un JSON stringificado.\nEjemplo: JSON.stringify({ success: true, data: {...} })",
217
+ "complexTypes": [],
218
+ "type": "string"
219
+ }
220
+ ]
221
+ },
222
+ {
223
+ "name": "PluginListenerHandle",
224
+ "slug": "pluginlistenerhandle",
225
+ "docs": "",
226
+ "tags": [],
227
+ "methods": [],
228
+ "properties": [
229
+ {
230
+ "name": "remove",
231
+ "tags": [],
232
+ "docs": "",
233
+ "complexTypes": [],
234
+ "type": "() => Promise<void>"
235
+ }
236
+ ]
237
+ },
238
+ {
239
+ "name": "HttpRequestData",
240
+ "slug": "httprequestdata",
241
+ "docs": "Datos de una petición HTTP entrante",
242
+ "tags": [],
243
+ "methods": [],
244
+ "properties": [
245
+ {
246
+ "name": "requestId",
247
+ "tags": [],
248
+ "docs": "ID único de la petición. Debe usarse en sendResponse()",
249
+ "complexTypes": [],
250
+ "type": "string"
251
+ },
252
+ {
253
+ "name": "method",
254
+ "tags": [],
255
+ "docs": "Método HTTP (GET, POST, PUT, PATCH, DELETE, OPTIONS)",
256
+ "complexTypes": [],
257
+ "type": "string"
258
+ },
259
+ {
260
+ "name": "path",
261
+ "tags": [],
262
+ "docs": "Ruta de la petición (ej: \"/api/users\")",
263
+ "complexTypes": [],
264
+ "type": "string"
265
+ },
266
+ {
267
+ "name": "body",
268
+ "tags": [],
269
+ "docs": "Cuerpo de la petición (opcional, presente en POST/PUT/PATCH)\nTípicamente es un string JSON",
270
+ "complexTypes": [],
271
+ "type": "string | undefined"
272
+ },
273
+ {
274
+ "name": "headers",
275
+ "tags": [],
276
+ "docs": "Encabezados HTTP de la petición",
277
+ "complexTypes": [
278
+ "Record"
279
+ ],
280
+ "type": "Record<string, string>"
281
+ },
282
+ {
283
+ "name": "query",
284
+ "tags": [],
285
+ "docs": "Parámetros de query string (ej: { id: \"123\", name: \"test\" })",
286
+ "complexTypes": [
287
+ "Record"
288
+ ],
289
+ "type": "Record<string, string>"
290
+ }
291
+ ]
292
+ }
293
+ ],
294
+ "enums": [],
295
+ "typeAliases": [
296
+ {
297
+ "name": "Record",
298
+ "slug": "record",
299
+ "docs": "Construct a type with a set of properties K of type T",
300
+ "types": [
301
+ {
302
+ "text": "{\r\n [P in K]: T;\r\n}",
303
+ "complexTypes": [
304
+ "K",
305
+ "T"
306
+ ]
307
+ }
308
+ ]
309
+ }
310
+ ],
311
+ "pluginConfigs": []
312
+ }
@@ -0,0 +1,170 @@
1
+ import type { PluginListenerHandle } from '@capacitor/core';
2
+ /**
3
+ * Resultado de la conexión del servidor HTTP local
4
+ */
5
+ export interface HttpConnectResult {
6
+ /**
7
+ * Dirección IP del servidor (ej: "192.168.1.100")
8
+ */
9
+ ip: string;
10
+ /**
11
+ * Puerto en el que escucha el servidor (típicamente 8080)
12
+ */
13
+ port: number;
14
+ }
15
+ /**
16
+ * Datos de una petición HTTP entrante
17
+ */
18
+ export interface HttpRequestData {
19
+ /**
20
+ * ID único de la petición. Debe usarse en sendResponse()
21
+ */
22
+ requestId: string;
23
+ /**
24
+ * Método HTTP (GET, POST, PUT, PATCH, DELETE, OPTIONS)
25
+ */
26
+ method: string;
27
+ /**
28
+ * Ruta de la petición (ej: "/api/users")
29
+ */
30
+ path: string;
31
+ /**
32
+ * Cuerpo de la petición (opcional, presente en POST/PUT/PATCH)
33
+ * Típicamente es un string JSON
34
+ */
35
+ body?: string;
36
+ /**
37
+ * Encabezados HTTP de la petición
38
+ */
39
+ headers?: Record<string, string>;
40
+ /**
41
+ * Parámetros de query string (ej: { id: "123", name: "test" })
42
+ */
43
+ query?: Record<string, string>;
44
+ }
45
+ /**
46
+ * Opciones para enviar una respuesta HTTP
47
+ */
48
+ export interface HttpSendResponseOptions {
49
+ /**
50
+ * ID de la petición (recibido en el evento 'onRequest')
51
+ */
52
+ requestId: string;
53
+ /**
54
+ * Cuerpo de la respuesta. Típicamente un JSON stringificado.
55
+ * Ejemplo: JSON.stringify({ success: true, data: {...} })
56
+ */
57
+ body: string;
58
+ }
59
+ /**
60
+ * Plugin para ejecutar un servidor HTTP local en dispositivos iOS y Android.
61
+ *
62
+ * Permite recibir peticiones HTTP desde otros dispositivos en la red local
63
+ * y responder desde JavaScript/TypeScript.
64
+ *
65
+ * @since 0.1.0
66
+ */
67
+ export interface HttpLocalServerSwifterPlugin {
68
+ /**
69
+ * Inicia el servidor HTTP local en el dispositivo.
70
+ *
71
+ * El servidor escucha en todas las interfaces de red (0.0.0.0)
72
+ * y es accesible desde otros dispositivos en la misma red local.
73
+ *
74
+ * @returns Promesa con la IP y puerto del servidor
75
+ * @throws Error si el servidor no puede iniciarse (ej: puerto ocupado)
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * const { ip, port } = await HttpLocalServerSwifter.connect();
80
+ * console.log(`Servidor corriendo en http://${ip}:${port}`);
81
+ * ```
82
+ *
83
+ * @since 0.1.0
84
+ */
85
+ connect(): Promise<HttpConnectResult>;
86
+ /**
87
+ * Detiene el servidor HTTP local.
88
+ *
89
+ * Cierra todas las conexiones activas y libera el puerto.
90
+ * Las peticiones pendientes recibirán un timeout.
91
+ *
92
+ * @returns Promesa que se resuelve cuando el servidor se detiene
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * await HttpLocalServerSwifter.disconnect();
97
+ * console.log('Servidor detenido');
98
+ * ```
99
+ *
100
+ * @since 0.1.0
101
+ */
102
+ disconnect(): Promise<void>;
103
+ /**
104
+ * Envía una respuesta HTTP de vuelta al cliente.
105
+ *
106
+ * Debe llamarse con el `requestId` recibido en el evento 'onRequest'.
107
+ * Si no se llama dentro de 5 segundos, el cliente recibirá un timeout (408).
108
+ *
109
+ * @param options - Objeto con requestId y cuerpo de la respuesta
110
+ * @returns Promesa que se resuelve cuando la respuesta se envía
111
+ * @throws Error si faltan requestId o body
112
+ *
113
+ * @example
114
+ * ```typescript
115
+ * await HttpLocalServerSwifter.sendResponse({
116
+ * requestId: '123-456-789',
117
+ * body: JSON.stringify({ status: 'ok', data: { id: 1 } })
118
+ * });
119
+ * ```
120
+ *
121
+ * @since 0.1.0
122
+ */
123
+ sendResponse(options: HttpSendResponseOptions): Promise<void>;
124
+ /**
125
+ * Registra un listener para recibir peticiones HTTP entrantes.
126
+ *
127
+ * Este evento se dispara cada vez que el servidor recibe una petición.
128
+ * Debes responder usando `sendResponse()` con el mismo `requestId`.
129
+ *
130
+ * @param eventName - Debe ser 'onRequest'
131
+ * @param listenerFunc - Callback que recibe los datos de la petición
132
+ * @returns Handle para remover el listener posteriormente
133
+ *
134
+ * @example
135
+ * ```typescript
136
+ * const listener = await HttpLocalServerSwifter.addListener('onRequest', async (data) => {
137
+ * console.log(`${data.method} ${data.path}`);
138
+ *
139
+ * const response = {
140
+ * message: 'Hello from device',
141
+ * timestamp: Date.now()
142
+ * };
143
+ *
144
+ * await HttpLocalServerSwifter.sendResponse({
145
+ * requestId: data.requestId,
146
+ * body: JSON.stringify(response)
147
+ * });
148
+ * });
149
+ *
150
+ * // Remover listener cuando ya no sea necesario
151
+ * await listener.remove();
152
+ * ```
153
+ *
154
+ * @since 0.1.0
155
+ */
156
+ addListener(eventName: 'onRequest', listenerFunc: (data: HttpRequestData) => void | Promise<void>): Promise<PluginListenerHandle>;
157
+ /**
158
+ * Elimina todos los listeners del evento 'onRequest'.
159
+ *
160
+ * @returns Promesa que se resuelve cuando se eliminan los listeners
161
+ *
162
+ * @example
163
+ * ```typescript
164
+ * await HttpLocalServerSwifter.removeAllListeners();
165
+ * ```
166
+ *
167
+ * @since 0.1.0
168
+ */
169
+ removeAllListeners(): Promise<void>;
170
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=definitions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\n\n/**\n * Resultado de la conexión del servidor HTTP local\n */\nexport interface HttpConnectResult {\n /**\n * Dirección IP del servidor (ej: \"192.168.1.100\")\n */\n ip: string;\n\n /**\n * Puerto en el que escucha el servidor (típicamente 8080)\n */\n port: number;\n}\n\n/**\n * Datos de una petición HTTP entrante\n */\nexport interface HttpRequestData {\n /**\n * ID único de la petición. Debe usarse en sendResponse()\n */\n requestId: string;\n\n /**\n * Método HTTP (GET, POST, PUT, PATCH, DELETE, OPTIONS)\n */\n method: string;\n\n /**\n * Ruta de la petición (ej: \"/api/users\")\n */\n path: string;\n\n /**\n * Cuerpo de la petición (opcional, presente en POST/PUT/PATCH)\n * Típicamente es un string JSON\n */\n body?: string;\n\n /**\n * Encabezados HTTP de la petición\n */\n headers?: Record<string, string>;\n\n /**\n * Parámetros de query string (ej: { id: \"123\", name: \"test\" })\n */\n query?: Record<string, string>;\n}\n\n/**\n * Opciones para enviar una respuesta HTTP\n */\nexport interface HttpSendResponseOptions {\n /**\n * ID de la petición (recibido en el evento 'onRequest')\n */\n requestId: string;\n\n /**\n * Cuerpo de la respuesta. Típicamente un JSON stringificado.\n * Ejemplo: JSON.stringify({ success: true, data: {...} })\n */\n body: string;\n}\n\n/**\n * Plugin para ejecutar un servidor HTTP local en dispositivos iOS y Android.\n * \n * Permite recibir peticiones HTTP desde otros dispositivos en la red local\n * y responder desde JavaScript/TypeScript.\n * \n * @since 0.1.0\n */\nexport interface HttpLocalServerSwifterPlugin {\n /**\n * Inicia el servidor HTTP local en el dispositivo.\n * \n * El servidor escucha en todas las interfaces de red (0.0.0.0)\n * y es accesible desde otros dispositivos en la misma red local.\n * \n * @returns Promesa con la IP y puerto del servidor\n * @throws Error si el servidor no puede iniciarse (ej: puerto ocupado)\n * \n * @example\n * ```typescript\n * const { ip, port } = await HttpLocalServerSwifter.connect();\n * console.log(`Servidor corriendo en http://${ip}:${port}`);\n * ```\n * \n * @since 0.1.0\n */\n connect(): Promise<HttpConnectResult>;\n\n /**\n * Detiene el servidor HTTP local.\n * \n * Cierra todas las conexiones activas y libera el puerto.\n * Las peticiones pendientes recibirán un timeout.\n * \n * @returns Promesa que se resuelve cuando el servidor se detiene\n * \n * @example\n * ```typescript\n * await HttpLocalServerSwifter.disconnect();\n * console.log('Servidor detenido');\n * ```\n * \n * @since 0.1.0\n */\n disconnect(): Promise<void>;\n\n /**\n * Envía una respuesta HTTP de vuelta al cliente.\n * \n * Debe llamarse con el `requestId` recibido en el evento 'onRequest'.\n * Si no se llama dentro de 5 segundos, el cliente recibirá un timeout (408).\n * \n * @param options - Objeto con requestId y cuerpo de la respuesta\n * @returns Promesa que se resuelve cuando la respuesta se envía\n * @throws Error si faltan requestId o body\n * \n * @example\n * ```typescript\n * await HttpLocalServerSwifter.sendResponse({\n * requestId: '123-456-789',\n * body: JSON.stringify({ status: 'ok', data: { id: 1 } })\n * });\n * ```\n * \n * @since 0.1.0\n */\n sendResponse(options: HttpSendResponseOptions): Promise<void>;\n\n /**\n * Registra un listener para recibir peticiones HTTP entrantes.\n * \n * Este evento se dispara cada vez que el servidor recibe una petición.\n * Debes responder usando `sendResponse()` con el mismo `requestId`.\n * \n * @param eventName - Debe ser 'onRequest'\n * @param listenerFunc - Callback que recibe los datos de la petición\n * @returns Handle para remover el listener posteriormente\n * \n * @example\n * ```typescript\n * const listener = await HttpLocalServerSwifter.addListener('onRequest', async (data) => {\n * console.log(`${data.method} ${data.path}`);\n * \n * const response = {\n * message: 'Hello from device',\n * timestamp: Date.now()\n * };\n * \n * await HttpLocalServerSwifter.sendResponse({\n * requestId: data.requestId,\n * body: JSON.stringify(response)\n * });\n * });\n * \n * // Remover listener cuando ya no sea necesario\n * await listener.remove();\n * ```\n * \n * @since 0.1.0\n */\n addListener(\n eventName: 'onRequest',\n listenerFunc: (data: HttpRequestData) => void | Promise<void>\n ): Promise<PluginListenerHandle>;\n\n /**\n * Elimina todos los listeners del evento 'onRequest'.\n * \n * @returns Promesa que se resuelve cuando se eliminan los listeners\n * \n * @example\n * ```typescript\n * await HttpLocalServerSwifter.removeAllListeners();\n * ```\n * \n * @since 0.1.0\n */\n removeAllListeners(): Promise<void>;\n}"]}
@@ -0,0 +1,33 @@
1
+ import type { HttpLocalServerSwifterPlugin } from './definitions';
2
+ /**
3
+ * Plugin de servidor HTTP local para Android e iOS.
4
+ *
5
+ * Permite crear un servidor HTTP en el dispositivo que puede recibir
6
+ * peticiones desde otros dispositivos en la misma red local.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * import { HttpLocalServerSwifter } from '@cappitolian/http-local-server-swifter';
11
+ *
12
+ * // Iniciar servidor
13
+ * const { ip, port } = await HttpLocalServerSwifter.connect();
14
+ * console.log(`Servidor en http://${ip}:${port}`);
15
+ *
16
+ * // Escuchar peticiones
17
+ * await HttpLocalServerSwifter.addListener('onRequest', async (data) => {
18
+ * console.log('Petición recibida:', data);
19
+ *
20
+ * // Procesar y responder
21
+ * await HttpLocalServerSwifter.sendResponse({
22
+ * requestId: data.requestId,
23
+ * body: JSON.stringify({ success: true })
24
+ * });
25
+ * });
26
+ *
27
+ * // Detener servidor
28
+ * await HttpLocalServerSwifter.disconnect();
29
+ * ```
30
+ */
31
+ declare const HttpLocalServerSwifter: HttpLocalServerSwifterPlugin;
32
+ export * from './definitions';
33
+ export { HttpLocalServerSwifter };
@@ -0,0 +1,36 @@
1
+ import { registerPlugin } from '@capacitor/core';
2
+ /**
3
+ * Plugin de servidor HTTP local para Android e iOS.
4
+ *
5
+ * Permite crear un servidor HTTP en el dispositivo que puede recibir
6
+ * peticiones desde otros dispositivos en la misma red local.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * import { HttpLocalServerSwifter } from '@cappitolian/http-local-server-swifter';
11
+ *
12
+ * // Iniciar servidor
13
+ * const { ip, port } = await HttpLocalServerSwifter.connect();
14
+ * console.log(`Servidor en http://${ip}:${port}`);
15
+ *
16
+ * // Escuchar peticiones
17
+ * await HttpLocalServerSwifter.addListener('onRequest', async (data) => {
18
+ * console.log('Petición recibida:', data);
19
+ *
20
+ * // Procesar y responder
21
+ * await HttpLocalServerSwifter.sendResponse({
22
+ * requestId: data.requestId,
23
+ * body: JSON.stringify({ success: true })
24
+ * });
25
+ * });
26
+ *
27
+ * // Detener servidor
28
+ * await HttpLocalServerSwifter.disconnect();
29
+ * ```
30
+ */
31
+ const HttpLocalServerSwifter = registerPlugin('HttpLocalServerSwifter', {
32
+ web: () => import('./web').then(m => new m.HttpLocalServerSwifterWeb()),
33
+ });
34
+ export * from './definitions';
35
+ export { HttpLocalServerSwifter };
36
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,sBAAsB,GAAG,cAAc,CAA+B,wBAAwB,EAAE;IACpG,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,yBAAyB,EAAE,CAAC;CACxE,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,sBAAsB,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\nimport type { HttpLocalServerSwifterPlugin } from './definitions';\n\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<HttpLocalServerSwifterPlugin>('HttpLocalServerSwifter', {\n web: () => import('./web').then(m => new m.HttpLocalServerSwifterWeb()),\n});\n\nexport * from './definitions';\nexport { HttpLocalServerSwifter };"]}
@@ -0,0 +1,14 @@
1
+ import { WebPlugin } from '@capacitor/core';
2
+ import type { HttpLocalServerSwifterPlugin, HttpConnectResult, HttpSendResponseOptions } from './definitions';
3
+ /**
4
+ * Implementación web (mock) del plugin HttpLocalServerSwifter.
5
+ *
6
+ * Proporciona funcionalidad simulada para desarrollo en navegador.
7
+ * El servidor real solo funciona en dispositivos iOS/Android nativos.
8
+ */
9
+ export declare class HttpLocalServerSwifterWeb extends WebPlugin implements HttpLocalServerSwifterPlugin {
10
+ private isRunning;
11
+ connect(): Promise<HttpConnectResult>;
12
+ disconnect(): Promise<void>;
13
+ sendResponse(options: HttpSendResponseOptions): Promise<void>;
14
+ }
@@ -0,0 +1,49 @@
1
+ import { WebPlugin } from '@capacitor/core';
2
+ /**
3
+ * Implementación web (mock) del plugin HttpLocalServerSwifter.
4
+ *
5
+ * Proporciona funcionalidad simulada para desarrollo en navegador.
6
+ * El servidor real solo funciona en dispositivos iOS/Android nativos.
7
+ */
8
+ export class HttpLocalServerSwifterWeb extends WebPlugin {
9
+ constructor() {
10
+ super(...arguments);
11
+ this.isRunning = false;
12
+ }
13
+ async connect() {
14
+ if (this.isRunning) {
15
+ console.warn('[HttpLocalServerSwifter Web] El servidor ya está ejecutándose (Mock).');
16
+ return { ip: '127.0.0.1', port: 8080 };
17
+ }
18
+ console.warn('[HttpLocalServerSwifter Web] El servidor HTTP nativo no está disponible en navegador.\n' +
19
+ 'Retornando valores mock para desarrollo.\n' +
20
+ 'Para funcionalidad real, ejecuta en un dispositivo iOS/Android.');
21
+ this.isRunning = true;
22
+ return {
23
+ ip: '127.0.0.1',
24
+ port: 8080
25
+ };
26
+ }
27
+ async disconnect() {
28
+ if (!this.isRunning) {
29
+ console.log('[HttpLocalServerSwifter Web] El servidor ya está detenido (Mock).');
30
+ return;
31
+ }
32
+ console.log('[HttpLocalServerSwifter Web] Servidor detenido (Mock).');
33
+ this.isRunning = false;
34
+ }
35
+ async sendResponse(options) {
36
+ if (!this.isRunning) {
37
+ throw new Error('Server is not running. Call connect() first.');
38
+ }
39
+ const { requestId, body } = options;
40
+ if (!requestId) {
41
+ throw new Error('Missing requestId');
42
+ }
43
+ if (!body) {
44
+ throw new Error('Missing body');
45
+ }
46
+ console.log(`[HttpLocalServerSwifter Web] Mock response sent for requestId: ${requestId}`, '\nBody preview:', body.substring(0, 100) + (body.length > 100 ? '...' : ''));
47
+ }
48
+ }
49
+ //# sourceMappingURL=web.js.map
@@ -0,0 +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}"]}