sleeproom 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/sleeproom/record/record.rb +25 -5
- data/lib/sleeproom/record/websocket.rb +5 -10
- data/lib/sleeproom/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ccc2b043aff09d26b34628f302b06b38f3cca3aba8193bcd0164a294b6a74df
|
4
|
+
data.tar.gz: 97fac01b4349e11eaa28cdb0fb4dbe83c4c9d4874d29c7002abc3ba2ec2f757b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ca356b737df0e57a5e442ff71e42a127698bcdd0b5a803272f35de0fcccc667d8b5796383795baa51706ba332f441ce2e4e59e54a971cbdc387d636cc489fd7
|
7
|
+
data.tar.gz: b3a840d7063a2a6ee531093134a56d3c975abb70fa826096c233f174a75d75692025543699597db2205333470e94cc5a6750bdf6a7be957a83f997376f5c047d
|
data/Gemfile.lock
CHANGED
@@ -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
|
-
|
117
|
-
if !
|
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(
|
123
|
-
task.sleep
|
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
|
-
@
|
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
|
-
@
|
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
|
-
@
|
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
|
-
@
|
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
|
data/lib/sleeproom/version.rb
CHANGED
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.
|
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
|
+
date: 2020-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|