-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstream.rb
More file actions
35 lines (29 loc) · 750 Bytes
/
stream.rb
File metadata and controls
35 lines (29 loc) · 750 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
require 'eventmachine'
require 'faye/websocket'
class MstdnStream
STREAMING_PATH = 'wss://mstdn-workers.com/api/v1/streaming'.freeze
TOKEN_FILE_NAME = '.access_token'.freeze
ACCESS_TOKEN = File.read(TOKEN_FILE_NAME).chomp.freeze
class << self
def set_stream
p 'begin'
EM.run do
url = "#{STREAMING_PATH}?access_token=#{ACCESS_TOKEN}&stream=public:local"
p url
conn = Faye::WebSocket::Client.new(url)
conn.on :open do
puts 'connection success.'
end
conn.on :error do |e|
p e
end
conn.on :close do
puts 'connection close.'
end
conn.on :message do |msg|
yield msg
end
end
end
end
end