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.
74 lines • 3.43 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.useCustomMutation = void 0;
var react_1 = require("react");
var enum_1 = require("../core/enum");
var enums_1 = require("./enums");
var utils_1 = __importDefault(require("./utils"));
function useCustomMutation(mutation, options) {
var _a = (0, react_1.useState)({
triggerFunction: null,
result: {
loading: true,
called: false,
},
}), mutationHookResult = _a[0], setMutationHookResult = _a[1];
var triggerFunction = (function (data) {
window.dispatchEvent(new CustomEvent(enum_1.HookEvents.PLUGIN_SENT_CHANGES_TO_BBB_CORE, {
detail: {
hook: enums_1.DataCreationHookEnums.TRIGGER_MUTATION,
hookArguments: {
mutation: mutation,
options: options,
},
data: data,
},
}));
});
// This function is responsible for setting the trigger function of the mutation
var handleMutationReadyEvent = (function (event) {
(0, utils_1.default)(setMutationHookResult, function (prevMutationResultObject) { return ({
triggerFunction: triggerFunction,
result: prevMutationResultObject.result,
}); }, enums_1.DataCreationHookEnums.MUTATION_READY, event, mutation, options);
});
// This function is responsible for setting the result of the mutation;
var handleMutationResultSentEvent = (function (event) {
(0, utils_1.default)(setMutationHookResult, function (prevMutationResultObject, dataFromEvent) { return ({
triggerFunction: prevMutationResultObject.triggerFunction,
result: dataFromEvent,
}); }, enums_1.DataCreationHookEnums.MUTATION_RESULT_SENT, event, mutation, options);
});
(0, react_1.useEffect)(function () {
window.dispatchEvent(new CustomEvent(enum_1.HookEvents.PLUGIN_SUBSCRIBED_TO_BBB_CORE, {
detail: {
hook: enums_1.DataCreationHookEnums.CREATE_NEW_CUSTOM_MUTATION,
hookArguments: {
mutation: mutation,
options: options,
},
},
}));
window.addEventListener(enum_1.HookEvents.BBB_CORE_UPDATED_STATE, handleMutationReadyEvent);
window.addEventListener(enum_1.HookEvents.BBB_CORE_UPDATED_STATE, handleMutationResultSentEvent);
return function () {
window.dispatchEvent(new CustomEvent(enum_1.HookEvents.PLUGIN_UNSUBSCRIBED_FROM_BBB_CORE, {
detail: {
hook: enums_1.DataCreationHookEnums.CREATE_NEW_CUSTOM_MUTATION,
hookArguments: {
mutation: mutation,
options: options,
},
},
}));
window.removeEventListener(enum_1.HookEvents.BBB_CORE_UPDATED_STATE, handleMutationReadyEvent);
window.removeEventListener(enum_1.HookEvents.BBB_CORE_UPDATED_STATE, handleMutationResultSentEvent);
};
}, []);
return [mutationHookResult.triggerFunction, mutationHookResult.result];
}
exports.useCustomMutation = useCustomMutation;
//# sourceMappingURL=hook.js.map