skyfall 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +4 -3
- data/lib/skyfall/cid.rb +8 -0
- data/lib/skyfall/collection.rb +1 -0
- data/lib/skyfall/operation.rb +6 -1
- data/lib/skyfall/stream.rb +58 -0
- data/lib/skyfall/version.rb +1 -1
- data/lib/skyfall/websocket_message.rb +4 -2
- 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: 6bc7ba74da06a265f8b1af42633b4c462f87fbf5764b38505628d9255bd97831
|
4
|
+
data.tar.gz: 9bbb8e00563fdab6ee906ce82a3ddcde4936b8f0ee187da4d4f8032f5f344446
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 440c94077709828c54814ed8a4d520dbb513755412fa5baaee443d55f2493833e5c9196ffbcee256a118b8bdc6e41d92479fa041514ab8d9d16978aa4ec1d4c7
|
7
|
+
data.tar.gz: b43da862f141b6ed476036eee85c8514a3b93a7a93bcaa16e089ee6149137c6b548639351445b2d3bddb3e2c458e8dc6e2c3eaa3f71d2efb9d92dad734f2fbf1
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -52,7 +52,8 @@ Each message passed to `on_message` is an instance of the `WebsocketMessage` cla
|
|
52
52
|
- `seq` (sequential number)
|
53
53
|
- `time` (Time)
|
54
54
|
- `repo` (string) - DID of the repository (user account)
|
55
|
-
- `commit` - CID
|
55
|
+
- `commit` - CID of the commit
|
56
|
+
- `prev` - CID of the previous commit in that repo
|
56
57
|
- `operations` - list of operations (usually one)
|
57
58
|
|
58
59
|
Operations are objects of type `Operation` and have such properties:
|
@@ -63,9 +64,9 @@ Operations are objects of type `Operation` and have such properties:
|
|
63
64
|
- `action` (symbol) - `:create`, `:update` or `:delete`
|
64
65
|
- `uri` (string) - the at:// URI
|
65
66
|
- `type` (symbol) - short name of the collection, e.g. `:bsky_post`
|
66
|
-
- `cid` - CID
|
67
|
+
- `cid` - CID of the operation/record (`nil` for delete operations)
|
67
68
|
|
68
|
-
|
69
|
+
Create and update operations will also have an attached record (JSON object) with details of the post, like etc. The record data is currently available as a Ruby hash via `raw_record` property (custom types will be added in a later version).
|
69
70
|
|
70
71
|
So for example, in order to filter only "create post" operations and print their details, you can do something like this:
|
71
72
|
|
data/lib/skyfall/cid.rb
CHANGED
@@ -16,6 +16,14 @@ module Skyfall
|
|
16
16
|
CID.new(data[1..-1])
|
17
17
|
end
|
18
18
|
|
19
|
+
def self.from_json(string)
|
20
|
+
raise DecodeError.new("Unexpected CID length") unless string.length == 59
|
21
|
+
raise DecodeError.new("Unexpected CID prefix") unless string[0] == 'b'
|
22
|
+
|
23
|
+
data = Base32.decode(string[1..-1].upcase)
|
24
|
+
CID.new(data)
|
25
|
+
end
|
26
|
+
|
19
27
|
def initialize(data)
|
20
28
|
@data = data
|
21
29
|
end
|
data/lib/skyfall/collection.rb
CHANGED
data/lib/skyfall/operation.rb
CHANGED
@@ -21,7 +21,11 @@ module Skyfall
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def collection
|
24
|
-
path.split('/')
|
24
|
+
path.split('/')[0]
|
25
|
+
end
|
26
|
+
|
27
|
+
def rkey
|
28
|
+
path.split('/')[1]
|
25
29
|
end
|
26
30
|
|
27
31
|
def type
|
@@ -33,6 +37,7 @@ module Skyfall
|
|
33
37
|
when Collection::BSKY_BLOCK then :bsky_block
|
34
38
|
when Collection::BSKY_PROFILE then :bsky_profile
|
35
39
|
when Collection::BSKY_LISTITEM then :bsky_listitem
|
40
|
+
when Collection::BSKY_FEED then :bsky_feed
|
36
41
|
else :unknown
|
37
42
|
end
|
38
43
|
end
|
data/lib/skyfall/stream.rb
CHANGED
@@ -9,10 +9,16 @@ module Skyfall
|
|
9
9
|
:subscribe_repos => SUBSCRIBE_REPOS
|
10
10
|
}
|
11
11
|
|
12
|
+
attr_accessor :heartbeat_timeout, :heartbeat_interval
|
13
|
+
|
12
14
|
def initialize(server, endpoint)
|
13
15
|
@endpoint = check_endpoint(endpoint)
|
14
16
|
@server = check_hostname(server)
|
15
17
|
@handlers = {}
|
18
|
+
@heartbeat_mutex = Mutex.new
|
19
|
+
@heartbeat_interval = 5
|
20
|
+
@heartbeat_timeout = 30
|
21
|
+
@last_update = nil
|
16
22
|
end
|
17
23
|
|
18
24
|
def connect
|
@@ -20,9 +26,11 @@ module Skyfall
|
|
20
26
|
|
21
27
|
url = "wss://#{@server}/xrpc/#{@endpoint}"
|
22
28
|
handlers = @handlers
|
29
|
+
stream = self
|
23
30
|
|
24
31
|
@websocket = WebSocket::Client::Simple.connect(url) do |ws|
|
25
32
|
ws.on :message do |msg|
|
33
|
+
stream.notify_heartbeat
|
26
34
|
handlers[:raw_message]&.call(msg.data)
|
27
35
|
|
28
36
|
if handlers[:message]
|
@@ -43,15 +51,61 @@ module Skyfall
|
|
43
51
|
handlers[:error]&.call(e)
|
44
52
|
end
|
45
53
|
end
|
54
|
+
|
55
|
+
if @heartbeat_interval && @heartbeat_timeout && @heartbeat_thread.nil?
|
56
|
+
hb_interval = @heartbeat_interval
|
57
|
+
hb_timeout = @heartbeat_timeout
|
58
|
+
|
59
|
+
@last_update = Time.now
|
60
|
+
|
61
|
+
@heartbeat_thread = Thread.new do
|
62
|
+
loop do
|
63
|
+
sleep(hb_interval)
|
64
|
+
@heartbeat_mutex.synchronize do
|
65
|
+
if Time.now - @last_update > hb_timeout
|
66
|
+
force_restart
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def force_restart
|
75
|
+
@websocket.close
|
76
|
+
@websocket = nil
|
77
|
+
|
78
|
+
timeout = 5
|
79
|
+
|
80
|
+
loop do
|
81
|
+
begin
|
82
|
+
@handlers[:reconnect]&.call
|
83
|
+
connect
|
84
|
+
break
|
85
|
+
rescue Exception => e
|
86
|
+
@handlers[:error]&.call(e)
|
87
|
+
sleep(timeout)
|
88
|
+
timeout *= 2
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
@last_update = Time.now
|
46
93
|
end
|
47
94
|
|
48
95
|
def disconnect
|
49
96
|
return unless @websocket
|
50
97
|
|
98
|
+
@heartbeat_thread&.kill
|
99
|
+
@heartbeat_thread = nil
|
100
|
+
|
51
101
|
@websocket.close
|
52
102
|
@websocket = nil
|
53
103
|
end
|
54
104
|
|
105
|
+
def notify_heartbeat
|
106
|
+
@heartbeat_mutex.synchronize { @last_update = Time.now }
|
107
|
+
end
|
108
|
+
|
55
109
|
alias close disconnect
|
56
110
|
|
57
111
|
def on_message(&block)
|
@@ -74,6 +128,10 @@ module Skyfall
|
|
74
128
|
@handlers[:error] = block
|
75
129
|
end
|
76
130
|
|
131
|
+
def on_reconnect(&block)
|
132
|
+
@handlers[:reconnect] = block
|
133
|
+
end
|
134
|
+
|
77
135
|
|
78
136
|
private
|
79
137
|
|
data/lib/skyfall/version.rb
CHANGED
@@ -12,7 +12,7 @@ module Skyfall
|
|
12
12
|
using Skyfall::Extensions
|
13
13
|
|
14
14
|
attr_reader :type_object, :data_object
|
15
|
-
attr_reader :type, :repo, :time, :seq, :commit, :blocks, :operations
|
15
|
+
attr_reader :type, :repo, :time, :seq, :commit, :prev, :blocks, :operations
|
16
16
|
|
17
17
|
def initialize(data)
|
18
18
|
objects = CBOR.decode_sequence(data)
|
@@ -34,7 +34,9 @@ module Skyfall
|
|
34
34
|
|
35
35
|
return unless @type == :commit
|
36
36
|
|
37
|
-
@commit = CID.from_cbor_tag(@data_object['commit'])
|
37
|
+
@commit = @data_object['commit'] && CID.from_cbor_tag(@data_object['commit'])
|
38
|
+
@prev = @data_object['prev'] && CID.from_cbor_tag(@data_object['prev'])
|
39
|
+
|
38
40
|
@blocks = CarArchive.new(@data_object['blocks'])
|
39
41
|
|
40
42
|
@operations = @data_object['ops'].map { |op|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: skyfall
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kuba Suder
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-06-
|
11
|
+
date: 2023-06-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: base32
|