We've got you covered in all your real-time collaboration use cases.
import Cyxth from '@cyxth/core';
import Colab from '@cyxth/colab';
const APP_URL = 'my-app.apps.cyxth.com';
const cyx = new Cyxth(APP_URL);
cyx.register([Colab]);
await cyx.connect('USER_TOKEN');
const stateId = 'tasks';
const tasks: Task[] = [];
const colab: Colab = await cyx.colab('https://cdn.cyxth/com/colab-0.0.1.wasm');
// start a new instance , use join or load for existing
await colab.start(stateId);
const addTask = async (task) => {
await colab.change('tasks').getList().insert(0, task);
colab.update(tasks);
};
// listen for changes
colab.on('change', ({ senderId, data }) => {
tasks = data.apply(tasks);
});
// presence broadcast
colab.on('presence', ({ senderId, data }) => {
if (data.type === 'cursor') {
// render cursor positions
}
});
// ...