initial commit

This commit is contained in:
Josh
2018-05-07 16:06:01 -04:00
commit 4037b6304e
125 changed files with 2493 additions and 0 deletions

View File

@ -0,0 +1,3 @@
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end

View File

99
app/models/meeting.rb Normal file
View 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
View 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
View 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