@liveblocks/client
provides you with JavaScript bindings for our realtime
collaboration APIs, built on top of WebSockets. Read our
getting started guides to learn more.
Creates a client that allows you to connect to Liveblocks servers.
You must define either authEndpoint
or publicApiKey
. Resolver functions
should be placed inside here, and a number of other options are available.
When creating a client with a public key, you don’t need to set up an authorization endpoint. We only recommend using a public key when prototyping, or on public landing pages, as it makes it possible for end users to access any room’s data. You should instead use an auth endpoint.
If you are not using a public key, you need to set up your own authEndpoint
.
Please refer to our Authentication guide.
If you need to add additional headers or use your own function to call your
endpoint, authEndpoint
can be provided as a custom callback. You should return
the token created with
Liveblocks.prepareSession
or liveblocks.identifyUser
,
learn more in authentication guide.
room
is the room ID that the user is connecting to. When using
Notifications, room
can be
undefined
, as the client is requesting a token that grants access to multiple
rooms, rather than a specific room.
Here’s an example of fetching your API endpoint at /api/liveblocks-auth
within
the callback.
You should return the token created with
Liveblocks.prepareSession
or liveblocks.identifyUser
.
These are the values the functions can return.
{ "token": "..." }
shaped response.{ "error": "forbidden", "reason": "..." }
shaped response. If this is
returned, the client will disconnect and won't keep trying to authorize.Any other error will be treated as an unexpected error, after which the client will retry the request until it receives either 1. or 2.
By default, the client throttles the WebSocket messages sent to one every 100
milliseconds, which translates to 10 updates per second. It’s possible to
override that configuration with the throttle
option with a value between 16
and 1000
milliseconds.
This option is helpful for smoothing out realtime animations in your application, as you can effectively increase the framerate without using any interpolation. Here are some examples with their approximate frames per second (FPS) values.
Liveblocks usually synchronizes milliseconds after a local change, but if a user
immediately closes their tab, or if they have a slow connection, it may take
longer for changes to synchronize. Enabling preventUnsavedChanges
will stop
tabs with unsaved changes closing, by opening a dialog that warns users. In
usual circumstances, it will very rarely trigger.
More specifically, this option triggers when:
Internally, this option uses the beforeunload event.
If you’re connected to a room and briefly lose connection, Liveblocks will reconnect automatically and quickly. However, if reconnecting takes longer than usual, for example if your network is offline, then the room will emit an event informing you about this.
How quickly this event is triggered can be configured with the
lostConnectionTimeout
setting, and it takes a number in milliseconds.
lostConnectionTimeout
can be set between 1000
and 30000
milliseconds. The
default is 5000
, or 5 seconds.
You can listen to the event with room.subscribe("lost-connection")
. Note
that this also affects when others
are reset to an empty array after a
disconnection. This helps prevent temporary flashes in your application as a
user quickly disconnects and reconnects. For a demonstration of this behavior,
see our connection status example.
By default, Liveblocks applications will maintain an active WebSocket connection
to the Liveblocks servers, even when running in a browser tab that’s in the
background. However, if you’d prefer for background tabs to disconnect after a
period of inactivity, then you can use backgroundKeepAliveTimeout
.
When backgroundKeepAliveTimeout
is specified, the client will automatically
disconnect applications that have been in an unfocused background tab for at
least the specified time. When the browser tab is refocused, the client will
immediately reconnect to the room and synchronize the document.
backgroundKeepAliveTimeout
accepts a number in milliseconds—we advise using a
value of at least a few minutes, to avoid unnecessary disconnections.
Comments stores user IDs in its system, but no other user information. To display user information in Comments components, such as a user’s name or avatar, you need to resolve these IDs into user objects. This function receives a list of user IDs and you should return a list of user objects of the same size, in the same order.
The name and avatar you return are rendered in
Thread
components.
The user objects returned by the resolver function take the shape of
UserMeta["info"]
, which contains name
and avatar
by default. These two
values are optional, though if you’re using the
Comments default components,
they are necessary. Here’s an example of userIds
and the exact values
returned.
You can also return custom information, for example, a user’s color
:
You can access any values set within resolveUsers
with the
useUser
hook.
When using Notifications
with Comments, room IDs will be used to
contextualize notifications (e.g. “Chris mentioned you in room-id”) in the
InboxNotification
component. To replace room IDs with more fitting names (e.g. document names,
“Chris mentioned you in Document A”), you can provide a resolver function to
the resolveRoomsInfo
option in createClient
.
This resolver function will receive a list of room IDs and should return a list of room info objects of the same size and in the same order.
In addition to the room’s name, you can also provide a room’s URL as the url
property. If you do so, the
InboxNotification
component will automatically use it. It’s possible to use an inbox
notification’s roomId
property to construct a room’s URL directly in React and
set it on
InboxNotification
via href
, but the room ID might not be enough for you to construct the URL ,
you might need to call your backend for example. In that case, providing it via
resolveRoomsInfo
is the preferred way.
To enable creating mentions in Comments,
you can provide a resolver function to the resolveMentionSuggestions
option in
createClient
. These mentions will be displayed in the
Composer
component.
This resolver function will receive the mention currently being typed (e.g. when
writing “@jane”, text
will be jane
) and should return a list of user IDs
matching that text. This function will be called every time the text changes but
with some debouncing.
To use @liveblocks/client
in Node.js, you need to provide WebSocket
and
fetch
polyfills. As polyfills, we recommend installing ws
and
node-fetch
.
Then, pass them to the createClient
polyfill option as below.
Note that node-fetch
v3+
does not support CommonJS.
If you are using CommonJS, downgrade node-fetch
to v2.
To use @liveblocks/client
with React Native, you
need to add an atob
polyfill. As a polyfill, we recommend installing
base-64
.
Then you can pass the decode
function to our atob
polyfill option when you
create the client.
Client returned by createClient
which allows you to connect to Liveblocks
servers in your application, and enter rooms.
Enters a room and returns both the local Room
instance, and a leave
unsubscribe function. The authentication endpoint is called as soon as you call
this function. Used for setting initial Presence
and initial Storage values.
Note that it’s possible to add types to your room.
Presence is used for storing temporary user-based values, such as a user’s
cursor coordinates, or their current selection. Each user has their own
presence, and this is readable for all other connected users. Set your initial
Presence value by using initialPresence
.
Each user’s Presence resets every time they disconnect, as this is only meant
for temporary data. Any JSON-serializable object is allowed (the JsonObject
type).
Storage is used to store permanent data that’s used in your application, such as
shapes on a whiteboard, nodes on a flowchart, or text in a form. The first time
a room is entered, you can set an initial value by using initialStorage
. Note
that this value is only read a single time.
Any
conflict-free live structures
and JSON-serializable objects are allowed (the LsonObject
type).
Gets a room by its ID. Returns null
if client.enterRoom
has not been
called previously.
It’s unlikely you’ll need this API if you’re using the newer
client.enterRoom
API. Note that it’s possible to
add types to your room.
Gets the current Liveblocks synchronization status.
Purges any auth tokens from the client’s memory. If there are any rooms that are still connected, they will be forced to reauthorize.
Use this function if you have a single page application (SPA) and you wish to
log your user out, and reauthenticate them. This is a way to update your user’s
info
after a connection has begun.
Room returned by client.enterRoom
(or client.getRoom
).
Return the current user’s Presence. Presence is used to store custom properties on each user that exist until the user disconnects. An example use would be storing a user’s cursor coordinates.
Presence is set with updatePresence
and can be typed
when you enter a room. The example above is using
the following type:
Updates the current user’s Presence. Only pass the properties you wish to update—any changes will be merged into the current presence. The entire presence object will not be replaced.
By default, Presence values are not added to history. However, using the
addToHistory
option will add items to the undo/redo stack.
See room.history
for more information.
Returns an array of currently connected users in the room. Returns a
User
object for each user. Note that you can also subscribe to
others using Room.subscribe("others")
.
Broadcast an event to other users in the Room. Events broadcast to the room can
be listened to with Room.subscribe("event")
. Takes a custom event payload
as first argument. Should be serializable to JSON.
To receive an event, use Room.subscribe("event")
. The user
property
received on the other end is the sender’s User
instance.
We recommend using a property such as type
, so that it’s easy to distinguish
between different events on the receiving end.
When defining your types, you can pass a RoomEvent
type
in your config file to receive type hints in your app. To define multiple
different custom events, use a union.
By default, broadcasting an event is a “fire and forget” action. If the sending
client is not currently connected to a room, the event is simply discarded. When
passing the shouldQueueEventIfNotReady
option, the client will queue up the
event, and only send it once the connection to the room is (re)established.
Gets the current User
. Returns null
if the client is not yet
connected to the room.
Here’s an example of a full return value, assuming Presence
and UserMeta
have been set.
Gets the current WebSocket connection status of the room. The possible value
are: initial
, connecting
, connected
, reconnecting
, or disconnected
.
Get the Storage status. Use this to tell whether Storage has been synchronized with the Liveblocks servers.
Subscribe to updates on a particular storage item, and takes a callback function
that’s called when the storage item is updated. The Storage root
is a
LiveObject
, which means you can subscribe to this, as well as other live
structures. Returns an unsubscribe function.
To type the Storage values you receive, make sure to set your Storage
type.
The type received in the callback will match the type passed. Learn more under typing your room.
You can subscribe to any live structure, be it the Storage root
, a child, or a
structure even more deeply nested.
It’s also possible to subscribe to a Storage item and all of its children by
passing an optional isDeep
option in the third argument. In this case, the
callback will be passed a list of updates instead of just the new Storage item.
Each such update is a { type, node, updates }
object.
You use an async
function inside the subscription callback, though bear in
mind that the callback itself is synchronous, and there’s no guarantee the
async
function will complete before the callback is run again.
If the order of updates is imporant in your application, and it’s important to
ensure that your async
function doesn’t start before the previous one
finishes, you can use a package such as
async-mutex
to help you with
this. Using runExclusive
will effectively form a queue for all upcoming
updates, guaranteeing serial execution.
Note that this may cause a performance penalty in your application, as certain updates will be ignored.
Subscribe to events broadcast by Room.broadcastEvent
. Takes a callback
that’s run when another user calls Room.broadcastEvent
. Provides the
event
along with the user
and their connectionId
of the user that sent the
message. Returns an unsubscribe function.
When defining your types, you can pass a RoomEvent
type
to your config file to receive type hints in your app. To define multiple
different custom events, use a union.
Events can be received from the server with either
liveblocks.broadcastEvent
or the
Broadcast Event API.
In events sent from the server, user
will be null
, and connectionId
will
be -1
.
Subscribe to the current user’s Presence. Takes a callback that is called every
time the current user presence is updated with Room.updatePresence
.
Returns an unsubscribe function.
To type the Presence values you receive, make sure to set your Presence type.
The type received in the callback will match the type passed. Learn more under typing your data.
Subscribe to every other users’ updates. Takes a callback that’s called when a user’s Presence updates, or when they enter or leave the room. Returns an unsubscribe function.
To type the Presence values you receive, make sure to set your Presence type.
The type received in the callback will match the type passed. Learn more under typing your data.
The event
parameter returns information on why the callback has just run, for
example if their Presence has updated, if they’ve just left or entered the room,
or if the current user has disconnected.
Here’s a basic example showing you how to render live cursors.
Room.updatePresence
is being used to update each user’s cursor position.
Check our examples page for live demos.
Subscribe to WebSocket connection status updates. Takes a callback that is
called whenever the connection status changes. Possible value are: initial
,
connecting
, connected
, reconnecting
, or disconnected
. Returns an
unsubscribe function.
Status is a low-level API that exposes the WebSocket’s connectivity status. You
can use this, for example, to update a connection status indicator in your UI.
It would be normal for a client to briefly lose the connection and restore it
with quick connected
→ reconnecting
→ connected
status jumps.
If you’d like to let users know that there may be connectivity issues, don’t use
this API, but instead refer to Room.subscribe("lost-connection")
which was
specially built for this purpose.
Do not use this API to detect when Storage or Presence are initialized or
loaded. "Connected" does not guarantee that Storage or Presence are ready. To
detect when Storage is loaded, rely on awaiting the Room.getStorage
promise or using the Room.subscribe("storage-status")
event.
A special-purpose event that will fire when a previously connected Liveblocks client has lost connection, for example due to a network outage, and was unable to recover quickly. This event is designed to help improve UX for your users, and will not trigger on short interruptions, those that are less than 5 seconds by default. The event only triggers if a previously connected client disconnects.
Lost connections events allows you to build high-quality UIs by warning your users that the application is still trying to re-establish the connection, for example through a toast notification. You may want to take extra care in the mean time to ensure their changes won’t go unsaved, or to help them understand why they’re not seeing updates made by others yet.
When this happens, this callback is called with the event lost
. Then, once the
connection restores, the callback will be called with the value restored
. If
the connection could definitively not be restored, it will be called with
failed
(uncommon).
The lostConnectionTimeout
configuration option will determine how quickly
the event triggers after a connection loss occurs. By default, it’s set to
5000
ms, which is 5 seconds.
Subscribe to unrecoverable room connection errors. This event will be emitted
immediately before the client disconnects and won’t try reconnecting again.
Returns an unsubscribe function. If you’d like to retry connecting, call
room.reconnect
.
You can use this event to trigger a “Not allowed” screen/dialog. It can also be helpful for implementing a redirect to another page.
When a room ID has been changed with
liveblocks.updateRoomId
or the
Update Room ID API,
error.message
will contain the new room ID.
Subscribe to the current user’s history changes. Returns an unsubscribe function.
Subscribe to Storage status changes. Use this to tell whether Storage has been synchronized with the Liveblocks servers. Returns an unsubscribe function.
Batches Storage and Presence modifications made during the given function. Each modification is grouped together, which means that other clients receive the changes as a single message after the batch function has run. When undoing or redoing these changes, the entire batch will be undone/redone together instead of atomically.
For the most part, you don’t need to batch updates. For example, given a whiteboard application, it’s perfectly fine to update a note’s position on the board multiple times per second, in separate updates. However, should you implement a “Delete all” button, that may delete 50 notes at once, this is where you should use a batch.
This batch places each
LiveMap.delete
call
into a single WebSocket update, instead of sending multiple updates. This will
be much quicker.
Batching changes will also group changes into a single history state.
Note that room.batch
cannot take an async
function.
Room’s history contains functions that let you undo and redo operations made to Storage and Presence on the current client. Each user has a separate history stored in memory, and history is reset when the page is reloaded.
By default, history is only enabled for Storage. However, you can use the
addToHistory
option to additionally
add Presence state to history.
Reverts the last operation. It does not impact operations made by other clients, and will only undo changes made by the current client.
Restores the last undone operation. It does not impact operations made by other clients, and will only restore changes made by the current client.
Returns true or false, depending on whether there are any operations to undo. Helpful for disabling undo buttons.
Returns true or false, depending on whether there are any operations to redo. Helpful for disabling redo buttons.
Clears the undo and redo stacks for the current client. Explicitly clearing history resets the ability to undo beyond the current document state. Other clients’ histories are unaffected.
All future modifications made on the Room will be merged together to create a single history item until resume is called.
Resumes history after a pause. Modifications made on the Room are not merged into a single history item any more.
Connect the local room instance to the Liveblocks server. Does nothing if the room is already connecting, reconnecting or connected. We don’t recommend using this API directly.
Reconnect the local room instance to the Liveblocks server, using a new WebSocket connection.
Disconnect the local room instance from the Liveblocks server. The room instance will remain functional (for example, it will still allow local presence or storage mutations), but since it’s no longer connected, changes will not be persisted or synchronized until the room instance is reconnected again. We don’t recommend using this API directly.
Returns threads, and their associated inbox notifications, that are in the current room. It also returns the request date that can be used for subsequent polling. It’s possible to filter for a thread’s resolved status and using custom metadata.
You can filter threads by those that are resolved, or unresolved, by passing a
boolean
to query.resolved
.
You can define custom metadata when
creating a thread,
and the query.metadata
option allows you to return only threads that match.
You can also filter for metadata that begins with a specific string.
Returns threads, and their associated inbox notifications, that have been
updated or deleted since the requested date. Helpful when used in combination
with Room.getThreads
to initially fetch all threads, then
receive updates later.
Returns a thread and its associated inbox notification, from its ID, if it exists.
The thread ID can be retrieved from existing threads.
Creates a thread, and its initial comment, in the current room. A comment’s body is an array of paragraphs, each containing child nodes, learn more under creating thread content.
A comment’s body is an array of paragraphs, each containing child nodes. Here’s
an example of how to construct the following simple comment body, which can be
passed to room.createThread
.
Hello world
Second paragraph!
It’s also possible to create links and mentions.
@Jody Hekla the Liveblocks website is cool!
Custom metadata can be attached to each thread. string
, number
, and
boolean
properties are allowed.
Deletes a thread by its ID.
Edits a thread’s custom metadata. Metadata can be a string
, number
, or
boolean
. To delete an existing metadata property, set its value to null
.
Marks a thread as resolved.
Marks a thread as unresolved.
Creates a comment in a given thread.
A comment’s body is an array of paragraphs, each containing child nodes. Here’s
an example of how to construct the following simple comment body, which can be
passed to room.createComment
.
Hello world
Second paragraph!
It’s also possible to create links and mentions.
@Jody Hekla the Liveblocks website is cool!
Edits a comment, replacing its existing comment body and optionally updating its attachments. Learn more about creating comment content.
Deletes a comment. If it is the last non-deleted comment, the thread also gets deleted.
Adds a reaction from the current user on a comment.
Removes a reaction from a comment.
Creates a local attachment from a file.
Uploads a local attachment.
Optionally, an
AbortSignal
can be passed to cancel the upload.
Returns a presigned URL for an attachment by its ID.
Returns the current user’s inbox notifications and their associated threads. It also returns the request date that can be used for subsequent polling.
Returns the updated and deleted inbox notifications and their associated threads
since the requested date. Helpful when used in combination with
Client.getInboxNotifications
to initially
fetch all notifications, then receive updates later.
Gets the number of unread inbox notifications for the current user.
Marks all inbox notifications as read, for the current user.
Marks an inbox notification as read, for the current user.
Deletes an inbox notification for the current user.
Deletes an inbox notification for the current user.
Gets the user’s notification settings for the current room.
Updates the user’s notification settings for the current room.
Each room contains Storage, a conflict-free data store that multiple users can edit at the same time. When users make edits simultaneously, conflicts are resolved automatically, and each user will see the same state. Storage is ideal for storing permanent document state, such as shapes on a canvas, notes on a whiteboard, or cells in a spreadsheet.
Storage provides three different conflict-free data structures, which you can use to build your application. All structures are permanent and persist when all users have left the room, unlike Presence which is temporary.
LiveObject
- Similar to JavaScript object. Use this for storing records
with fixed key names and where the values don’t necessarily have the same
types. For example, a Person
with a name: string
and an age: number
field. If multiple clients update the same property simultaneously, the last
modification received by the Liveblocks servers is the winner.
LiveList
- An ordered collection of items synchronized across clients.
Even if multiple users add/remove/move elements simultaneously, LiveList will
solve the conflicts to ensure everyone sees the same collection of items.
LiveMap
- Similar to a JavaScript Map. Use this for indexing values that
all have the same structure. For example, to store an index of Person
values
by their name. If multiple users update the same property simultaneously, the
last modification received by the Liveblocks servers is the winner.
To type the Storage values you receive, make sure to set your Storage
type.
The type received in the callback will match the type passed. Learn more under typing your data.
All Storage data structures can be nested, allowing you to create complex trees of conflict-free data.
Get the room’s Storage asynchronously (returns a Promise). The promise will
resolve once the Storage’s root is loaded and available. The Storage’s root is
always a LiveObject
.
The LiveObject
class is similar to a JavaScript object that is synchronized on
all clients. Use this for storing records with fixed key names and where the
values don’t necessarily have the same types. For example, a Person
with
name
and age
fields. To add typing, read more under
typing Storage.
Keys are strings, and values can contain other Storage structures, or JSON-serializable data. If multiple clients update the same property simultaneously, the last modification received by the Liveblocks servers is the winner.
Create an empty LiveObject
Create a LiveObject
with initial data.
The Storage root is LiveObject
itself, so you can use LiveObject.set
to
add a new property to your root. If you’ve typed Storage
you’ll have type hints as you build.
Delete a property from the LiveObject
Get a property from the LiveObject
.
Adds or updates a property with the specified key and a value.
Adds or updates multiple properties at once. Nested changes to other Storage types will not be applied.
Returns a deep copy of the LiveObject
that can be inserted elsewhere in the
Storage tree.
Returns an immutable JavaScript object that is equivalent to the LiveObject
.
Nested values will also be immutable.
Transform the LiveObject
into a normal JavaScript object.
Please note that this method won’t recursively convert Live structures, which may be surprising:
The LiveMap
class is similar to a
JavaScript Map
that is synchronized on all clients. Use this for indexing values that all have
the same structure. For example, to store an index of Person
values by their
name. To add typing, read more under typing Storage.
Keys are strings, and values can contain other Storage structures, or JSON-serializable data. If multiple clients update the same property simultaneously, the last modification received by the Liveblocks servers is the winner.
Create an empty LiveMap
.
Create a LiveMap
with initial data.
The Storage root is a LiveObject
, so you can create a new LiveMap
then use
LiveObject.set
to add it to your root. If you’ve
typed Storage you’ll have type hints as you build.
Removes the specified element by key. Returns true if an element existed and has been removed, or false if the element does not exist.
Returns a new
Iterator
object that contains the [key, value]
pairs for each element.
Executes a provided function once per each key/value pair in the Map object, in insertion order.
Returns a specified element from the LiveMap
. Returns undefined
if the key
can’t be found.
Returns a boolean indicating whether an element with the specified key exists or not.
Returns a new Iterator object that contains the keys for each element.
Adds or updates an element with a specified key and a value.
Returns the number of elements in the LiveMap
.
Returns a new Iterator object that contains the the values for each element.
Returns a deep copy of the LiveMap
that can be inserted elsewhere in the
Storage tree.
Returns an immutable ES6 Map that is equivalent to the LiveMap
. Nested values
will also be immutable.
The LiveList
class represents an ordered collection of items that is
synchronized across clients. To add typing, read more under
typing Storage.
Items can contain other Storage structures, or JSON-serializable data.
Create an empty LiveList
.
Create a LiveList
with initial data.
Removes all the elements.
Deletes an element at the specified index. If the index doesn’t exist, an
Error
is thrown.
Tests whether all elements pass the test implemented by the provided function. Returns true if the predicate function returns a truthy value for every element. Otherwise, false.
Creates an array with all elements that pass the test implemented by the provided function.
Returns the first element that satisfies the provided testing function. If no
item passes the test, undefined
is returned.
Returns the index of the first element in the LiveList
that satisfies the
provided testing function. If no item passes the test, -1
is returned.
Executes a provided function once for each element.
Get the element at the specified index. Returns undefined
if the index doesn’t
exist.
Returns the first index at which a given element can be found in the LiveList
.
Returns -1
if it is not present.
Inserts one element at a specified index. Throws an Error
if the index is out
of bounds.
Returns the last index at which a given element can be found in the LiveList
,
or -1 if it is not present. The LiveList
is searched backwards, starting at
fromIndex. Returns -1
if it is not present.
Returns the number of elements.
Creates an array populated with the results of calling a provided function on every element.
Moves one element at a specified index.
Adds one element to the end of the LiveList
.
Replace one element at the specified index.
Tests whether at least one element in the LiveList
passes the test implemented
by the provided function.
Returns a deep copy of the LiveList
that can be inserted elsewhere in the
Storage tree.
Returns an immutable JavaScript array that is equivalent to the LiveList
.
Nested values will also be immutable.
Transforms the LiveList
into a normal JavaScript array.
Please note that this method won’t recursively convert Live structures, which may be surprising:
client.resolvers.invalidateUsers
can be used to invalidate some or all users
that were previously cached by resolveUsers
.
It can be used when updating the current user’s avatar for example, to instantly refresh the user data everywhere without having to perform a page reload.
client.resolvers.invalidateRoomsInfo
can be used to invalidate some or all
rooms that were previously cached by
resolveRoomsInfo
.
It can be used when updating a room’s name for example, to instantly refresh the room info everywhere without having to perform a page reload.
client.resolvers.invalidateRoomsInfo
can be used to invalidate all mention
suggestions that were previously cached by
resolveMentionSuggestions
.
It can be used when updating a room’s list of users for example, to prevent creating out-of-date mentions without having to perform a page reload.
Returns an array of each user’s ID that has been mentioned in a CommentBody
(found under comment.body
).
Here’s an example with a custom CommentBody
.
Used to convert a CommentBody
(found under comment.body
) into either a plain
string, Markdown, HTML, or a custom format.
A number of options are available.
Here are a number of different formatting examples derived from the same
CommentBody
.
It’s possible to have automatic types flow through your application by defining
a global Liveblocks
interface. We recommend doing this in a
liveblocks.config.ts
file in the root of your app, so it’s easy to keep track
of your types. Each type (Presence
, Storage
, etc.), is optional, but it’s
recommended to make use of them.
Here are some example values that might be used.
Before Liveblocks 2.0, it was recommended to type your data by passing
Presence
, Storage
, UserMeta
, and RoomEvents
types to
client.enterRoom
. This is no longer
the recommended method for setting up Liveblocks, but it
can still be helpful, for example you can use client.enter
multiple times to
create different room types, each with their own correctly typed hooks.
You can also pass types to
client.getRoom
.
User
is a type that’s returned by room.getSelf
, room.getOthers
,
and other functions. Some of its values are set when
typing your room, here are some example values:
Enters a room and returns its local Room
instance.
Leaves a room.
We use cookies to collect data to improve your experience on our site. Read our Privacy Policy to learn more.