Closed
Description
I've set up a JSBridgeClass for the WebSocket class using the following code, but I get "TypeError: 'send' called on an object that does not implement WebSocket" or "expression unexpectedly raised an error: TypeError: Can only call WebSocket.send on instances of WebSocket: file JavaScriptKit/JSFunction.swift, line"
class WebSocket: JSBridgedClass {
public class var constructor: JSFunction { JSObject.global.WebSocket.function! }
public convenience init(uri: String) {
print("trying to connect to: \(uri)")
self.init(unsafelyWrapping: Self.constructor.new(uri)) //This works, my server connects
}
public func sendMessage(data: Data) {
if let string = String(data: data, encoding: .ascii) {
//Tried Importing DOMKit to use Blob
//let l = BufferSourceOrBlobOrString.string(string)
//let blob = Blob(blobParts: [l])
if let function = self.jsObject.send.function {
function(string) //TypeError: 'send' called on an object that does not implement interface
//function(blob.jsObject)
function("MAYBE THIS WILL WORK?") //TypeError: 'send' called on an object that does not implement interface
}
}
}
}
I would appreciate some direction 😩 . Perhaps I am misunderstanding how to implement JSBridgedClass properly.
Metadata
Metadata
Assignees
Labels
No labels