Configuration

Update the following parameters on the Push Notifications tab under Sendbird:

{
  "active": true | false,
  "autoRegister": true | false, // if true push permission will be requested automatically
  “appId”: STRING // optional - if defined the Sendbird SDK will be initialized automatically
}

👍

Developer Demo

Display our demo page in your app to test during development https://median.dev/sendbird/

Android push notifications

Android push notifications are sent using Firebase Cloud Messaging and require google-services.json be embedded in the app by uploading on the Build & Download tab. Push notifications must also be enabled within your Sendbird Dashboard by adding the FCM server key. Refer to the Sendbird documentation.

SDK Initialization

There are two ways to initialize the Sendbird SDK.

  1. Define appId in the Sendbird configuration hardcoded into the app as noted above. The Sendbird SDK will be initialized automatically on app launch.
  2. Call the median.sendbird.initialize() method documented below. The Sendbird SDK will be initialized at runtime, and then automatically on subsequent app launches.

JavaScript Bridge Functions

Runtime initialization

Initialize the Sendbird SDK with the provided appId. The appId will be saved, and the app will automatically initialize Sendbird SDK on the next app start.

Note that the function median.sendbird.isInitialized() should be used to check whether the Sendbird SDK is already initialized to prevent multiple initializations

↔️Median JavaScript Bridge

median.sendbird.initialize(STRING)

Check whether the SDK is already initialized. If already initialized the current appId is returned to facilitate prevention of a redundant/unnecessary second initialization.

Provide a callback function or otherwise returns a promise. If initialized the appId used for the initialization will be returned.

↔️Median JavaScript Bridge

median.sendbird.isInitialized({callback: function})
// Return value if initialized:
{
  "initialized": true,
  "appId": STRING
}

// Return value if not initialized (appId was not defined in configuration):
{
  "initialized": false
}

Push Notification Permission

Prompt for Push Notification permission, will show a dialog for users to confirm permission. For Android the dialog is only shown on Android 13 and above. Android 12 and below will always be granted without user intervention.

Provide a callback function or otherwise returns a promise.

↔️Median JavaScript Bridge

median.sendbird.promptNotification({'callback': function})
// Return value:
{
  "granted": true | false
}

Check if the user has granted Push Notification permission. For Android must be checked first to ensure that Push Notification will show on Android 13 and above. Android 12 and below will always return true.

Provide a callback function or otherwise returns a promise.

↔️Median JavaScript Bridge

median.sendbird.notificationEnabled({'callback': function})
// Return value:
{
  "granted": true | false
}

User management

Set and login the Sendbird user account. The user will be automatically logged in on subsequent app starts if logout is not called. If userId does not exist a new user will be registered.

↔️Median JavaScript Bridge

median.sendbird.setUserId(STRING)

Retrieve the current userId.

Provide a callback function or otherwise returns a promise.

↔️Median JavaScript Bridge

median.sendbird.getUserId({callback: function})
// Return value:
{
  "userId": STRING
}

Check whether the user is connected to the Sendbird server after logging in.

Provide a callback function or otherwise returns a promise.

↔️Median JavaScript Bridge

median.sendbird.isConnected({callback: function})
// Return value:
{
  "connected": BOOLEAN
}

Update profile for the current user.

Provide a callback function or otherwise returns a promise.

↔️Median JavaScript Bridge

median.sendbird.updateUserInfo({
  nickname: STRING, // optional
  profileImageUrl: STRING, // optional
  callback: function
})
// Return value:
{
  "success": BOOLEAN
}

Logout the current user. Disconnects the current user from the Sendbird server and removes user details from the app. This will also unregister push notifications.

Provide a callback function or otherwise returns a promise.

↔️Median JavaScript Bridge

median.sendbird.logout({callback: function})
// Return value:
{
  "success": BOOLEAN
}

Disconnect the current user session. User details will be saved in the app and the app will continue to receive Sendbird push notifications.

Provide a callback function or otherwise returns a promise.

↔️Median JavaScript Bridge

median.sendbird.disconnect({callback: function})
// Return value:
{
  "success": BOOLEAN
}

Channel Management

Create Group Channel

↔️Median JavaScript Bridge

median.sendbird.createGroupChannel({
  name: STRING,
  coverImageUrl: STRING, // optional
  userIds: [STRING],     // at least 1 userId is required
  isDistinct: BOOLEAN,   // default is false, set to true to ensure if there is an existing channel it is utilized
  customType: STRING,    // optional channel type for grouping
  callback: function
})
// Return value:
{
  "success": BOOLEAN,
  "channelUrl": STRING
}

Native UI

Launch the Sendbird Channels UI of the currently logged-in user

↔️Median JavaScript Bridge

median.sendbird.showUI()

Launch Sendbird UI and deep link into an active channel

↔️Median JavaScript Bridge

median.sendbird.showChannelUI({
  url: STRING
})

UI Closed Callback

↔️Median JavaScript Bridge

If defined on the webpage the following callback will be invoked by the native app when the UI is closed

function median_sendbird_uiclosed(){
  alert('UI Closed');
}