Skip to content
Snippets Groups Projects
Select Git revision
  • debf782c70dde00db32f1aca8c9b7f047dc4c964
  • master default protected
  • v3-modify-mail
  • snyk-fix-207483a1e839c807f95a55077e86527d
  • translations_3b5aa4f3c755059914cfa23d7d2edcde_ru
  • translations_6e4a5e377a3e50f17e6402264fdbfcc6_ru
  • translations_3b5aa4f3c755059914cfa23d7d2edcde_fa_IR
  • translations_en-yml--master_fa_IR
  • snyk-fix-7d634f2eb65555f41bf06d6af930e812
  • translations_en-yml--master_ar
  • translations_3b5aa4f3c755059914cfa23d7d2edcde_el
  • jfederico-patch-1
  • v2
  • v3
  • v1
  • release-3.1.0.2
  • release-3.1.0.1
  • release-3.1.0
  • release-2.14.8.4
  • release-3.0.9.1
  • release-3.0.9
  • release-3.0.8.1
  • release-2.14.8.3
  • release-3.0.8
  • release-3.0.7.1
  • release-2.14.8.2
  • release-3.0.7
  • release-3.0.6.1
  • release-3.0.6
  • release-3.0.5.4
  • release-3.0.5.3
  • release-2.14.8.1
  • release-3.0.5.2
  • release-3.0.5.1
  • release-3.0.5
35 results

recording_creator.rb

Blame
  • user avatar
    Khemissi Amir authored and GitHub committed
    * Added missing tests.
    
    * Met expected scenarios.
    a7ff82e1
    History
    recording_creator.rb 3.79 KiB
    # BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
    #
    # Copyright (c) 2022 BigBlueButton Inc. and by respective authors (see below).
    #
    # This program is free software; you can redistribute it and/or modify it under the
    # terms of the GNU Lesser General Public License as published by the Free Software
    # Foundation; either version 3.0 of the License, or (at your option) any later
    # version.
    #
    # Greenlight is distributed in the hope that it will be useful, but WITHOUT ANY
    # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
    # PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    #
    # You should have received a copy of the GNU Lesser General Public License along
    # with Greenlight; if not, see <http://www.gnu.org/licenses/>.
    
    # frozen_string_literal: true
    
    class RecordingCreator
      def initialize(recording:)
        @recording = recording
      end
    
      def call
        meeting_id = @recording[:metadata][:meetingId] || @recording[:meetingID]
        room_id = Room.find_by(meeting_id:)&.id
    
        raise ActiveRecord::RecordNotFound if room_id.nil?
    
        visibility = get_recording_visibility(recording: @recording)
    
        # Get length of presentation format(s)
        length = get_recording_length(recording: @recording)
    
        new_name = @recording[:metadata][:name] || @recording[:name]
    
        new_recording = Recording.find_or_initialize_by(record_id: @recording[:recordID])
        new_recording.room_id = room_id
        new_recording.name = new_name
        new_recording.visibility = visibility
        new_recording.participants = @recording[:participants]
        new_recording.length = length
        new_recording.protectable = @recording[:protected].present?
        new_recording.recorded_at = @recording[:startTime]
        new_recording.save!
    
        # Create format(s)
        create_formats(recording: @recording, new_recording:)
      end
    
      private
    
      # Returns the visibility of the recording (published, unpublished or protected)
      def get_recording_visibility(recording:)
        list = recording[:metadata][:'gl-listed'].to_s == 'true'
        protect = recording[:protected].to_s == 'true'
        publish = recording[:published].to_s == 'true'
    
        visibility = visibility_for(publish:, protect:, list:)
    
        return visibility unless visibility.nil?
    
        Recording::VISIBILITIES[:unpublished]
      end
    
      # 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.find_or_create_by(recording_id: new_recording.id, recording_type: format[:type], url: format[:url])
          end
        else
          Format.find_or_create_by(recording_id: new_recording.id, recording_type: recording[:playback][:format][:type],
                                   url: recording[:playback][:format][:url])
        end
      end
    
      # Visibilitiy Map
      def visibility_for(publish:, protect:, list:)
        params_for = {
          { publish: false, protect: false, list: false } => Recording::VISIBILITIES[:unpublished],
          { publish: true, protect: false, list: false } => Recording::VISIBILITIES[:published],
          { publish: true, protect: false, list: true } => Recording::VISIBILITIES[:public],
          { publish: true, protect: true, list: false } => Recording::VISIBILITIES[:protected],
          { publish: true, protect: true, list: true } => Recording::VISIBILITIES[:public_protected]
        }
    
        params_for[{ publish:, protect:, list: }]
      end
    end