add live meeting in broadcast screen

This commit is contained in:
Bilal
2020-09-14 15:57:38 +03:00
parent 28e0eb36b7
commit de0b12a0e4
12 changed files with 89 additions and 4 deletions

View File

@@ -32,3 +32,6 @@ CUSTOM_API_TOKEN=
# Required for simulcasting to Millicast for director mode
MILLICAST_API_SECRET=
MILLICAST_ACCOUNT_ID=
# Daily.co live chat API token
DAILY_API_TOKEN=

View File

@@ -114,7 +114,7 @@ class BroadcastsController < ApplicationController
end
def conference_url_for(broadcast)
broadcast.video_conference_url_override.presence || url_for([broadcast.project, broadcast, :zoom_meeting])
broadcast.video_conference_url_override.presence || url_for([broadcast.project, broadcast, :live_meeting])
end
def log_create_analytics

View File

@@ -0,0 +1,6 @@
class LiveMeetingsController < ApplicationController
def show
authorize broadcast = Broadcast.find(params[:broadcast_id])
@live_meeting_url = broadcast.project.live_meeting_url
end
end

View File

@@ -44,7 +44,7 @@ class Public::BroadcastsController < Public::BaseController
end
def conference_url_for(broadcast)
broadcast.video_conference_url_override.presence || broadcast_zoom_meeting_url(broadcast.token)
broadcast.video_conference_url_override.presence || broadcast_live_meeting_url(broadcast.token)
end
class MultiViewBroadcast

View File

@@ -0,0 +1,9 @@
class Public::LiveMeetingsController < Public::BaseController
skip_after_action :verify_authorized
def show
broadcast = Broadcast.find_by_token!(params[:broadcast_token])
@live_meeting_url = broadcast.project.live_meeting_url
render 'public/live_meetings/show'
end
end

View File

@@ -14,6 +14,7 @@ class Broadcast < ApplicationRecord
# Should we use callbacks for this, or something else?
after_create :create_mux_live_stream
after_create :create_live_meeting_if_not_created
after_destroy :destroy_mux_live_stream
pg_search_scope :search, {
@@ -59,6 +60,14 @@ class Broadcast < ApplicationRecord
self.save!
end
def create_live_meeting_if_not_created
if project.live_meeting_url.blank?
room = Daily.create_room
room_url = room['url']
project.update live_meeting_url: room_url
end
end
def destroy_mux_live_stream
begin
stream = MuxLiveStream.new

View File

@@ -0,0 +1,13 @@
<%= javascript_include_tag "https://unpkg.com/@daily-co/daily-js" %>
<%= javascript_tag nonce: true do %>
callFrame = window.DailyIframe.createFrame({
showLeaveButton: true,
iframeStyle: {
position: 'fixed',
width: '100%',
height: '90%'
}
});
callFrame.join({ url: '<%= @live_meeting_url %>' });
<% end %>

View File

@@ -0,0 +1,13 @@
<%= javascript_include_tag "https://unpkg.com/@daily-co/daily-js" %>
<%= javascript_tag nonce: true do %>
callFrame = window.DailyIframe.createFrame({
showLeaveButton: true,
iframeStyle: {
position: 'fixed',
width: '100%',
height: '90%'
}
});
callFrame.join({ url: '<%= @live_meeting_url %>' });
<% end %>

View File

@@ -0,0 +1 @@
require 'daily'

View File

@@ -104,7 +104,7 @@ Rails.application.routes.draw do
member do
delete :destroy_file
end
resource :zoom_meeting, only: [:show]
resource :live_meeting, only: [:show]
resources :broadcast_recordings, only: [:destroy]
end
resources :directories, except: [:index] do
@@ -149,7 +149,7 @@ Rails.application.routes.draw do
end
end
resources :broadcasts, param: :token, only: [:show, :update] do
resource :zoom_meeting, only: [:show]
resource :live_meeting, only: [:show]
resources :broadcast_recordings, only: [:edit, :update] do
resources :broadcast_recording_starrings, only: :create
end

View File

@@ -0,0 +1,5 @@
class AddLiveMeetingUrlToProjects < ActiveRecord::Migration[6.0]
def change
add_column :projects, :live_meeting_url, :text
end
end

26
lib/daily.rb Normal file
View File

@@ -0,0 +1,26 @@
# frozen_string_literal: true
class Daily
include HTTParty
base_uri 'api.daily.co/v1'
class << self
def create_room
response = post "#{base_uri}/rooms", headers: headers
if response.code != 200
throw StandardError.new('Failed to create a room')
end
response.parsed_response
end
private
def headers
{
'Authorization': "Bearer #{ENV['DAILY_API_TOKEN']}"
}
end
end
end