forked from External/greenlight
initial commit
This commit is contained in:
3
app/models/application_record.rb
Normal file
3
app/models/application_record.rb
Normal file
@ -0,0 +1,3 @@
|
||||
class ApplicationRecord < ActiveRecord::Base
|
||||
self.abstract_class = true
|
||||
end
|
0
app/models/concerns/.keep
Normal file
0
app/models/concerns/.keep
Normal file
99
app/models/meeting.rb
Normal file
99
app/models/meeting.rb
Normal file
@ -0,0 +1,99 @@
|
||||
class Meeting < ApplicationRecord
|
||||
|
||||
before_create :generate_meeting_id
|
||||
|
||||
belongs_to :room
|
||||
|
||||
# Creates a meeting on the BigBlueButton server.
|
||||
def create(options = {})
|
||||
create_options = {
|
||||
record: options[:meeting_recorded].to_s,
|
||||
logoutURL: options[:meeting_logout_url] || '',
|
||||
moderatorPW: random_password(12),
|
||||
attendeePW: random_password(12),
|
||||
moderatorOnlyMessage: options[:moderator_message],
|
||||
"meta_#{BigBlueHelper::META_LISTED}": false,
|
||||
"meta_#{BigBlueHelper::META_TOKEN}": name
|
||||
}
|
||||
|
||||
#meeting_options.merge!(
|
||||
#{ "meta_room-id": options[:room_owner],
|
||||
# "meta_meeting-name": options[:meeting_name]}
|
||||
#) if options[:room_owner]
|
||||
|
||||
# Send the create request.
|
||||
begin
|
||||
bbb.create_meeting(name, uid, create_options)
|
||||
rescue BigBlueButton::BigBlueButtonException => exc
|
||||
puts "BigBlueButton failed on create: #{exc.key}: #{exc.message}"
|
||||
end
|
||||
end
|
||||
|
||||
# Returns a URL to join a user into a meeting.
|
||||
def join_path(username, options = {})
|
||||
# Create the meeting if it isn't running.
|
||||
create(options) unless is_running?
|
||||
|
||||
# Set meeting options.
|
||||
options[:meeting_logout_url] ||= nil
|
||||
options[:moderator_message] ||= ''
|
||||
options[:user_is_moderator] ||= false
|
||||
|
||||
options[:meeting_recorded] ||= false
|
||||
|
||||
#options[:wait_for_moderator] ||= false
|
||||
#options[:meeting_name] ||= name
|
||||
#options[:room_owner] ||= nil
|
||||
|
||||
return call_invalid_res if !bbb
|
||||
|
||||
# Get the meeting info.
|
||||
meeting_info = bbb.get_meeting_info(uid, nil)
|
||||
|
||||
# Determine the password to use when joining.
|
||||
password = if options[:user_is_moderator]
|
||||
meeting_info[:moderatorPW]
|
||||
else
|
||||
meeting_info[:attendeePW]
|
||||
end
|
||||
|
||||
# Generate the join URL.
|
||||
bbb.join_meeting_url(uid, username, password)
|
||||
end
|
||||
|
||||
# Checks if a meeting is running on the BigBlueButton server.
|
||||
def is_running?
|
||||
begin
|
||||
bbb.get_meeting_info(uid, nil)
|
||||
return true
|
||||
rescue BigBlueButton::BigBlueButtonException => exc
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def bbb_endpoint
|
||||
Rails.configuration.bigbluebutton_endpoint
|
||||
end
|
||||
|
||||
def bbb_secret
|
||||
Rails.configuration.bigbluebutton_secret
|
||||
end
|
||||
|
||||
# Use one common instance of the BigBlueButton API for all meetings.
|
||||
def bbb
|
||||
@@bbb ||= BigBlueButton::BigBlueButtonApi.new(bbb_endpoint + "api", bbb_secret, "0.8")
|
||||
end
|
||||
|
||||
# Generates a BigBlueButton meeting id from a meeting token.
|
||||
def generate_meeting_id
|
||||
self.uid = Digest::SHA1.hexdigest(Rails.application.secrets[:secret_key_base] + name + Time.now.to_i.to_s).to_s
|
||||
end
|
||||
|
||||
# Generates a random password for a meeting.
|
||||
def random_password(length)
|
||||
o = ([('a'..'z'), ('A'..'Z')].map do |i| i.to_a end).flatten
|
||||
((0...length).map do o[rand(o.length)] end).join
|
||||
end
|
||||
end
|
17
app/models/room.rb
Normal file
17
app/models/room.rb
Normal file
@ -0,0 +1,17 @@
|
||||
class Room < ApplicationRecord
|
||||
|
||||
before_create :set_uid
|
||||
|
||||
belongs_to :user
|
||||
has_many :meetings
|
||||
|
||||
def owned_by?(user)
|
||||
user.room == self
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_uid
|
||||
self.uid = Digest::SHA1.hexdigest(user.uid + user.provider + user.username)[0..12]
|
||||
end
|
||||
end
|
51
app/models/user.rb
Normal file
51
app/models/user.rb
Normal file
@ -0,0 +1,51 @@
|
||||
class User < ApplicationRecord
|
||||
|
||||
has_one :room
|
||||
|
||||
class << self
|
||||
|
||||
# Generates a user from omniauth.
|
||||
def from_omniauth(auth)
|
||||
user = find_or_initialize_by(uid: auth['uid'], provider: auth['provider'])
|
||||
user.name = send("#{auth['provider']}_name", auth)
|
||||
user.username = send("#{auth['provider']}_username", auth)
|
||||
user.email = send("#{auth['provider']}_email", auth)
|
||||
#user.token = auth['credentials']['token']
|
||||
|
||||
# Create a room for the user if they don't have one.
|
||||
user.room = Room.create unless user.room
|
||||
|
||||
user.save!
|
||||
user
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Provider attributes.
|
||||
def twitter_name(auth)
|
||||
auth['info']['name']
|
||||
end
|
||||
|
||||
def twitter_username(auth)
|
||||
auth['info']['nickname']
|
||||
end
|
||||
|
||||
def twitter_email(auth)
|
||||
auth['info']['email']
|
||||
end
|
||||
|
||||
def google_name(auth)
|
||||
auth['info']['name']
|
||||
end
|
||||
|
||||
def google_username(auth)
|
||||
auth['info']['email'].split('@').first
|
||||
end
|
||||
|
||||
def google_email(auth)
|
||||
auth['info']['email']
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
Reference in New Issue
Block a user