@cappitolian/http-local-server-swifter 0.0.15 → 0.0.16
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.
|
@@ -23,15 +23,25 @@ public protocol HttpLocalServerSwifterDelegate: AnyObject {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
@objc public func connect(_ call: CAPPluginCall) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
26
|
+
// Run server startup in a background thread to avoid blocking the Main/UI thread
|
|
27
|
+
DispatchQueue.global(qos: .userInitiated).async {
|
|
28
|
+
self.disconnect()
|
|
29
|
+
self.webServer = HttpServer()
|
|
30
|
+
self.setupHandlers()
|
|
31
|
+
|
|
32
|
+
do {
|
|
33
|
+
try self.webServer?.start(self.defaultPort, forceIPv4: true)
|
|
34
|
+
let ip = Self.getWiFiAddress() ?? "127.0.0.1"
|
|
35
|
+
|
|
36
|
+
// Resolve the promise back to JS
|
|
37
|
+
call.resolve([
|
|
38
|
+
"ip": ip,
|
|
39
|
+
"port": Int(self.defaultPort)
|
|
40
|
+
])
|
|
41
|
+
print("🚀 Server started on \(ip):\(self.defaultPort)")
|
|
42
|
+
} catch {
|
|
43
|
+
call.reject("Failed to start server: \(error.localizedDescription)")
|
|
44
|
+
}
|
|
35
45
|
}
|
|
36
46
|
}
|
|
37
47
|
|
|
@@ -98,10 +108,13 @@ public protocol HttpLocalServerSwifterDelegate: AnyObject {
|
|
|
98
108
|
|
|
99
109
|
DispatchQueue.main.async { self.delegate?.httpLocalServerSwifterDidReceiveRequest(requestData) }
|
|
100
110
|
|
|
101
|
-
|
|
102
|
-
|
|
111
|
+
// Inside HttpLocalServerSwifter.swift -> processRequest
|
|
112
|
+
let result = semaphore.wait(timeout: .now() + 5.0) // Lower timeout to 5 seconds for testing
|
|
113
|
+
|
|
103
114
|
if result == .timedOut {
|
|
104
|
-
|
|
115
|
+
print("⚠️ Request \(requestId) timed out waiting for JS")
|
|
116
|
+
Self.queue.async { Self.pendingResponses.removeValue(forKey: requestId) }
|
|
117
|
+
return .raw(408, "Request Timeout", nil, nil)
|
|
105
118
|
}
|
|
106
119
|
|
|
107
120
|
return createDynamicResponse(responseString ?? "{\"error\":\"no_response\"}")
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cappitolian/http-local-server-swifter",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.16",
|
|
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",
|