Class: Async::WebSocket::Connection

Inherits:
Protocol::WebSocket::Connection
  • Object
show all
Includes:
Protocol::WebSocket::Headers
Defined in:
lib/async/websocket/connection.rb

Overview

This is a basic synchronous websocket client:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(framer, protocol = nil, **options) ⇒ Connection

Returns a new instance of Connection.



38
39
40
41
# File 'lib/async/websocket/connection.rb', line 38

def initialize(framer, protocol = nil, **options)
	super(framer, **options)
	@protocol = protocol
end

Instance Attribute Details

#protocolObject (readonly)

Returns the value of attribute protocol.



43
44
45
# File 'lib/async/websocket/connection.rb', line 43

def protocol
  @protocol
end

Class Method Details

.call(framer, protocol = [], **options) ⇒ Object



34
35
36
# File 'lib/async/websocket/connection.rb', line 34

def self.call(framer, protocol = [], **options)
	return self.new(framer, Array(protocol).first, **options)
end

Instance Method Details

#callObject



63
64
65
# File 'lib/async/websocket/connection.rb', line 63

def call
	self.close
end

#dump(object) ⇒ Object



59
60
61
# File 'lib/async/websocket/connection.rb', line 59

def dump(object)
	JSON.dump(object)
end

#parse(buffer) ⇒ Object



55
56
57
# File 'lib/async/websocket/connection.rb', line 55

def parse(buffer)
	JSON.parse(buffer, symbolize_names: true)
end

#readObject



45
46
47
48
49
# File 'lib/async/websocket/connection.rb', line 45

def read
	if buffer = super
		parse(buffer)
	end
end

#write(object) ⇒ Object



51
52
53
# File 'lib/async/websocket/connection.rb', line 51

def write(object)
	super(dump(object))
end