Class: Slack::RealTime::Socket

Inherits:
Object
  • Object
show all
Defined in:
lib/slack/real_time/socket.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, options = {}) ⇒ Socket

Returns a new instance of Socket.



7
8
9
10
# File 'lib/slack/real_time/socket.rb', line 7

def initialize(url, options = {})
  @url = url
  @options = options
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



5
6
7
# File 'lib/slack/real_time/socket.rb', line 5

def options
  @options
end

#urlObject

Returns the value of attribute url.



4
5
6
# File 'lib/slack/real_time/socket.rb', line 4

def url
  @url
end

Instance Method Details

#connect! {|@ws| ... } ⇒ Object

Yields:

  • (@ws)


16
17
18
19
20
21
22
23
24
25
26
# File 'lib/slack/real_time/socket.rb', line 16

def connect!(&_block)
  return if connected?

  @ws = Faye::WebSocket::Client.new(url, nil, options)

  @ws.on :close do |event|
    close(event)
  end

  yield @ws if block_given?
end

#connected?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/slack/real_time/socket.rb', line 32

def connected?
  !@ws.nil?
end

#disconnect!Object



28
29
30
# File 'lib/slack/real_time/socket.rb', line 28

def disconnect!
  @ws.close if @ws
end

#send_data(data) ⇒ Object



12
13
14
# File 'lib/slack/real_time/socket.rb', line 12

def send_data(data)
  @ws.send(data) if @ws
end