Class: WebSocket::Protocol
- Inherits:
-
Object
- Object
- WebSocket::Protocol
show all
- Defined in:
- lib/websocket/protocol.rb,
lib/websocket/protocol/hybi.rb,
lib/websocket/protocol/client.rb,
lib/websocket/protocol/draft75.rb,
lib/websocket/protocol/draft76.rb,
lib/websocket/protocol/hybi/stream_reader.rb
Defined Under Namespace
Classes: Client, CloseEvent, Draft75, Draft76, Hybi, MessageEvent, OpenEvent
Constant Summary
collapse
- STATES =
[:connecting, :open, :closing, :closed]
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(socket, options = {}) ⇒ Protocol
Returns a new instance of Protocol.
57
58
59
60
61
62
|
# File 'lib/websocket/protocol.rb', line 57
def initialize(socket, options = {})
@socket = socket
@options = options
@queue = []
@ready_state = 0
end
|
Instance Attribute Details
#protocol ⇒ Object
Returns the value of attribute protocol.
55
56
57
|
# File 'lib/websocket/protocol.rb', line 55
def protocol
@protocol
end
|
#ready_state ⇒ Object
Returns the value of attribute ready_state.
55
56
57
|
# File 'lib/websocket/protocol.rb', line 55
def ready_state
@ready_state
end
|
Class Method Details
.jruby? ⇒ Boolean
20
21
22
|
# File 'lib/websocket/protocol.rb', line 20
def self.jruby?
defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
end
|
.rbx? ⇒ Boolean
24
25
26
|
# File 'lib/websocket/protocol.rb', line 24
def self.rbx?
defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
end
|
Instance Method Details
#binary(message) ⇒ Object
80
81
82
|
# File 'lib/websocket/protocol.rb', line 80
def binary(message)
false
end
|
#close(reason = nil, code = nil) ⇒ Object
88
89
90
91
92
93
|
# File 'lib/websocket/protocol.rb', line 88
def close(reason = nil, code = nil)
return false unless @ready_state == 1
@ready_state = 3
dispatch(:onclose, CloseEvent.new(nil, nil))
true
end
|
#onclose(&block) ⇒ Object
110
111
112
113
|
# File 'lib/websocket/protocol.rb', line 110
def onclose(&block)
@onclose = block if block_given?
@onclose
end
|
#onerror(&block) ⇒ Object
105
106
107
108
|
# File 'lib/websocket/protocol.rb', line 105
def onerror(&block)
@onerror = block if block_given?
@onerror
end
|
#onmessage(&block) ⇒ Object
100
101
102
103
|
# File 'lib/websocket/protocol.rb', line 100
def onmessage(&block)
@onmessage = block if block_given?
@onmessage
end
|
#onopen(&block) ⇒ Object
95
96
97
98
|
# File 'lib/websocket/protocol.rb', line 95
def onopen(&block)
@onopen = block if block_given?
@onopen
end
|
#ping(*args) ⇒ Object
84
85
86
|
# File 'lib/websocket/protocol.rb', line 84
def ping(*args)
false
end
|
#start ⇒ Object
69
70
71
72
73
74
|
# File 'lib/websocket/protocol.rb', line 69
def start
return false unless @ready_state == 0
@socket.write(handshake_response)
open unless @stage == -1
true
end
|
#state ⇒ Object
64
65
66
67
|
# File 'lib/websocket/protocol.rb', line 64
def state
return nil unless @ready_state >= 0
STATES[@ready_state]
end
|
#text(message) ⇒ Object
76
77
78
|
# File 'lib/websocket/protocol.rb', line 76
def text(message)
frame(message)
end
|