handle errors and fix join form

This commit is contained in:
Josh
2018-06-11 13:05:54 -04:00
parent 2b0f75e62b
commit 2b065eb7fa
23 changed files with 114 additions and 239 deletions

View File

@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/

View File

@ -85,6 +85,13 @@ a {
width: 60%;
}
.center-page {
position: absolute;
top: 50%;
left:50%;
transform: translate(-50%,-50%);
}
iframe{
position: absolute;
top: 0;

View File

@ -0,0 +1,3 @@
// Place all the styles related to the Errors controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View File

@ -35,14 +35,6 @@ class ApplicationController < ActionController::Base
end
helper_method :allow_greenlight_users?
# Generate a URL to start a meeting.
def owner_meeting_url
opts = default_meeting_options
opts[:user_is_moderator] = true
@room.meeting.join_path(current_user.name, opts)
end
helper_method :owner_meeting_url
# Determines if a form field needs the is-invalid class.
def form_is_invalid?(obj, key)
'is-invalid' if !obj.errors.messages[key].empty?

View File

@ -0,0 +1,14 @@
class ErrorsController < ApplicationController
def not_found
render status: 404
end
def unprocessable
render status: 422
end
def internal_error
render status: 500
end
end

View File

@ -35,14 +35,18 @@ class RoomsController < ApplicationController
opts = default_meeting_options
# Assign join name if passed.
if params[@room.invite_path]
if params[@room.invite_path][:join_name]
@join_name = params[@room.invite_path][:join_name]
else
# Join name not passed.
return
end
if @room.is_running?
if current_user
redirect_to @room.join_path(current_user, opts)
elsif join_name = params[:join_name] || params[@room.invite_path][:join_name]
redirect_to @room.join_path(current_user.name, opts, current_user.uid)
else
join_name = params[@room.invite_path][:join_name]
redirect_to @room.join_path(join_name, opts)
end
else
@ -65,7 +69,7 @@ class RoomsController < ApplicationController
opts = default_meeting_options
opts[:user_is_moderator] = true
redirect_to @room.join_path(current_user, opts)
redirect_to @room.join_path(current_user.name, opts, current_user.uid)
# Notify users that the room has started.
# Delay 5 seconds to allow for server start, although the request will retry until it succeeds.

View File

@ -0,0 +1,2 @@
module ErrorsHelper
end

View File

@ -7,7 +7,6 @@ class Room < ApplicationRecord
belongs_to :owner, class_name: 'User', foreign_key: :user_id
has_one :meeting
ROOM_ICONS = %w(circle star certificate play cloud heart square bookmark cog)
RETURNCODE_SUCCESS = "SUCCESS"
# Determines if a user owns a room.
@ -21,19 +20,6 @@ class Room < ApplicationRecord
bbb.is_meeting_running?(bbb_id)
end
# Retrieves all the users in a room.
def participants
begin
res = bbb.get_meeting_info(bbb_id, nil)
res[:attendees].map do |att|
User.find_by(uid: att[:userID], name: att[:fullName])
end
rescue BigBlueButton::BigBlueButtonException => exc
# The meeting is most likely not running.
[]
end
end
# Determines the invite URL for the room.
def invite_path
"/r/#{uid}"
@ -68,7 +54,7 @@ class Room < ApplicationRecord
end
# Returns a URL to join a user into a meeting.
def join_path(user, options = {})
def join_path(name, options = {}, uid = nil)
# Create the meeting if it isn't running.
start_session(options) unless is_running?
@ -95,10 +81,10 @@ class Room < ApplicationRecord
end
# Generate the join URL.
if user.is_a?(User)
bbb.join_meeting_url(bbb_id, user.name, password, {userID: user.uid})
if uid
bbb.join_meeting_url(bbb_id, name, password, {userID: uid})
else
bbb.join_meeting_url(bbb_id, user, password)
bbb.join_meeting_url(bbb_id, name, password)
end
end
@ -109,6 +95,19 @@ class Room < ApplicationRecord
})
end
# Retrieves all the users in a room.
def participants
begin
res = bbb.get_meeting_info(bbb_id, nil)
res[:attendees].map do |att|
User.find_by(uid: att[:userID], name: att[:fullName])
end
rescue BigBlueButton::BigBlueButtonException => exc
# The meeting is most likely not running.
[]
end
end
# Fetches all recordings for a meeting.
def recordings
res = bbb.get_recordings(meetingID: bbb_id)
@ -168,8 +167,6 @@ class Room < ApplicationRecord
def setup
self.uid = [owner.firstname, (0...9).map { (65 + rand(26)).chr }.join].join('-').downcase
self.bbb_id = Digest::SHA1.hexdigest(Rails.application.secrets[:secret_key_base] + Time.now.to_i.to_s).to_s
self.icon = ROOM_ICONS.sample
end
# Rereives the loadbalanced BigBlueButton credentials for a user.

View File

@ -0,0 +1,7 @@
<div class="text-center center-page">
<h1 class="display-2 font-weight-400">Oh no!</h1>
<h3>Looks like something went wrong on our end.</h3>
<%= link_to root_url do %>
<h4>Return to home page.</h4>
<% end %>
</div>

View File

@ -0,0 +1,8 @@
<div class="text-center center-page">
<h1 class="display-2 font-weight-400">Whoops!</h1>
<h2>Looks like we can't find that resource.</h2>
<h3>Is it possible its been removed?</h3>
<%= link_to root_url do %>
<h4>Return to home page.</h4>
<% end %>
</div>

View File

@ -0,0 +1,7 @@
<div class="text-center center-page">
<h1 class="display-2 font-weight-400">Oops!</h1>
<h3>Request is unprocessable.</h3>
<%= link_to root_url do %>
<h4>Return to home page.</h4>
<% end %>
</div>

View File

@ -1,7 +1,12 @@
<%= render 'shared/room_event' do %>
<%= form_for room_path, method: :post do |f| %>
<div class="input-group" style="height: 48px;">
<%= f.text_field :join_name, class: "form-control main-large", placeholder: "Enter your name!", value: "#{current_user ? current_user.name : ''}" %>
<%= f.text_field :join_name,
required: true,
class: "form-control main-large",
placeholder: "Enter your name!",
value: "#{current_user ? current_user.name : ''}",
readonly: !current_user.nil? %>
<span class="input-group-append">
<%= f.submit "Join", class: "btn btn-primary px-7 main-large" %>
</span>

View File

@ -3,6 +3,7 @@
<p class="subtitle"><%= subtitle %></p>
</div>
<% if search %>
<!--
<div class="col-3">
<div class="input-icon">
<span class="input-icon-addon">
@ -11,6 +12,7 @@
<input type="text" class="form-control btn-pill" placeholder="Search...">
</div>
</div>
-->
<% end %>
</div>
<hr class="mt-0">