Skip to content

Instantly share code, notes, and snippets.

@freeman42x
Created October 16, 2019 20:50
Show Gist options
  • Save freeman42x/f82576c7dc1ebd0c9cb552dd467a7ac9 to your computer and use it in GitHub Desktop.
Save freeman42x/f82576c7dc1ebd0c9cb552dd467a7ac9 to your computer and use it in GitHub Desktop.
electron miso websockets bug
freeman42x> does this look like it is an Electron issue? https://stackoverflow.com/q/58421285/750216 or could it be server related?
<jaawerth> I didn't know it was airbnb-branded haha
<ljharb> jaawerth: why do you need to schedule a meeting to pull in a package
<jaawerth> ljharb: oh that's DOM ones, I mean like ES ones
<devsnek> https://github.com/airbnb/js-shims
<devsnek> browser-shims includes js-shims
<jaawerth> ljharb: I'm not saying you do. I'm saying using the shim package is an easier sell than adding babel to hte project or uprading node
<jaawerth> since it's an easier transition
<sillyslux> "Haskell jsaddle warp miso server" wtf is your keyboard broken?
<jaawerth> just install it and make sure it's sourced and done
<ljharb> jaawerth: airbnb-browser-shims contains airbnb-js-shimselectron miso websockets bug
<jaawerth> yeahh I see it now, thanks
<jaawerth> if you're the maintainer it shouldn't be called airbnb anymore, but I suppose it's fair since they paid you to build up the ecosystem for so long, heh
<devsnek> ljharb-browser-shims
<jaawerth> and such a well-organized and maintained shim collection is certainly a public service
<jaawerth> or just es-shims :P
<ljharb> jaawerth: tbh it probably shouldn't have been called airbnb in the first place
<ljharb> but yes i'll be making a catch-all language shims package at some point
<sillyslux> freeman42x, the browser side of electron should have WebSocket
<jaawerth> and whatwg-browser-shims I suppose
<sillyslux> ws is on the node side
<freeman42x> sillyslux, so what would the solution be?
<devsnek> freeman42x: don't try to require ws
<devsnek> there's a global called WebSocket in the electron renderer
<sillyslux> try using window.WebSocket
<freeman42x> devsnek, where am I requiring ws in the code I linked?
<freeman42x> sillyslux, where would I use that?
<devsnek> freeman42x: whatever localhost:8080 has
<devsnek> is trying to require ws
<freeman42x> devsnek, I think that the library I am using requires WS to work.
<devsnek> ws is just a websocket library for node
<freeman42x> so my issue is figuring out how to enable WS for Electron?
<devsnek> electron already has ws
<devsnek> built in
<devsnek> its the global WebSocket
<freeman42x> ok, but then why is it not working?
<devsnek> because it doesn't have require('ws')
<freeman42x> devsnek, where do I add require('ws') ?
<devsnek> freeman42x: nowhere
<devsnek> you don't want it
<freeman42x> so... what should I do?
<jaawerth> I mean, server-side you probably want it
<jaawerth> unless it's built into electron's embedded node
<freeman42x> the app loads fine in a browser
<freeman42x> it is just broken in Electron
<jaawerth> I mean the server-side in electron
<freeman42x> the server-side has no direct mention of WS, but I assume it is using it under the hood... so I need it
<devsnek> freeman42x: that means its detection is broken
<devsnek> file a bug with miso
<jaawerth> client-sidei n electron you can just use the global WebSocket. server-side you'd want to require and use the ws module unless tehre's some built-in that electron embed in node (but I don't know of any)
<jaawerth> then again I don't do much with electron
<devsnek> god i love this so much https://gc.gy/38963801.png
<jaawerth> yeah looks like you'd use ws for the electron server and just use global WebSocket in the electron client code
<devsnek> app code should do like
<devsnek> window ? window.WebSocket : require('ws').WebSocket
<devsnek> but it is clearly flipping that
<devsnek> require ? require('ws').WebSocket : window.WebSocket
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment