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.



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

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

Instance Attribute Details

#driverObject (readonly)

Returns the value of attribute driver.



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

def driver
  @driver
end

#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

#close(_event = nil) ⇒ Object



51
52
53
# File 'lib/slack/real_time/socket.rb', line 51

def close(_event=nil)
  @driver = nil
end

#connect! {|driver| ... } ⇒ Object

Yields:



23
24
25
26
27
28
29
# File 'lib/slack/real_time/socket.rb', line 23

def connect!
  return if connected?

  connect

  yield driver if block_given?
end

#connected?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/slack/real_time/socket.rb', line 35

def connected?
  !driver.nil?
end

#disconnect!Object



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

def disconnect!
  driver.close
end

#send_data(message) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/slack/real_time/socket.rb', line 14

def send_data(message)
  case message
  when Numeric then driver.text(message.to_s)
  when String  then driver.text(message)
  when Array   then driver.binary(message)
  else false
  end
end

#start_async#join

Returns:

  • (#join)


47
48
49
# File 'lib/slack/real_time/socket.rb', line 47

def start_async
  fail NotImplementedError, "Expected #{self.class} to implement #{__method__}."
end

#start_sync(&block) ⇒ Object



39
40
41
42
43
44
# File 'lib/slack/real_time/socket.rb', line 39

def start_sync(&block)
  thread = start_async(&block)
  thread.join if thread
rescue Interrupt
  thread.exit if thread
end