Class: Mumble::Connection
- Inherits:
-
Object
- Object
- Mumble::Connection
- Defined in:
- lib/mumble-ruby/connection.rb
Instance Method Summary collapse
- #connect ⇒ Object
- #disconnect ⇒ Object
-
#initialize(host, port, cert_manager) ⇒ Connection
constructor
A new instance of Connection.
- #read_message ⇒ Object
- #send_message(sym, attrs) ⇒ Object
- #send_udp_packet(packet) ⇒ Object
Constructor Details
#initialize(host, port, cert_manager) ⇒ Connection
Returns a new instance of Connection.
7 8 9 10 11 12 |
# File 'lib/mumble-ruby/connection.rb', line 7 def initialize(host, port, cert_manager) @host = host @port = port @cert_manager = cert_manager @write_lock = Mutex.new end |
Instance Method Details
#connect ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/mumble-ruby/connection.rb', line 14 def connect context = OpenSSL::SSL::SSLContext.new(:TLSv1) context.verify_mode = OpenSSL::SSL::VERIFY_NONE [:key, :cert].each { |s| context.send("#{s}=", @cert_manager.send(s)) } tcp_sock = TCPSocket.new @host, @port @sock = OpenSSL::SSL::SSLSocket.new tcp_sock, context @sock.connect end |
#disconnect ⇒ Object
23 24 25 |
# File 'lib/mumble-ruby/connection.rb', line 23 def disconnect @sock.close end |
#read_message ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/mumble-ruby/connection.rb', line 27 def header = read_data 6 type, len = header.unpack Messages::HEADER_FORMAT data = read_data len if type == (:udp_tunnel) # UDP Packet -- No Protobuf = (:udp_tunnel).new .packet = data else = type, data end end |
#send_message(sym, attrs) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/mumble-ruby/connection.rb', line 46 def (sym, attrs) type, klass = (sym) = klass.new attrs.each { |k, v| .send("#{k}=", v) } serial = .serialize_to_string header = [type, serial.size].pack Messages::HEADER_FORMAT send_data(header + serial) end |
#send_udp_packet(packet) ⇒ Object
41 42 43 44 |
# File 'lib/mumble-ruby/connection.rb', line 41 def send_udp_packet(packet) header = [(:udp_tunnel), packet.length].pack Messages::HEADER_FORMAT send_data(header + packet) end |