rakie 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rakie/version.rb +1 -1
- data/lib/rakie/websocket.rb +50 -39
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 196e26c710b29918f06ee04e5303caf7f08a1ab989cd6614e36cb469dd3e24b3
|
4
|
+
data.tar.gz: 15d0459b668f44c3fe8e9b323a24f8f1c19c647e29ec7a7cd9477615063a6961
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f1ac0ed83237b1c57c3c1a58d4b9415602804d92d035ac89238435927efa7f8eb7c29166f0e174bb91bf92b47d63ec47a159c6b8a427b2a280509908acb06cb
|
7
|
+
data.tar.gz: 6ebde9c958b93c395b88c30c6ac53eb8418eeb8c9571043d66364b508df148d97456a5b10948993b4b42422324618f1568632287e2e0cf3468d37e53a1b2799a
|
data/lib/rakie/version.rb
CHANGED
data/lib/rakie/websocket.rb
CHANGED
@@ -21,64 +21,75 @@ module Rakie
|
|
21
21
|
@client_side = true
|
22
22
|
end
|
23
23
|
|
24
|
+
# @param [String] data
|
24
25
|
def on_recv(channel, data)
|
25
26
|
Log.debug("Rakie::Websocket recv: #{data}")
|
26
27
|
|
27
|
-
|
28
|
-
message = @recv_message
|
28
|
+
total_parsed = 0
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
end
|
30
|
+
while data.length > 0
|
31
|
+
# @type [WebsocketMessage] request
|
32
|
+
message = @recv_message
|
34
33
|
|
35
|
-
|
34
|
+
if message.parse_status == ParseStatus::COMPLETE
|
35
|
+
message = WebsocketMessage.new
|
36
|
+
@recv_message = message
|
37
|
+
end
|
36
38
|
|
37
|
-
|
39
|
+
len = message.parse(data)
|
40
|
+
total_parsed += len
|
38
41
|
|
39
|
-
|
40
|
-
response = WebsocketMessage.new
|
42
|
+
Log.debug("Rakie::Websocket receive message: #{message.to_s} parse with #{len}")
|
41
43
|
|
42
|
-
if message.
|
43
|
-
response
|
44
|
-
response.op_code = WebsocketMessage::OP_PONG
|
45
|
-
response.payload = "Rakie::Websocket: op pong"
|
44
|
+
if message.parse_status == ParseStatus::COMPLETE
|
45
|
+
response = WebsocketMessage.new
|
46
46
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
if message.op_code == WebsocketMessage::OP_PING
|
48
|
+
response.fin = true
|
49
|
+
response.op_code = WebsocketMessage::OP_PONG
|
50
|
+
response.payload = "Rakie::Websocket: op pong"
|
51
51
|
|
52
|
-
|
53
|
-
|
52
|
+
elsif message.op_code == WebsocketMessage::OP_PONG
|
53
|
+
response.fin = true
|
54
|
+
response.op_code = WebsocketMessage::OP_PING
|
55
|
+
response.payload = "Rakie::Websocket: op ping"
|
54
56
|
|
55
|
-
|
56
|
-
|
57
|
+
elsif message.op_code == WebsocketMessage::OP_CLOSE
|
58
|
+
channel.close
|
57
59
|
|
58
|
-
|
59
|
-
|
60
|
-
return len
|
60
|
+
Log.debug("Rakie::Websocket: op close")
|
61
|
+
return 0
|
61
62
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
63
|
+
elsif @delegate
|
64
|
+
@delegate.on_message(self, message.payload)
|
65
|
+
|
66
|
+
else
|
67
|
+
response.fin = true
|
68
|
+
response.op_code = WebsocketMessage::OP_TEXT
|
69
|
+
response.payload = "Rakie!"
|
70
|
+
end
|
71
|
+
|
72
|
+
response_data = response.to_s
|
69
73
|
|
70
|
-
|
74
|
+
Log.debug("Rakie::Websocket response: #{response_data}")
|
71
75
|
|
72
|
-
|
76
|
+
channel.write(response_data) # Response data
|
73
77
|
|
74
|
-
|
75
|
-
|
78
|
+
elsif message.parse_status == ParseStatus::ERROR
|
79
|
+
channel.close
|
80
|
+
|
81
|
+
Log.debug("Rakie::Websocket: Illegal message")
|
82
|
+
return 0
|
83
|
+
end
|
84
|
+
|
85
|
+
if len >= data.length
|
86
|
+
break
|
87
|
+
end
|
76
88
|
|
77
|
-
|
78
|
-
return 0
|
89
|
+
data = data[len .. -1]
|
79
90
|
end
|
80
91
|
|
81
|
-
return
|
92
|
+
return total_parsed
|
82
93
|
end
|
83
94
|
|
84
95
|
def on_send(channel)
|