realtimex 2.0.0 → 2.0.2
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 +26 -5
- 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: f61de2147a65d0ce6897de4ef64d53d4922ab65181efb2693e52815db8c4c654
|
|
4
|
+
data.tar.gz: 42678dd92c6aa73f8af6aed6dca8be74839f30f814cc9dc2a646f991494798ba
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 675bb33e988ce2d37fdd9a7a8ee6ab4397b43eef362f1c3245aa00245a3bd737837b0a1fbe136f24b63238802cf43f32c68586033c758507335553104be16812
|
|
7
|
+
data.tar.gz: c75138edd9e9cbf30b688bc361f8c370716fdd669a3b57c521abce709a601e1b33f2e6f294ebb92d79a142f77f9260a6f39bf3819a1037251244aaaeba800018
|
data/lib/realtimex/connection.rb
CHANGED
|
@@ -8,6 +8,7 @@ class RealtimeX::Connection
|
|
|
8
8
|
@callbacks = {}
|
|
9
9
|
@debug = debug
|
|
10
10
|
@connected = false
|
|
11
|
+
@emitting = false
|
|
11
12
|
end
|
|
12
13
|
|
|
13
14
|
def connect
|
|
@@ -19,7 +20,7 @@ class RealtimeX::Connection
|
|
|
19
20
|
puts "[RealtimeX] WebSocket client created successfully" if @debug
|
|
20
21
|
rescue => e
|
|
21
22
|
puts "[RealtimeX] Connection failed: #{e.message}" if @debug
|
|
22
|
-
|
|
23
|
+
@callbacks['error']&.call({ message: e.message, type: 'connection_error' })
|
|
23
24
|
raise e
|
|
24
25
|
end
|
|
25
26
|
end
|
|
@@ -39,7 +40,8 @@ class RealtimeX::Connection
|
|
|
39
40
|
|
|
40
41
|
@socket.on :error do |error|
|
|
41
42
|
puts "[RealtimeX] WebSocket error: #{error}" if @debug
|
|
42
|
-
emit
|
|
43
|
+
# Прямой вызов callback без emit для избежания рекурсии
|
|
44
|
+
@callbacks['error']&.call(error)
|
|
43
45
|
end
|
|
44
46
|
|
|
45
47
|
@socket.on :message do |msg|
|
|
@@ -49,13 +51,26 @@ class RealtimeX::Connection
|
|
|
49
51
|
end
|
|
50
52
|
|
|
51
53
|
def handle_message(data)
|
|
54
|
+
return unless data.is_a?(String)
|
|
55
|
+
|
|
56
|
+
puts "[RealtimeX] Parsing message: #{data}" if @debug
|
|
57
|
+
|
|
52
58
|
# Parse Socket.IO message format: 42["event",{data}]
|
|
53
59
|
if data.start_with?('42[')
|
|
54
|
-
|
|
55
|
-
|
|
60
|
+
# Extract JSON part safely
|
|
61
|
+
json_start = data.index('[', 2)
|
|
62
|
+
return unless json_start
|
|
63
|
+
|
|
64
|
+
json_part = data[json_start..-1]
|
|
65
|
+
parts = JSON.parse(json_part)
|
|
66
|
+
|
|
67
|
+
return unless parts.is_a?(Array) && parts.length >= 2
|
|
68
|
+
|
|
56
69
|
event = parts[0]
|
|
57
70
|
event_data = parts[1]
|
|
58
71
|
|
|
72
|
+
puts "[RealtimeX] Parsed event: #{event}" if @debug
|
|
73
|
+
|
|
59
74
|
case event
|
|
60
75
|
when 'server-event'
|
|
61
76
|
emit('message', event_data)
|
|
@@ -64,7 +79,9 @@ class RealtimeX::Connection
|
|
|
64
79
|
end
|
|
65
80
|
end
|
|
66
81
|
rescue JSON::ParserError => e
|
|
67
|
-
puts "[RealtimeX]
|
|
82
|
+
puts "[RealtimeX] JSON parse error: #{e.message}" if @debug
|
|
83
|
+
rescue => e
|
|
84
|
+
puts "[RealtimeX] Message handling error: #{e.message}" if @debug
|
|
68
85
|
end
|
|
69
86
|
|
|
70
87
|
def send_subscribe(channel)
|
|
@@ -94,7 +111,11 @@ class RealtimeX::Connection
|
|
|
94
111
|
end
|
|
95
112
|
|
|
96
113
|
def emit(event, data = nil)
|
|
114
|
+
return if @emitting # Защита от рекурсии
|
|
115
|
+
@emitting = true
|
|
97
116
|
@callbacks[event]&.call(data)
|
|
117
|
+
ensure
|
|
118
|
+
@emitting = false
|
|
98
119
|
end
|
|
99
120
|
|
|
100
121
|
def disconnect
|
data/lib/realtimex/version.rb
CHANGED