app/controllers/bigbluebutton/rooms_controller.rb in bigbluebutton_rails-1.2.0 vs app/controllers/bigbluebutton/rooms_controller.rb in bigbluebutton_rails-1.3.0.beta1
- old
+ new
@@ -1,11 +1,15 @@
require 'bigbluebutton_api'
class Bigbluebutton::RoomsController < ApplicationController
- before_filter :find_room, :only => [:show, :edit, :update, :destroy, :join, :invite, :running, :end, :destroy, :end, :join_mobile]
+ before_filter :find_room, :except => [:index, :create, :new, :auth, :external, :external_auth]
before_filter :find_server, :only => [:external, :external_auth]
+
+ # set headers only in actions that might trigger api calls
+ before_filter :set_request_headers, :only => [:join_mobile, :end, :running, :join, :destroy, :auth, :external_auth]
+
respond_to :html, :except => :running
respond_to :json, :only => [:running, :show, :new, :index, :create, :update]
def index
respond_with(@rooms = BigbluebuttonRoom.all)
@@ -33,12 +37,11 @@
respond_with @room do |format|
if @room.save
message = t('bigbluebutton_rails.rooms.notice.create.success')
format.html {
- params[:redir_url] ||= bigbluebutton_room_path(@room)
- redirect_to params[:redir_url], :notice => message
+ redirect_to params[:redir_url] ||= bigbluebutton_room_path(@room), :notice => message
}
format.json { render :json => { :message => message }, :status => :created }
else
format.html {
unless params[:redir_url].blank?
@@ -52,64 +55,57 @@
end
end
end
def update
- if !params[:bigbluebutton_room].has_key?(:meetingid) or
- params[:bigbluebutton_room][:meetingid].blank?
- params[:bigbluebutton_room][:meetingid] = params[:bigbluebutton_room][:name]
- end
-
respond_with @room do |format|
if @room.update_attributes(params[:bigbluebutton_room])
message = t('bigbluebutton_rails.rooms.notice.update.success')
format.html {
- params[:redir_url] ||= bigbluebutton_room_path(@room)
- redirect_to params[:redir_url], :notice => message
+ redirect_to params[:redir_url] ||= bigbluebutton_room_path(@room), :notice => message
}
format.json { render :json => { :message => message } }
else
format.html {
unless params[:redir_url].blank?
- message = t('bigbluebutton_rails.rooms.notice.update.failure')
- redirect_to params[:redir_url], :error => message
+ flash[:error] = t('bigbluebutton_rails.rooms.notice.update.failure')
+ redirect_to params[:redir_url]
else
render :edit
end
}
format.json { render :json => @room.errors.full_messages, :status => :unprocessable_entity }
end
end
end
def destroy
- # TODO Destroy the room record even if end_meeting failed?
-
error = false
begin
@room.fetch_is_running?
@room.send_end if @room.is_running?
+ message = t('bigbluebutton_rails.rooms.notice.destroy.success')
rescue BigBlueButton::BigBlueButtonException => e
error = true
- message = e.to_s
- # TODO Better error message: "Room destroyed in DB, but not in BBB..."
+ message = t('bigbluebutton_rails.rooms.notice.destroy.success_with_bbb_error', :error => e.to_s[0..200])
end
+ # TODO: what if it fails?
@room.destroy
respond_with do |format|
format.html {
flash[:error] = message if error
- params[:redir_url] ||= bigbluebutton_rooms_url
- redirect_to params[:redir_url]
+ redirect_to params[:redir_url] ||= bigbluebutton_rooms_url
}
- if error
- format.json { render :json => { :message => message }, :status => :error }
- else
- message = t('bigbluebutton_rails.rooms.notice.destroy.success')
- format.json { render :json => { :message => message } }
- end
+ format.json {
+ if error
+ render :json => { :message => message }, :status => :error
+ else
+ render :json => { :message => message }
+ end
+ }
end
end
# Used by logged users to join public rooms.
def join
@@ -120,15 +116,15 @@
# anonymous users or users with the role :password join through #invite
elsif bigbluebutton_user.nil? or @user_role == :password
redirect_to :action => :invite, :mobile => params[:mobile]
else
- join_internal(bigbluebutton_user.name, @user_role, :join)
+ join_internal(bigbluebutton_user.name, @user_role, bigbluebutton_user.id, :join)
end
end
- # Used to join private rooms or to invited anonymous users (not logged)
+ # Used to join private rooms or to invite anonymous users (not logged)
def invite
respond_with @room do |format|
@user_role = bigbluebutton_role(@room)
if @user_role.nil?
@@ -144,24 +140,30 @@
# Uses params[:id] to get the target room
def auth
@room = BigbluebuttonRoom.find_by_param(params[:id]) unless params[:id].blank?
if @room.nil?
message = t('bigbluebutton_rails.rooms.errors.auth.wrong_params')
- redirect_to request.referer, :notice => message
+ redirect_to :back, :notice => message
return
end
+ # gets the user information, given priority to a possible logged user
name = bigbluebutton_user.nil? ? params[:user][:name] : bigbluebutton_user.name
+ id = bigbluebutton_user.nil? ? nil : bigbluebutton_user.id
+ # the role: nil means access denied, :password means check the room
+ # password, otherwise just use it
@user_role = bigbluebutton_role(@room)
if @user_role.nil?
raise BigbluebuttonRails::RoomAccessDenied.new
elsif @user_role == :password
- @user_role = @room.user_role(params[:user])
+ role = @room.user_role(params[:user])
+ else
+ role = @user_role
end
- unless @user_role.nil? or name.nil? or name.empty?
- join_internal(name, @user_role, :invite)
+ unless role.nil? or name.nil? or name.empty?
+ join_internal(name, role, id, :invite)
else
flash[:error] = t('bigbluebutton_rails.rooms.errors.auth.failure')
render :invite, :status => :unauthorized
end
end
@@ -169,12 +171,11 @@
# receives :server_id to indicate the server and :meeting to indicate the
# MeetingID of the meeting that should be joined
def external
if params[:meeting].blank?
message = t('bigbluebutton_rails.rooms.errors.external.blank_meetingid')
- params[:redir_url] ||= bigbluebutton_rooms_path
- redirect_to params[:redir_url], :notice => message
+ redirect_to params[:redir_url] ||= bigbluebutton_rooms_path, :notice => message
end
@room = BigbluebuttonRoom.new(:server => @server, :meetingid => params[:meeting])
end
# Authenticates an user using name and password passed in the params from #external
@@ -189,42 +190,36 @@
message = t('bigbluebutton_rails.rooms.errors.external.wrong_params')
end
unless message.nil?
@room = nil
- redirect_to request.referer, :notice => message
+ redirect_to :back, :notice => message
return
end
# This is just to check if the room is not blocked, not to get the actual role
raise BigbluebuttonRails::RoomAccessDenied.new if bigbluebutton_role(@room).nil?
# if there's a user logged, use his name instead of the name in the params
name = bigbluebutton_user.nil? ? params[:user][:name] : bigbluebutton_user.name
+ id = bigbluebutton_user.nil? ? nil : bigbluebutton_user.id
role = @room.user_role(params[:user])
- # FIXME: use internal_join ?
unless role.nil? or name.nil? or name.empty?
- url = @room.perform_join(name, role, request)
- unless url.nil?
- redirect_to(url)
- else
- flash[:error] = t('bigbluebutton_rails.rooms.errors.auth.not_running')
- render :external
- end
+ join_internal(name, role, id, :external)
else
flash[:error] = t('bigbluebutton_rails.rooms.errors.auth.failure')
render :external, :status => :unauthorized
end
end
def running
begin
@room.fetch_is_running?
rescue BigBlueButton::BigBlueButtonException => e
- flash[:error] = e.to_s
- render :json => { :running => "false", :error => "#{e.to_s}" }
+ flash[:error] = e.to_s[0..200]
+ render :json => { :running => "false", :error => "#{e.to_s[0..200]}" }
else
render :json => { :running => "#{@room.is_running?}" }
end
end
@@ -239,18 +234,18 @@
error = true
message = t('bigbluebutton_rails.rooms.notice.end.not_running')
end
rescue BigBlueButton::BigBlueButtonException => e
error = true
- message = e.to_s
+ message = e.to_s[0..200]
end
if error
respond_with do |format|
format.html {
flash[:error] = message
- redirect_to request.referer
+ redirect_to :back
}
format.json { render :json => message, :status => :error }
end
else
respond_with do |format|
@@ -271,32 +266,92 @@
# logged. so we are using the full BBB url for now.
@qrcode_url = @room.join_url(bigbluebutton_user.name, bigbluebutton_role(@room))
@qrcode_url.gsub!(/http:\/\//i, "bigbluebutton://")
end
+ def fetch_recordings
+ error = false
+
+ if @room.server.nil?
+ error = true
+ message = t('bigbluebutton_rails.rooms.error.fetch_recordings.no_server')
+ else
+ begin
+ # filter only recordings created by this room
+ filter = { :meetingID => @room.meetingid }
+ @room.server.fetch_recordings(filter)
+ message = t('bigbluebutton_rails.rooms.notice.fetch_recordings.success')
+ rescue BigBlueButton::BigBlueButtonException => e
+ error = true
+ message = e.to_s[0..200]
+ end
+ end
+
+ respond_with do |format|
+ format.html {
+ flash[error ? :error : :notice] = message
+ redirect_to bigbluebutton_room_path(@room)
+ }
+ format.json {
+ if error
+ render :json => { :message => message }, :status => :error
+ else
+ head :ok
+ end
+ }
+ end
+ end
+
+ def recordings
+ respond_with(@recordings = @room.recordings)
+ end
+
protected
def find_room
@room = BigbluebuttonRoom.find_by_param(params[:id])
end
def find_server
@server = BigbluebuttonServer.find(params[:server_id])
end
- def join_internal(username, role, wait_action)
+ def set_request_headers
+ unless @room.nil?
+ @room.request_headers["x-forwarded-for"] = request.remote_ip
+ end
+ end
+
+ def join_internal(username, role, id, wait_action)
begin
- url = @room.perform_join(username, role, request)
+ # first check if we have to create the room and if the user can do it
+ @room.fetch_is_running?
+ unless @room.is_running?
+ if bigbluebutton_can_create?(@room, role)
+ @room.create_meeting(username, id, request)
+ else
+ flash[:error] = t('bigbluebutton_rails.rooms.errors.auth.cannot_create')
+ render wait_action
+ return
+ end
+ end
+
+ # room created and running, try to join it
+ url = @room.join_url(username, role)
unless url.nil?
- url.gsub!(/http:\/\//i, "bigbluebutton://") if BigbluebuttonRails::value_to_boolean(params[:mobile])
+ # change the protocol to join with BBB-Android/Mconf-Mobile if set
+ if BigbluebuttonRails::value_to_boolean(params[:mobile])
+ url.gsub!(/http:\/\//i, "bigbluebutton://")
+ end
redirect_to(url)
else
flash[:error] = t('bigbluebutton_rails.rooms.errors.auth.not_running')
render wait_action
end
+
rescue BigBlueButton::BigBlueButtonException => e
- flash[:error] = e.to_s
- redirect_to request.referer
+ flash[:error] = e.to_s[0..200]
+ redirect_to :back
end
end
end