bbb_client_controller.rb 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # frozen_string_literal: true
  2. require 'digest/sha1'
  3. module BigBlue
  4. class BbbClientController < ApplicationController
  5. before_action :ensure_logged_in
  6. def create
  7. render json: {
  8. url: build_url(params)
  9. }
  10. end
  11. private
  12. def build_url(args)
  13. return false unless SiteSetting.bbb_endpoint && SiteSetting.bbb_secret
  14. meeting_id = args['meetingID']
  15. url = SiteSetting.bbb_endpoint
  16. secret = SiteSetting.bbb_secret
  17. attendee_pw = args['attendeePW']
  18. moderator_pw = args['moderatorPW']
  19. query = {
  20. meetingID: meeting_id,
  21. attendeePW: attendee_pw,
  22. moderatorPW: moderator_pw
  23. }.to_query
  24. checksum = Digest::SHA1.hexdigest ("create" + query + secret)
  25. create_url = "#{url}create?#{query}&checksum=#{checksum}"
  26. response = Excon.get(create_url)
  27. if response.status != 200
  28. Rails.logger.warn("Could not create meeting: #{response.inspect}")
  29. return false
  30. end
  31. join_params = {
  32. fullName: current_user.name || current_user.username,
  33. meetingID: meeting_id,
  34. password: attendee_pw # TODO: pass moderator username or staff as moderator?
  35. }.to_query
  36. join_checksum = Digest::SHA1.hexdigest ("join" + join_params + secret)
  37. "#{url}join?#{join_params}&checksum=#{join_checksum}"
  38. end
  39. end
  40. end