@cappitolian/http-local-server 0.0.7 → 0.0.9
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/android/src/main/java/com/cappitolian/plugins/httplocalserver/HttpLocalServer.java +306 -108
- package/android/src/main/java/com/cappitolian/plugins/httplocalserver/HttpLocalServerPlugin.java +47 -11
- package/dist/docs.json +115 -19
- package/dist/esm/definitions.d.ts +35 -6
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/index.d.ts +24 -3
- package/dist/esm/index.js +24 -6
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/web.d.ts +7 -5
- package/dist/esm/web.js +36 -4
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +60 -7
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +60 -7
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/HttpLocalServerPlugin/HttpLocalServer.swift +274 -96
- package/package.json +1 -1
package/dist/docs.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"api": {
|
|
3
3
|
"name": "HttpLocalServerPlugin",
|
|
4
4
|
"slug": "httplocalserverplugin",
|
|
5
|
-
"docs": "",
|
|
5
|
+
"docs": "Plugin para manejar un servidor HTTP local en dispositivos nativos",
|
|
6
6
|
"tags": [],
|
|
7
7
|
"methods": [
|
|
8
8
|
{
|
|
@@ -10,7 +10,16 @@
|
|
|
10
10
|
"signature": "() => Promise<HttpConnectResult>",
|
|
11
11
|
"parameters": [],
|
|
12
12
|
"returns": "Promise<HttpConnectResult>",
|
|
13
|
-
"tags": [
|
|
13
|
+
"tags": [
|
|
14
|
+
{
|
|
15
|
+
"name": "returns",
|
|
16
|
+
"text": "Promesa con la IP y puerto del servidor"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"name": "throws",
|
|
20
|
+
"text": "Error si el servidor no puede iniciarse"
|
|
21
|
+
}
|
|
22
|
+
],
|
|
14
23
|
"docs": "Inicia el servidor local en el dispositivo nativo.\nDevuelve la IP y el puerto asignado.",
|
|
15
24
|
"complexTypes": [
|
|
16
25
|
"HttpConnectResult"
|
|
@@ -22,25 +31,45 @@
|
|
|
22
31
|
"signature": "() => Promise<void>",
|
|
23
32
|
"parameters": [],
|
|
24
33
|
"returns": "Promise<void>",
|
|
25
|
-
"tags": [
|
|
26
|
-
|
|
34
|
+
"tags": [
|
|
35
|
+
{
|
|
36
|
+
"name": "returns",
|
|
37
|
+
"text": "Promesa que se resuelve cuando el servidor se detiene"
|
|
38
|
+
}
|
|
39
|
+
],
|
|
40
|
+
"docs": "Detiene el servidor local y limpia todos los recursos.",
|
|
27
41
|
"complexTypes": [],
|
|
28
42
|
"slug": "disconnect"
|
|
29
43
|
},
|
|
30
44
|
{
|
|
31
45
|
"name": "sendResponse",
|
|
32
|
-
"signature": "(options:
|
|
46
|
+
"signature": "(options: HttpSendResponseOptions) => Promise<void>",
|
|
33
47
|
"parameters": [
|
|
34
48
|
{
|
|
35
49
|
"name": "options",
|
|
36
|
-
"docs": "",
|
|
37
|
-
"type": "
|
|
50
|
+
"docs": "- Objeto con requestId y body de la respuesta",
|
|
51
|
+
"type": "HttpSendResponseOptions"
|
|
38
52
|
}
|
|
39
53
|
],
|
|
40
54
|
"returns": "Promise<void>",
|
|
41
|
-
"tags": [
|
|
55
|
+
"tags": [
|
|
56
|
+
{
|
|
57
|
+
"name": "param",
|
|
58
|
+
"text": "options - Objeto con requestId y body de la respuesta"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"name": "returns",
|
|
62
|
+
"text": "Promesa que se resuelve cuando la respuesta se envía"
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"name": "throws",
|
|
66
|
+
"text": "Error si faltan requestId o body"
|
|
67
|
+
}
|
|
68
|
+
],
|
|
42
69
|
"docs": "Envía la respuesta de vuelta al cliente que hizo la petición.\nEl requestId debe coincidir con el recibido en 'onRequest'.",
|
|
43
|
-
"complexTypes": [
|
|
70
|
+
"complexTypes": [
|
|
71
|
+
"HttpSendResponseOptions"
|
|
72
|
+
],
|
|
44
73
|
"slug": "sendresponse"
|
|
45
74
|
},
|
|
46
75
|
{
|
|
@@ -49,17 +78,30 @@
|
|
|
49
78
|
"parameters": [
|
|
50
79
|
{
|
|
51
80
|
"name": "eventName",
|
|
52
|
-
"docs": "",
|
|
81
|
+
"docs": "- Debe ser 'onRequest'",
|
|
53
82
|
"type": "'onRequest'"
|
|
54
83
|
},
|
|
55
84
|
{
|
|
56
85
|
"name": "listenerFunc",
|
|
57
|
-
"docs": "",
|
|
86
|
+
"docs": "- Callback que recibe los datos de la petición",
|
|
58
87
|
"type": "(data: HttpRequestData) => void"
|
|
59
88
|
}
|
|
60
89
|
],
|
|
61
90
|
"returns": "Promise<PluginListenerHandle>",
|
|
62
|
-
"tags": [
|
|
91
|
+
"tags": [
|
|
92
|
+
{
|
|
93
|
+
"name": "param",
|
|
94
|
+
"text": "eventName - Debe ser 'onRequest'"
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
"name": "param",
|
|
98
|
+
"text": "listenerFunc - Callback que recibe los datos de la petición"
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
"name": "returns",
|
|
102
|
+
"text": "Handle para remover el listener"
|
|
103
|
+
}
|
|
104
|
+
],
|
|
63
105
|
"docs": "Escucha las peticiones HTTP entrantes.",
|
|
64
106
|
"complexTypes": [
|
|
65
107
|
"PluginListenerHandle",
|
|
@@ -72,7 +114,12 @@
|
|
|
72
114
|
"signature": "() => Promise<void>",
|
|
73
115
|
"parameters": [],
|
|
74
116
|
"returns": "Promise<void>",
|
|
75
|
-
"tags": [
|
|
117
|
+
"tags": [
|
|
118
|
+
{
|
|
119
|
+
"name": "returns",
|
|
120
|
+
"text": "Promesa que se resuelve cuando se eliminan los listeners"
|
|
121
|
+
}
|
|
122
|
+
],
|
|
76
123
|
"docs": "Elimina todos los listeners registrados.",
|
|
77
124
|
"complexTypes": [],
|
|
78
125
|
"slug": "removealllisteners"
|
|
@@ -84,7 +131,7 @@
|
|
|
84
131
|
{
|
|
85
132
|
"name": "HttpConnectResult",
|
|
86
133
|
"slug": "httpconnectresult",
|
|
87
|
-
"docs": "",
|
|
134
|
+
"docs": "Resultado de la conexión del servidor",
|
|
88
135
|
"tags": [],
|
|
89
136
|
"methods": [],
|
|
90
137
|
"properties": [
|
|
@@ -104,6 +151,29 @@
|
|
|
104
151
|
}
|
|
105
152
|
]
|
|
106
153
|
},
|
|
154
|
+
{
|
|
155
|
+
"name": "HttpSendResponseOptions",
|
|
156
|
+
"slug": "httpsendresponseoptions",
|
|
157
|
+
"docs": "Opciones para enviar una respuesta",
|
|
158
|
+
"tags": [],
|
|
159
|
+
"methods": [],
|
|
160
|
+
"properties": [
|
|
161
|
+
{
|
|
162
|
+
"name": "requestId",
|
|
163
|
+
"tags": [],
|
|
164
|
+
"docs": "",
|
|
165
|
+
"complexTypes": [],
|
|
166
|
+
"type": "string"
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
"name": "body",
|
|
170
|
+
"tags": [],
|
|
171
|
+
"docs": "",
|
|
172
|
+
"complexTypes": [],
|
|
173
|
+
"type": "string"
|
|
174
|
+
}
|
|
175
|
+
]
|
|
176
|
+
},
|
|
107
177
|
{
|
|
108
178
|
"name": "PluginListenerHandle",
|
|
109
179
|
"slug": "pluginlistenerhandle",
|
|
@@ -123,7 +193,7 @@
|
|
|
123
193
|
{
|
|
124
194
|
"name": "HttpRequestData",
|
|
125
195
|
"slug": "httprequestdata",
|
|
126
|
-
"docs": "",
|
|
196
|
+
"docs": "Datos de una petición HTTP entrante",
|
|
127
197
|
"tags": [],
|
|
128
198
|
"methods": [],
|
|
129
199
|
"properties": [
|
|
@@ -153,19 +223,45 @@
|
|
|
153
223
|
"tags": [],
|
|
154
224
|
"docs": "",
|
|
155
225
|
"complexTypes": [],
|
|
156
|
-
"type": "string"
|
|
226
|
+
"type": "string | undefined"
|
|
157
227
|
},
|
|
158
228
|
{
|
|
159
229
|
"name": "headers",
|
|
160
230
|
"tags": [],
|
|
161
231
|
"docs": "",
|
|
162
|
-
"complexTypes": [
|
|
163
|
-
|
|
232
|
+
"complexTypes": [
|
|
233
|
+
"Record"
|
|
234
|
+
],
|
|
235
|
+
"type": "Record<string, string>"
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
"name": "query",
|
|
239
|
+
"tags": [],
|
|
240
|
+
"docs": "",
|
|
241
|
+
"complexTypes": [
|
|
242
|
+
"Record"
|
|
243
|
+
],
|
|
244
|
+
"type": "Record<string, string>"
|
|
164
245
|
}
|
|
165
246
|
]
|
|
166
247
|
}
|
|
167
248
|
],
|
|
168
249
|
"enums": [],
|
|
169
|
-
"typeAliases": [
|
|
250
|
+
"typeAliases": [
|
|
251
|
+
{
|
|
252
|
+
"name": "Record",
|
|
253
|
+
"slug": "record",
|
|
254
|
+
"docs": "Construct a type with a set of properties K of type T",
|
|
255
|
+
"types": [
|
|
256
|
+
{
|
|
257
|
+
"text": "{\r\n [P in K]: T;\r\n}",
|
|
258
|
+
"complexTypes": [
|
|
259
|
+
"K",
|
|
260
|
+
"T"
|
|
261
|
+
]
|
|
262
|
+
}
|
|
263
|
+
]
|
|
264
|
+
}
|
|
265
|
+
],
|
|
170
266
|
"pluginConfigs": []
|
|
171
267
|
}
|
|
@@ -1,39 +1,68 @@
|
|
|
1
1
|
import type { PluginListenerHandle } from '@capacitor/core';
|
|
2
|
+
/**
|
|
3
|
+
* Resultado de la conexión del servidor
|
|
4
|
+
*/
|
|
2
5
|
export interface HttpConnectResult {
|
|
3
6
|
ip: string;
|
|
4
7
|
port: number;
|
|
5
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Datos de una petición HTTP entrante
|
|
11
|
+
*/
|
|
6
12
|
export interface HttpRequestData {
|
|
7
13
|
requestId: string;
|
|
8
14
|
method: string;
|
|
9
15
|
path: string;
|
|
16
|
+
body?: string;
|
|
17
|
+
headers?: Record<string, string>;
|
|
18
|
+
query?: Record<string, string>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Opciones para enviar una respuesta
|
|
22
|
+
*/
|
|
23
|
+
export interface HttpSendResponseOptions {
|
|
24
|
+
requestId: string;
|
|
10
25
|
body: string;
|
|
11
|
-
headers?: any;
|
|
12
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Plugin para manejar un servidor HTTP local en dispositivos nativos
|
|
29
|
+
*/
|
|
13
30
|
export interface HttpLocalServerPlugin {
|
|
14
31
|
/**
|
|
15
32
|
* Inicia el servidor local en el dispositivo nativo.
|
|
16
33
|
* Devuelve la IP y el puerto asignado.
|
|
34
|
+
*
|
|
35
|
+
* @returns Promesa con la IP y puerto del servidor
|
|
36
|
+
* @throws Error si el servidor no puede iniciarse
|
|
17
37
|
*/
|
|
18
38
|
connect(): Promise<HttpConnectResult>;
|
|
19
39
|
/**
|
|
20
|
-
* Detiene el servidor local.
|
|
40
|
+
* Detiene el servidor local y limpia todos los recursos.
|
|
41
|
+
*
|
|
42
|
+
* @returns Promesa que se resuelve cuando el servidor se detiene
|
|
21
43
|
*/
|
|
22
44
|
disconnect(): Promise<void>;
|
|
23
45
|
/**
|
|
24
46
|
* Envía la respuesta de vuelta al cliente que hizo la petición.
|
|
25
47
|
* El requestId debe coincidir con el recibido en 'onRequest'.
|
|
48
|
+
*
|
|
49
|
+
* @param options - Objeto con requestId y body de la respuesta
|
|
50
|
+
* @returns Promesa que se resuelve cuando la respuesta se envía
|
|
51
|
+
* @throws Error si faltan requestId o body
|
|
26
52
|
*/
|
|
27
|
-
sendResponse(options:
|
|
28
|
-
requestId: string;
|
|
29
|
-
body: string;
|
|
30
|
-
}): Promise<void>;
|
|
53
|
+
sendResponse(options: HttpSendResponseOptions): Promise<void>;
|
|
31
54
|
/**
|
|
32
55
|
* Escucha las peticiones HTTP entrantes.
|
|
56
|
+
*
|
|
57
|
+
* @param eventName - Debe ser 'onRequest'
|
|
58
|
+
* @param listenerFunc - Callback que recibe los datos de la petición
|
|
59
|
+
* @returns Handle para remover el listener
|
|
33
60
|
*/
|
|
34
61
|
addListener(eventName: 'onRequest', listenerFunc: (data: HttpRequestData) => void): Promise<PluginListenerHandle>;
|
|
35
62
|
/**
|
|
36
63
|
* Elimina todos los listeners registrados.
|
|
64
|
+
*
|
|
65
|
+
* @returns Promesa que se resuelve cuando se eliminan los listeners
|
|
37
66
|
*/
|
|
38
67
|
removeAllListeners(): Promise<void>;
|
|
39
68
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\n\nexport interface HttpConnectResult {\n ip: string;\n port: number;\n}\n\nexport interface HttpRequestData {\n requestId: string;\n method: string;\n path: string;\n body
|
|
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\n */\nexport interface HttpConnectResult {\n ip: string;\n port: number;\n}\n\n/**\n * Datos de una petición HTTP entrante\n */\nexport interface HttpRequestData {\n requestId: string;\n method: string;\n path: string;\n body?: string; // Ahora es opcional (GET/DELETE no tienen body)\n headers?: Record<string, string>; // Mejor tipado que 'any'\n query?: Record<string, string>; // Agregado: query parameters\n}\n\n/**\n * Opciones para enviar una respuesta\n */\nexport interface HttpSendResponseOptions {\n requestId: string;\n body: string;\n}\n\n/**\n * Plugin para manejar un servidor HTTP local en dispositivos nativos\n */\nexport interface HttpLocalServerPlugin {\n /**\n * Inicia el servidor local en el dispositivo nativo.\n * Devuelve la IP y el puerto asignado.\n * \n * @returns Promesa con la IP y puerto del servidor\n * @throws Error si el servidor no puede iniciarse\n */\n connect(): Promise<HttpConnectResult>;\n\n /**\n * Detiene el servidor local y limpia todos los recursos.\n * \n * @returns Promesa que se resuelve cuando el servidor se detiene\n */\n disconnect(): Promise<void>;\n\n /**\n * Envía la respuesta de vuelta al cliente que hizo la petición.\n * El requestId debe coincidir con el recibido en 'onRequest'.\n * \n * @param options - Objeto con requestId y body 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 sendResponse(options: HttpSendResponseOptions): Promise<void>;\n\n /**\n * Escucha las peticiones HTTP entrantes.\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\n */\n addListener(\n eventName: 'onRequest',\n listenerFunc: (data: HttpRequestData) => void\n ): Promise<PluginListenerHandle>;\n\n /**\n * Elimina todos los listeners registrados.\n * \n * @returns Promesa que se resuelve cuando se eliminan los listeners\n */\n removeAllListeners(): Promise<void>;\n}"]}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,8 +1,29 @@
|
|
|
1
1
|
import type { HttpLocalServerPlugin } from './definitions';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
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.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { HttpLocalServer } from '@cappitolian/http-local-server';
|
|
11
|
+
*
|
|
12
|
+
* // Iniciar servidor
|
|
13
|
+
* const { ip, port } = await HttpLocalServer.connect();
|
|
14
|
+
* console.log(`Servidor en http://${ip}:${port}`);
|
|
15
|
+
*
|
|
16
|
+
* // Escuchar peticiones
|
|
17
|
+
* await HttpLocalServer.addListener('onRequest', async (data) => {
|
|
18
|
+
* console.log('Petición recibida:', data);
|
|
19
|
+
*
|
|
20
|
+
* // Procesar y responder
|
|
21
|
+
* await HttpLocalServer.sendResponse({
|
|
22
|
+
* requestId: data.requestId,
|
|
23
|
+
* body: JSON.stringify({ success: true })
|
|
24
|
+
* });
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
6
27
|
*/
|
|
7
28
|
declare const HttpLocalServer: HttpLocalServerPlugin;
|
|
8
29
|
export * from './definitions';
|
package/dist/esm/index.js
CHANGED
|
@@ -1,16 +1,34 @@
|
|
|
1
1
|
import { registerPlugin } from '@capacitor/core';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
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.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { HttpLocalServer } from '@cappitolian/http-local-server';
|
|
11
|
+
*
|
|
12
|
+
* // Iniciar servidor
|
|
13
|
+
* const { ip, port } = await HttpLocalServer.connect();
|
|
14
|
+
* console.log(`Servidor en http://${ip}:${port}`);
|
|
15
|
+
*
|
|
16
|
+
* // Escuchar peticiones
|
|
17
|
+
* await HttpLocalServer.addListener('onRequest', async (data) => {
|
|
18
|
+
* console.log('Petición recibida:', data);
|
|
19
|
+
*
|
|
20
|
+
* // Procesar y responder
|
|
21
|
+
* await HttpLocalServer.sendResponse({
|
|
22
|
+
* requestId: data.requestId,
|
|
23
|
+
* body: JSON.stringify({ success: true })
|
|
24
|
+
* });
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
6
27
|
*/
|
|
7
28
|
const HttpLocalServer = registerPlugin('HttpLocalServer', {
|
|
8
29
|
web: () => import('./web').then(m => new m.HttpLocalServerWeb()),
|
|
9
30
|
});
|
|
10
|
-
// Exportamos las interfaces para que el usuario pueda tipar sus variables
|
|
11
31
|
export * from './definitions';
|
|
12
|
-
// Exportamos el objeto del plugin
|
|
13
32
|
export { HttpLocalServer };
|
|
14
|
-
// Exportación por defecto opcional para mayor compatibilidad
|
|
15
33
|
export default HttpLocalServer;
|
|
16
34
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGjD
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGjD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,eAAe,GAAG,cAAc,CAAwB,iBAAiB,EAAE;IAC/E,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,kBAAkB,EAAE,CAAC;CACjE,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,eAAe,EAAE,CAAC;AAC3B,eAAe,eAAe,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\nimport type { HttpLocalServerPlugin } 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.\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<HttpLocalServerPlugin>('HttpLocalServer', {\n web: () => import('./web').then(m => new m.HttpLocalServerWeb()),\n});\n\nexport * from './definitions';\nexport { HttpLocalServer };\nexport default HttpLocalServer;"]}
|
package/dist/esm/web.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { WebPlugin } from '@capacitor/core';
|
|
2
|
-
import type { HttpLocalServerPlugin, HttpConnectResult } from './definitions';
|
|
2
|
+
import type { HttpLocalServerPlugin, HttpConnectResult, HttpSendResponseOptions } from './definitions';
|
|
3
|
+
/**
|
|
4
|
+
* Implementación web del plugin HttpLocalServer.
|
|
5
|
+
* Proporciona funcionalidad mock para desarrollo en navegador.
|
|
6
|
+
*/
|
|
3
7
|
export declare class HttpLocalServerWeb extends WebPlugin implements HttpLocalServerPlugin {
|
|
8
|
+
private isRunning;
|
|
4
9
|
connect(): Promise<HttpConnectResult>;
|
|
5
10
|
disconnect(): Promise<void>;
|
|
6
|
-
sendResponse(options:
|
|
7
|
-
requestId: string;
|
|
8
|
-
body: string;
|
|
9
|
-
}): Promise<void>;
|
|
11
|
+
sendResponse(options: HttpSendResponseOptions): Promise<void>;
|
|
10
12
|
}
|
package/dist/esm/web.js
CHANGED
|
@@ -1,15 +1,47 @@
|
|
|
1
1
|
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
/**
|
|
3
|
+
* Implementación web del plugin HttpLocalServer.
|
|
4
|
+
* Proporciona funcionalidad mock para desarrollo en navegador.
|
|
5
|
+
*/
|
|
2
6
|
export class HttpLocalServerWeb extends WebPlugin {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
|
+
this.isRunning = false;
|
|
10
|
+
}
|
|
3
11
|
async connect() {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
12
|
+
if (this.isRunning) {
|
|
13
|
+
console.warn('HttpLocalServer: El servidor ya está ejecutándose (Mock).');
|
|
14
|
+
return { ip: '127.0.0.1', port: 8080 };
|
|
15
|
+
}
|
|
16
|
+
console.warn('HttpLocalServer: El servidor nativo no está disponible en navegador. ' +
|
|
17
|
+
'Retornando valores mock para desarrollo.');
|
|
18
|
+
this.isRunning = true;
|
|
19
|
+
return {
|
|
20
|
+
ip: '127.0.0.1',
|
|
21
|
+
port: 8080
|
|
22
|
+
};
|
|
7
23
|
}
|
|
8
24
|
async disconnect() {
|
|
25
|
+
if (!this.isRunning) {
|
|
26
|
+
console.log('HttpLocalServer: El servidor ya está detenido (Mock).');
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
9
29
|
console.log('HttpLocalServer: Servidor detenido (Mock).');
|
|
30
|
+
this.isRunning = false;
|
|
10
31
|
}
|
|
11
32
|
async sendResponse(options) {
|
|
12
|
-
|
|
33
|
+
if (!this.isRunning) {
|
|
34
|
+
console.warn('HttpLocalServer: El servidor no está ejecutándose (Mock).');
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const { requestId, body } = options;
|
|
38
|
+
if (!requestId) {
|
|
39
|
+
throw new Error('Missing requestId');
|
|
40
|
+
}
|
|
41
|
+
if (!body) {
|
|
42
|
+
throw new Error('Missing body');
|
|
43
|
+
}
|
|
44
|
+
console.log(`HttpLocalServer: Respuesta mock enviada para requestId: ${requestId}`, '\nBody:', body.substring(0, 100) + (body.length > 100 ? '...' : ''));
|
|
13
45
|
}
|
|
14
46
|
}
|
|
15
47
|
//# sourceMappingURL=web.js.map
|
package/dist/esm/web.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAO5C;;;GAGG;AACH,MAAM,OAAO,kBAAmB,SAAQ,SAAS;IAAjD;;QAEU,cAAS,GAAG,KAAK,CAAC;IAoD5B,CAAC;IAlDC,KAAK,CAAC,OAAO;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,CACrE,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\nimport type {\n HttpLocalServerPlugin,\n HttpConnectResult,\n HttpSendResponseOptions\n} from './definitions';\n\n/**\n * Implementación web del plugin HttpLocalServer.\n * Proporciona funcionalidad mock para desarrollo en navegador.\n */\nexport class HttpLocalServerWeb extends WebPlugin implements HttpLocalServerPlugin {\n\n private isRunning = false;\n\n async connect(): Promise<HttpConnectResult> {\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\n console.warn(\n 'HttpLocalServer: El servidor nativo no está disponible en navegador. ' +\n 'Retornando valores mock para desarrollo.'\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('HttpLocalServer: El servidor ya está detenido (Mock).');\n return;\n }\n\n console.log('HttpLocalServer: Servidor detenido (Mock).');\n this.isRunning = false;\n }\n\n async sendResponse(options: HttpSendResponseOptions): Promise<void> {\n if (!this.isRunning) {\n console.warn('HttpLocalServer: El servidor no está ejecutándose (Mock).');\n return;\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 `HttpLocalServer: Respuesta mock enviada para requestId: ${requestId}`,\n '\\nBody:', body.substring(0, 100) + (body.length > 100 ? '...' : '')\n );\n }\n}"]}
|
package/dist/plugin.cjs.js
CHANGED
|
@@ -5,25 +5,78 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var core = require('@capacitor/core');
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* Plugin de servidor HTTP local para Android e iOS.
|
|
9
|
+
*
|
|
10
|
+
* Permite crear un servidor HTTP en el dispositivo que puede recibir
|
|
11
|
+
* peticiones desde otros dispositivos en la misma red.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { HttpLocalServer } from '@cappitolian/http-local-server';
|
|
16
|
+
*
|
|
17
|
+
* // Iniciar servidor
|
|
18
|
+
* const { ip, port } = await HttpLocalServer.connect();
|
|
19
|
+
* console.log(`Servidor en http://${ip}:${port}`);
|
|
20
|
+
*
|
|
21
|
+
* // Escuchar peticiones
|
|
22
|
+
* await HttpLocalServer.addListener('onRequest', async (data) => {
|
|
23
|
+
* console.log('Petición recibida:', data);
|
|
24
|
+
*
|
|
25
|
+
* // Procesar y responder
|
|
26
|
+
* await HttpLocalServer.sendResponse({
|
|
27
|
+
* requestId: data.requestId,
|
|
28
|
+
* body: JSON.stringify({ success: true })
|
|
29
|
+
* });
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
11
32
|
*/
|
|
12
33
|
const HttpLocalServer = core.registerPlugin('HttpLocalServer', {
|
|
13
34
|
web: () => Promise.resolve().then(function () { return web; }).then(m => new m.HttpLocalServerWeb()),
|
|
14
35
|
});
|
|
15
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Implementación web del plugin HttpLocalServer.
|
|
39
|
+
* Proporciona funcionalidad mock para desarrollo en navegador.
|
|
40
|
+
*/
|
|
16
41
|
class HttpLocalServerWeb extends core.WebPlugin {
|
|
42
|
+
constructor() {
|
|
43
|
+
super(...arguments);
|
|
44
|
+
this.isRunning = false;
|
|
45
|
+
}
|
|
17
46
|
async connect() {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
47
|
+
if (this.isRunning) {
|
|
48
|
+
console.warn('HttpLocalServer: El servidor ya está ejecutándose (Mock).');
|
|
49
|
+
return { ip: '127.0.0.1', port: 8080 };
|
|
50
|
+
}
|
|
51
|
+
console.warn('HttpLocalServer: El servidor nativo no está disponible en navegador. ' +
|
|
52
|
+
'Retornando valores mock para desarrollo.');
|
|
53
|
+
this.isRunning = true;
|
|
54
|
+
return {
|
|
55
|
+
ip: '127.0.0.1',
|
|
56
|
+
port: 8080
|
|
57
|
+
};
|
|
21
58
|
}
|
|
22
59
|
async disconnect() {
|
|
60
|
+
if (!this.isRunning) {
|
|
61
|
+
console.log('HttpLocalServer: El servidor ya está detenido (Mock).');
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
23
64
|
console.log('HttpLocalServer: Servidor detenido (Mock).');
|
|
65
|
+
this.isRunning = false;
|
|
24
66
|
}
|
|
25
67
|
async sendResponse(options) {
|
|
26
|
-
|
|
68
|
+
if (!this.isRunning) {
|
|
69
|
+
console.warn('HttpLocalServer: El servidor no está ejecutándose (Mock).');
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const { requestId, body } = options;
|
|
73
|
+
if (!requestId) {
|
|
74
|
+
throw new Error('Missing requestId');
|
|
75
|
+
}
|
|
76
|
+
if (!body) {
|
|
77
|
+
throw new Error('Missing body');
|
|
78
|
+
}
|
|
79
|
+
console.log(`HttpLocalServer: Respuesta mock enviada para requestId: ${requestId}`, '\nBody:', body.substring(0, 100) + (body.length > 100 ? '...' : ''));
|
|
27
80
|
}
|
|
28
81
|
}
|
|
29
82
|
|
package/dist/plugin.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\n/**\n *
|
|
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.\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":";;;;;;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,M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