Class: BigBlueButtonBot

Inherits:
Object
  • Object
show all
Defined in:
lib/bigbluebutton_bot.rb

Constant Summary collapse

BOT_FILENAME =
"../extras/bbb-bot.jar"
@@pids =
[]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api, meeting, salt = "", count = 1, timeout = 20) ⇒ BigBlueButtonBot

Returns a new instance of BigBlueButtonBot.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/bigbluebutton_bot.rb', line 5

def initialize(api, meeting, salt="", count=1, timeout=20)
  server = parse_server_url(api.url)

  # note: fork + exec with these parameters was the only solution found to run the command in background
  # and be able to wait for it (kill it) later on (see BigBlueButtonBot.finalize)
  pid = Process.fork do
    bot_file = File.join(File.dirname(__FILE__), BOT_FILENAME)
    exec("java", "-jar", "#{bot_file}", "-s", "#{server}", "-p", "#{salt}", "-m", "#{meeting}", "-n", "#{count}")

    # other options that didn't work:
    # IO::popen("java -jar #{bot_file} -s \"#{server}\" -m \"#{meeting}\" -n #{count} >/dev/null")
    # exec(["java", "-jar #{bot_file} -s \"#{server}\" -m \"#{meeting}\" -n #{count} >/dev/null"])
    # exec("java -jar #{bot_file} -s \"#{server}\" -m \"#{meeting}\" -n #{count} >/dev/null")
    # Process.exit!
  end
  @@pids << pid

  wait_bot_startup(api, meeting, count, timeout)
end

Class Method Details

.finalizeObject



25
26
27
28
29
30
31
# File 'lib/bigbluebutton_bot.rb', line 25

def self.finalize
  @@pids.each do |pid|
    p = Process.kill("TERM", pid)
    Process.detach(pid)
  end
  @@pids.clear
end

Instance Method Details

#parse_server_url(full_url) ⇒ Object



33
34
35
36
37
38
# File 'lib/bigbluebutton_bot.rb', line 33

def parse_server_url(full_url)
  uri = URI.parse(full_url)
  uri_s = uri.scheme + "://" + uri.host
  uri_s = uri_s + ":" + uri.port.to_s if uri.port != uri.default_port
  uri_s
end

#wait_bot_startup(api, meeting, participants, timeout = 20) ⇒ Object

wait until the meeting is running with a certain number of participants



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/bigbluebutton_bot.rb', line 41

def wait_bot_startup(api, meeting, participants, timeout=20)
  Timeout::timeout(timeout) do
    stop_wait = false
    while !stop_wait
      sleep 1

      # find the meeting and hope it is running
      response = api.get_meetings
      selected = response[:meetings].reject!{ |m| m[:meetingID] != meeting }
      if selected and selected.size > 0 and selected[0][:running]

        # check how many participants are in the meeting
        pass = selected[0][:moderatorPW]
        response = api.get_meeting_info(meeting, pass)
        stop_wait = response[:participantCount] >= participants
      end
    end
  end
end