Initial commit

This commit is contained in:
Senad Uka
2020-05-31 22:38:19 +02:00
commit 858fafc3c5
1280 changed files with 65918 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
module ApplicationCable
class Channel < ActionCable::Channel::Base
end
end

View File

@@ -0,0 +1,17 @@
module ApplicationCable
class Connection < ActionCable::Connection::Base
identified_by :current_user
def connect
self.current_user = find_verified_user
end
private
def find_verified_user
if verified_user = env['warden'].user
verified_user
end
end
end
end

View File

@@ -0,0 +1,47 @@
class BroadcastsChannel < ApplicationCable::Channel
def subscribed
broadcast = Broadcast.find_by_token!(params[:token])
stream_for broadcast
end
def unsubscribed
# Any cleanup needed when channel is unsubscribed
end
def self.broadcast_stream_updates(broadcast)
status_content = ApplicationController.render partial: "broadcasts/broadcast_status", locals: { broadcast: broadcast }
video_content = ApplicationController.render partial: "broadcasts/video", locals: { broadcast: broadcast }
broadcast_to broadcast, {
event: :broadcast_stream_update,
status: broadcast.status,
playback_url: broadcast.stream_playback_url,
video_content: video_content,
status_content: status_content,
streamer_status: broadcast.streamer_status
}
end
def self.stream_recording_ready(broadcast, recordings, message)
flash_message = OpenStruct.new(notice: message, alert: nil)
flash_content = ApplicationController.render partial: "application/flash", locals: { flash: flash_message }
recordings_content = ApplicationController.render partial: "broadcasts/broadcast_recordings", locals: { recordings: recordings, broadcast: broadcast }
recordings_nav_content = ApplicationController.render partial: "broadcasts/broadcast_recording_nav", collection: recordings, as: :broadcast_recording
broadcast_to broadcast,
event: :stream_recording_ready,
flash_content: flash_content,
recordings_content: recordings_content,
recordings_nav_content: recordings_nav_content
end
def self.file_upload_updates(broadcast, files, pagination_content)
files_content = ApplicationController.render partial: "broadcasts/file", collection: files
broadcast_to broadcast, {
event: :file_upload_update,
files_content: files_content,
pagination_content: pagination_content
}
end
end

View File

@@ -0,0 +1,36 @@
class ProjectsChannel < ApplicationCable::Channel
def subscribed
# TODO: How can we get the current account in this context
project = current_user.accessible_projects_for(current_user.primary_account).find(params[:id])
stream_for project
end
def unsubscribed
# Any cleanup needed when channel is unsubscribed
end
def self.broadcast_video_analysis_update(video)
content = ApplicationController.render partial: "video_analyses/video_status_updated", locals: { video: video }
broadcast_to video.project, event: :video_status_update, content: content
end
def self.broadcast_download_generation_update(download, notification)
if download.failure?
flash = OpenStruct.new(notice: nil, alert: notification)
else
flash = OpenStruct.new(notice: notification, alert: nil)
end
content = ApplicationController.render partial: "application/flash", locals: { flash: flash }
broadcast_to download.project, event: :download_status_update, content: content
end
def self.conference_recording_ready(project, recording)
link = ApplicationController.helpers.link_to('Download here.', recording.service_url, target: '_blank', class: 'alert-link')
notification = "A recording of your video conference is now available. #{link}"
flash = OpenStruct.new(notice: notification)
content = ApplicationController.render partial: 'application/flash', locals: { flash: flash }
broadcast_to project, event: :conference_recording_ready, content: content
end
end