Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS] Integrate Jitsi SDK with Transcription support and JitsiSDK Update #23323

Merged
merged 6 commits into from
May 31, 2024

Conversation

iccub
Copy link
Contributor

@iccub iccub commented Apr 29, 2024

Resolves brave/brave-browser#38368
Security ticket https://github.com/brave/reviews/issues/1613

Submitter Checklist:

  • I confirm that no security/privacy review is needed and no other type of reviews are needed, or that I have requested them
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally:
    • npm run test -- brave_browser_tests, npm run test -- brave_unit_tests wiki
    • npm run presubmit wiki, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

  1. The call has to be started from a desktop or android device, iOS does not offer recording options for both transcripts and video.
  2. Join the call from desktop/android
  3. on iOS the transcripts are gathered during the call only. It does not store transcripts prior to joining the call.
  4. Tap on the arrow in top left to enter picture in picture
  5. Tap on the menu to open Leo
  6. Tap "Summarize this page"
  7. Leo returns the transcript summary

Few notes

  1. iOS cannot start recording transcripts or video calls, it can only join existing calls/
  2. Unlike desktop, iOS transcripts start when joined only, it does not transcripts right from the beginning.
  3. It has to be done in picture in picture mode, if you leave the call the transcript is gone
  4. We have no direct control over the Brave Talk UI, it comes from our vendor in a form of native SDK.

@iccub iccub changed the title wip [iOS] JitsiSDK Update Apr 29, 2024
@iccub iccub added CI/skip-android Do not run CI builds for Android CI/skip-macos-x64 Do not run CI builds for macOS x64 CI/skip-windows-x64 Do not run CI builds for Windows x64 labels May 6, 2024
@iccub iccub marked this pull request as ready for review May 13, 2024 15:41
@iccub iccub requested a review from a team as a code owner May 13, 2024 15:41
@iccub iccub changed the title [iOS] JitsiSDK Update [iOS] Brave Talk x Leo transcript integration and JitsiSDK Update May 14, 2024
@iccub iccub changed the title [iOS] Brave Talk x Leo transcript integration and JitsiSDK Update [iOS] Integrate Jitsi SDK with Transcription support and JitsiSDK Update May 14, 2024
@@ -35,3 +35,13 @@ public func XCTAssertAsyncNoThrow<T>(
XCTFail(message(), file: file, line: line)
}
}

// swift-format-ignore
public func XCTunwrapAsync<T>(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor nit: XCTUnwrapAsync


import Collections
import Foundation
@_spi(AppLaunch) import Shared
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need @_spi(AppLaunch) since you're not updating the channel in this test

Comment on lines +47 to +48
@MainActor
func processTranscript(dictionary: [AnyHashable: Any]) async {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does simple JSON decoding have to be done on the main actor?

@@ -3693,3 +3694,13 @@ extension BrowserViewController {
present(chatController, animated: true)
}
}

extension BraveTalkJitsiCoordinator: AIChatBraveTalkJavascript {
@MainActor
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

main actor is not needed

import Foundation
import os.log

public class BraveTalkJitsiTranscriptProcessor {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like you want an actor here based on number of MainActor additions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has been an actor but @Brandon-T reverted it to a class when integrating with Leo :P I think he ran into some issues

@@ -14,6 +14,7 @@ public class AIChatViewModel: NSObject, ObservableObject {
private var api: AIChat!
private weak var webView: WKWebView?
private let script: any AIChatJavascript.Type
private let braveTalkScript: AIChatBraveTalkJavascript?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(any AIChatBraveTalkJavascript)?

@@ -19,3 +19,8 @@ public protocol AIChatJavascript {
@MainActor
static func getPrintViewPDF(webView: WKWebView) async -> Data
}

public protocol AIChatBraveTalkJavascript {
@MainActor
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why main actor isolated?

Copy link
Contributor

[puLL-Merge] - brave/brave-core@23323

Description

This PR adds the ability to use Brave Talk transcripts as context for AI chat. It introduces a new BraveTalkJitsiTranscriptProcessor class to handle processing and storing transcripts received from Jitsi, and exposes this functionality to the AIChatViewModel through a new AIChatBraveTalkJavascript protocol.

The main motivation for this change seems to be enhancing the AI chat experience by leveraging the conversation context from Brave Talk calls.

Changes

Changes

  • ios/brave-ios/App/Client.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved: Updates the revision of the Jitsi WebRTC dependency.
  • ios/brave-ios/Package.swift: Adds test target dependencies for BraveTalkTests.
  • ios/brave-ios/Sources/AIChat/ModelView/AIChatJavaScript.swift: Defines a new AIChatBraveTalkJavascript protocol for retrieving Brave Talk transcripts.
  • ios/brave-ios/Sources/AIChat/ModelView/AIChatViewModel.swift:
    • Adds braveTalkScript property and initializer parameter to support AIChatBraveTalkJavascript.
    • In getContext(), attempts to retrieve a Brave Talk transcript before falling back to other context sources.
  • ios/brave-ios/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController.swift:
    • Passes self.braveTalkJitsiCoordinator to AIChatViewModel initializer.
    • Extends BraveTalkJitsiCoordinator to conform to AIChatBraveTalkJavascript.
  • ios/brave-ios/Sources/Brave/Frontend/Settings/SettingsViewController.swift: Passes nil for braveTalkScript when initializing AIChatViewModel from settings.
  • ios/brave-ios/Sources/BraveTalk/BraveTalkJitsiCoordinator.swift:
    • Adds jitsiTranscriptProcessor property to store a BraveTalkJitsiTranscriptProcessor instance.
    • Updates JitsiDelegate to handle transcript chunk events.
  • ios/brave-ios/Sources/BraveTalk/BraveTalkJitsiTranscriptProcessor.swift: Implements the new BraveTalkJitsiTranscriptProcessor class for handling Jitsi transcripts.
  • ios/brave-ios/Sources/TestHelpers/ConcurrencyHelpers.swift: Adds a new XCTunwrapAsync helper function.
  • ios/brave-ios/Tests/BraveTalkTests/BraveTalkJitsiTranscriptProcessorTests.swift: Adds tests for BraveTalkJitsiTranscriptProcessor.
  • third_party/ios_deps/JitsiMeet/: Updates the bundled Jitsi Meet SDK.

Security Hotspots

The main potential security concern I see is around handling the transcript data received from Jitsi. It's important to ensure this external data is properly validated and sanitized before using it in any way, to prevent issues like injection attacks or unintended data leakage. The current implementation does deserialize the received data, but it would be good to have an extra validation step.

The tests added for BraveTalkJitsiTranscriptProcessor help provide some confidence that the transcript handling behaves as expected, but additional testing around edge cases and malformed data would further improve coverage.

@iccub iccub merged commit ddf2eb7 into master May 31, 2024
19 checks passed
@iccub iccub deleted the bugfix/jitsi_9.2.2 branch May 31, 2024 13:49
@github-actions github-actions bot added this to the 1.68.x - Nightly milestone May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI/skip-android Do not run CI builds for Android CI/skip-macos-x64 Do not run CI builds for macOS x64 CI/skip-windows-x64 Do not run CI builds for Windows x64 needs-security-review puLL-Merge
Projects
None yet
3 participants