Skip to content
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

syncing multible dbs over a single socket.io connection [feature] #37

Open
svogl opened this issue Feb 12, 2020 · 5 comments
Open

syncing multible dbs over a single socket.io connection [feature] #37

svogl opened this issue Feb 12, 2020 · 5 comments

Comments

@svogl
Copy link

svogl commented Feb 12, 2020

We wanted to get pouch synchronisation working over an existing socket.io connection (for authorisation, other data) as well as synchronize more than one DB.

For this to work at the server side, we added a piggy() function to the server side that you can pass a reference to an existing socket object and start listening. We typically call this after authorisation has been performed. The synchronisation logic registers for messages with topic 'pouch', when a createDatabase message is received, everything is set up to sync this database using its name for the topic.

On the client side, the existing socket can be passed in the constructor options ( opts.socket = ...).

If you're interested, you can find the current state in this fork:
https://github.com/voxel-dot-at/socket-pouch

Simon

@svogl svogl changed the title syncing multible dbs over a single socket.io connection syncing multible dbs over a single socket.io connection [feature] Feb 12, 2020
@kripper
Copy link

kripper commented Oct 23, 2021

Hi @svogl, is your "piggy version" stable?

@svogl
Copy link
Author

svogl commented Oct 24, 2021

@kripper it's working in a production environment for ~2years now, so 'works for me' :)

@kripper
Copy link

kripper commented Oct 25, 2021

Hi @svogl,

I got it working but only without a proxy.

When using the same Apache proxy I used with the original socket-pouch version, the request returns a Session ID unknown error, so I guess we need some additional config for the proxy.
I'm not sure if I want to use a proxy at all, because I guess it will need more resources (RAM and CPU).
The reason we were using a proxy was just to support SSL and avoid errors when running via web.
I'm thinking in a) implementing SSL support on socket-pouch-voxel or b) try to fix the Apache Proxy config or c) both: do b if a fails when the special port is not accesible.

What is your environment?
Are you using a proxy to serve SSL?
Did your proxy need some special config?

@nolanlawson: Since socket-pouch-voxel is the improved version, shouldn't we merge with the official pouchdb-community version?

BTW, I'm commenting here because socket-pouch-voxel has the issues panel disabled.

I'm also surprised that socket-pouch's user base is so small, being the only solution to properly work with more than 5 PouchDBs.

@kripper
Copy link

kripper commented Oct 26, 2021

Hi @svogl,

I was wrong. Your repo is broken.

BTW, I don't understand why all your functions trigger an emit after sending a response (which was already triggered by anoter previous emit).

function sendSuccess(socket, messageId, data, options) {
  if (options.topic) {
    socket.emit(options.topic, messageId + ':1:' + JSON.stringify(data));
  } else {
    socket.send(messageId + ':1:' + JSON.stringify(data));
  }
}

This causes problems beacuse the response to a request is emited and processed as a new request causing this kind of stack trace:

  pouchdb:socket:server  -> sendSuccess plihgXA_K8HHoIR6AAAA 9FD5254F-0403-BB59-A448-8B52E105E8EE +7ms
  pouchdb:socket:server TOP! dte-devel%2Fadmin(590)%2Femisor 9FD5254F-0403-BB59-A448-8B52E105E8EE:1:{"ok":true} +0ms
  pouchdb:socket:server invalid message, ignoring TypeError: args.forEach is not a function
    at destringifyArgs (/project/socket-pouch-server/libs/socket-pouch-voxel/lib/server/index.js:19:8)
    at onReceiveTextMessage (/project/socket-pouch-server/libs/socket-pouch-voxel/lib/server/index.js:312:16)
    at Socket.<anonymous> (/project/socket-pouch-server/libs/socket-pouch-voxel/lib/server/index.js:259:5)
    at Socket.emit (events.js:193:13)
    at sendSuccess (/project/socket-pouch-server/libs/socket-pouch-voxel/lib/server/index.js:54:12)
    at /project/socket-pouch-server/libs/socket-pouch-voxel/lib/server/index.js:263:5
    at processTicksAndRejections (internal/process/task_queues.js:86:5) +6ms

Maybe the client is outdated and doesn't support this new "topic" based protocol.

This other repo (with a previous version of yours) works fine:
https://github.com/angelmerino/socket-pouch

@kripper
Copy link

kripper commented Oct 27, 2021

Nevermind. This repo works perfect, supports multiplexing, socket.io (on top of engine.io) and is clean:
https://github.com/CoMfUcIoS/socket.io-pouch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants