ueberdosis / hocuspocus

The CRDT Yjs WebSocket backend for conflict-free real-time collaboration in your app.
https://tiptap.dev/docs/hocuspocus/introduction
MIT License
1.21k stars 117 forks source link

Koa integration #104

Closed DenysPoliarush closed 3 years ago

DenysPoliarush commented 3 years ago

Hi guys!

I am trying to connect your hocuspocus library to my koa server and it does not work as expected. After some time, the connection to the socket is interrupted and not restored.

I made a connection, as described in the documentation.

I use:

FRONTEND:

BACKEND:

And this is my setup:

const server = Server.configure({
  extensions: [
    new RocksDB({
      path: './tiptap-store'
    })
  ],

  timeout: 30000
});

router.get('/:projectId', async ctx => {
  try {
    if (ctx.ws) {
      const ws = await ctx.ws();

      server.handleConnection(ws, ctx.request, ctx.params.projectId);
    }
  } catch (err) {
    ctx.bad(400, err);
  }
});

Could you please add support for Koa as you have for Express?

hanspagel commented 3 years ago

Thanks! Any chance you can help with that?

We’ve got a few donations allowing us to focus on hocuspocus, but on different areas.

hanspagel commented 3 years ago

I’ve looked into this and had the same time out when I tried to rebuild your code, but could get it working when I started form scratch. I have no prior experience with Koa, but maybe that helps you to find the issue:

https://www.hocuspocus.dev/installation/koa

DenysPoliarush commented 3 years ago

Hi Hans! Thank you for your time.

I tried to do it as you wrote, but nothing has changed. I created a new empty project, pulled the latest version of hocuspocus, and created a clear connection as you described in your guide.

This is what I see in my console and network: One connection that is closed and no new open connections, so I can't work with the editor.

Screenshot 2021-06-02 at 16 26 23 Screenshot 2021-06-02 at 15 48 03

To make sure your extensin works the way I need it, I left your example site open all night and when I returned in the morning I saw it. Screenshot 2021-06-02 at 17 38 34

There are many closed connections, and one is always open, so I could go back and continue writing in the editor. This is what I need now so that I can continue writing in the editor after some time of inactivity. This is not possible in my project.

On your example site, I also see the same errors in the console, but this is not a problem, since everything works.

Any ideas what can be wrong?

Thanks!

hanspagel commented 3 years ago

Hm … I have no prior experience with Koa. Did you try the exact same code provided in the documentation? That worked for me.

I’m closing this for now, but I’d love to have help debugging this.