realtimex 1.0.5 → 2.0.1
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 +52 -32
- data/lib/realtimex/version.rb +1 -1
- data/lib/realtimex.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9fe93a87a37917d71f417e879a14a8c30a561fa65caeccf2e8448764e19b3459
|
|
4
|
+
data.tar.gz: 3f3ca0cd8cd25a19942ea75ee5130b66b477059be6358040d630450b210b8803
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f7a41f4a01cdddfc78e40cb9bb4634067c83969a7da8cbe9c44c1b66ce9bc608134b091c8d1a11a7be3fcbab79ae84f524689d3f700ba17e11c2c7292a6ae7bb
|
|
7
|
+
data.tar.gz: ffcce8f81349772680fc2e52119e35aa842412c7ddcc04da39d2ddbe8d2bd1f6fe76f95354ee6427b0da3e01153de10c6d09ee3e49b53e2e22f2a9ac2fc89f2d
|
data/lib/realtimex/connection.rb
CHANGED
|
@@ -1,14 +1,5 @@
|
|
|
1
|
-
require '
|
|
2
|
-
require '
|
|
3
|
-
|
|
4
|
-
# Patch for Ruby 3.4 compatibility
|
|
5
|
-
module URI
|
|
6
|
-
def self.encode(str)
|
|
7
|
-
CGI.escape(str)
|
|
8
|
-
end
|
|
9
|
-
end unless URI.respond_to?(:encode)
|
|
10
|
-
|
|
11
|
-
require 'socket.io-client-simple'
|
|
1
|
+
require 'websocket-client-simple'
|
|
2
|
+
require 'json'
|
|
12
3
|
|
|
13
4
|
class RealtimeX::Connection
|
|
14
5
|
def initialize(url, debug: false)
|
|
@@ -23,9 +14,9 @@ class RealtimeX::Connection
|
|
|
23
14
|
puts "[RealtimeX] Connecting to: #{@url}" if @debug
|
|
24
15
|
|
|
25
16
|
begin
|
|
26
|
-
@socket =
|
|
17
|
+
@socket = WebSocket::Client::Simple.connect(@url)
|
|
27
18
|
setup_handlers
|
|
28
|
-
puts "[RealtimeX]
|
|
19
|
+
puts "[RealtimeX] WebSocket client created successfully" if @debug
|
|
29
20
|
rescue => e
|
|
30
21
|
puts "[RealtimeX] Connection failed: #{e.message}" if @debug
|
|
31
22
|
emit('error', { message: e.message, type: 'connection_error' })
|
|
@@ -34,54 +25,83 @@ class RealtimeX::Connection
|
|
|
34
25
|
end
|
|
35
26
|
|
|
36
27
|
def setup_handlers
|
|
37
|
-
@socket.on :
|
|
28
|
+
@socket.on :open do
|
|
38
29
|
@connected = true
|
|
39
|
-
puts "[RealtimeX]
|
|
30
|
+
puts "[RealtimeX] WebSocket connected successfully" if @debug
|
|
40
31
|
emit('connected')
|
|
41
32
|
end
|
|
42
33
|
|
|
43
|
-
@socket.on :
|
|
34
|
+
@socket.on :close do
|
|
44
35
|
@connected = false
|
|
45
|
-
puts "[RealtimeX]
|
|
36
|
+
puts "[RealtimeX] WebSocket disconnected" if @debug
|
|
46
37
|
emit('disconnected')
|
|
47
38
|
end
|
|
48
39
|
|
|
49
40
|
@socket.on :error do |error|
|
|
50
|
-
puts "[RealtimeX]
|
|
41
|
+
puts "[RealtimeX] WebSocket error: #{error}" if @debug
|
|
51
42
|
emit('error', error)
|
|
52
43
|
end
|
|
53
44
|
|
|
54
|
-
@socket.on
|
|
55
|
-
puts "[RealtimeX] Received
|
|
56
|
-
|
|
45
|
+
@socket.on :message do |msg|
|
|
46
|
+
puts "[RealtimeX] Received message: #{msg.data}" if @debug
|
|
47
|
+
handle_message(msg.data)
|
|
57
48
|
end
|
|
49
|
+
end
|
|
58
50
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
51
|
+
def handle_message(data)
|
|
52
|
+
return unless data.is_a?(String)
|
|
53
|
+
|
|
54
|
+
puts "[RealtimeX] Parsing message: #{data}" if @debug
|
|
55
|
+
|
|
56
|
+
# Parse Socket.IO message format: 42["event",{data}]
|
|
57
|
+
if data.start_with?('42[')
|
|
58
|
+
# Extract JSON part safely
|
|
59
|
+
json_start = data.index('[', 2)
|
|
60
|
+
return unless json_start
|
|
61
|
+
|
|
62
|
+
json_part = data[json_start..-1]
|
|
63
|
+
parts = JSON.parse(json_part)
|
|
64
|
+
|
|
65
|
+
return unless parts.is_a?(Array) && parts.length >= 2
|
|
66
|
+
|
|
67
|
+
event = parts[0]
|
|
68
|
+
event_data = parts[1]
|
|
69
|
+
|
|
70
|
+
puts "[RealtimeX] Parsed event: #{event}" if @debug
|
|
71
|
+
|
|
72
|
+
case event
|
|
73
|
+
when 'server-event'
|
|
74
|
+
emit('message', event_data)
|
|
75
|
+
when 'realtimex_internal:subscription_succeeded'
|
|
76
|
+
emit('subscription_succeeded', event_data)
|
|
77
|
+
end
|
|
62
78
|
end
|
|
79
|
+
rescue JSON::ParserError => e
|
|
80
|
+
puts "[RealtimeX] JSON parse error: #{e.message}" if @debug
|
|
81
|
+
rescue => e
|
|
82
|
+
puts "[RealtimeX] Message handling error: #{e.message}" if @debug
|
|
63
83
|
end
|
|
64
84
|
|
|
65
85
|
def send_subscribe(channel)
|
|
66
86
|
ensure_connected
|
|
67
87
|
puts "[RealtimeX] Subscribing to channel: #{channel}" if @debug
|
|
68
|
-
|
|
88
|
+
message = "42[\"realtimex:subscribe\",{\"channel\":\"#{channel}\"}]"
|
|
89
|
+
@socket.send(message)
|
|
69
90
|
end
|
|
70
91
|
|
|
71
92
|
def send_client_event(channel, event, data)
|
|
72
93
|
ensure_connected
|
|
73
94
|
puts "[RealtimeX] Sending client event: #{event} to #{channel}" if @debug
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
data: data
|
|
78
|
-
})
|
|
95
|
+
data_json = JSON.generate(data)
|
|
96
|
+
message = "42[\"client-event\",{\"channel\":\"#{channel}\",\"event\":\"#{event}\",\"data\":#{data_json}}]"
|
|
97
|
+
@socket.send(message)
|
|
79
98
|
end
|
|
80
99
|
|
|
81
100
|
def send_unsubscribe(channel)
|
|
82
101
|
ensure_connected
|
|
83
102
|
puts "[RealtimeX] Unsubscribing from channel: #{channel}" if @debug
|
|
84
|
-
|
|
103
|
+
message = "42[\"realtimex:unsubscribe\",{\"channel\":\"#{channel}\"}]"
|
|
104
|
+
@socket.send(message)
|
|
85
105
|
end
|
|
86
106
|
|
|
87
107
|
def bind(event, &block)
|
|
@@ -94,7 +114,7 @@ class RealtimeX::Connection
|
|
|
94
114
|
|
|
95
115
|
def disconnect
|
|
96
116
|
puts "[RealtimeX] Disconnecting..." if @debug
|
|
97
|
-
@socket&.
|
|
117
|
+
@socket&.close
|
|
98
118
|
@connected = false
|
|
99
119
|
end
|
|
100
120
|
|
data/lib/realtimex/version.rb
CHANGED
data/lib/realtimex.rb
CHANGED
|
@@ -57,7 +57,7 @@ class RealtimeX
|
|
|
57
57
|
end
|
|
58
58
|
|
|
59
59
|
def build_url
|
|
60
|
-
protocol = @options[:encrypted] ? '
|
|
60
|
+
protocol = @options[:encrypted] ? 'wss' : 'ws'
|
|
61
61
|
host = @options[:ws_host]
|
|
62
62
|
port = @options[:ws_port]
|
|
63
63
|
"#{protocol}://#{host}:#{port}/socket.io/?EIO=4&transport=websocket&api_key=#{@api_key}"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: realtimex
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- RealtimeX Team
|
|
@@ -11,19 +11,19 @@ cert_chain: []
|
|
|
11
11
|
date: 2025-12-11 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
|
-
name:
|
|
14
|
+
name: websocket-client-simple
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
17
|
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '
|
|
19
|
+
version: '0.9'
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
24
|
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '
|
|
26
|
+
version: '0.9'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: json
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|