Browser synchronization
By default, TalkJS allows you to create and update users and conversations in your frontend code with the JavaScript SDK. The changes you make are then synchronized with the TalkJS backend.
If you exclusively use the REST API to create or update TalkJS users or conversations, you may want to disable synchronization for users, conversations or both.
In the Security settings section of the Settings tab of the TalkJS dashboard, uncheck the checkboxes for synchronizing users, conversations or both:
If user synchronization in the browser is turned on, the JavaScript SDK lets you create or update a user by calling the User
constructor with UserOptions
data:
The user will then be synchronized with the TalkJS backend if they are the current user in a session. If they are not the current user, and they are part of an existing conversation, they will be synchronized when the UI is mounted.
If user synchronization in the browser is turned off, the user will not be synchronized and you will see an error in your browser console. If you want to reference an existing user, you should call the User
constructor with just the user's ID instead, which uses the details already stored for the user:
1const me = new Talk.User(123456);
If conversation synchronization in the browser is turned on, the JavaScript SDK lets you create new conversations with the getOrCreateConversation
method, and update existing ones with the setParticipant
and setAttributes
methods. The conversation will then be synchronized with the TalkJS backend when the UI is mounted.
If conversation synchronization in the browser is turned off, you can get existing conversations with getOrCreateConversation
but not create new ones. You cannot update the conversation with setParticipant
or setAttributes
. If you try to create or update a conversation you will see an error in your browser console:
1// This will only work if the conversation already exists2const conversation = session.getOrCreateConversation(3 Talk.oneOnOneId(me, other)4);56// Trying to set a participant via the SDK will cause an error7conversation.setParticipant(me);8conversation.setParticipant(other);910// Trying to set the the conversation's attributes will also cause an error11conversation.setAttributes({12 subject: 'Hello world!',13});
See the tutorial on how to ban a user from all chats for an example of how to use Authentication (Identity verification) together with disabling browser synchronization, to ensure the integrity of your user's data.