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.

How to disable browser synchronization

In the Security settings section of the Settings tab of the TalkJS dashboard, uncheck the checkboxes for synchronizing users, conversations or both:

Disable synchronization in the TalkJS dashboard

User synchronization

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:

1const me = new Talk.User({
2 id: '123456',
3 name: 'Alice',
4 email: '[email protected]',
5});

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);

Conversation synchronization

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 exists
2const conversation = session.getOrCreateConversation(
3 Talk.oneOnOneId(me, other)
4);
5
6// Trying to set a participant via the SDK will cause an error
7conversation.setParticipant(me);
8conversation.setParticipant(other);
9
10// Trying to set the the conversation's attributes will also cause an error
11conversation.setAttributes({
12 subject: 'Hello world!',
13});

Further reading

See our tutorial on how to ban a user from all chats for an example of how to use identity verification together with disabling browser synchronization to ensure the integrity of your user's data.