mirror of
https://github.com/osnr/TabFS.git
synced 2024-04-27 11:41:54 +02:00
safari: successfully exchanges 1 req/resp over ws, then fails
This commit is contained in:
parent
7211a5fdea
commit
4fdcf4be9d
|
@ -38,13 +38,13 @@ class SafariWebExtensionHandler: NSObject, NSExtensionRequestHandling {
|
||||||
// need this one XPC call to actually initialize the service
|
// need this one XPC call to actually initialize the service
|
||||||
service?.upperCaseString("hello XPC") { response in
|
service?.upperCaseString("hello XPC") { response in
|
||||||
os_log(.default, "Response from XPC service: %{public}@", response)
|
os_log(.default, "Response from XPC service: %{public}@", response)
|
||||||
}
|
|
||||||
|
// FIXME: report port back?
|
||||||
// FIXME: report port back?
|
let response = NSExtensionItem()
|
||||||
let response = NSExtensionItem()
|
response.userInfo = [ "message": [ "aResponse to": "moop" ] ]
|
||||||
response.userInfo = [ "message": [ "aResponse to": "moop" ] ]
|
context.completeRequest(returningItems: [response]) { (what) in
|
||||||
context.completeRequest(returningItems: [response]) { (what) in
|
print(what)
|
||||||
print(what)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
Binary file not shown.
|
@ -34,7 +34,6 @@ class TabFSService: NSObject, TabFSServiceProtocol {
|
||||||
|
|
||||||
var ws: NWListener!
|
var ws: NWListener!
|
||||||
func startWs() {
|
func startWs() {
|
||||||
// websocket server
|
|
||||||
let port = NWEndpoint.Port(rawValue: 9991)!
|
let port = NWEndpoint.Port(rawValue: 9991)!
|
||||||
let parameters = NWParameters(tls: nil)
|
let parameters = NWParameters(tls: nil)
|
||||||
parameters.allowLocalEndpointReuse = true
|
parameters.allowLocalEndpointReuse = true
|
||||||
|
@ -56,9 +55,13 @@ class TabFSService: NSObject, TabFSServiceProtocol {
|
||||||
var handleRequest: ((_ req: Data) -> Void)?
|
var handleRequest: ((_ req: Data) -> Void)?
|
||||||
ws.newConnectionHandler = { conn in
|
ws.newConnectionHandler = { conn in
|
||||||
conn.start(queue: .main)
|
conn.start(queue: .main)
|
||||||
|
|
||||||
handleRequest = { req in
|
handleRequest = { req in
|
||||||
conn.send(content: req, completion: .contentProcessed({ err in
|
let metaData = NWProtocolWebSocket.Metadata(opcode: .text)
|
||||||
|
let context = NWConnection.ContentContext(identifier: "context", metadata: [metaData])
|
||||||
|
conn.send(content: req, contentContext: context, completion: .contentProcessed({ err in
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
os_log(.default, "%{public}@ error: %{public}@", String(data: req, encoding: .utf8) as! CVarArg, err!.debugDescription as CVarArg)
|
||||||
// FIXME: ERROR
|
// FIXME: ERROR
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
|
|
Loading…
Reference in a new issue