Class: SleepRoom::Record::Showroom

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

Constant Summary collapse

SITE =
"showroom"

Instance Method Summary collapse

Constructor Details

#initialize(room:, group: "default", queue:) ⇒ Showroom

Returns a new instance of Showroom.



8
9
10
11
12
13
14
15
# File 'lib/sleeproom/record/record.rb', line 8

def initialize(room:, group: "default", queue:)
  @room = room
  @group = group
  @queue = queue
  @running = false
  @downlaoding = false
  @reconnection = false
end

Instance Method Details

#log(str) ⇒ Object



70
71
72
# File 'lib/sleeproom/record/record.rb', line 70

def log(str)
  SleepRoom.info("[#{@room}] #{str}")
end

#record(reconnection: false) ⇒ Boolean

Parameters:

  • user (String)

Returns:

  • (Boolean)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/sleeproom/record/record.rb', line 19

def record(reconnection: false)
  room = @room
  Async do |task|
    set_room_info
    task.async do |t|
      while @is_live
        if status = SleepRoom.load_config(:status).find{|hash| hash[:room] == room}
          if !status[:pid].nil?
            break if SleepRoom.running?(status[:pid]) == false
          else
            break
          end
        else
          break
        end
        t.sleep 60
      end
    end.wait
    if @is_live
      start_time = Time.now
      log("Live broadcast.")
      streaming_url = parse_streaming_url
      output = build_output
      pid = SleepRoom::Record.call_minyami(url: streaming_url, output: output)
      downloading(streaming_url, pid, start_time)
      record
    else
      log("Status: Stop.")
      waiting_live(ws: :init)
      Async do |task|
        while true
          if @running == false && @reconnection == false
            start_websocket
          elsif @reconnection == true
            set_room_info
            start_websocket
            @reconnection = false
          end
          task.sleep 10
        end
      end
    end
  rescue => e
    add_error(e)
    SleepRoom.error(e.full_message)
    log("Retry...")
    task.sleep 5
    retry
  end
end