-
Notifications
You must be signed in to change notification settings - Fork 289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WebSocket support #124
WebSocket support #124
Conversation
I did some initial investigation on why the export function __wbg_setonmessage_8bf4fad923b5767c(arg0, arg1) {
console.log(new WebSocketPair()[1]);
let ws = getObject(arg0);
console.log(ws);
ws.onmessage = function (evt) {
console.log(evt);
let fn = getObject(arg1);
console.log(fn);
fn(evt);
};
}; The first log was solely to figure how the WS should look. These logs are written once a ws-request is received. then I have the ws.onmessage and it's contents are never logged. So it does not seem to be an issue with the closure, but it implies that the ResponseInit did not properly carry the webSocket to the browser, I think? Taking a look into the workers-chat-demo, I see return new Response(null, { status: 101, webSocket: pair[0] }); Which should be the same as my rust implementation. #[doc = "Change the `webSocket` field of this object."]
pub fn websocket(&mut self, val: &WebSocket) -> &mut Self {
let r = ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("webSocket"), val.as_ref());
debug_assert!(
r.is_ok(),
"setting properties should never fail on our dictionary objects"
);
let _ = r;
self
} But debugs of it show: The webSocket is defined in the ResponseInit:
|
I intended to go to sleep when I was sending my investigation answer, but I wanted to get this done, so I kept searching. The issue was more stupid than I thought; It's not "set_onmessage", as implied by the generated WebSocket bindings from wasm, but set_event_handler. |
@nilslice Will do! Planning to complete documentation later today (this evening) and will turn it into "Ready for Review". What probably is important: I removed the |
Yeah this would be awesome @ByteAlex! You're making great progress and it looks pretty good so far. Edit: Removed clippy reminder, forgot it isn't commented out anymore we just pinned wasm-bindgen instead. |
aka make linter happy again
Haha yeah, Linters / Formatter is always complaining about my code, but I think it should be all good now + it's ready for review! 🚀 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super minor changes, but overall this is awesome :)
My initial approach to supporting websockets in workers-rs.
Sending data works fine, though receiving data - for example through onmessage - does not work yet.
I'd appreciate some help figuring this out!
Also at maintainers, would this PR, if properly documented, get an OK from you?