diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.json index 0b317ce..731a778 100644 --- a/.claude-plugin/marketplace.json +++ b/.claude-plugin/marketplace.json @@ -12,7 +12,7 @@ "source": "git-subdir", "url": "https://github.com/sendbird/sendbird-client-plugin.git", "path": "plugins/sendbird-client", - "ref": "v0.1.42" + "ref": "v0.1.43" }, "description": "Sendbird integration helper for Chat (incl. auth/session), UIKit, and Calls across iOS, Android, and JS. Includes hooks that run local shell scripts; see README \"What runs on your machine\"." } diff --git a/plugins/sendbird-client/.claude-plugin/plugin.json b/plugins/sendbird-client/.claude-plugin/plugin.json index 99007f2..4f0ef8c 100644 --- a/plugins/sendbird-client/.claude-plugin/plugin.json +++ b/plugins/sendbird-client/.claude-plugin/plugin.json @@ -1,7 +1,7 @@ { "name": "sendbird-client", "displayName": "Sendbird Client", - "version": "0.1.42", + "version": "0.1.43", "description": "Sendbird integration helper for Chat (incl. auth/session), UIKit, and Calls across iOS, Android, and JS", "author": { "name": "Sendbird", diff --git a/plugins/sendbird-client/.codex-plugin/plugin.json b/plugins/sendbird-client/.codex-plugin/plugin.json index 3ae9a9c..f76b16d 100644 --- a/plugins/sendbird-client/.codex-plugin/plugin.json +++ b/plugins/sendbird-client/.codex-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "sendbird-client", - "version": "0.1.42", + "version": "0.1.43", "description": "Sendbird integration helper for Chat (incl. auth/session), UIKit, and Calls across iOS, Android, and JS", "author": { "name": "Sendbird", diff --git a/plugins/sendbird-client/README.md b/plugins/sendbird-client/README.md index 5a73cb0..0b2f5ce 100644 --- a/plugins/sendbird-client/README.md +++ b/plugins/sendbird-client/README.md @@ -3,7 +3,7 @@ > Generated by `tools/editions/build.sh` from the repository root. Do not edit this folder; > change the root and rerun the build. -`sendbird-client` v0.1.42 — Sendbird integration helper for Chat (incl. auth/session), UIKit, and Calls across iOS, Android, and JS. +`sendbird-client` v0.1.43 — Sendbird integration helper for Chat (incl. auth/session), UIKit, and Calls across iOS, Android, and JS. ## Products @@ -29,11 +29,16 @@ codex plugin add sendbird-client@sendbird - `/sendbird-client:add-feature` - `/sendbird-client:auth-recipes` +- `/sendbird-client:calls-incoming` +- `/sendbird-client:diagnose-channel` - `/sendbird-client:docs-search` - `/sendbird-client:explain-error` +- `/sendbird-client:fix-build` - `/sendbird-client:performance-audit` +- `/sendbird-client:permissions-setup` - `/sendbird-client:push-setup` - `/sendbird-client:setup` +- `/sendbird-client:start-chat` - `/sendbird-client:trace-sdk` - `/sendbird-client:ui-customize` - `/sendbird-client:verify-integration` diff --git a/plugins/sendbird-client/config/plugin-config.json b/plugins/sendbird-client/config/plugin-config.json index 4cce5e7..953e92a 100644 --- a/plugins/sendbird-client/config/plugin-config.json +++ b/plugins/sendbird-client/config/plugin-config.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.1.42", + "schemaVersion": "0.1.43", "knowledge": { "mode": "runtime-fetch", "_modes": [ diff --git a/plugins/sendbird-client/core/index.json b/plugins/sendbird-client/core/index.json index c05a6b7..ca95154 100644 --- a/plugins/sendbird-client/core/index.json +++ b/plugins/sendbird-client/core/index.json @@ -1,6 +1,6 @@ { "schemaVersion": 1, - "generatedAt": "2026-10-14T18:33:49Z", + "generatedAt": "2026-10-14T19:23:16Z", "count": 48, "entries": [ { diff --git a/plugins/sendbird-client/hooks/welcome.sh b/plugins/sendbird-client/hooks/welcome.sh index 97d3597..e840163 100755 --- a/plugins/sendbird-client/hooks/welcome.sh +++ b/plugins/sendbird-client/hooks/welcome.sh @@ -4,7 +4,7 @@ set -euo pipefail ROOT="${CLAUDE_PLUGIN_ROOT:-$(cd "$(dirname "$0")/.." && pwd)}" cat <` elements by `android:name`, so an app or another library that declared the same class collided with it (Sendbird staff explanation in the first case; the second case shows the same error with UIKit 3.3.3). +- **Fix:** Upgrade UIKit. The 3.5.4 release notes list "Improved FileProvider compatibility" (source: https://github.com/sendbird/sendbird-uikit-android/blob/07ffe8efc97e2d71dedc466ad868df817e5f433e/CHANGELOG.md#L338-L341). In 3.26.3 the AAR manifest declares its own class, `com.sendbird.uikit.model.SendbirdUIKitFileProvider`, with the authority `${applicationId}.sendbird.uikit.provider`, so it no longer shares a merge key with an app's `androidx.core.content.FileProvider` (source: uikit-3.26.3.aar AndroidManifest.xml lines 153-161). +- **Cases:** https://community.sendbird.com/t/sendbird-uikit-using-androidx-core-content-fileprovider-directly/2687, https://community.sendbird.com/t/fileprovider-manifest-merger-conflict-with-other-dependencies/6393 + ## Connection and auth ### `connect` fails with 400302, or a user who used to connect without a token is now rejected diff --git a/plugins/sendbird-client/knowledge/curated/android/hosts/compose.md b/plugins/sendbird-client/knowledge/curated/android/hosts/compose.md index 1722c43..05c77db 100644 --- a/plugins/sendbird-client/knowledge/curated/android/hosts/compose.md +++ b/plugins/sendbird-client/knowledge/curated/android/hosts/compose.md @@ -247,6 +247,35 @@ class UniqueTokenMessagingService : SendbirdPushHandler() { ``` (source: https://sendbird.com/docs/chat/uikit/v3/jetpack-compose/essentials/push-notifications) (source: sendbird-chat-4.36.4.aar javap -c com.sendbird.android.push.SendbirdPushHandler — `onTokenUpdated` calls `isUniquePushToken()` and passes it to `SendbirdPushHelper.registerPushToken`) (source: knowledge/curated/android/cross-cutting/push.md) +## Start a 1:1 chat from a button (Compose UIKit) +Create the channel with the Chat SDK and `isDistinct = true` (knowledge/curated/android/products/chat.md, "Create and list group channels"), then call `navController.navigateToChannel(url)` on the `NavController` whose `NavHost` contains `sendbirdGroupChannelNavGraph(navController)`. The same call opens a channel from a push tap once you have its channel URL (the payload is in knowledge/curated/android/cross-cutting/push.md). The template `templates/android/compose/uikit/UikitComposeApp.kt` builds that `NavHost`. + +```kotlin +import androidx.compose.material3.Button +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.navigation.NavController +import com.sendbird.android.channel.GroupChannel +import com.sendbird.android.params.GroupChannelCreateParams +import com.sendbird.uikit.compose.navigation.navigateToChannel + +@Composable +fun ChatWithSellerButton(navController: NavController, sellerUserId: String) { + Button(onClick = { + val params = GroupChannelCreateParams().apply { + userIds = listOf(sellerUserId) + isDistinct = true // same members -> the existing channel comes back + } + GroupChannel.createChannel(params) { channel, e -> + if (e == null && channel != null) navController.navigateToChannel(channel.url) + } + }) { + Text("Chat with seller") + } +} +``` +(source: https://sendbird.com/docs/chat/uikit/v3/jetpack-compose/navigation) (source: knowledge/curated/android/products/chat.md — Create and list group channels) (uikit-compose 1.3.6 AAR `javap` on `com.sendbird.uikit.compose.navigation.NavigationKt`: `navigateToChannel(NavController, String)`, `sendbirdGroupChannelNavGraph`; also templates/android/compose/uikit/UikitComposeApp.kt, compile-checked) + ## Related - View host: knowledge/curated/android/hosts/view.md - AI Agent: knowledge/curated/android/products/ai-agent.md diff --git a/plugins/sendbird-client/knowledge/curated/android/products/calls.md b/plugins/sendbird-client/knowledge/curated/android/products/calls.md index 522df5d..8b8e55f 100644 --- a/plugins/sendbird-client/knowledge/curated/android/products/calls.md +++ b/plugins/sendbird-client/knowledge/curated/android/products/calls.md @@ -34,6 +34,60 @@ SendBirdCall.addListener(UNIQUE_HANDLER_ID, new SendBirdCallListener() { ``` (source: sendbird-calls 1.12.4 — `SendBirdCallListener` has TWO required abstract methods, `onRinging(DirectCall)` + `onInvitationReceived(RoomInvitation)`, verified via javap of the published AAR 2026-06-22. `RoomInvitation` = `com.sendbird.calls.RoomInvitation`.) +## Receive calls in the background or after the app was closed (FCM) +A device without a live Calls connection gets incoming calls through FCM. The docs' steps: upload the FCM service account key in the dashboard, register the FCM token with `SendBirdCall.registerPushToken(...)` from `onNewToken` (the overload to use is below), and pass every FCM message to `SendBirdCall.handleFirebaseMessageData(remoteMessage.getData())`, which returns `true` for a Calls push and `false` for any other push. (source: https://sendbird.com/docs/calls/sdk/v1/android/features/push-notifications) + +The SDK then raises `onRinging` on a listener added with `SendBirdCall.addListener(...)`. When FCM starts the app process, only `Application.onCreate` has run, so the public Direct Call QuickStart calls `SendBirdCall.init(...)` and adds the listener there. Its FCM service registers the token only when `SendBirdCall.currentUser` is set and otherwise saves it for after sign-in. (source: https://github.com/sendbird/quickstart-calls-directcall-android/blob/1e8cf929f0a891b93bc31ed9b394525a209520ac/directcall-kotlin/app/src/main/java/com/sendbird/calls/quickstart/BaseApplication.kt#L27-L61) (source: https://github.com/sendbird/quickstart-calls-directcall-android/blob/1e8cf929f0a891b93bc31ed9b394525a209520ac/directcall-kotlin/app/src/main/java/com/sendbird/calls/quickstart/fcm/MyFirebaseMessagingService.kt#L12-L31) + +```kotlin +import android.app.Application +import com.google.firebase.messaging.FirebaseMessagingService +import com.google.firebase.messaging.RemoteMessage +import com.sendbird.calls.DirectCall +import com.sendbird.calls.RoomInvitation +import com.sendbird.calls.SendBirdCall +import com.sendbird.calls.SendBirdException +import com.sendbird.calls.handler.CompletionHandler +import com.sendbird.calls.handler.SendBirdCallListener +import com.sendbird.calls.internal.PushTokenType + +class CallsApplication : Application() { + override fun onCreate() { + super.onCreate() + // Runs again when FCM starts the process for an incoming call. + if (SendBirdCall.init(applicationContext, APP_ID)) { + SendBirdCall.addListener("incoming-calls", object : SendBirdCallListener() { + override fun onRinging(call: DirectCall) { + // Show the incoming-call UI (see the notification notes below). + } + override fun onInvitationReceived(invitation: RoomInvitation) {} + }) + } + } +} + +class CallsMessagingService : FirebaseMessagingService() { + override fun onMessageReceived(remoteMessage: RemoteMessage) { + if (SendBirdCall.handleFirebaseMessageData(remoteMessage.data)) return + // Not a Calls push: handle your other notifications here. + } + + override fun onNewToken(token: String) { + if (SendBirdCall.currentUser == null) return // register after authenticate instead + SendBirdCall.registerPushToken(token, PushTokenType.FCM_VOIP, false, object : CompletionHandler { + override fun onResult(e: SendBirdException?) {} + }) + } +} +``` + +The three-argument `registerPushToken(token, unique, handler)` shown on the docs page is deprecated since 1.11.0; the compiler names the replacement, `registerPushToken(pushToken, pushTokenType, unique, handler)`, and the QuickStart passes `PushTokenType.FCM_VOIP` (`com.sendbird.calls.internal.PushTokenType`, values `FCM_VOIP` and `HMS_VOIP`). (source: https://github.com/sendbird/quickstart-calls-directcall-android/blob/1e8cf929f0a891b93bc31ed9b394525a209520ac/directcall-kotlin/app/src/main/java/com/sendbird/calls/quickstart/utils/PushUtils.kt#L34-L50) (sendbird-calls 1.12.5 `javap -public com.sendbird.calls.SendBirdCall`: `init(Context, String)` returns boolean, `getCurrentUser()`, `registerPushToken(String, PushTokenType, boolean, CompletionHandler)`, `addListener(String, SendBirdCallListener)`, `handleFirebaseMessageData(Map)` returns boolean; `SendBirdCallListener` is an abstract class with `onRinging(DirectCall)` and `onInvitationReceived(RoomInvitation)`; `CompletionHandler.onResult(SendBirdException)`; deprecation message from `compile-snippets-android.sh`) + +**Showing the ringing call.** The SDK does not draw a notification for you; the QuickStart does it in its own foreground service (`CallService`): +- `onRinging` starts the service with `startForegroundService`. The service posts a `NotificationCompat.CATEGORY_CALL` notification with `PRIORITY_HIGH` on an `IMPORTANCE_HIGH` channel, with accept and decline actions and `setFullScreenIntent(...)` for the ringing screen. (source: https://github.com/sendbird/quickstart-calls-directcall-android/blob/1e8cf929f0a891b93bc31ed9b394525a209520ac/directcall-kotlin/app/src/main/java/com/sendbird/calls/quickstart/call/CallService.kt#L83-L139) +- It calls `startForeground` with `FOREGROUND_SERVICE_TYPE_PHONE_CALL` while ringing, and adds `FOREGROUND_SERVICE_TYPE_MICROPHONE` only after the call connects. The sample's comment says that including the microphone type while the app is still in the background throws a `SecurityException` on Android 15+. (source: https://github.com/sendbird/quickstart-calls-directcall-android/blob/1e8cf929f0a891b93bc31ed9b394525a209520ac/directcall-kotlin/app/src/main/java/com/sendbird/calls/quickstart/call/CallService.kt#L150-L167) +- Its manifest declares `FOREGROUND_SERVICE`, `FOREGROUND_SERVICE_PHONE_CALL`, `FOREGROUND_SERVICE_MICROPHONE`, `POST_NOTIFICATIONS`, `USE_FULL_SCREEN_INTENT`, `WAKE_LOCK` and `MANAGE_OWN_CALLS`, and registers the service with `android:foregroundServiceType="phoneCall|microphone"`. (source: https://github.com/sendbird/quickstart-calls-directcall-android/blob/1e8cf929f0a891b93bc31ed9b394525a209520ac/directcall-kotlin/app/src/main/AndroidManifest.xml#L7-L93) + ## Make a call ```java DialParams params = new DialParams(CALLEE_ID); diff --git a/plugins/sendbird-client/knowledge/curated/android/products/uikit.md b/plugins/sendbird-client/knowledge/curated/android/products/uikit.md index bf1bb50..f76f51d 100644 --- a/plugins/sendbird-client/knowledge/curated/android/products/uikit.md +++ b/plugins/sendbird-client/knowledge/curated/android/products/uikit.md @@ -435,6 +435,38 @@ The header applies the appearance and then sets a fixed text size (`HeaderView.k **Long channel names are cut to one line.** This is the layout, not a bug: the channel list row title is `singleLine` with `ellipsize="end"` (`sb_view_channel_list_item.xml` line 32-40), and the channel header title is `maxLines="1"` with `ellipsize="end"` (`sb_view_header.xml` line 54-59). To show more of the name, render the row with a custom channel item (see "Channel list" above) or the header with a custom `ChannelHeaderComponent`. (source: https://github.com/sendbird/sendbird-uikit-android/blob/main/uikit/src/main/res/layout/sb_view_channel_list_item.xml#L32-L40) (source: https://github.com/sendbird/sendbird-uikit-android/blob/main/uikit/src/main/res/layout/sb_view_header.xml#L54-L59) (community context: https://github.com/sendbird/sendbird-uikit-android/discussions/28) +## Start a 1:1 chat from a button (no channel list) +For a "Chat with seller" button: create the channel with `isDistinct = true`, which returns the existing 1:1 channel when one already has the same members, and start `ChannelActivity` for its URL. Back returns to your screen. To open the same channel from a notification tap, the public UIKit sample builds the notification's `PendingIntent` from a redirect intent; `ChannelListActivity.newRedirectToChannelIntent(context, channelUrl)` opens the list and moves into the channel, so back lands on the list. + +```kotlin +import android.app.PendingIntent +import android.content.Context +import android.content.Intent +import com.sendbird.android.channel.GroupChannel +import com.sendbird.android.params.GroupChannelCreateParams +import com.sendbird.uikit.activities.ChannelActivity +import com.sendbird.uikit.activities.ChannelListActivity + +fun Activity.openChatWith(sellerUserId: String) { + val params = GroupChannelCreateParams().apply { + userIds = listOf(sellerUserId) + isDistinct = true // same members -> the existing channel comes back + } + GroupChannel.createChannel(params) { channel, e -> + if (e != null || channel == null) return@createChannel + startActivity(ChannelActivity.newIntent(this, channel.url)) + } +} + +// In your push handler: data["sendbird"] is JSON whose channel object holds channel_url. +fun channelTapIntent(context: Context, channelUrl: String, requestCode: Int): PendingIntent { + val intent = ChannelListActivity.newRedirectToChannelIntent(context, channelUrl) + .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) + return PendingIntent.getActivity(context, requestCode, intent, PendingIntent.FLAG_IMMUTABLE) +} +``` +(source: knowledge/curated/android/products/chat.md — Create and list group channels) (source: https://github.com/sendbird/sendbird-uikit-android/blob/07ffe8efc97e2d71dedc466ad868df817e5f433e/uikit-samples/src/main/java/com/sendbird/uikit/samples/common/fcm/MyFirebaseMessagingService.kt#L54-L117 — reads `data["sendbird"]`, takes the channel URL, and builds the tap `PendingIntent` from a redirect intent with `FLAG_ACTIVITY_CLEAR_TOP`) (uikit 3.26.3 AAR `javap` on `com.sendbird.uikit.activities.ChannelActivity` and `com.sendbird.uikit.activities.ChannelListActivity`: `newIntent(Context, String)`, `newRedirectToChannelIntent(Context, String)`) + ## Message menu and message taps (View host) A long press on a message opens the message menu, which `makeMessageContextMenu(message)` builds as a list of `DialogListItem`s; each item is identified by its string resource key, such as `R.string.sb_text_channel_anchor_edit`. To change the menu, subclass `ChannelFragment`, filter or add items in `makeMessageContextMenu`, and handle your own items in `onMessageContextMenuItemClicked` (return `true` when you handled it). Install the subclass with `ChannelFragment.Builder(channelUrl).setCustomFragment(...)`, usually inside `FragmentProviders.channel`. diff --git a/plugins/sendbird-client/knowledge/curated/ios/hosts/swiftui.md b/plugins/sendbird-client/knowledge/curated/ios/hosts/swiftui.md index d921f11..f4da8fa 100644 --- a/plugins/sendbird-client/knowledge/curated/ios/hosts/swiftui.md +++ b/plugins/sendbird-client/knowledge/curated/ios/hosts/swiftui.md @@ -318,6 +318,42 @@ func applyBrandTheme(isDark: Bool) { ``` Call `applyBrandTheme(isDark:)` at launch, before SendbirdSwiftUI is initialized. For strings, the rules in knowledge/curated/ios/cross-cutting/theme.md apply unchanged. (source: SendbirdSwiftUI.swiftinterface (1.2.2) lines 18900–18903 (`SBUTheme.set(theme:)`, `set(colorScheme:)`), 102 (`asUIColor()`), 21462 (`asUIFont()`), 107 (`ColorSet`), 595 (`FontSet`), 7889–7890 and 10122–10123 (`SBUColorSet` and `SBUFontSet` deprecated, renamed to `ColorSet` and `FontSet`), 18454 (`SBUStringSet`); source: https://sendbird.com/docs/chat/uikit/v3/swiftui/theme-and-style-resources/color-resources; source: https://sendbird.com/docs/chat/uikit/v3/swiftui/theme-and-style-resources/font-resources; source: https://github.com/sendbird/sendbird-uikit-ios/blob/3.36.1/Sources/Constant/SBUStringSet.swift#L17; source: https://github.com/sendbird/sendbird-swiftui-ios/blob/1.2.2/Sample/QuickStartSwiftUI/CustomSample/CustomViews/Theme/Theme/Custom/CustomTheme.Theme.Custom.Main.swift#L25-L29; source: https://sendbird.com/docs/chat/uikit/v3/swiftui/theme-and-style-resources/theme-resources) +## Start a 1:1 chat from a button (SendbirdSwiftUI) +Create the channel with `isDistinct = true` (knowledge/curated/ios/products/chat.md, "Create and list group channels"), keep its URL in state, and push `GroupChannelView(provider: GroupChannelViewProvider(channelURL:))`. The public sample pushes `GroupChannelView` from its own navigation link the same way. `navigationDestination(isPresented:)` is SwiftUI's iOS 16 API; on iOS 15, use the `NavigationLink` the sample uses. + +```swift +import SwiftUI +import SendbirdChatSDK +import SendbirdSwiftUI + +@available(iOS 16.0, *) +struct ChatWithSellerButton: View { + let sellerUserId: String + @State private var channelURL: String? + + var body: some View { + Button("Chat with seller") { + let params = GroupChannelCreateParams() + params.userIds = [sellerUserId] + params.isDistinct = true // same members -> the existing channel comes back + GroupChannel.createChannel(params: params) { channel, error in + guard let channel, error == nil else { return } + channelURL = channel.channelURL + } + } + .navigationDestination(isPresented: Binding( + get: { channelURL != nil }, + set: { if !$0 { channelURL = nil } } + )) { + if let channelURL { + GroupChannelView(provider: GroupChannelViewProvider(channelURL: channelURL)) + } + } + } +} +``` +Put the button inside a `NavigationStack`. (source: https://github.com/sendbird/sendbird-swiftui-ios/blob/1.2.2/Sample/QuickStartSwiftUI/CustomSample/CustomSampleSubView.swift#L36-L53 — the sample pushes its destination with a hidden `NavigationLink`) (source: https://github.com/sendbird/sendbird-swiftui-ios/blob/1.2.2/Sample/QuickStartSwiftUI/CustomSample/CustomViews/GroupChannel/SwiftUI/View/CustomGroupChannel.SwiftUI.View.Main.swift#L9-L15 — `GroupChannelView(provider:)` with a channel URL) (SendbirdSwiftUI.swiftinterface 1.2.2: `GroupChannelViewProvider.init(channelURL:startingPoint:messageListParams:)` 1144, `GroupChannelView.init(provider:headerItem:listItem:inputItem:)` 1634) (source: knowledge/curated/ios/products/chat.md — Create and list group channels) + ## Related - UIKit host: knowledge/curated/ios/hosts/uikit.md - AI Agent: knowledge/curated/ios/products/ai-agent.md diff --git a/plugins/sendbird-client/knowledge/curated/ios/products/calls.md b/plugins/sendbird-client/knowledge/curated/ios/products/calls.md index 886505d..f8890e2 100644 --- a/plugins/sendbird-client/knowledge/curated/ios/products/calls.md +++ b/plugins/sendbird-client/knowledge/curated/ios/products/calls.md @@ -35,6 +35,92 @@ SendBirdCall.addDelegate(self, identifier: UNIQUE_HANDLER_ID) // SendBirdCallD ``` (source: sendbird-calls-ios README §"device-specific event handler") +## Receive calls in the background or after the app was closed (PushKit + CallKit) +The docs say `didStartRinging` alone delivers incoming calls only while the app is in the foreground: "if both CallKit and PushKit are implemented, the Calls SDK will be able to receive incoming calls even when the app is in the background or closed." The SDK receives these calls only through PushKit, so the app reports each one to CallKit from `didStartRinging`. (source: https://sendbird.com/docs/calls/sdk/v1/ios/features/voip-push-notifications) + +Wiring, as in Sendbird's public Direct Call QuickStart: +- Turn on the Push Notifications capability and the Background Modes "Voice over IP" mode, and upload the VoIP credential in the dashboard by following the docs page above. +- At launch, add the Calls delegate and create a `PKPushRegistry` for `.voIP`. In `pushRegistry(_:didUpdate:for:)` register the token with `registerVoIPPush(token:unique:completionHandler:)`. The user must be authenticated first; if the token arrives earlier, keep it and register it after `authenticate` succeeds. +- Forward every incoming VoIP push to `pushRegistry(_:didReceiveIncomingPushWith:for:completionHandler:)` on `SendBirdCall`. Its handler receives the call's UUID, or `nil` when the push did not produce a call; the sample then reports a placeholder call and ends it right away. +- In `didStartRinging(_:)`, report the call with CallKit's `reportNewIncomingCall(with:update:completion:)`, using `call.callUUID` as the CallKit UUID. +- In the `CXProviderDelegate`, find the call with `getCall(forUUID:)`; answer with `accept(with:)` and end with `end()`. Pass CallKit's audio session to `audioSessionDidActivate(_:)` and `audioSessionDidDeactivate(_:)`. + + +```swift +import AVFoundation +import CallKit +import PushKit +import SendBirdCalls + +final class IncomingCallCoordinator: NSObject, PKPushRegistryDelegate, SendBirdCallDelegate, CXProviderDelegate { + private let voipRegistry = PKPushRegistry(queue: .main) + private let provider = CXProvider(configuration: CXProviderConfiguration()) + + // Call after SendBirdCall.configure(appId:) at launch. + func start() { + SendBirdCall.addDelegate(self, identifier: "incoming-calls") + provider.setDelegate(self, queue: .main) + voipRegistry.delegate = self + voipRegistry.desiredPushTypes = [.voIP] + } + + func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) { + // The user must be authenticated before this call succeeds. + SendBirdCall.registerVoIPPush(token: pushCredentials.token, unique: false) { error in } + } + + func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, + for type: PKPushType, completion: @escaping () -> Void) { + SendBirdCall.pushRegistry(registry, didReceiveIncomingPushWith: payload, for: type) { uuid in + if uuid == nil { + // Every VoIP push must be reported to CallKit; report a placeholder and end it. + let placeholder = UUID() + let update = CXCallUpdate() + update.remoteHandle = CXHandle(type: .generic, value: "invalid") + self.provider.reportNewIncomingCall(with: placeholder, update: update) { _ in + self.provider.reportCall(with: placeholder, endedAt: Date(), reason: .failed) + } + } + completion() + } + } + + func didStartRinging(_ call: DirectCall) { + guard let uuid = call.callUUID else { return } + let update = CXCallUpdate() + update.remoteHandle = CXHandle(type: .generic, value: call.caller?.userId ?? "Unknown") + update.hasVideo = call.isVideoCall + provider.reportNewIncomingCall(with: uuid, update: update) { error in } + } + + func providerDidReset(_ provider: CXProvider) {} + + func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) { + guard let call = SendBirdCall.getCall(forUUID: action.callUUID) else { action.fail(); return } + let options = CallOptions(isAudioEnabled: true, isVideoEnabled: call.isVideoCall, useFrontCamera: true) + call.accept(with: AcceptParams(callOptions: options)) + action.fulfill() + } + + func provider(_ provider: CXProvider, perform action: CXEndCallAction) { + SendBirdCall.getCall(forUUID: action.callUUID)?.end() + action.fulfill() + } + + func provider(_ provider: CXProvider, didActivate audioSession: AVAudioSession) { + SendBirdCall.audioSessionDidActivate(audioSession) + } + + func provider(_ provider: CXProvider, didDeactivate audioSession: AVAudioSession) { + SendBirdCall.audioSessionDidDeactivate(audioSession) + } +} +``` + +(source: https://github.com/sendbird/quickstart-calls-directcall-ios/blob/2ebe32e1f6abcf2dc08ee9a23d67ce69ad05d3de/QuickStart/AppDelegate.swift#L41-L45 — delegate and VoIP registry at launch) (source: https://github.com/sendbird/quickstart-calls-directcall-ios/blob/2ebe32e1f6abcf2dc08ee9a23d67ce69ad05d3de/QuickStart/AppDelegate%2BVoIPPush.swift#L15-L55 — token registration, forwarding, placeholder call) (source: https://github.com/sendbird/quickstart-calls-directcall-ios/blob/2ebe32e1f6abcf2dc08ee9a23d67ce69ad05d3de/QuickStart/AppDelegate%2BSendBirdCallsDelegates.swift#L16-L40 — `didStartRinging` reports to CallKit) (source: https://github.com/sendbird/quickstart-calls-directcall-ios/blob/2ebe32e1f6abcf2dc08ee9a23d67ce69ad05d3de/QuickStart/CXExtensions/CXCallManager.swift#L109-L189 — answer, end, audio session) (SendBirdCalls.swiftinterface 1.12.3: `DirectCall.accept(with:)` 112, `end()` 113, `PushRegistryHandler` 448, `didStartRinging(_:)` 650, `DirectCall` 680 with `callUUID` 694, `caller` 697, `isVideoCall` 760, `CallOptions` initializer 829, `addDelegate(_:identifier:)` 863, `getCall(forUUID:)` 870, `pushRegistry(_:didReceiveIncomingPushWith:for:completionHandler:)` 883, `registerVoIPPush(token:unique:completionHandler:)` 884, `audioSessionDidActivate(_:)` 897, `audioSessionDidDeactivate(_:)` 898, `AcceptParams(callOptions:)` 917) + +The QuickStart registers with `unique: true`, which keeps only this device's token. Use `unique: false` when the same user should ring on several devices (see "Only the most recently used device gets push notifications" in knowledge/curated/ios/cross-cutting/troubleshooting.md). + ## Make a call ```swift let dialParams = DialParams(calleeId: CALLEE_ID, isVideoCall: false, callOptions: CallOptions(), customItems: [:]) diff --git a/plugins/sendbird-client/knowledge/curated/ios/products/uikit.md b/plugins/sendbird-client/knowledge/curated/ios/products/uikit.md index f2c369c..f330243 100644 --- a/plugins/sendbird-client/knowledge/curated/ios/products/uikit.md +++ b/plugins/sendbird-client/knowledge/curated/ios/products/uikit.md @@ -966,6 +966,40 @@ SendbirdUI.connectIfNeeded { user, error in ``` (source: https://github.com/sendbird/sendbird-uikit-ios/blob/3.36.1/Sources/Manager/SBUEmojiManager.swift#L56-L75 (`loadAllEmojis(completionHandler:)` at line 149); source: https://github.com/sendbird/sendbird-uikit-ios/blob/3.36.1/Sources/SendbirdUI.swift#L250-L254 (the load starts in a `defer` after connect); community context: https://github.com/sendbird/sendbird-uikit-ios/discussions/50) +## Start a 1:1 chat from a button (no channel list) +For a "Chat with seller" button: create the channel with `isDistinct = true`, which returns the existing 1:1 channel when one already has the same members, and then open the channel screen by its URL. Push `SBUGroupChannelViewController(channelURL:)` on your own navigation controller, so the back button returns to your screen. + +```swift +import UIKit +import SendbirdChatSDK +import SendbirdUIKit + +final class SellerProfileViewController: UIViewController { + var sellerUserId = "" + + @objc func chatWithSellerTapped() { + let params = GroupChannelCreateParams() + params.userIds = [sellerUserId] + params.isDistinct = true // same members -> the existing channel comes back + GroupChannel.createChannel(params: params) { [weak self] channel, error in + guard let self, let channel, error == nil else { return } + let channelVC = SBUGroupChannelViewController(channelURL: channel.channelURL) + self.navigationController?.pushViewController(channelVC, animated: true) + } + } + + // From a notification tap, where no navigation controller of yours is at hand. + // Payload format: knowledge/curated/ios/cross-cutting/push.md ("Handle a notification payload"). + func openChannel(fromPush userInfo: [AnyHashable: Any]) { + let sendbird = userInfo["sendbird"] as? [String: Any] + guard let channelURL = (sendbird?["channel"] as? [String: Any])?["channel_url"] as? String else { return } + SendbirdUI.moveToChannel(channelURL: channelURL, basedOnChannelList: false) + } +} +``` + +`SendbirdUI.moveToChannel(channelURL:basedOnChannelList:messageListParams:channelType:rootViewController:)` returns without doing anything when `SBUGlobals.currentUser` is not set. It starts from the window's root view controller (or the selected tab), reuses a channel list or channel screen it finds there, and otherwise presents `SBUViewControllerSet.GroupChannelViewController` in a new `UINavigationController`. With `basedOnChannelList: true` (the default) it presents a channel list first and opens the channel from it. UIKit's own `startChatWithAIBot` uses the same create-then-`moveToChannel(..., basedOnChannelList: false)` sequence. (source: https://github.com/sendbird/sendbird-uikit-ios/blob/3.36.1/Sources/SendbirdUI.swift#L750-L872 — `moveToChannel` and `showChannelViewController`) (source: https://github.com/sendbird/sendbird-uikit-ios/blob/3.36.1/Sources/SendbirdUI.swift#L1096-L1116 — create with `isDistinct`, then move) (SendbirdUIKit.swiftinterface 3.36.2: `moveToChannel` 16572, `SBUGroupChannelViewController.init(channelURL:startingPoint:messageListParams:)` 7363) (source: knowledge/curated/ios/products/chat.md — Create and list group channels) + ## Attachment permissions (Info.plist) UIKit lets users attach photos, videos, and documents, and save media. The docs list four `Info.plist` usage descriptions for these features: `NSPhotoLibraryUsageDescription` (pick from the library), `NSCameraUsageDescription` (take a photo or video), `NSMicrophoneUsageDescription` (record sound with a video), and `NSPhotoLibraryAddUsageDescription` (save media to the library). When camera capture from the message input fails while picking from the library works, check the camera and microphone keys first. Documents from iCloud also need the iCloud capability with iCloud Documents checked under Signing & Capabilities. diff --git a/plugins/sendbird-client/knowledge/curated/js/cross-cutting/troubleshooting.md b/plugins/sendbird-client/knowledge/curated/js/cross-cutting/troubleshooting.md index dbc4482..b60499b 100644 --- a/plugins/sendbird-client/knowledge/curated/js/cross-cutting/troubleshooting.md +++ b/plugins/sendbird-client/knowledge/curated/js/cross-cutting/troubleshooting.md @@ -37,6 +37,16 @@ - **Fix — Web:** Render Sendbird components only on the client. Load the component that imports `@sendbird/uikit-react` with Next.js `dynamic(() => import(...), { ssr: false })`. For `sendbird-calls`, the "self is not defined" crash was fixed in 1.10.5, so use 1.10.5 or later (the pinned 1.10.21 includes the fix). - **Cases:** https://community.sendbird.com/t/syntaxerror-cannot-use-import-statement-outside-a-module/5142, https://community.sendbird.com/t/sendbird-calls-v1-9-3-error-referenceerror-self-is-not-defined/6885 +### webpack 5, Vite, or Create React App: the build names a Node.js core module (`crypto`, `events`, `https`, ...) inside a Sendbird package + +- **Cause:** The browser entries of the pinned packages import no Node.js core module, so the message points to one of three things. + - The app imports `@sendbird/chat/node`. That is the Node.js entry; its first line imports `events`, `https`, `http`, `net`, `tls`, `crypto`, `stream`, `url`, `zlib`, `fs`, `path`, `os`, `buffer`, and `util`. In the published `@sendbird/chat` 4.22.13 files, only `node.js` and `cjs/node.cjs` import those modules. (source: @sendbird/chat 4.22.13 package.json `exports["./node"]` ; node.js:1) + - The app runs `@sendbird/chat` 4.13.2. That release pulled Node.js packages into the browser bundle, and Vite printed `Module "events" has been externalized for browser compatibility, imported by ".../@sendbird/chat/lib/__bundle-....js"` (and the same for `https`, `net`, `crypto`, ...). 4.13.3 "Fixed a build error related to Node.js package inclusion". (source: @sendbird/chat 4.22.13 CHANGELOG.md:543-545) + - The app runs a `@sendbird/uikit-react` v3 beta. With Create React App (webpack 5) the 3.0.0 betas failed with webpack's "BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules" error; the reporter confirmed it went away when v3 reached general availability. +- **Fix — Web:** Upgrade to the pinned versions (`@sendbird/chat` 4.22.13, `@sendbird/uikit-react` 3.19.1), and import `@sendbird/chat` instead of `@sendbird/chat/node` in browser code. Do not add Node.js polyfills for Sendbird. Sendbird's own Vite samples for UIKit React build with only `@vitejs/plugin-react` in `vite.config` (source: https://github.com/sendbird/sendbird-uikit-react/blob/v3.19.1/samples/router/vite.config.ts ; https://github.com/sendbird/sendbird-uikit-react/blob/v3.19.1/samples/groupchannel/vite.config.js). If the path in the message is not under `node_modules/@sendbird/`, another package brings in the module. +- **"process is not defined" from `@sendbird/uikit-react`:** reported with 3.1.1 under webpack 5, where the stack pointed at a `debuglog` helper in `MessageInput.js`; the posted workaround was a community polyfill. In 3.19.1 the only `process` reference in the published files is `process.env.NODE_ENV`, and webpack 5 sets that value from `mode` by default (source: https://webpack.js.org/configuration/optimization/#optimizationnodeenv). Upgrade before adding a polyfill. +- **Cases:** https://community.sendbird.com/t/sdk-4-13-2-uses-node-libraries/9854, https://community.sendbird.com/t/ui-kit-v3-5-beta-does-not-work-with-create-react-app/4766 — community, https://community.sendbird.com/t/breaking-change-webpack-5-used-to-include-polyfills-for-node-js-core-modules-by-default/4837, https://community.sendbird.com/t/uncaught-referenceerror-process-is-not-defined-in-react-uikit-v3/5394 — community + ### Errors that come from two copies of a Sendbird package - **Symptom — React Native:** After an upgrade, UIKit hooks report a missing BottomSheet or ActionMenu context. diff --git a/plugins/sendbird-client/knowledge/curated/js/products/chat.md b/plugins/sendbird-client/knowledge/curated/js/products/chat.md index ac659c2..7b8ae08 100644 --- a/plugins/sendbird-client/knowledge/curated/js/products/chat.md +++ b/plugins/sendbird-client/knowledge/curated/js/products/chat.md @@ -65,22 +65,26 @@ const channel = await sb.groupChannel.createChannel({ For a live-updating channel list (the common case for a channel-list screen), use a collection instead of a one-shot query: ```ts -import { GroupChannelFilter, GroupChannelListOrder } from '@sendbird/chat/groupChannel'; +import type { BaseChannel } from '@sendbird/chat'; +import { GroupChannelFilter, GroupChannelListOrder, type GroupChannel } from '@sendbird/chat/groupChannel'; const collection = sb.groupChannel.createGroupChannelCollection({ filter: new GroupChannelFilter(), // e.g. filter.includeEmpty = true order: GroupChannelListOrder.LATEST_LAST_MESSAGE, }); +// The handlers receive BaseChannel[]; narrow them before they go into GroupChannel[] state. +const asGroup = (list: BaseChannel[]) => list.filter((c): c is GroupChannel => c.isGroupChannel()); collection.setGroupChannelCollectionHandler({ - onChannelsAdded: (context, channels) => { /* prepend/merge into UI state */ }, - onChannelsUpdated: (context, channels) => { /* re-render changed rows */ }, + onChannelsAdded: (context, channels) => { /* add asGroup(channels) to UI state */ }, + onChannelsUpdated: (context, channels) => { /* replace rows by url with asGroup(channels) */ }, onChannelsDeleted: (context, channelUrls) => { /* remove rows */ }, }); -const channels = await collection.loadMore(); // first page; call again to paginate +const channels = await collection.loadMore(); // GroupChannel[]; first page, call again to paginate // collection.dispose() when the screen unmounts ``` +The handler arguments are typed `BaseChannel[]`, so passing them straight into `GroupChannel[]` state (for example `setChannels((prev) => [...channels, ...prev])` in React) fails to type-check. Narrow them with the `isGroupChannel()` type guard, as above; `loadMore()` and the `channels` getter already return `GroupChannel[]`. (source: `@sendbird/chat@4.22.13` lib/__definition.d.ts:196 `isGroupChannel(): this is GroupChannel` on `BaseChannel` :169, :5347 `get channels(): GroupChannel[]`, :5374 `onChannelsAdded?: (context, channels: BaseChannel[])`, :5376 `onChannelsUpdated?: (context, channels: BaseChannel[])`) `createGroupChannelCollection(params?: GroupChannelCollectionParams)` is on `GroupChannelModule`; `setGroupChannelCollectionHandler(handler)` and `loadMore(): Promise` are on the returned `BaseChannelCollection`, along with `hasMore` and event fields `onChannelsAdded` / `onChannelsUpdated` / `onChannelsDeleted`. `dispose()` is declared on `GroupChannelCollection` itself. A one-shot alternative exists as `sb.groupChannel.createMyGroupChannelListQuery(params)` (returns a `GroupChannelListQuery`), and `createPublicGroupChannelListQuery(params)` lists channels the current user hasn't joined yet. (source: `@sendbird/chat@4.22.13` lib/__definition.d.ts:6156 `createGroupChannelCollection`, :6162 `createMyGroupChannelListQuery`, :6175 `createPublicGroupChannelListQuery`, :5338-5357 `BaseChannelCollection` incl. `setGroupChannelCollectionHandler`/`loadMore`/`hasMore`, :5502-5506 `GroupChannelCollection.dispose`, :5374-5378 `onChannelsAdded/Updated/Deleted`, :5918 `GroupChannelListOrder`) ## Send a message diff --git a/plugins/sendbird-client/knowledge/curated/js/products/uikit.md b/plugins/sendbird-client/knowledge/curated/js/products/uikit.md index a2a06fb..0c9e771 100644 --- a/plugins/sendbird-client/knowledge/curated/js/products/uikit.md +++ b/plugins/sendbird-client/knowledge/curated/js/products/uikit.md @@ -288,6 +288,42 @@ import { GroupChannelHeader } from '@sendbird/uikit-react/GroupChannel/component Use `onChatHeaderActionClick` on `GroupChannel` if you only need to react to the default info button. (source: https://github.com/sendbird/sendbird-uikit-react/blob/v3.19.1/src/modules/GroupChannel/components/GroupChannelHeader/GroupChannelHeaderView.tsx ; @sendbird/uikit-react@3.19.1 types/modules/GroupChannel/components/GroupChannelUI/GroupChannelUIView.d.ts:25 ; types/modules/GroupChannel/components/GroupChannelHeader/index.d.ts:3-6 ; types/ui/Header/index.d.ts:6-10 `HeaderCustomProps` ; types/modules/GroupChannelList/components/GroupChannelListHeader/index.d.ts:4-11 ; types/modules/GroupChannel/context/types.d.ts:74) +### Start a 1:1 chat from a button (no channel list) +Inside `SendbirdProvider`, get the create function with `sendbirdSelectors.getCreateGroupChannel(useSendbirdStateContext())`, create the channel with `isDistinct: true` (the existing 1:1 channel comes back when one has the same members), and show only `GroupChannel` for its URL. Sendbird's public router sample does the navigation part with react-router: the route `channels/:channelUrl` renders `GroupChannel channelUrl={channelUrl}`, and `onBackClick` navigates back. + +```tsx +import { GroupChannel } from '@sendbird/uikit-react/GroupChannel'; +import useSendbirdStateContext from '@sendbird/uikit-react/useSendbirdStateContext'; +import sendbirdSelectors from '@sendbird/uikit-react/sendbirdSelectors'; + +// Render inside . onOpen navigates to your conversation route or sets state. +export function ChatWithSellerButton({ sellerUserId, onOpen }: { sellerUserId: string; onOpen: (channelUrl: string) => void }) { + const createChannel = sendbirdSelectors.getCreateGroupChannel(useSendbirdStateContext()); + return ( + + ); +} + +// The conversation alone, without a channel list. +export function SellerChatPage({ channelUrl, onBack }: { channelUrl: string; onBack: () => void }) { + return ( +
+ +
+ ); +} +``` +(source: https://github.com/sendbird/sendbird-uikit-react/blob/v3.19.1/samples/router/src/MobileLayout/Router.tsx#L9-L27 — `channels/:channelUrl` route) (source: https://github.com/sendbird/sendbird-uikit-react/blob/v3.19.1/samples/router/src/MobileLayout/Channel.tsx#L6-L31 — `GroupChannel` for the route's channel URL) (source: @sendbird/uikit-react 3.19.1 types/lib/selectors.d.ts:76, 226-248 — `getCreateGroupChannel` and the default export ; types/lib/Sendbird/context/hooks/useSendbirdStateContext.d.ts:2-3 ; package.json `exports` `./sendbirdSelectors`, `./useSendbirdStateContext`) (source: knowledge/curated/js/products/chat.md — Create and list group channels) + +Opening a channel from a browser notification tap is not covered here: these docs have no verified web push guide for `@sendbird/chat` (see knowledge/curated/js/cross-cutting/push.md). + ### Threads Set `replyType="THREAD"` on `GroupChannel` (or `uikitOptions.groupChannel.replyType: 'thread'` on the provider) to show "Reply in thread" in the message menu. The thread screen is a separate module, `Thread`, that you render yourself: `onReplyInThreadClick({ message })` on `GroupChannel` gives you the parent message, and `Thread` takes `channelUrl` and `message`. `onMoveToParentMessage` on `Thread` receives the parent message and its channel. `threadReplySelectType` decides whether tapping a reply in the channel opens the thread or scrolls to the parent message. Threads are one level deep, in group and supergroup channels only. @@ -566,6 +602,48 @@ To change every UIKit header at once (for example to hand them to React Navigati (source: https://github.com/sendbird/sendbird-uikit-react-native/blob/v3.12.10/packages/uikit-react-native/src/domain/groupChannel/component/GroupChannelHeader.tsx lines 11-51 ; src/domain/groupChannel/types.ts:70-74,143-151 ; src/domain/groupChannel/index.ts:8 ; src/containers/SendbirdUIKitContainer.tsx:107-113,252 ; @sendbird/uikit-react-native-foundation@3.12.10 src/ui/Header/index.tsx:12-25 `HeaderProps` ; src/index.ts:7,33 `Icon`, `Header` ; https://sendbird.com/docs/chat/uikit/v3/react-native/customization/sendbirduikitcontainer) +### Start a 1:1 chat from a button (no channel list) +Get the SDK instance with `useSendbirdChat()`, create the channel with `isDistinct: true`, and navigate to a screen that loads the channel by URL with `useGroupChannel(sdk, channelUrl)` from `@sendbird/uikit-chat-hooks` and renders the group channel fragment. This is how Sendbird's public sample builds its `GroupChannel` route: React Navigation passes `{ channelUrl }` as the route params. For a push tap, read the channel URL with `parseSendbirdNotification` (knowledge/curated/js/cross-cutting/push.md, "React Native: opening a channel from a push tap") and navigate to the same route. + +```tsx +import React from 'react'; +import { Button } from 'react-native'; +import { createGroupChannelFragment, useSendbirdChat } from '@sendbird/uikit-react-native'; +import { useGroupChannel } from '@sendbird/uikit-chat-hooks'; + +// onOpen: for example (url) => navigation.navigate('GroupChannel', { channelUrl: url }) +export function ChatWithSellerButton({ sellerUserId, onOpen }: { sellerUserId: string; onOpen: (channelUrl: string) => void }) { + const { sdk } = useSendbirdChat(); + return ( +