bbb.js.es6 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import { withPluginApi } from "discourse/lib/plugin-api";
  2. import showModal from "discourse/lib/show-modal";
  3. import { iconHTML } from "discourse-common/lib/icon-library";
  4. import { ajax } from "discourse/lib/ajax";
  5. import { popupAjaxError } from "discourse/lib/ajax-error";
  6. function launchBBB($elem, fullWindow) {
  7. const data = $elem.data();
  8. ajax("/bbb/create.json", {
  9. type: "POST",
  10. data: data
  11. })
  12. .then(res => {
  13. if (res.url) {
  14. console.log(fullWindow);
  15. if (fullWindow) {
  16. window.location.href = res.url;
  17. } else {
  18. $elem.children().hide();
  19. $elem.append(
  20. `<iframe src="${res.url}" allow="camera;microphone;fullscreen;speaker" width="690" height="500" style="border:none"></iframe>`
  21. );
  22. }
  23. }
  24. })
  25. .catch(function(error) {
  26. popupAjaxError(error);
  27. });
  28. }
  29. function attachButton($elem, fullWindow) {
  30. const buttonLabel = $elem.data("label") || I18n.t("bbb.launch");
  31. $elem.html(
  32. `<button class='launch-bbb btn'>${iconHTML(
  33. "video"
  34. )} ${buttonLabel}</button>`
  35. );
  36. $elem.find("button").on("click", () => launchBBB($elem, fullWindow));
  37. }
  38. function attachBBB($elem, helper) {
  39. if (helper) {
  40. const siteSettings = Discourse.__container__.lookup("site-settings:main");
  41. const fullWindow = siteSettings.bbb_full_window;
  42. $elem.find("[data-wrap=discourse-bbb]").each((idx, val) => {
  43. attachButton($(val), fullWindow);
  44. });
  45. }
  46. }
  47. export default {
  48. name: "insert-bbb",
  49. initialize() {
  50. withPluginApi("0.8.31", api => {
  51. const currentUser = api.getCurrentUser();
  52. const siteSettings = api.container.lookup("site-settings:main");
  53. api.onToolbarCreate(toolbar => {
  54. if (siteSettings.bbb_staff_only && !currentUser.staff) {
  55. return;
  56. }
  57. toolbar.addButton({
  58. title: "bbb.composer_title",
  59. id: "insertBBB",
  60. group: "insertions",
  61. icon: "fab-bootstrap",
  62. perform: e =>
  63. showModal("insert-bbb").setProperties({ toolbarEvent: e })
  64. });
  65. });
  66. api.decorateCooked(attachBBB, { id: "discourse-bbb" });
  67. });
  68. }
  69. };