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

Pass user information with the op to remote clients. #512

Open
maxfortun opened this issue Aug 24, 2021 · 3 comments
Open

Pass user information with the op to remote clients. #512

maxfortun opened this issue Aug 24, 2021 · 3 comments

Comments

@maxfortun
Copy link

Use case: Visually track change attribution across remote clients.

[#224] allows to store metadata, which contains userId, but falls short of pushing metadata out to remote clients.

Proposed solution:

On a server side:

Retain backend constructor options in order to pass around options.opsOptions to configure metadata behavior.

Include message.m in agent's _sendOp based on backend.options.opsOptions.metadata configuration.

Include op.m in SubmitRequest based on backend.options.opsOptions.metadata configuration.

On a client side:

Emit op.m with every op related event.

this.emit('op', componentOp.op, source, op.src, op.m);
@alecgibson
Copy link
Collaborator

I think it might be possible to get this to work without any modifications. You're allowed to set an arbitrary ID on your Connection:

connection = nw Connection(socket);
// Concat with a `uuid` in case the same user has multiple sessions, since
// the Connection ID should be unique per-connection
connection.id = [userId, uuid()].join(':');

Then in remote clients, on the 'op' event, you can check the src:

doc.on('op', (op, source, src) => {
  const [userId] = src.split(':');
  // Do something with userId...
});

@maxfortun
Copy link
Author

@alecgibson , thank you for a quick response! I will experiment with your suggestion and it may be good enough for now. I was using userId as a simplified example and was ultimately hoping to pass around a more sophisticated metadata object with multiple fields. Code suggests that that's what op.m is intended for, so I researched that vector. Using a connection id is a cool idea.

@alecgibson
Copy link
Collaborator

Yeah that's fair; I've long thought we should be able to facilitate getting op metadata to clients!

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