Skip to content

feat(plugins): Add support for the plugin to unmount on meeting end - #22671

Merged
antobinary merged 6 commits into
bigbluebutton:v3.0.x-releasefrom
GuiLeme:unmount-plugin-on-meeting-end
May 13, 2025
Merged

antobinary merged 6 commits into
bigbluebutton:v3.0.x-releasefrom
GuiLeme:unmount-plugin-on-meeting-end

Conversation

@GuiLeme

@GuiLeme GuiLeme commented Mar 12, 2025 •

Copy link
Copy Markdown
Contributor

What does this PR do?

This PR basically creates a way for the plugin to decide whether to unmount when the meeting is ended or the user is ejected.

Motivation

This PR fixes the problem where the pick-random-user modal continues open when meeting terminates (if it was open before).

A subsequent PR is going to be sent to the pick-random-user plugin repo implementing this function.

It's worth mentioning that if, for any reason, the plugin dev doesn't want to terminate the plugin once the meeting is over, that's still possible, once this function is not even mandatory.

How to test

Use this branch to test the pick-random-user:

  • Open the modal to pick another user;
  • End the meeting via API call to bbb-web.

More

Closely related to SDK PR bigbluebutton/bigbluebutton-html-plugin-sdk#157
Closely related the Plugin PR: bigbluebutton/bbb-plugin-pick-random-user#31

Just a reminder: Don't merge it until the SDK's PR is merged and the version is bumped

See demo ahead:

fix_plugin_unmount.mp4

@coderabbitai

coderabbitai Bot commented Mar 12, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

The changes introduce a new React functional component, PluginTopLevelManager, and a corresponding interface, PluginTopLevelManagerProps, to manage plugin events related to meeting status. Within the existing PresenceManager component, the rendering of the new component is integrated by computing a boolean variable, userCurrentlyInMeeting, based on several meeting state conditions. This variable is then passed as a prop (currentUserCurrentlyInMeeting) to the PluginTopLevelManager. In the new component, a custom hook (useStatePreviousValue) is used to detect changes in the prop's value. When a change occurs, the component dispatches a custom event (HookEvents.BBB_CORE_UPDATED_MEETING_STATUS) that includes the updated meeting status. The component itself does not render any UI elements and simply returns null.

Sequence Diagram(s)

sequenceDiagram
    participant PM as PresenceManager
    participant PTLM as PluginTopLevelManager
    participant Hook as useStatePreviousValue
    participant EVT as CustomEvent Dispatcher

    PM->>PTLM: Render PluginTopLevelManager(currentUserCurrentlyInMeeting)
    PTLM->>Hook: Retrieve previous value of currentUserCurrentlyInMeeting
    Hook-->>PTLM: Return previous value
    alt Value Changed
        PTLM->>EVT: Dispatch HookEvents.BBB_CORE_UPDATED_MEETING_STATUS with new status
    else No Change
        PTLM-->>PTLM: No event dispatched
    end
Loading

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 30923f6 and 98930cf.

📒 Files selected for processing (1)
  • bigbluebutton-html5/imports/ui/components/join-handler/presenceManager/component.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • bigbluebutton-html5/imports/ui/components/join-handler/presenceManager/component.tsx
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: build-package (others)
  • GitHub Check: build-package (bbb-html5)
  • GitHub Check: build-package (bbb-graphql-server)
  • GitHub Check: build-package (bbb-playback-record)
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🔭 Outside diff range comments (1)
bigbluebutton-html5/imports/ui/components/join-handler/presenceManager/utils.tsx (1)

22-23: 🛠️ Refactor suggestion

Export as a proper React hook.

After converting the function to a proper React hook, update the export to match the new name.

-export default updateMeetingStatusForPlugin;
+export default useUpdateMeetingStatusForPlugin;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3a11339 and db54ee8.

📒 Files selected for processing (2)
  • bigbluebutton-html5/imports/ui/components/join-handler/presenceManager/component.tsx (2 hunks)
  • bigbluebutton-html5/imports/ui/components/join-handler/presenceManager/utils.tsx (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: Typescript - compile code
bigbluebutton-html5/imports/ui/components/join-handler/presenceManager/utils.tsx

[error] 2-2: error TS2305: Module '"bigbluebutton-html-plugin-sdk"' has no exported member 'MeetingStatusData'.


[error] 4-4: error TS2305: Module '"bigbluebutton-html-plugin-sdk/dist/cjs/core/enum"' has no exported member 'GENERIC_HOOK_PLUGIN'.


[error] 10-10: error TS2339: Property 'BBB_CORE_UPDATED_MEETING_STATUS' does not exist on type 'typeof HookEvents'.

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: build-package (others)
  • GitHub Check: build-package (bbb-html5)
  • GitHub Check: build-package (bbb-graphql-server)
  • GitHub Check: build-package (bbb-playback-record)
🔇 Additional comments (2)
bigbluebutton-html5/imports/ui/components/join-handler/presenceManager/component.tsx (2)

166-167: Good refactoring of meeting render condition.

Extracting the complex conditional expression into a named constant improves readability and makes the code's intent clearer. This is a good practice.


172-172: Simplified render condition improves code readability.

Using the extracted renderMeeting constant simplifies the JSX and makes the code more maintainable. Good improvement.

@gustavotrott

Copy link
Copy Markdown
Contributor

renderMeeting is not self-explanatory in my opinion.
what if you name the new prop as userCurrentlyInMeeting?

@antobinary antobinary added this to the Release 3.0 milestone Mar 12, 2025

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

♻️ Duplicate comments (2)
bigbluebutton-html5/imports/ui/components/join-handler/presenceManager/utils.tsx (2)

1-5: ⚠️ Potential issue

TypeScript import errors need to be fixed.

There are TypeScript compiler errors indicating several imports cannot be resolved:

  • MeetingStatusData from bigbluebutton-html-plugin-sdk
  • GENERIC_HOOK_PLUGIN from bigbluebutton-html-plugin-sdk/dist/cjs/core/enum
  • BBB_CORE_UPDATED_MEETING_STATUS property doesn't exist on HookEvents

Check if the SDK exports have changed or if you need to update to a newer SDK version.

🧰 Tools
🪛 GitHub Actions: Typescript - compile code

[error] 2-2: error TS2305: Module '"bigbluebutton-html-plugin-sdk"' has no exported member 'MeetingStatusData'.


[error] 4-4: error TS2305: Module '"bigbluebutton-html-plugin-sdk/dist/cjs/core/enum"' has no exported member 'GENERIC_HOOK_PLUGIN'.


6-21: ⚠️ Potential issue

Hooks usage outside of component context violates React's Rules of Hooks.

Using useRef inside a utility function breaks React's Rules of Hooks. Hooks must only be called inside:

  1. React function components
  2. Custom React hooks (names must start with "use")

This will cause unpredictable behavior as the hook won't maintain state properly between renders.

Convert this to a proper custom React hook:

-const updateMeetingStatusForPlugin = (currentUserCurrentlyInMeeting: boolean) => {
+const useUpdateMeetingStatusForPlugin = (currentUserCurrentlyInMeeting: boolean) => {
   const previousUserCurrentlyInMeeting = useRef(true);
   
+  useEffect(() => {
     if (previousUserCurrentlyInMeeting.current !== currentUserCurrentlyInMeeting) {
       window.dispatchEvent(new CustomEvent<UpdatedEventDetails<MeetingStatusData>>(
         HookEvents.BBB_CORE_UPDATED_MEETING_STATUS,
         {
           detail: {
             data: {
               userCurrentlyInMeeting: currentUserCurrentlyInMeeting,
             },
             hook: GENERIC_HOOK_PLUGIN,
           },
         },
       ));
+      previousUserCurrentlyInMeeting.current = currentUserCurrentlyInMeeting;
     }
+  }, [currentUserCurrentlyInMeeting]);
 };

Also, you'll need to update imports to include useEffect from React:

-import { useRef } from 'react';
+import { useRef, useEffect } from 'react';

The consuming component will need to be updated to use this hook properly.

🧰 Tools
🪛 GitHub Actions: Typescript - compile code

[error] 10-10: error TS2339: Property 'BBB_CORE_UPDATED_MEETING_STATUS' does not exist on type 'typeof HookEvents'.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between db54ee8 and 5d978de.

📒 Files selected for processing (2)
  • bigbluebutton-html5/imports/ui/components/join-handler/presenceManager/component.tsx (2 hunks)
  • bigbluebutton-html5/imports/ui/components/join-handler/presenceManager/utils.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • bigbluebutton-html5/imports/ui/components/join-handler/presenceManager/component.tsx
🧰 Additional context used
🪛 GitHub Actions: Typescript - compile code
bigbluebutton-html5/imports/ui/components/join-handler/presenceManager/utils.tsx

[error] 2-2: error TS2305: Module '"bigbluebutton-html-plugin-sdk"' has no exported member 'MeetingStatusData'.


[error] 4-4: error TS2305: Module '"bigbluebutton-html-plugin-sdk/dist/cjs/core/enum"' has no exported member 'GENERIC_HOOK_PLUGIN'.


[error] 10-10: error TS2339: Property 'BBB_CORE_UPDATED_MEETING_STATUS' does not exist on type 'typeof HookEvents'.

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: build-package (others)
  • GitHub Check: build-package (bbb-html5)
  • GitHub Check: build-package (bbb-graphql-server)
  • GitHub Check: build-package (bbb-playback-record)

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5d978de and a1a26ad.

📒 Files selected for processing (3)
  • bigbluebutton-html5/imports/ui/components/join-handler/presenceManager/component.tsx (2 hunks)
  • bigbluebutton-html5/imports/ui/components/meeting-status-update/component.tsx (1 hunks)
  • bigbluebutton-html5/imports/ui/components/meeting-status-update/types.ts (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: Typescript - compile code
bigbluebutton-html5/imports/ui/components/meeting-status-update/component.tsx

[error] 2-2: error TS2305: Module '"bigbluebutton-html-plugin-sdk"' has no exported member 'MeetingStatusData'.


[error] 4-4: error TS2305: Module '"bigbluebutton-html-plugin-sdk/dist/cjs/core/enum"' has no exported member 'GENERIC_HOOK_PLUGIN'.


[error] 15-15: error TS2339: Property 'BBB_CORE_UPDATED_MEETING_STATUS' does not exist on type 'typeof HookEvents'.

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: build-package (others)
  • GitHub Check: build-package (bbb-html5)
  • GitHub Check: build-package (bbb-graphql-server)
  • GitHub Check: build-package (bbb-playback-record)
🔇 Additional comments (6)
bigbluebutton-html5/imports/ui/components/meeting-status-update/types.ts (1)

1-3: Clean and well-structured interface definition.

The interface is clearly named and follows TypeScript best practices with a descriptive property name. This type definition provides good structure for the component props.

bigbluebutton-html5/imports/ui/components/join-handler/presenceManager/component.tsx (3)

19-19: Good addition of import statement.

This import correctly references the new component that will handle meeting status updates for plugins.


166-167: Improved code clarity with descriptive variable name.

Extracting this condition into a named variable improves readability and makes the code more maintainable. The variable name userCurrentlyInMeeting clearly communicates its purpose, which is better than the previous inline condition approach.


170-174: Good implementation of the new component.

The component is correctly placed within the JSX structure and receives the appropriate prop. The refactoring of the conditional rendering to use the new variable makes the code more readable.

bigbluebutton-html5/imports/ui/components/meeting-status-update/component.tsx (2)

8-10: Good component declaration with proper TypeScript typing.

The component declaration correctly uses the React.FC type with the defined props interface. The destructuring of props is also implemented correctly.


27-30: Component correctly returns null.

Since this component's purpose is to handle side effects (dispatching events) rather than rendering UI elements, returning null is appropriate.

@GuiLeme
GuiLeme force-pushed the unmount-plugin-on-meeting-end branch from ef15d34 to e28d862 Compare March 14, 2025 19:08

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
bigbluebutton-html5/imports/ui/components/plugin-top-level-manager/component.tsx (1)

22-22: Consider renaming to match PR objectives feedback.

In the PR comments, user gustavotrott suggested renaming this property to improve clarity. The current name userCurrentlyInMeeting is good, but for consistency with the interface prop name, consider using the same terminology.

- userCurrentlyInMeeting: currentUserCurrentlyInMeeting,
+ currentUserCurrentlyInMeeting: currentUserCurrentlyInMeeting,
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a1a26ad and e28d862.

📒 Files selected for processing (3)
  • bigbluebutton-html5/imports/ui/components/join-handler/presenceManager/component.tsx (2 hunks)
  • bigbluebutton-html5/imports/ui/components/plugin-top-level-manager/component.tsx (1 hunks)
  • bigbluebutton-html5/imports/ui/components/plugin-top-level-manager/types.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • bigbluebutton-html5/imports/ui/components/join-handler/presenceManager/component.tsx
🧰 Additional context used
🪛 GitHub Actions: Typescript - compile code
bigbluebutton-html5/imports/ui/components/plugin-top-level-manager/component.tsx

[error] 2-2: error TS2305: Module '"bigbluebutton-html-plugin-sdk"' has no exported member 'MeetingStatusData'.


[error] 4-4: error TS2305: Module '"bigbluebutton-html-plugin-sdk/dist/cjs/core/enum"' has no exported member 'GENERIC_HOOK_PLUGIN'.


[error] 18-18: error TS2339: Property 'BBB_CORE_UPDATED_MEETING_STATUS' does not exist on type 'typeof HookEvents'.

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: build-package (others)
  • GitHub Check: build-package (bbb-html5)
  • GitHub Check: build-package (bbb-graphql-server)
  • GitHub Check: build-package (bbb-playback-record)
🔇 Additional comments (1)
bigbluebutton-html5/imports/ui/components/plugin-top-level-manager/types.ts (1)

1-3: Interface definition looks clean and appropriate.

The PluginTopLevelManagerProps interface is well-defined with a clear property name that accurately represents its purpose. It follows TypeScript best practices for interface naming and property definition.

@Tainan404 Tainan404 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

@sonarqubecloud

Copy link
Copy Markdown

@GuiLeme
GuiLeme marked this pull request as draft March 17, 2025 14:31
@GuiLeme

GuiLeme commented Mar 17, 2025

Copy link
Copy Markdown
Contributor Author

Just converted to draft until the SDK PR is Merged and has it's version bumped.

@github-actions

Copy link
Copy Markdown

This pull request has conflicts ☹
Please resolve those so we can review the pull request.
Thanks.

@antobinary

Copy link
Copy Markdown
Member

Looks like the SDK PR was merged. Please resolve the conflict and we can have it in.

@GuiLeme
GuiLeme marked this pull request as ready for review May 12, 2025 20:20
@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

Automated tests Summary

✅ All the CI tests have passed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants