Requirement: I need to distinguish which user triggered this event based on the information on the event in the observe callback function.
Scenario: I need to support speaker operation and follow operation for my collaboration function
Can anyone provide some suggestions or methods? I would be very grateful.
YMap.observeDeep((eventArray, transaction) => {
if (!transaction.origin) return;
});
Every change on the shared document happens in a transaction. Observer calls and the update event are called after each transaction. You should bundle changes into a single transaction to reduce event calls. I.e. doc.transact(() => { yarray.insert(ā¦); ymap.set(ā¦) }) triggers a single change event.
You can specify an optional origin parameter that is stored on transaction.origin and on(āupdateā, (update, origin) => ā¦)"
Origins are not persisted, and they donāt tell you anything about the user who created the operation. The origin is useful to distinguish which component of your application generated the changeāmainly to avoid infinite loops. However, the undo manager also uses them.
The transaction only works locally. For example, if the y-websocket provider receives a change it will apply the change to the Y.Doc. The origin will be the the y-websocket provider object.
You can setup PermanentUserData to figure out which user created which content. There is no API to figure out which āuserā created a specific change, because Yjs has no concept of users.
You can, however, distinguish local from remote changes using transaction.local.