Class: WebSocket::Driver
- Inherits:
-
Object
show all
- Includes:
- EventEmitter
- Defined in:
- lib/websocket/driver.rb,
lib/websocket/driver/hybi.rb,
lib/websocket/driver/client.rb,
lib/websocket/driver/server.rb,
lib/websocket/driver/draft75.rb,
lib/websocket/driver/draft76.rb,
lib/websocket/driver/headers.rb,
lib/websocket/driver/event_emitter.rb,
lib/websocket/driver/hybi/stream_reader.rb
Defined Under Namespace
Modules: EventEmitter
Classes: Client, CloseEvent, ConnectEvent, Draft75, Draft76, Headers, Hybi, MessageEvent, OpenEvent, ProtocolError, Server
Constant Summary
collapse
- MAX_LENGTH =
0x3ffffff
- STATES =
[:connecting, :open, :closing, :closed]
Instance Attribute Summary collapse
Instance Method Summary
collapse
#add_listener, #emit, #listener_count, #listeners, #on, #remove_all_listeners, #remove_listener
Constructor Details
#initialize(socket, options = {}) ⇒ Driver
Returns a new instance of Driver.
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/websocket/driver.rb', line 59
def initialize(socket, options = {})
super()
@socket = socket
@options = options
@max_length = options[:max_length] || MAX_LENGTH
@headers = Headers.new
@queue = []
@ready_state = 0
end
|
Instance Attribute Details
#protocol ⇒ Object
Returns the value of attribute protocol.
57
58
59
|
# File 'lib/websocket/driver.rb', line 57
def protocol
@protocol
end
|
#ready_state ⇒ Object
Returns the value of attribute ready_state.
57
58
59
|
# File 'lib/websocket/driver.rb', line 57
def ready_state
@ready_state
end
|
Instance Method Details
#binary(message) ⇒ Object
92
93
94
|
# File 'lib/websocket/driver.rb', line 92
def binary(message)
false
end
|
#close(reason = nil, code = nil) ⇒ Object
100
101
102
103
104
105
|
# File 'lib/websocket/driver.rb', line 100
def close(reason = nil, code = nil)
return false unless @ready_state == 1
@ready_state = 3
emit(:close, CloseEvent.new(nil, nil))
true
end
|
#ping(*args) ⇒ Object
96
97
98
|
# File 'lib/websocket/driver.rb', line 96
def ping(*args)
false
end
|
75
76
77
78
79
|
# File 'lib/websocket/driver.rb', line 75
def (name, value)
return false unless @ready_state <= 0
@headers[name] = value
true
end
|
#start ⇒ Object
81
82
83
84
85
86
|
# File 'lib/websocket/driver.rb', line 81
def start
return false unless @ready_state == 0
@socket.write(Driver.encode(handshake_response, :binary))
open unless @stage == -1
true
end
|
#state ⇒ Object
70
71
72
73
|
# File 'lib/websocket/driver.rb', line 70
def state
return nil unless @ready_state >= 0
STATES[@ready_state]
end
|
#text(message) ⇒ Object
88
89
90
|
# File 'lib/websocket/driver.rb', line 88
def text(message)
frame(message)
end
|