Skip to content

Commit

Permalink
Merge pull request #132 from GuiLeme/plugin-notification
Browse files Browse the repository at this point in the history
feat(plugins): Notification API support for plugins
  • Loading branch information
antobinary authored Nov 6, 2024
2 parents b531211 + f1c6673 commit b461129
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ One other thing is that the type of the return is precisely the same type requir
- close: this function will close the presentation area content automatically;
- conference:
- setSpeakerLevel: this function will set the speaker volume level(audio output) of the conference to a certain number between 0 and 1;
- notification:
- send: This function will send a notification for the client to render, keep in mind that it's only client-side. Should you want it to be rendered in multiple clients, use this with a data-channel;
- user-status:
- setAwayStatus: this function will set the away status of the user to a certain status;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
LayoutPresentatioAreaUiDataNames,
UiLayouts,
pluginLogger,
NotificationTypeUiCommand,
} from 'bigbluebutton-html-plugin-sdk';
import * as ReactDOM from 'react-dom/client';
import { IsMeetingBreakoutGraphqlResponse, SampleActionButtonDropdownPluginProps } from './types';
Expand Down Expand Up @@ -43,6 +44,21 @@ function SampleActionButtonDropdownPlugin(
const { data: isMeetingBreakoutFromGraphql } = pluginApi.useCustomSubscription<
IsMeetingBreakoutGraphqlResponse>(IS_MEETING_BREAKOUT);

useEffect(() => {
pluginApi.uiCommands.notification.send({
message: 'Notification message',
icon: 'presentation',
type: NotificationTypeUiCommand.INFO,
options: {
// helpLabel: 'teste help label', // this is not necessary
// helpLink: 'teste help link',
autoClose: 20000,
},
content: 'Content of my notification',
small: false,
});
}, []);

useEffect(() => {
pluginLogger.info('isMeetingBreakout data: ', isMeetingBreakoutFromGraphql?.meeting);
}, [isMeetingBreakoutFromGraphql]);
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export * from './ui-data-hooks';

export * from './server-commands';

export * from './ui-commands';

export * from './core';

export * from './utils';
2 changes: 2 additions & 0 deletions src/ui-commands/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { sidekickOptionsContainer } from './sidekick-options-container/commands'
import { presentationArea } from './presentation-area/commands';
import { userStatus } from './user-status/commands';
import { conference } from './conference/commands';
import { notification } from './notification/commands';

export const uiCommands = {
chat,
Expand All @@ -12,4 +13,5 @@ export const uiCommands = {
presentationArea,
userStatus,
conference,
notification,
};
1 change: 1 addition & 0 deletions src/ui-commands/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { NotificationTypeUiCommand } from './notification/enums';
17 changes: 17 additions & 0 deletions src/ui-commands/notification/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { NotificationEnum } from './enums';
import { SendNotificationCommandArguments } from './types';

export const notification = {
/**
* Sends notification to be rendered in the front-end.
*/
send: (information: SendNotificationCommandArguments) => {
window.dispatchEvent(
new CustomEvent<
SendNotificationCommandArguments
>(NotificationEnum.SEND, {
detail: information,
}),
);
},
};
11 changes: 11 additions & 0 deletions src/ui-commands/notification/enums.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export enum NotificationEnum {
SEND = 'SEND_NOTIFICATION',
}

export enum NotificationTypeUiCommand {
INFO = 'info',
DEFAULT = 'default',
WARNING = 'warning',
SUCCESS = 'success',
ERROR = 'error'
}
20 changes: 20 additions & 0 deletions src/ui-commands/notification/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { NotificationTypeUiCommand } from './enums';

export interface SendNotificationCommandArgumentsOptions {
helpLabel?: string,
helpLink?: string,
autoClose?: number, // Time, in milliseconds, to auto-close the notification
}

export interface SendNotificationCommandArguments {
message: string;
icon: string;
type: NotificationTypeUiCommand;
options?: SendNotificationCommandArgumentsOptions;
content?: string;
small?: boolean;
}

export interface UiCommandsNotificationObject {
send: (information: SendNotificationCommandArguments) => void;
}
2 changes: 2 additions & 0 deletions src/ui-commands/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { UiCommandsSidekickOptionsContainerObject } from './sidekick-options-con
import { UiCommandsPresentationAreaObject } from './presentation-area/types';
import { UiCommandsUserStatusObject } from './user-status/types';
import { UiCommandsConferenceObject } from './conference/types';
import { UiCommandsNotificationObject } from './notification/types';

export interface UiCommands {
chat: UiCommandsChatObject;
Expand All @@ -12,4 +13,5 @@ export interface UiCommands {
presentationArea: UiCommandsPresentationAreaObject;
userStatus: UiCommandsUserStatusObject;
conference: UiCommandsConferenceObject;
notification: UiCommandsNotificationObject;
}

0 comments on commit b461129

Please sign in to comment.