yjs / y-websocket

Websocket Connector for Yjs
https://docs.yjs.dev/ecosystem/connection-provider/y-websocket
MIT License
524 stars 262 forks source link

Using y-websocket in Node.js: Depends on `window` #55

Closed hanspagel closed 3 years ago

hanspagel commented 3 years ago

Describe the bug I’m trying to use y-websocket in Node.js (for testing purposes). As described in the README I’m passing ws as a WebsocketPolyfill, like this:

const wsProvider = new WebsocketProvider('ws://localhost:1234', 'my-roomname', doc, { WebSocketPolyfill: require('ws') })

When I try to run this code there are two parts that expect to run in a Browser context:

  1. https://github.com/yjs/y-websocket/blob/02f691d89c8cfea884d9f9fa98f0ff192b0eb7d9/src/y-websocket.js#L279-L281
  2. https://github.com/dmonad/lib0/blob/01005b5435f7c4e91fb8ea9933e734cc0a6c3451/broadcastchannel.js#L45:L45

To Reproduce

  1. Execute the above code in a Node.js environment
  2. See errors

Expected behavior I’d expect y-websocket to use window only when available.

Environment Information

Additional context I don’t know if it’s dumb using y-websocket in Node.js, but using Cypress feels like overkill. ¯\_(ツ)_/¯

hanspagel commented 3 years ago

Oops, duplicate of #51.

kriskbx commented 3 years ago

Thanks a bunch for working on lib0. But there's still a window reference in y-websocket itself: https://github.com/yjs/y-websocket/blob/9d7e5eaec89050a191b301c45e484357f1c44ae8/src/y-websocket.js#L279