Closed maksymalist closed 1 year ago
Hi @maksymalist,
If you want to send custom messages, you can extend the binary protocol. The issue occurs because the client expects a binary message where the first byte indicates the kind of message. If you send a string, the client simply doesn't understand.
Protocol messages that the server uses: https://github.com/yjs/y-protocols
Another approach might be to use Yjs or the Awareness instance to communicate with the clients. Or create another WebSocket connection that implements a protocol you can design yourself.
Thanks for helping me out!
Describe the bug
Whenever I try to send a websocket event to my server (https://github.com/yjs/yjs-demos/blob/main/demo-server/demo-server.js) it always throws me an error:
and that goes both ways so when I try to send an event from my server to the client listeners it sends me the same error but it's happening in the server code
To Reproduce
Steps to reproduce the server:
setInterval(() => { wss.clients.forEach((client) => { client.send('testing') }) }, 1000)
const provider = new WebsocketProvider('wss://demos.yjs.dev', 'prosemirror-demo', ydoc)
const provider = new WebsocketProvider('ws://localhost:1234', 'prosemirror-demo', ydoc)
provider.ws.addEventListener('testing', () => { console.log('testing event received') })
├─┬ y-prosemirror@1.0.19 │ └── yjs@13.5.36 deduped ├─┬ y-websocket@1.4.3 │ ├─┬ y-leveldb@0.1.1 │ │ └── yjs@13.5.36 deduped │ └── yjs@13.5.36 deduped └── yjs@13.5.36
├─┬ y-websocket@1.3.9 │ └─┬ y-leveldb@0.1.0 │ └── yjs@13.4.12 deduped └── yjs@13.4.12