Ver Fonte

Add support for moderators, show usernames of people that already joined the call

Penar Musaraj há 4 anos atrás
pai
commit
211c8d6b92

+ 44 - 11
app/controllers/bbb_client_controller.rb

@@ -1,4 +1,5 @@
 # frozen_string_literal: true
+
 require 'digest/sha1'
 
 module BigBlue
@@ -7,30 +8,31 @@ module BigBlue
 
     def create
       render json: {
-        url: build_url(params)
+        url: create_and_join(params)
       }
     end
 
+    def status
+      render json: get_status(params)
+    end
+
     private
 
-    def build_url(args)
+    def create_and_join(args)
       return false unless SiteSetting.bbb_endpoint && SiteSetting.bbb_secret
 
       meeting_id = args['meetingID']
-      url = SiteSetting.bbb_endpoint
-      secret = SiteSetting.bbb_secret
       attendee_pw = args['attendeePW']
       moderator_pw = args['moderatorPW']
 
       query = {
         meetingID: meeting_id,
         attendeePW: attendee_pw,
-        moderatorPW: moderator_pw
+        moderatorPW: moderator_pw,
+        logoutURL: SiteSetting.bbb_full_window ? Discourse.base_url : "default"
       }.to_query
 
-      checksum = Digest::SHA1.hexdigest ("create" + query + secret)
-
-      create_url = "#{url}create?#{query}&checksum=#{checksum}"
+      create_url = build_url("create", query)
       response = Excon.get(create_url)
 
       if response.status != 200
@@ -41,11 +43,42 @@ module BigBlue
       join_params = {
         fullName: current_user.name || current_user.username,
         meetingID: meeting_id,
-        password: attendee_pw # TODO: pass moderator username or staff as moderator?
+        userID: current_user.username,
+        password: is_moderator ? moderator_pw : attendee_pw
       }.to_query
 
-      join_checksum = Digest::SHA1.hexdigest ("join" + join_params + secret)
-      "#{url}join?#{join_params}&checksum=#{join_checksum}"
+      build_url("join", join_params)
+    end
+
+    def get_status(args)
+      return {} unless SiteSetting.bbb_endpoint && SiteSetting.bbb_secret
+
+      url = build_url("getMeetingInfo", "meetingID=#{args['meeting_id']}")
+      response = Excon.get(url)
+      data = Hash.from_xml(response.body)
+
+      if data['response']['returncode'] == "SUCCESS"
+        att = data['response']['attendees']['attendee']
+        {
+          count: data['response']['participantCount'],
+          usernames: att.is_a?(Array) ? att.pluck("userID") : [att["userID"]]
+        }
+      else
+        {}
+      end
+    end
+
+    def build_url(type, query)
+      secret = SiteSetting.bbb_secret
+      checksum = Digest::SHA1.hexdigest(type + query + secret)
+      "#{SiteSetting.bbb_endpoint}#{type}?#{query}&checksum=#{checksum}"
+    end
+
+    def is_moderator
+      return true if current_user.staff?
+
+      group = SiteSetting.bbb_moderator_group_name
+      return true if group.present? && current_user.groups.pluck(:name).include?(group)
     end
   end
 end

+ 14 - 1
assets/javascripts/discourse/initializers/bbb.js.es6

@@ -3,6 +3,7 @@ import showModal from "discourse/lib/show-modal";
 import { iconHTML } from "discourse-common/lib/icon-library";
 import { ajax } from "discourse/lib/ajax";
 import { popupAjaxError } from "discourse/lib/ajax-error";
+import { avatarImg } from "discourse/widgets/post";
 
 function launchBBB($elem, fullWindow) {
   const data = $elem.data();
@@ -13,7 +14,6 @@ function launchBBB($elem, fullWindow) {
   })
     .then(res => {
       if (res.url) {
-        console.log(fullWindow);
         if (fullWindow) {
           window.location.href = res.url;
         } else {
@@ -40,6 +40,17 @@ function attachButton($elem, fullWindow) {
   $elem.find("button").on("click", () => launchBBB($elem, fullWindow));
 }
 
+function attachStatus($elem, helper) {
+  const status = $elem.find(".bbb-status");
+  const data = $elem.data();
+
+  ajax(`/bbb/status/${data.meetingID}.json`).then(res => {
+    if (res.usernames) {
+      status.html(`On the call: ${res.usernames.join(", ")}`);
+    }
+  });
+}
+
 function attachBBB($elem, helper) {
   if (helper) {
     const siteSettings = Discourse.__container__.lookup("site-settings:main");
@@ -47,6 +58,8 @@ function attachBBB($elem, helper) {
 
     $elem.find("[data-wrap=discourse-bbb]").each((idx, val) => {
       attachButton($(val), fullWindow);
+      $(val).append("<span class='bbb-status'></span>");
+      attachStatus($(val), helper);
     });
   }
 }

+ 4 - 0
assets/stylesheets/common/bbb.scss

@@ -0,0 +1,4 @@
+.bbb-status {
+  margin-left: 1em;
+  font-size: 0.9em;
+}

+ 1 - 0
config/locales/server.en.yml

@@ -5,3 +5,4 @@ en:
     bbb_secret: "BigBlueButton Shared Secret"
     bbb_full_window: "If unchecked, video conference will load in an iframe."
     bbb_staff_only: "Only show toolbar button to staff members."
+    bbb_moderator_group_name: "Add the name of a group whose members should log in as moderators in video conferences."

+ 3 - 0
config/settings.yml

@@ -15,3 +15,6 @@ plugins:
   bbb_staff_only:
     default: true
     client: true
+  bbb_moderator_group_name:
+    default: ""
+    client: false

+ 2 - 0
plugin.rb

@@ -7,6 +7,7 @@
 # url: https://github.com/pmusaraj/discourse-bbb
 
 enabled_site_setting :bbb_enabled
+register_asset "stylesheets/common/bbb.scss"
 register_svg_icon "fab-bootstrap"
 register_svg_icon "video"
 
@@ -26,6 +27,7 @@ after_initialize do
 
   BigBlue::Engine.routes.draw do
     post '/create' => 'bbb_client#create', constraints: { format: :json }
+    get '/status/:meeting_id' => 'bbb_client#status', constraints: { format: :json }
   end
 
   Discourse::Application.routes.append do