diff --git a/app/assets/javascripts/meetings.js b/app/assets/javascripts/meetings.js index 284ff9dd..e69de29b 100644 --- a/app/assets/javascripts/meetings.js +++ b/app/assets/javascripts/meetings.js @@ -1,29 +0,0 @@ -$(document).on("turbolinks:load", function() { - - var action = $("body").data('action'); - var controller = $("body").data('controller'); - - // If the user is on the waiting screen. - if (controller == 'meetings' && action == 'wait') { - - setTimeout(refresh, 10000); - } -}); - -// Send a request to the meeting wait endpoint. -// This checks if the meeting is running on the -// server and will auto join the user if it is. -var refresh = function() { - $.ajax({ - url: window.location.pathname, - type: 'POST', - data: { - unauthenticated_join_name: $('#unauthenticated_join_name_').val() - }, - headers: { - 'Content-Type': 'application/x-www-form-urlencoded' - } - }); - - setTimeout(refresh, 10000); -} \ No newline at end of file diff --git a/app/assets/javascripts/rooms.coffee b/app/assets/javascripts/rooms.coffee deleted file mode 100644 index 24f83d18..00000000 --- a/app/assets/javascripts/rooms.coffee +++ /dev/null @@ -1,3 +0,0 @@ -# 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/ diff --git a/app/assets/javascripts/rooms.js b/app/assets/javascripts/rooms.js new file mode 100644 index 00000000..7a1aa73c --- /dev/null +++ b/app/assets/javascripts/rooms.js @@ -0,0 +1,27 @@ +$(document).on("turbolinks:load", function() { + var action = $("body").data('action'); + var controller = $("body").data('controller'); + + // If the user is on the waiting screen. + if (controller == 'rooms' && action == 'wait') { + setTimeout(refresh, 10000); + } +}); + +// Send a request to the meeting wait endpoint. +// This checks if the meeting is running on the +// server and will auto join the user if it is. +var refresh = function() { + $.ajax({ + url: window.location.pathname, + type: 'POST', + data: { + unauthenticated_join_name: $('#unauthenticated_join_name_').val() + }, + headers: { + 'Content-Type': 'application/x-www-form-urlencoded' + } + }); + + setTimeout(refresh, 10000); +} \ No newline at end of file diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b6f58987..8f11cba6 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -39,9 +39,6 @@ class ApplicationController < ActionController::Base # Ensure the user is logged into the room they are accessing. def verify_room_ownership - return unless params.include?(:room_uid) - @room = Room.find_by(uid: params[:room_uid]) - # Redirect to correct room or root if not logged in. if current_user.nil? redirect_to root_path diff --git a/app/controllers/meetings_controller.rb b/app/controllers/meetings_controller.rb index 312288f4..b149130b 100644 --- a/app/controllers/meetings_controller.rb +++ b/app/controllers/meetings_controller.rb @@ -1,102 +1,14 @@ class MeetingsController < ApplicationController before_action :verify_room_ownership - skip_before_action :verify_room_ownership, only: [:join, :wait] # GET /rooms/:room_uid/meetings def index - - end - - # GET /rooms/:room_uid/meetings/:meeting_uid - def show - - end - - # POST /rooms/:room_uid/meetings - def create - @meeting = Meeting.new(meeting_params(@room)) - - if @meeting.save - # Create the meeting on the BigBlueButton server and join the user into the meeting. - redirect_to join_meeting_path(room_uid: @room.uid, meeting_uid: @meeting.uid) - else - # Meeting couldn't be created, handle error. - - end - end - - # GET /rooms/:room_uid/meetings/:meeting_uid/join - def join - @meeting = Meeting.find_by(uid: params[:meeting_uid]) - - if @meeting - opts = default_meeting_options - if @meeting.is_running? - if current_user - # Check if the current user is the room/session owner. - opts[:user_is_moderator] = @meeting.room.owned_by?(current_user) - redirect_to @meeting.join_path(current_user.name, opts) - else - # If the unauthenticated user has supplied a join name. - if params[:join_name] - redirect_to @meeting.join_path(params[:join_name], opts) - else - # Render the join page so they can supply their name. - render :join - end - end - else - # Only start the meeting if owner is joining first. - if current_user && @meeting.room.owned_by?(current_user) - opts[:user_is_moderator] = true - redirect_to @meeting.join_path(current_user.name, opts) - else - # Send the user to a polling page that will auto join them when it starts. - # The wait action/page handles input of name for unauthenticated users. - redirect_to wait_meeting_path(room_uid: @meeting.room.uid, meeting_uid: @meeting.uid) - end - end - else - # Handle meeting doesn't exist. - - end - end - - # GET /rooms/:room_uid/meetings/:meeting_uid/wait - def wait - @meeting = Meeting.find_by(uid: params[:meeting_uid]) - - if @meeting - if @meeting.is_running? - if current_user - # If they are logged in and waiting, use their account name. - redirect_to @meeting.join_path(current_user.name, default_meeting_options) - elsif !params[:unauthenticated_join_name].blank? - # Otherwise, use the name they submitted on the wating page. - redirect_to @meeting.join_path(params[:unauthenticated_join_name], default_meeting_options) - end - end - else - # Handle meeting doesn't exist. - - end end private - def meeting_params(room) - params.require(:meeting).permit(:name).merge!(room: room) - #params.require(:meeting).permit(:name).merge!(room_id: room.id) - end - - def default_meeting_options - { - user_is_moderator: false, - meeting_logout_url: request.base_url + room_path(room_uid: @meeting.room.uid), - meeting_recorded: true, - moderator_message: "To invite someone to the meeting, send them this link: - #{request.base_url + join_meeting_path(room_uid: @meeting.room.uid, meeting_uid: @meeting.uid)}" - } - end + #def meeting_params(room) + # params.require(:meeting).permit(:name).merge!(room: room) + #end end diff --git a/app/controllers/rooms_controller.rb b/app/controllers/rooms_controller.rb index e6e7ebf0..dffbbbe9 100644 --- a/app/controllers/rooms_controller.rb +++ b/app/controllers/rooms_controller.rb @@ -1,9 +1,82 @@ class RoomsController < ApplicationController - before_action :verify_room_ownership + before_action :find_room, :verify_room_ownership + skip_before_action :verify_room_ownership, only: [:join, :wait] # GET /rooms/:room_uid def index - @meeting = Meeting.new + end -end + + # GET /rooms/:room_uid/join + def join + if @meeting + opts = default_meeting_options + if @meeting.is_running? + if current_user + # Check if the current user is the room/session owner. + opts[:user_is_moderator] = @meeting.room.owned_by?(current_user) + redirect_to @meeting.join_path(current_user.name, opts) + else + # If the unauthenticated user has supplied a join name. + if params[:join_name] + redirect_to @meeting.join_path(params[:join_name], opts) + else + # Render the join page so they can supply their name. + render :join + end + end + else + # Only start the meeting if owner is joining first. + if current_user && @room.owned_by?(current_user) + opts[:user_is_moderator] = true + redirect_to @meeting.join_path(current_user.name, opts) + else + # Send the user to a polling page that will auto join them when it starts. + # The wait action/page handles input of name for unauthenticated users. + redirect_to wait_room_path(room_uid: @room.uid) + end + end + else + # Handle room doesn't exist. + + end + end + + # GET /rooms/:room_uid/wait + def wait + if @room + if @meeting.is_running? + if current_user + # If they are logged in and waiting, use their account name. + redirect_to @meeting.join_path(current_user.name, default_meeting_options) + elsif !params[:unauthenticated_join_name].blank? + # Otherwise, use the name they submitted on the wating page. + redirect_to @meeting.join_path(params[:unauthenticated_join_name], default_meeting_options) + end + end + else + # Handle room doesn't exist. + + end + end + + private + + # Find the room from the uid. + def find_room + @room = Room.find_by(uid: params[:room_uid]) + @meeting = @room.meeting + end + + # Default, unconfigured meeting options. + def default_meeting_options + { + user_is_moderator: false, + meeting_logout_url: request.base_url + room_path(room_uid: @room.uid), + meeting_recorded: true, + moderator_message: "To invite someone to the meeting, send them this link: + #{request.base_url + join_room_path(room_uid: @room.uid)}" + } + end +end \ No newline at end of file diff --git a/app/models/room.rb b/app/models/room.rb index f27a4d35..d6883e92 100644 --- a/app/models/room.rb +++ b/app/models/room.rb @@ -3,9 +3,10 @@ class Room < ApplicationRecord before_create :set_uid belongs_to :user - has_many :meetings + has_one :meeting def owned_by?(user) + return false if user.nil? user.room == self end diff --git a/app/models/user.rb b/app/models/user.rb index 89e187bd..585e8a15 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -68,7 +68,7 @@ class User < ApplicationRecord # Initializes a room for the user. def initialize_room - self.room = Room.new - self.save! + room = Room.create(user_id: self.id) + Meeting.create(room_id: room.id, name: "Example") end end diff --git a/app/views/meetings/index.html.erb b/app/views/meetings/index.html.erb new file mode 100644 index 00000000..e69de29b diff --git a/app/views/rooms/index.html.erb b/app/views/rooms/index.html.erb index 8ddb1fe1..8c9c41cd 100644 --- a/app/views/rooms/index.html.erb +++ b/app/views/rooms/index.html.erb @@ -1,22 +1,23 @@

This is a room.

<%= @room.user.name %>

+

<%= @room.meeting.uid %>

+

<%= @room.uid %>

<%= link_to 'Sessions', root_path %> <%= link_to 'Recordings', root_path %> <%= link_to 'Settings', root_path %> -

Enter a name to start a session.

-<%= form_for @meeting do |f| %> - <%= f.text_field :name %> - <%= f.submit "Start" %> +

Click below to join the meeting.

+ +<% if @room.meeting.is_running? %> +

meeting is already running

+<% else %> + <%= form_tag join_room_path, method: :get do %> + <%= submit_tag 'Start Meeting' %> + <% end %> <% end %> -




-

Previous Sessions

-<% current_user.room.meetings.each do |m| %> -

<%= m.name + " " + m.is_running?.to_s + " " + m.recordings.to_s %>

-<% end %> -
+

<%= link_to 'Logout', logout_path %> \ No newline at end of file diff --git a/app/views/meetings/join.html.erb b/app/views/rooms/join.html.erb similarity index 100% rename from app/views/meetings/join.html.erb rename to app/views/rooms/join.html.erb diff --git a/app/views/meetings/wait.html.erb b/app/views/rooms/wait.html.erb similarity index 100% rename from app/views/meetings/wait.html.erb rename to app/views/rooms/wait.html.erb diff --git a/config/routes.rb b/config/routes.rb index 2f18fd91..c5886fa4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,13 +1,11 @@ Rails.application.routes.draw do # Room and Meeting routes. - scope '/rooms' do - scope '/:room_uid' do - get '/', to: 'rooms#index', as: :room - resources :meetings, only: [:index, :show, :create], param: :meeting_uid - match '/meetings/:meeting_uid/join', to: 'meetings#join', as: :join_meeting, via: [:get, :post] - match '/meetings/:meeting_uid/wait', to: 'meetings#wait', as: :wait_meeting, via: [:get, :post] - end + scope '/rooms/:room_uid' do + get '/', to: 'rooms#index', as: :room + match '/join', to: 'rooms#join', as: :join_room, via: [:get, :post] + match '/wait', to: 'rooms#wait', as: :wait_room, via: [:get, :post] + resources :meetings, only: [:index], param: :meeting_uid end # Signup routes.