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

feat(plugin): asset persistence #133

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion samples/sample-action-button-dropdown-plugin/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
"name": "SampleActionButtonDropdownPlugin",
"javascriptEntrypointUrl": "SampleActionButtonDropdownPlugin.js",
"localesBaseUrl": "https://cdn.dominio.com/pluginabc/",
"enabledForBreakoutRooms": true
"assetPersistence": {
"enabled": true,
"maxFileSize": 10000000,
"maxUploadSizePerUser": 100000000
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react';
import { useState, useEffect } from 'react';
import { AssetType } from 'bigbluebutton-html-plugin-sdk/dist/cjs/asset-persistence/enums';
import * as ReactModal from 'react-modal';
import './style.css';

Expand Down Expand Up @@ -45,13 +46,22 @@ function SampleActionButtonDropdownPlugin(
IsMeetingBreakoutGraphqlResponse>(IS_MEETING_BREAKOUT);

useEffect(() => {
// This line is commented once it will upload a
// PDF everytime you enter a meeting
// (if you have presenter role).
// Uncomment them to test this feature!
pluginApi.persistAsset(
'https://pdfobject.com/pdf/sample.pdf',
AssetType.PRESENTATION,
'my-presentation.pdf',
);
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',
// helpLabel: 'test help label', // this is not necessary
// helpLink: 'test help link',
autoClose: 20000,
},
content: 'Content of my notification',
Expand Down
7 changes: 7 additions & 0 deletions src/asset-persistence/enums.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export enum AssetPersistenceEvents {
ASSET_PERSISTED = 'PLUGIN_ASSET_PERSISTED',
}

export enum AssetType {
PRESENTATION = 'PLUGIN_ASSET_PERSISTENCE_TYPE_PRESENTATION'
}
23 changes: 23 additions & 0 deletions src/asset-persistence/hook.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {
AssetPersistenceDetails,
} from './types';
import { AssetPersistenceEvents, AssetType } from './enums';

export const persistAssetFunctionWrapper = (
pluginName: string,
assetUrl: string,
typeOfAsset: AssetType,
assetName?: string,
) => {
window.dispatchEvent(
new CustomEvent<
AssetPersistenceDetails>(AssetPersistenceEvents.ASSET_PERSISTED, {
detail: {
pluginName,
assetUrl,
typeOfAsset,
assetName,
},
}),
);
};
14 changes: 14 additions & 0 deletions src/asset-persistence/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { AssetType } from './enums';

export interface AssetPersistenceDetails {
pluginName: string;
assetUrl: string;
typeOfAsset: AssetType;
assetName?: string;
}

export type PersistAssetFunction = (
assetUrl: string,
typeOfAsset: AssetType,
assetName?: string,
) => void;
12 changes: 12 additions & 0 deletions src/core/api/BbbPluginSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ import { sendGenericDataForLearningAnalyticsDashboard } from '../../learning-ana
import { GenericDataForLearningAnalyticsDashboard } from '../../learning-analytics-dashboard/types';
import { getRemoteData } from '../../remote-data/utils';
import { persistEventFunctionWrapper } from '../../event-persistence/hooks';
import { persistAssetFunctionWrapper } from '../../asset-persistence/hook';
import { AssetType } from '../../asset-persistence/enums';

declare const window: PluginBrowserWindow;

Expand Down Expand Up @@ -123,6 +125,16 @@ export abstract class BbbPluginSdk {
eventName,
payload,
);
pluginApi.persistAsset = (
assetUrl: string,
typeOfAsset: AssetType,
assetName?: string,
) => persistAssetFunctionWrapper(
pluginName,
assetUrl,
typeOfAsset,
assetName,
);
} else {
throw new Error('Plugin name not set');
}
Expand Down
8 changes: 8 additions & 0 deletions src/core/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { UseUserCameraDomElementsFunction } from '../../dom-element-manipulation
import { ScreenshareHelperInterface, UserCameraHelperInterface } from '../../extensible-areas';
import { GetDataSource } from '../../remote-data/types';
import { PersistEventFunction } from '../../event-persistence/types';
import { PersistAssetFunction } from '../../asset-persistence/types';

// Setter Functions for the API
export type SetPresentationToolbarItems = (presentationToolbarItem:
Expand Down Expand Up @@ -259,6 +260,13 @@ export interface PluginApi {
*
*/
persistEvent?: PersistEventFunction;
/**
* Persists assets to the current meeting, e.g.: presentation.
*
* @param payload - payload to be persisted in `events.xml`
*
*/
persistAsset?: PersistAssetFunction;
}

export interface PluginBrowserWindow extends Window {
Expand Down