realtimex 2.0.2 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/realtimex/connection.rb +29 -11
- data/lib/realtimex/version.rb +1 -1
- 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: 53ea4a0b72b990dc97fc9967096f478f8c324fa017f8e75954cf87947a48706a
|
|
4
|
+
data.tar.gz: 18716f63a59ed6eeccaa8e893eb5db040029963eedf577f5cd42c2d2aab1923e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0271bd649c73b60c4b6651cef17c5e3fe4b471d20da880e1e3c0fcd0b6896ae9615e6ff8036471152204a863f692d4163ea79c275274d29c58bcc01ee823d163
|
|
7
|
+
data.tar.gz: 65f9d31587b67967d4be72e959a17bf5de6d24d14e9f1850524b8ec92963de83a81391fbb2bb0c571c1869f242fb33530b525d2ba31b491c04796db2aaa2e2ba
|
data/lib/realtimex/connection.rb
CHANGED
|
@@ -26,27 +26,28 @@ class RealtimeX::Connection
|
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
def setup_handlers
|
|
29
|
+
connection = self # Сохраняем ссылку на self
|
|
30
|
+
|
|
29
31
|
@socket.on :open do
|
|
30
|
-
|
|
31
|
-
puts "[RealtimeX] WebSocket connected successfully" if
|
|
32
|
-
emit('connected')
|
|
32
|
+
connection.instance_variable_set(:@connected, true)
|
|
33
|
+
puts "[RealtimeX] WebSocket connected successfully" if connection.instance_variable_get(:@debug)
|
|
34
|
+
connection.emit('connected')
|
|
33
35
|
end
|
|
34
36
|
|
|
35
37
|
@socket.on :close do
|
|
36
|
-
|
|
37
|
-
puts "[RealtimeX] WebSocket disconnected" if
|
|
38
|
-
emit('disconnected')
|
|
38
|
+
connection.instance_variable_set(:@connected, false)
|
|
39
|
+
puts "[RealtimeX] WebSocket disconnected" if connection.instance_variable_get(:@debug)
|
|
40
|
+
connection.emit('disconnected')
|
|
39
41
|
end
|
|
40
42
|
|
|
41
43
|
@socket.on :error do |error|
|
|
42
|
-
puts "[RealtimeX] WebSocket error: #{error}" if
|
|
43
|
-
|
|
44
|
-
@callbacks['error']&.call(error)
|
|
44
|
+
puts "[RealtimeX] WebSocket error: #{error}" if connection.instance_variable_get(:@debug)
|
|
45
|
+
connection.send(:handle_error, error)
|
|
45
46
|
end
|
|
46
47
|
|
|
47
48
|
@socket.on :message do |msg|
|
|
48
|
-
puts "[RealtimeX] Received message: #{msg.data}" if
|
|
49
|
-
handle_message
|
|
49
|
+
puts "[RealtimeX] Received message: #{msg.data}" if connection.instance_variable_get(:@debug)
|
|
50
|
+
connection.send(:handle_message, msg.data)
|
|
50
51
|
end
|
|
51
52
|
end
|
|
52
53
|
|
|
@@ -55,6 +56,19 @@ class RealtimeX::Connection
|
|
|
55
56
|
|
|
56
57
|
puts "[RealtimeX] Parsing message: #{data}" if @debug
|
|
57
58
|
|
|
59
|
+
# Socket.IO handshake: 0{"sid":"...","upgrades":[],"pingInterval":25000,"pingTimeout":20000}
|
|
60
|
+
if data.start_with?('0{')
|
|
61
|
+
puts "[RealtimeX] Received handshake, sending connect (40)" if @debug
|
|
62
|
+
@socket.send('40') # Завершаем handshake
|
|
63
|
+
return
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Socket.IO connect confirmation: 40
|
|
67
|
+
if data == '40'
|
|
68
|
+
puts "[RealtimeX] Socket.IO connected" if @debug
|
|
69
|
+
return
|
|
70
|
+
end
|
|
71
|
+
|
|
58
72
|
# Parse Socket.IO message format: 42["event",{data}]
|
|
59
73
|
if data.start_with?('42[')
|
|
60
74
|
# Extract JSON part safely
|
|
@@ -136,6 +150,10 @@ class RealtimeX::Connection
|
|
|
136
150
|
@connected
|
|
137
151
|
end
|
|
138
152
|
|
|
153
|
+
def handle_error(error)
|
|
154
|
+
@callbacks['error']&.call(error)
|
|
155
|
+
end
|
|
156
|
+
|
|
139
157
|
private
|
|
140
158
|
|
|
141
159
|
def ensure_connected
|
data/lib/realtimex/version.rb
CHANGED