UNPKG

bigbluebutton-html-plugin-sdk

Version:

This repository contains the SDK for developing BigBlueButton plugins. Plugins are React components that can be loaded from external sources by the BigBlueButton HTML5 client to extend its functionalities.

61 lines 3.24 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useDataChannelGeneral = void 0; var react_1 = require("react"); var enum_1 = require("../core/enum"); var enums_1 = require("./enums"); var utils_1 = require("./utils"); exports.useDataChannelGeneral = (function (channelName, subChannelName, pluginName, pluginApi, dataChannelType) { var _a = (0, react_1.useState)({ loading: true }), data = _a[0], setData = _a[1]; var _b = (0, react_1.useState)(), pushEntryFunction = _b[0], setPushEntryFunction = _b[1]; var deleteEntryFunction = function (objectToDelete) { return (0, utils_1.deleteEntryFunctionUtil)(objectToDelete, channelName, subChannelName, pluginName); }; var replaceEntryFunction = function (entryId, payloadJson) { return (0, utils_1.replaceEntryFunctionUtil)(entryId, channelName, subChannelName, pluginName, payloadJson); }; var channelIdentifier = (0, utils_1.createChannelIdentifier)(channelName, subChannelName, pluginName); var handleDataChange = (function (customEvent) { var eventDetail = customEvent.detail; var hookArguments = eventDetail === null || eventDetail === void 0 ? void 0 : eventDetail.hookArguments; if ((hookArguments === null || hookArguments === void 0 ? void 0 : hookArguments.dataChannelType) === dataChannelType) { setData(eventDetail.data); } }); var handleListenToChangePushEntryFunction = (function () { setPushEntryFunction(function () { return pluginApi.mapOfPushEntryFunctions[channelIdentifier]; }); window.removeEventListener("".concat(channelIdentifier, "::pushEntryFunction"), handleListenToChangePushEntryFunction); }); (0, react_1.useEffect)(function () { window.addEventListener(channelIdentifier, handleDataChange); window.addEventListener("".concat(channelIdentifier, "::pushEntryFunction"), handleListenToChangePushEntryFunction); window.dispatchEvent(new CustomEvent(enum_1.HookEvents.PLUGIN_SUBSCRIBED_TO_BBB_CORE, { detail: { hook: enums_1.DataChannelHooks.DATA_CHANNEL_BUILDER, hookArguments: { channelName: channelName, pluginName: pluginName, dataChannelType: dataChannelType, subChannelName: subChannelName, }, }, })); return function () { window.dispatchEvent(new CustomEvent(enum_1.HookEvents.PLUGIN_UNSUBSCRIBED_FROM_BBB_CORE, { detail: { hook: enums_1.DataChannelHooks.DATA_CHANNEL_BUILDER, hookArguments: { channelName: channelName, pluginName: pluginName, dataChannelType: dataChannelType, subChannelName: subChannelName, }, }, })); window.removeEventListener(channelIdentifier, handleDataChange); }; }, []); return { data: data, pushEntry: pushEntryFunction, deleteEntry: deleteEntryFunction, replaceEntry: replaceEntryFunction, }; }); //# sourceMappingURL=hooks.js.map