You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
The problem here is that let function = self.jsObject.send.function returns an unbound function, meaning that calling it will not properly set the this value on the JS side. Since you’re requiring the jsObject to be an instance of WebSocket, this code should work:
publicfunc sendMessage(data:Data){iflet string =String(data: data, encoding:.ascii){
//Tried Importing DOMKit to use Blob
//let blob = Blob(blobParts: [.string(string)])
jsObject.send(string)}}
Fatal error: 'try!' expression unexpectedly raised an error: InvalidStateError: The object is in an invalid state.: file JavaScriptKit/JSFunction.swift, line 22
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"
I would appreciate some direction 😩 . Perhaps I am misunderstanding how to implement JSBridgedClass properly.
The text was updated successfully, but these errors were encountered: