post_publish_recording_ready_callback.rb error

50 views
Skip to first unread message

İsmail Erden

unread,
Sep 20, 2024, 12:34:29 PM9/20/24
to BigBlueButton-dev
$LOAD_PATH.unshift(File.expand_path('../../../lib', __FILE__))

require 'optimist'
require 'net/http'
require 'net/https'
require 'uri'
require 'json'
require 'aws-sdk-s3' # AWS S3 için gerekli
require File.expand_path('../../../lib/recordandplayback', __FILE__)

logger = Logger.new("/var/log/bigbluebutton/post_publish.log", 'weekly')
logger.level = Logger::INFO
BigBlueButton.logger = logger

opts = Optimist::options do
  opt :meeting_id, "Meeting id to archive", :type => String
  opt :format, "Playback format name", :type => String
end

meeting_id = opts[:meeting_id]
format = opts[:format]

# AWS S3 Yükleme İşlemi
def upload_to_s3(meeting_id)
  require 'aws-sdk-s3'

  # AWS S3 yapılandırması
  s3_bucket_name = 'videobucket' # Buraya kendi S3 bucket adınızı yazın
  region = 'eu-north-1'

  recording_file = "/var/bigbluebutton/published/video/#{meeting_id}/video-0.mp4"

  # Dosyanın var olup olmadığını kontrol edin
  unless File.exist?(recording_file)
    BigBlueButton.logger.error("Recording file not found: #{recording_file}")
    return false
  end

  s3_client = Aws::S3::Client.new(region: region)

  # Dosyayı S3'e yükleme
  begin
    s3_key = "#{meeting_id}.mp4" # Dosya adı meetingId.mp4 olacak

    File.open(recording_file, 'rb') do |file|
      s3_client.put_object(bucket: s3_bucket_name, key: s3_key, body: file)
    end

    BigBlueButton.logger.info("Uploaded #{recording_file} to s3://#{s3_bucket_name}/#{s3_key}")
    return true
  rescue Aws::S3::Errors::ServiceError => e
    BigBlueButton.logger.error("Failed to upload to S3: #{e.message}")
    return false
  end
end

# Kayıtları Silme
def delete_recording(meeting_id)
  begin
    BigBlueButton.logger.info("Deleting recordings for meeting ID: #{meeting_id}")
    system("bbb-recording-delete --recording #{meeting_id} --force")
    BigBlueButton.logger.info("Recordings deleted for meeting ID: #{meeting_id}")
  rescue => e
    BigBlueButton.logger.error("Failed to delete recordings: #{e.message}")
  end
end

# API'ye Bildirim Gönderme
def notify_api(meeting_id)
  require 'net/http'
  require 'uri'
  require 'json'

  api_endpoint = 'https://XXX'

  name_value = '36fe8f0d'

  uri = URI.parse(api_endpoint)
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = (uri.scheme == 'https')

  request = Net::HTTP::Post.new(uri.request_uri, { 'Content-Type' => 'application/json' })
  request.body = { meetingId: meeting_id, name: name_value }.to_json

  response = http.request(request)
  code = response.code.to_i

  if code >= 200 && code < 300
    BigBlueButton.logger.info("API notification successful: #{meeting_id} (code #{code})")
  else
    BigBlueButton.logger.error("API notification failed: #{response.code} #{response.message} (code #{code})")
  end
end

#
# Ana Kod
#
BigBlueButton.logger.info("Recording Ready Notify for [#{meeting_id}] starts")

begin
  # AWS S3'e yükleme işlemi
  BigBlueButton.logger.info("Uploading recording to AWS S3 for meeting: #{meeting_id}")
  upload_success = upload_to_s3(meeting_id)

  if upload_success
    #BigBlueButton.logger.info("Deleting recordings for meeting: #{meeting_id}")
    #delete_recording(meeting_id)

    # API'ye bildirim gönderme
    BigBlueButton.logger.info("Notifying API for meeting: #{meeting_id}")
    notify_api(meeting_id)
  else
    BigBlueButton.logger.error("Upload failed for meeting: #{meeting_id}, skipping deletion and API notification")
  end

rescue => e
  BigBlueButton.logger.error("Error in post_publish_recording_ready_callback.rb: #{e.message}")
  BigBlueButton.logger.error(e.backtrace.join("\n"))
end

BigBlueButton.logger.info("Recording Ready notify ends")

exit 0


Hello, what do you think is the reason for me getting this error?
I installed gems and aws without any problems.
Is there a definite working version of this example?

Thank you very much for your answers.
f1f.jpg

İsmail Erden

unread,
Sep 20, 2024, 6:58:07 PM9/20/24
to BigBlueButton-dev
Is there really no one among us who knows Ruby?

20 Eylül 2024 Cuma tarihinde saat 19:34:29 UTC+3 itibarıyla İsmail Erden şunları yazdı:

İsmail Erden

unread,
Sep 21, 2024, 10:10:51 AM9/21/24
to BigBlueButton-dev
I got it done guys. Thank you very much. If anyone gets stuck I can help you.

21 Eylül 2024 Cumartesi tarihinde saat 01:58:07 UTC+3 itibarıyla İsmail Erden şunları yazdı:

Fred Dixon

unread,
Sep 23, 2024, 6:39:22 AM9/23/24
to bigblueb...@googlegroups.com
Hi İsmail,

Thanks for the update.  Could you share how you got it working -- is there anything you recommend we change in the code?

Regards,... Fred


--
You received this message because you are subscribed to the Google Groups "BigBlueButton-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bigbluebutton-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bigbluebutton-dev/716b6741-6aee-473e-ba44-fa7ddac3c6c3n%40googlegroups.com.


--
Co-founder BigBlueButton

Like BigBlueButton?  Tweet us at @bigbluebutton

İsmail Erden

unread,
Sep 23, 2024, 2:41:36 PM9/23/24
to BigBlueButton-dev
Hi Fred,
Thank you for your answer.
There was no error in the code. I just couldn't install the packages. I deleted them and reinstalled them and it worked.
Thank you very much for your effort.

23 Eylül 2024 Pazartesi tarihinde saat 13:39:22 UTC+3 itibarıyla Fred Dixon şunları yazdı:
Reply all
Reply to author
Forward
0 new messages