Class: Async::Slack::RealTime
Instance Method Summary
collapse
#initialize
Instance Method Details
#connect(**options, &block) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/async/slack/real_time.rb', line 31
def connect(**options, &block)
response = self.post
parameters = response.read
url = parameters[:url]
endpoint = Async::HTTP::Endpoint.parse(url)
Async::WebSocket::Client.connect(endpoint, **options) do |connection|
self.start(connection, &block)
end
end
|
#start(connection, &block) ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/async/slack/real_time.rb', line 44
def start(connection, &block)
id = 1
pinger = Async do |task|
while true
task.sleep 60
Async.logger.debug(self) {"Sending ping #{id}..."}
connection.write({type: "ping", id: "pinger-#{id}"})
connection.flush
id += 1
end
end
yield connection
ensure
pinger.stop
end
|