Chat JavaScript v4
Chat JavaScript
Chat
JavaScript
Home
/
Chat
/
JavaScript
This is the new Docs for Chat SDK v4 beta for JavaScript. To see the previous Docs, click here.

Application

Before you start building your chat, it is important to understand that your Sendbird application has core functionalities to maintain chat service stability and basic features for application management. This page presents how you can use a Sendbird application in your app to ensure optimal performance.


Default settings

To prevent abnormal user activity, a Sendbird application has the following limits on the number of messages per second which a user can send and an open channel can display.

Limits on number of messages per second

Imposed onLimitIf exceeded

User

5 messages per second

Excess messages are neither sent to the channel nor saved in the database but are displayed in the user's channel view.

Open channel

5 messages per second

Excess messages are not displayed, but saved in the database.

* This setting isn't effective in a group channel.


Manage connections with Sendbird server

Unlike the Chat SDKs for iOS and Android, the Chat SDK for JavaScript doesn't manage a connection to Sendbird server when the foreground and background states of your web app changes on a various types of devices. In that context, you should call the connect() or disconnect() methods explicitly depending on how you implement your use cases.

One user ID can make connections to up to 30 devices or browsers simultaneously. All connections from one user ID are counted and reflected in your application’s concurrent connections. Since they are used to calculate your service billing, caution is advised.


Retrieve a list of users

You can retrieve a list of all or certain users in your Sendbird application using an ApplicationUserListQuery instance. The next() method returns a list of User objects which contain information on users within the application.

const query = sb.createApplicationUserListQuery({ limit: 20 });
const users = await query.next();

With the several different types of filters the ApplicationUserListQuery instance provides, you can retrieve a list of specific users that match the set values in the filters. Currently the ApplicationUserListQuery instance supports the following filters.

List of filters

NameFilters

UserIdsFilter

Users who are using the specified user IDs. Specifying the userIdsFilter option enables this filter.

MetaDataKeyFilter

Users with metadata containing an item with the specified key and values. Specifying the metaDataKeyFilter option along with the metaDataValuesFilter below enables this filter.

MetaDataValuesFilter

Users with metadata containing an item with the specified key and values. Specifying the metaDataValuesFilter option along with the metaDataKeyFilter above enables this filter.

NicknameStartsWithFilter

Users whose nicknames start with the specified value. Specifying the nicknameStartsWithFilter option enables this filter.

Note: We recommend you set the maximum number of user IDs to 250 in the UserID filter. If exceeded, your query may receive an HTTP 414 error indicating that the submitted request data is longer than Sendbird server is willing to interpret.

// Retrieve certain users using the UserID filter.
const query = sb.createApplicationUserListQuery({
    userIdsFilter: ['Harry', 'Jay', 'Jin'],
});
const users = await query.next();

// Retrieve certain users using the MetaDataKey and MetaDataValue filter.
const query = sb.createApplicationUserListQuery({
    metaDataKeyFilter: 'hobby',
    metaDataValuesFilter: ['movie', 'book', 'exercise'],
});
const users = await query.next();

// Retrieve certain users using the NicknameStartsWith filter.
const query = sb.createApplicationUserListQuery({
    nicknameStartsWithFilter: 'Ja',
});
const users = await query.next();

Block and unblock other users

A user can block specific users to stop receiving further messages from them in 1-to-1 group channels and notifications of their messages in 1-to-N group channels. You can choose whether or not users can view which users they have blocked in the channel UI.

A Sendbird application provides two blocking options: including or excluding blocked users when sending invitations and turning on/off push notifications from blocked users. The previous block modes are now deprecated and only supported for customers who have been using them from before.

  • Including or excluding blocked users when sending invitations: determines whether or not to automatically filter out blocked users when a user invites a group of users to a new group channel. The value of this option can be adjusted only from our side before integrating your Sendbird application to an app. If you want to change the value, contact our sales team for further assistance. (Default: including)
  • Turning on/off push notifications from blocked users: determines whether or not to send push notifications to a user for the messages that blocked users sent in a specific 1-to-N group channel where they are members together. The value of this option can be set individually by channel. If you want to use this option, contact our sales team for further assistance. (Default: off)

1-to-1 group channel

Channel listPush notificationsMessages

A user's channel list won't be updated and rearranged from the blocked user's messages.

A user won't be notified that the blocked user sent a message.

New messages sent from the blocked user won't be delivered to the channel, but are saved in the database and displayed in the blocked user's channel view. The blocked user is not aware of their blocked status. A user can only see the messages that the blocked user has sent before being blocked.

* If the blocked user is unblocked, a user can see all the messages except those that were sent during the blocking period.

1-to-N group channel (group chat)

Channel listPush notificationsMessages

For a blocked user's message, a user's channel list will be updated and rearranged.

A user will be notified of messages from blocked users if push notifications from blocked users is turned on. Otherwise, they will not be notified.

All the messages from blocked users are delivered to the channel. You can choose whether a user can view which users they have blocked in the UI of the channel.

You can allow a users to block and unblock other users by implementing the following code to your client app.

const user = await sb.blockUser(USER);

Note: You can use the blockUserWithUserId() and unblockUserWithUserId() methods, instead of the blockUser() and unblockUser() methods, as they have same functionalities. See our API reference for more information on the blockUserWithUserId() and unblockUserWithUserID().


Retrieve a list of blocked users

You can retrieve a list of all or certain blocked users in your Sendbird application using a BlockedUserListQuery instance. The next() method returns a list of User objects which contain information on blocked users.

// Retrieve all blocked users.
const query = sb.createBlockedUserListQuery();
const blockedUsers = await query.next();

With the BlockedUserListQuery's UserID filter, you can retrieve a list of the blocked users that match the user IDs in the filter.

const query = sb.createBlockedUserListQuery({
    userIdsFilter: ['John', 'Daniel', 'Jeff'],
});
const blockedUsers = await query.next();

Check if a user is online

You can check if a certain user is currently connected to Sendbird server.

const query = sb.createApplicationUserListQuery({
    userIdsFilter: ['Jeff'],
});
const [jeff] = await query.next();
if (jeff.connectionStatus === UserOnlineState.ONLINE) {
    // Jeff is currently online.
    // User.connectionStatus consists of NON_AVAILABLE, ONLINE, and OFFLINE.
    ...
}