realtimex 1.0.4 → 2.0.0
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 +51 -42
- 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: 8401391664a412d0b303e7b627ec75580d6d56f1d6b20d4cccb5b537d0f3f07a
|
|
4
|
+
data.tar.gz: 984978e072d033e17394e63a14c57228dad5851be3ac854fb965079d12cec125
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d6a3aba3f5638d32dc590e89bdf84ca32f750eed94decc155aab2c96f3ed42ceeec4fe0f71b3de63899cba5e9f4880b55563090dad817e9e2fc37453e8a74fec
|
|
7
|
+
data.tar.gz: fc0dd351bdffaddedc26493265acc6f3a9489455ee76f2b4fe6f62b76090705cf97956f6305811a08be4d693d0c92c4f31cacec1cea4857eecac5bd6c09e5745
|
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)
|
|
@@ -20,68 +11,82 @@ class RealtimeX::Connection
|
|
|
20
11
|
end
|
|
21
12
|
|
|
22
13
|
def connect
|
|
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
|
-
|
|
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' })
|
|
32
23
|
raise e
|
|
33
24
|
end
|
|
34
25
|
end
|
|
35
26
|
|
|
36
27
|
def setup_handlers
|
|
37
|
-
@socket.on :
|
|
28
|
+
@socket.on :open do
|
|
38
29
|
@connected = true
|
|
39
|
-
|
|
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
|
-
|
|
36
|
+
puts "[RealtimeX] WebSocket disconnected" if @debug
|
|
46
37
|
emit('disconnected')
|
|
47
38
|
end
|
|
48
39
|
|
|
49
40
|
@socket.on :error do |error|
|
|
50
|
-
|
|
41
|
+
puts "[RealtimeX] WebSocket error: #{error}" if @debug
|
|
51
42
|
emit('error', error)
|
|
52
43
|
end
|
|
53
44
|
|
|
54
|
-
@socket.on
|
|
55
|
-
|
|
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
|
+
# Parse Socket.IO message format: 42["event",{data}]
|
|
53
|
+
if data.start_with?('42[')
|
|
54
|
+
json_part = data[3..-2] # Remove '42[' and ']'
|
|
55
|
+
parts = JSON.parse("[#{json_part}]")
|
|
56
|
+
event = parts[0]
|
|
57
|
+
event_data = parts[1]
|
|
58
|
+
|
|
59
|
+
case event
|
|
60
|
+
when 'server-event'
|
|
61
|
+
emit('message', event_data)
|
|
62
|
+
when 'realtimex_internal:subscription_succeeded'
|
|
63
|
+
emit('subscription_succeeded', event_data)
|
|
64
|
+
end
|
|
62
65
|
end
|
|
66
|
+
rescue JSON::ParserError => e
|
|
67
|
+
puts "[RealtimeX] Failed to parse message: #{e.message}" if @debug
|
|
63
68
|
end
|
|
64
69
|
|
|
65
70
|
def send_subscribe(channel)
|
|
66
71
|
ensure_connected
|
|
67
|
-
|
|
68
|
-
|
|
72
|
+
puts "[RealtimeX] Subscribing to channel: #{channel}" if @debug
|
|
73
|
+
message = "42[\"realtimex:subscribe\",{\"channel\":\"#{channel}\"}]"
|
|
74
|
+
@socket.send(message)
|
|
69
75
|
end
|
|
70
76
|
|
|
71
77
|
def send_client_event(channel, event, data)
|
|
72
78
|
ensure_connected
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
data: data
|
|
78
|
-
})
|
|
79
|
+
puts "[RealtimeX] Sending client event: #{event} to #{channel}" if @debug
|
|
80
|
+
data_json = JSON.generate(data)
|
|
81
|
+
message = "42[\"client-event\",{\"channel\":\"#{channel}\",\"event\":\"#{event}\",\"data\":#{data_json}}]"
|
|
82
|
+
@socket.send(message)
|
|
79
83
|
end
|
|
80
84
|
|
|
81
85
|
def send_unsubscribe(channel)
|
|
82
86
|
ensure_connected
|
|
83
|
-
|
|
84
|
-
|
|
87
|
+
puts "[RealtimeX] Unsubscribing from channel: #{channel}" if @debug
|
|
88
|
+
message = "42[\"realtimex:unsubscribe\",{\"channel\":\"#{channel}\"}]"
|
|
89
|
+
@socket.send(message)
|
|
85
90
|
end
|
|
86
91
|
|
|
87
92
|
def bind(event, &block)
|
|
@@ -93,11 +98,19 @@ class RealtimeX::Connection
|
|
|
93
98
|
end
|
|
94
99
|
|
|
95
100
|
def disconnect
|
|
96
|
-
|
|
97
|
-
@socket&.
|
|
101
|
+
puts "[RealtimeX] Disconnecting..." if @debug
|
|
102
|
+
@socket&.close
|
|
98
103
|
@connected = false
|
|
99
104
|
end
|
|
100
105
|
|
|
106
|
+
def wait_for_connection(timeout = 5)
|
|
107
|
+
start_time = Time.now
|
|
108
|
+
while !@connected && (Time.now - start_time) < timeout
|
|
109
|
+
sleep 0.1
|
|
110
|
+
end
|
|
111
|
+
@connected
|
|
112
|
+
end
|
|
113
|
+
|
|
101
114
|
def connected?
|
|
102
115
|
@connected
|
|
103
116
|
end
|
|
@@ -109,8 +122,4 @@ class RealtimeX::Connection
|
|
|
109
122
|
raise "Not connected to RealtimeX. Call connect() first."
|
|
110
123
|
end
|
|
111
124
|
end
|
|
112
|
-
|
|
113
|
-
def debug_log(message)
|
|
114
|
-
puts "[RealtimeX] #{message}" if @debug
|
|
115
|
-
end
|
|
116
125
|
end
|
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.0
|
|
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
|