Class: RocketChat::Realtime::Connector

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/rocket_chat/realtime/connector.rb

Overview

Socket manager

Since:

  • 0.1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Connector

Returns a new instance of Connector.

Parameters:

  • url (String)

    the websocket server to connect

Since:

  • 0.1.0



23
24
25
# File 'lib/rocket_chat/realtime/connector.rb', line 23

def initialize(url)
  @uri = URI(url)
end

Instance Attribute Details

#uriObject (readonly)

Since:

  • 0.1.0



18
19
20
# File 'lib/rocket_chat/realtime/connector.rb', line 18

def uri
  @uri
end

Instance Method Details

#connectSocket Also known as: socket

Connect to server

Returns:

  • (Socket)

    the socket

Since:

  • 0.1.0



30
31
32
33
34
35
# File 'lib/rocket_chat/realtime/connector.rb', line 30

def connect
  return @socket if @socket
  return raw_socket unless ssl?

  ssl_socket
end

#portNumber

The port to connect

Returns:

  • (Number)

    the port

Since:

  • 0.1.0



53
54
55
# File 'lib/rocket_chat/realtime/connector.rb', line 53

def port
  @uri.port || (ssl? ? 443 : 80)
end

#ssl?Boolean

Check the SSL enabled

Returns:

  • (Boolean)

    is enabled

Since:

  • 0.1.0



44
45
46
# File 'lib/rocket_chat/realtime/connector.rb', line 44

def ssl?
  @uri.scheme == 'wss'
end