class Slack::RealTime::Socket
Attributes
driver[R]
options[RW]
url[RW]
Public Class Methods
new(url, options = {})
click to toggle source
# File lib/slack/real_time/socket.rb, line 8 def initialize(url, options = {}) @url = url @options = options @driver = nil end
Public Instance Methods
close(_event=nil)
click to toggle source
# File lib/slack/real_time/socket.rb, line 51 def close(_event=nil) @driver = nil end
connect!() { |driver| ... }
click to toggle source
# File lib/slack/real_time/socket.rb, line 23 def connect! return if connected? connect yield driver if block_given? end
connected?()
click to toggle source
# File lib/slack/real_time/socket.rb, line 35 def connected? !driver.nil? end
disconnect!()
click to toggle source
# File lib/slack/real_time/socket.rb, line 31 def disconnect! driver.close end
send_data(message)
click to toggle source
# 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()
click to toggle source
@return [#join]
# File lib/slack/real_time/socket.rb, line 47 def start_async fail NotImplementedError, "Expected #{self.class} to implement #{__method__}." end
start_sync(&block)
click to toggle source
# 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
Protected Instance Methods
addr()
click to toggle source
# File lib/slack/real_time/socket.rb, line 57 def addr URI(url).host end
connect()
click to toggle source
# File lib/slack/real_time/socket.rb, line 76 def connect fail NotImplementedError, "Expected #{self.class} to implement #{__method__}." end
port()
click to toggle source
# File lib/slack/real_time/socket.rb, line 65 def port case (uri = URI(url)).scheme when 'wss'.freeze, 'https'.freeze URI::HTTPS::DEFAULT_PORT when 'ws', 'http'.freeze URI::HTTP::DEFAULT_PORT else uri.port end end
secure?()
click to toggle source
# File lib/slack/real_time/socket.rb, line 61 def secure? port == URI::HTTPS::DEFAULT_PORT end