Skip to content
Snippets Groups Projects
Unverified Commit 1ca5b53c authored by Hadi Cheaito's avatar Hadi Cheaito Committed by GitHub
Browse files

Back-end: Recordings Re-Sync (#3441)


* Back-end: Recordings Re-Sync

* Better naming

* CR cleaning

* Removing some comments

* CR Changes

* rebase

Co-authored-by: default avatarAhmad Farhat <ahmad.af.farhat@gmail.com>
parent 4db95a55
No related branches found
No related tags found
No related merge requests found
......@@ -53,6 +53,7 @@ Metrics/BlockLength:
IgnoredMethods: [ 'describe', 'context' ]
Exclude:
- 'config/routes.rb'
Max: 30
# A calculated magnitude based on number of assignments,
# branches, and conditions.
......
......@@ -3,6 +3,8 @@
module Api
module V1
class RecordingsController < ApplicationController
skip_before_action :verify_authenticity_token # TODO: - Revisit this.
# GET /api/v1/recordings.json
# Returns: { data: Array[serializable objects(recordings)] , errors: Array[String] }
# Does: Returns all the Recordings from all the current user's rooms
......@@ -11,6 +13,12 @@ module Api
render_json(data: recordings, status: :ok, include: :formats)
end
def recordings
RecordingsSync.new(user: current_user).call
render_json(status: :ok)
end
end
end
end
......@@ -32,6 +32,11 @@ class BigBlueButtonApi
bbb_server.is_meeting_running?(room.friendly_id)
end
# Retrieve the recordings that belong to room with given meeting_id
def get_recordings(meeting_ids:)
bbb_server.get_recordings(meetingID: meeting_ids)
end
private
def bbb_endpoint
......
# frozen_string_literal: true
class RecordingsSync
def initialize(params)
@user = params[:user]
end
def call
rooms = @user.rooms
# Get the meeting_id of all the current user's rooms
meeting_ids = rooms.map(&:meeting_id)
Recording.destroy_by(room_id: rooms.map(&:id))
recordings = BigBlueButtonApi.new.get_recordings(meeting_ids:)
recordings[:recordings].each do |recording|
room_id = Room.find_by(meeting_id: recording[:meetingID]).id
# Get length of presentation format(s)
length = get_recording_length(recording:)
new_recording = Recording.create(room_id:, name: recording[:name], record_id: recording[:recordID], visibility: 'Unlisted',
users: recording[:participants], length:)
# Create format(s)
create_formats(recording:, new_recording:)
end
end
private
# Returns the length of presentation recording for the recording given
def get_recording_length(recording:)
length = 0
if recording[:playback][:format].is_a?(Array)
recording[:playback][:format].each do |formats|
length = formats[:length] if formats[:type] == 'presentation'
end
else
length = recording[:playback][:format][:length]
end
length
end
# Creates format(s) for given new_recording
def create_formats(recording:, new_recording:)
if recording[:playback][:format].is_a?(Array)
recording[:playback][:format].each do |format|
Format.create(recording_id: new_recording.id, recording_type: format[:type], url: format[:url])
end
else
Format.create(recording_id: new_recording.id, recording_type: recording[:playback][:format][:type], url: recording[:playback][:format][:url])
end
end
end
......@@ -26,7 +26,11 @@ Rails.application.routes.draw do
end
end
resources :room_settings, only: %i[show update], param: :friendly_id
resources :recordings, only: [:index]
resources :recordings, only: [:index] do
collection do
get '/recordingsReSync', to: 'recordings#recordings'
end
end
end
end
match '*path', to: 'components#index', via: :all, constraints: lambda { |req|
......
......@@ -28,4 +28,16 @@ RSpec.describe Api::V1::RecordingsController, type: :controller do
expect(response_recording_ids).to be_empty
end
end
describe '#recordings' do
it 'calls the RecordingsSync service correctly' do
expect_any_instance_of(RecordingsSync).to receive(:call)
get :recordings
end
it 'calls the RecordingsSync service with correct params' do
expect(RecordingsSync).to receive(:new).with(user:)
get :recordings
end
end
end
......@@ -68,5 +68,12 @@ describe BigBlueButtonApi, type: :service do
bbb_service.start_meeting room:, meeting_starter: nil, options: {}
end
end
describe 'calls bbb#get_recordings' do
it 'With list of meeting ids given as param' do
expect(bbb_server).to receive(:get_recordings).with(meetingID: [1, 2, 3])
bbb_service.get_recordings(meeting_ids: [1, 2, 3])
end
end
end
end
# frozen_string_literal: true
require 'rails_helper'
require 'bigbluebutton_api'
describe RecordingsSync, type: :service do
let(:user) { create(:user) }
let(:room) { create(:room, user:) }
let(:recordings_sync_service) { described_class.new(user:) }
before do
ENV['BIGBLUEBUTTON_ENDPOINT'] = 'http://test.com/bigbluebutton/api'
ENV['BIGBLUEBUTTON_SECRET'] = 'test'
end
describe '#call' do
it 'creates no new recordings and deletes all existing ones based on response' do
create_list(:recording, 5, room:)
allow_any_instance_of(BigBlueButtonApi).to receive(:get_recordings).and_return(no_recording_response)
recordings_sync_service.call
expect(room.recordings.count).to eq(0)
end
it 'creates single recording and format based on response' do
room.update(meeting_id: 'random-1291479')
record_id = 'f0e2be4518868febb0f381ebe7d46ae61364ef1e-1652287428125'
allow_any_instance_of(BigBlueButtonApi).to receive(:get_recordings).and_return(single_format_response)
recordings_sync_service.call
expect(room.recordings.first.formats.count).to eq(1)
expect(room.recordings.first.record_id).to eq(record_id)
expect(room.recordings.first.formats.first.recording_type).to eq('presentation')
end
it 'creates multiple formats based on response' do
room.update(meeting_id: 'random-5678484')
allow_any_instance_of(BigBlueButtonApi).to receive(:get_recordings).and_return(multiple_formats_response)
recordings_sync_service.call
expect(room.recordings.first.formats.count).to eq(2)
expect(room.recordings.first.formats.first.recording_type).to eq('presentation')
expect(room.recordings.first.formats.second.recording_type).to eq('podcast')
end
end
private
def no_recording_response
{ returncode: true,
recordings: [],
messageKey: '',
message: '' }
end
def single_format_response
{ returncode: true,
recordings: [{ recordID: 'f0e2be4518868febb0f381ebe7d46ae61364ef1e-1652287428125',
meetingID: 'random-1291479',
internalMeetingID: 'f0e2be4518868febb0f381ebe7d46ae61364ef1e-1652287428125',
name: 'random-1291479',
isBreakout: 'false',
published: true,
state: 'published',
startTime: 'Wed, 11 May 2022 12:43:48 -0400'.to_datetime,
endTime: 'Wed, 11 May 2022 12:44:20 -0400'.to_datetime,
participants: '1',
rawSize: '977816',
metadata: { isBreakout: 'false', meetingId: 'random-1291479', meetingName: 'random-1291479' },
size: '305475',
playback: { format: { type: 'presentation',
url: 'https://test24.bigbluebutton.org/playback/presentation/2.3/f0e2be4518868febb0f381ebe7d46ae61364ef1e-1652287428125',
processingTime: '6386',
length: 0,
size: '305475' } },
data: {} }],
messageKey: '',
message: '' }
end
def multiple_formats_response
{ returncode: true,
recordings: [{ recordID: '955458f326d02d78ef8d27f4fbf5fafb7c2f666a-1652296432321',
meetingID: 'random-5678484',
internalMeetingID: '955458f326d02d78ef8d27f4fbf5fafb7c2f666a-1652296432321',
name: 'random-5678484',
isBreakout: 'false',
published: true,
state: 'published',
startTime: 'Wed, 11 May 2022 15:13:52 -0400'.to_datetime,
endTime: 'Wed, 11 May 2022 15:14:19 -0400'.to_datetime,
participants: '1',
rawSize: '960565',
metadata: { isBreakout: 'false', meetingId: 'random-5678484', meetingName: 'random-5678484' },
size: '272997',
playback: { format: [{ type: 'presentation',
url: 'https://test24.bigbluebutton.org/playback/presentation/2.3/955458f326d02d78ef8d27f4fbf5fafb7c2f666a-1652296432321',
processingTime: '5780',
length: 0,
size: '211880' },
{ type: 'podcast',
url: 'https://test24.bigbluebutton.org/podcast/955458f326d02d78ef8d27f4fbf5fafb7c2f666a-1652296432321/audio.ogg',
processingTime: '0',
length: 0,
size: '61117' }] },
data: {} }],
messageKey: '',
message: '' }
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment