sleeproom 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 602c623c73913b772f7b1375ce6a7d9c3415df23bcd564d78ae58ddb21fd7b7b
4
- data.tar.gz: 3b6859da62f1a29c1f8f05b65d039a593f78ba6e5e6b4fa9d9c9636d5f6c56ca
3
+ metadata.gz: 8ccc2b043aff09d26b34628f302b06b38f3cca3aba8193bcd0164a294b6a74df
4
+ data.tar.gz: 97fac01b4349e11eaa28cdb0fb4dbe83c4c9d4874d29c7002abc3ba2ec2f757b
5
5
  SHA512:
6
- metadata.gz: 2af5ad3283bcaa58d7b6524a12413b81ef1aaf294d0d5bc95e5abfdae9892a876bb7a7cd32f6a8ad56154054afe3c3e61f5f0fe69bb445f37935fe1c80fbca5f
7
- data.tar.gz: 881a889d97e13a3a3c78c7a98a94563ddb1d2ecd338809ba313ae3748e4f10403dde1a6c8b48f70c0200c7426446a71da96671516be82f5bb9cd9940c94ab1a7
6
+ metadata.gz: 8ca356b737df0e57a5e442ff71e42a127698bcdd0b5a803272f35de0fcccc667d8b5796383795baa51706ba332f441ce2e4e59e54a971cbdc387d636cc489fd7
7
+ data.tar.gz: b3a840d7063a2a6ee531093134a56d3c975abb70fa826096c233f174a75d75692025543699597db2205333470e94cc5a6750bdf6a7be957a83f997376f5c047d
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sleeproom (0.1.2)
4
+ sleeproom (0.2.0)
5
5
  async
6
6
  async-http-faraday
7
7
  async-websocket
@@ -112,15 +112,27 @@ module SleepRoom
112
112
  end
113
113
 
114
114
  Async do |task|
115
+ last_ack = nil
116
+ last_ping = nil
115
117
  while @running && @downlaoding == false
116
- status = ws.status
117
- if !status[:last_ack].nil? && Time.now.to_i - status[:last_ack].to_i > 65
118
+ queue = ws.queue.items
119
+ if !queue.empty?
120
+ queue.each do |event|
121
+ case event[:event]
122
+ when :ack
123
+ last_ack = event[:time]
124
+ when :ping
125
+ last_ping = event[:ping]
126
+ end
127
+ end
128
+ end
129
+ if !last_ack.nil? && Time.now.to_i - last_ack.to_i > 65
118
130
  ws.running = false
119
131
  @running = false
120
132
  task.stop
121
133
  end
122
- waiting_live(status)
123
- task.sleep 30
134
+ waiting_live({last_ack: last_ack})
135
+ task.sleep 1
124
136
  end
125
137
  end
126
138
  task.children.each(&:wait)
@@ -131,17 +143,25 @@ module SleepRoom
131
143
  end
132
144
 
133
145
  def set_room_info
134
- api = API::RoomAPI.new(room)
146
+ api = API::RoomAPI.new(@room)
135
147
  @room_id = api.room_id
136
148
  @room_name = api.room_name
137
149
  @is_live = api.live?
138
150
  @broadcast_host = api.broadcast_host
139
151
  @broadcast_key = api.broadcast_key
152
+ rescue => e
153
+ SleepRoom.error(e.message)
154
+ log("[setRoomInfo] Retry...")
155
+ retry
140
156
  end
141
157
 
142
158
  def parse_streaming_url(task: Async::Task.current)
143
159
  api = API::StreamingAPI.new(@room_id)
144
160
  streaming_url_list = api.streaming_url
161
+ rescue => e
162
+ SleepRoom.error(e.message)
163
+ log("[parseStreamingUrl] Retry...")
164
+ retry
145
165
  end
146
166
 
147
167
  def build_output(task: Async::Task.current)
@@ -6,12 +6,13 @@ require "json"
6
6
  module SleepRoom
7
7
  module Record
8
8
  class WebSocket
9
+ attr_accessor :queue
9
10
  def initialize(room:, broadcast_key:, url:)
10
11
  @room = room
11
12
  @url = "wss://" + url
12
13
  @broadcast_key = broadcast_key
13
14
  @running = false
14
- @status = {}
15
+ @queue = Async::Queue.new
15
16
  end
16
17
 
17
18
  def connect(task: Async::Task.current)
@@ -23,12 +24,12 @@ module SleepRoom
23
24
  connection.write("SUB\t#{@broadcast_key}")
24
25
  connection.flush
25
26
  log("Connect to websocket server.")
26
- @status[:last_update] = Time.now
27
+ @queue.enqueue({event: :connect, time: Time.now})
27
28
 
28
29
  ping_task = task.async do |sub|
29
30
  while @running
30
31
  sub.sleep 60
31
- @status[:last_ping] = Time.now
32
+ @queue.enqueue({event: :ping, time: Time.now})
32
33
  connection.write("PING\tshowroom")
33
34
  connection.flush
34
35
  end
@@ -44,12 +45,10 @@ module SleepRoom
44
45
  end
45
46
 
46
47
  while message = connection.read
47
- @status[:last_update]
48
48
  if message == "ACK\tshowroom"
49
- @status[:last_ack] = Time.now if message == "ACK\tshowroom"
49
+ @queue.enqueue({event: :ack, time: Time.now}) if message == "ACK\tshowroom"
50
50
  end
51
51
  if message.start_with?("MSG")
52
- @status[:last_msg] = Time.now
53
52
  begin
54
53
  yield JSON.parse(message.split("\t")[2])
55
54
  rescue => e
@@ -79,10 +78,6 @@ module SleepRoom
79
78
  @connection.close
80
79
  end
81
80
 
82
- def status
83
- @status
84
- end
85
-
86
81
  def log(str)
87
82
  SleepRoom.info("[#{@room}] #{str}")
88
83
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SleepRoom
4
- VERSION = "0.1.2"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sleeproom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Koell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-11 00:00:00.000000000 Z
11
+ date: 2020-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize