realtimex 1.0.4 → 1.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 186c4a4f137225ab7ca45bfa90451ec86b5ec8fad21aeb61b8900bf43b7f5a6e
4
- data.tar.gz: ace0043ea61e33a3ccffe10a30e879af118179c2757e8a48ee5cc5313bcaa1ac
3
+ metadata.gz: 17ae2b32fc50afe30a02e8c071875b887d3dc301e20674f1720cb857f1dd4685
4
+ data.tar.gz: 30c7174d203fadbfce73c9bade2dcefebd5b0eb0b82afcfe55a028f21c89dc87
5
5
  SHA512:
6
- metadata.gz: 96e9b4348dd23ae60c4e5ff9e0b69826a56f22d6c56a3911ed4379b5b859d9d8c1c7992924abef71f09ed254dd431f8e75ed958bb116a7e178972a52634ceb31
7
- data.tar.gz: 31de2c7549e275d9586649ac96d8a5468755a1c0508a7822f50338114b6e223a43b064441c86dce4b3f0bf7613a9aaff5f50f886ecc1b8ae63fa67815ce24b3c
6
+ metadata.gz: 5d6337ee9057d96f9ce332f517509c88107ac02d44a6be3cc2abdefc086942c69bb19098418b29dcc7af138776e539b49208cbee63a8fdaa89210cf75f5b02f3
7
+ data.tar.gz: e9df898748ff73e5ab97a839d0f897a25ba236995ee92ece8cd1ddb416e14e7427d17a8044418611dc1d4729b9a16020ad23231e51db43b21f6f70a1b8069080
@@ -20,14 +20,14 @@ class RealtimeX::Connection
20
20
  end
21
21
 
22
22
  def connect
23
- debug_log "Connecting to: #{@url}"
23
+ puts "[RealtimeX] Connecting to: #{@url}" if @debug
24
24
 
25
25
  begin
26
26
  @socket = SocketIO::Client::Simple.connect(@url, transports: ['websocket'])
27
27
  setup_handlers
28
- debug_log "Socket.IO client created successfully"
28
+ puts "[RealtimeX] Socket.IO client created successfully" if @debug
29
29
  rescue => e
30
- debug_log "Connection failed: #{e.message}"
30
+ puts "[RealtimeX] Connection failed: #{e.message}" if @debug
31
31
  emit('error', { message: e.message, type: 'connection_error' })
32
32
  raise e
33
33
  end
@@ -36,41 +36,41 @@ class RealtimeX::Connection
36
36
  def setup_handlers
37
37
  @socket.on :connect do
38
38
  @connected = true
39
- debug_log "Socket.IO connected successfully"
39
+ puts "[RealtimeX] Socket.IO connected successfully" if @debug
40
40
  emit('connected')
41
41
  end
42
42
 
43
43
  @socket.on :disconnect do
44
44
  @connected = false
45
- debug_log "Socket.IO disconnected"
45
+ puts "[RealtimeX] Socket.IO disconnected" if @debug
46
46
  emit('disconnected')
47
47
  end
48
48
 
49
49
  @socket.on :error do |error|
50
- debug_log "Socket.IO error: #{error}"
50
+ puts "[RealtimeX] Socket.IO error: #{error}" if @debug
51
51
  emit('error', error)
52
52
  end
53
53
 
54
54
  @socket.on 'server-event' do |data|
55
- debug_log "Received server-event: #{data}"
55
+ puts "[RealtimeX] Received server-event: #{data}" if @debug
56
56
  emit('message', data)
57
57
  end
58
58
 
59
59
  @socket.on 'realtimex_internal:subscription_succeeded' do |data|
60
- debug_log "Subscription succeeded: #{data}"
60
+ puts "[RealtimeX] Subscription succeeded: #{data}" if @debug
61
61
  emit('subscription_succeeded', data)
62
62
  end
63
63
  end
64
64
 
65
65
  def send_subscribe(channel)
66
66
  ensure_connected
67
- debug_log "Subscribing to channel: #{channel}"
67
+ puts "[RealtimeX] Subscribing to channel: #{channel}" if @debug
68
68
  @socket.emit('realtimex:subscribe', { channel: channel })
69
69
  end
70
70
 
71
71
  def send_client_event(channel, event, data)
72
72
  ensure_connected
73
- debug_log "Sending client event: #{event} to #{channel}"
73
+ puts "[RealtimeX] Sending client event: #{event} to #{channel}" if @debug
74
74
  @socket.emit('client-event', {
75
75
  channel: channel,
76
76
  event: event,
@@ -80,7 +80,7 @@ class RealtimeX::Connection
80
80
 
81
81
  def send_unsubscribe(channel)
82
82
  ensure_connected
83
- debug_log "Unsubscribing from channel: #{channel}"
83
+ puts "[RealtimeX] Unsubscribing from channel: #{channel}" if @debug
84
84
  @socket.emit('realtimex:unsubscribe', { channel: channel })
85
85
  end
86
86
 
@@ -93,11 +93,19 @@ class RealtimeX::Connection
93
93
  end
94
94
 
95
95
  def disconnect
96
- debug_log "Disconnecting..."
96
+ puts "[RealtimeX] Disconnecting..." if @debug
97
97
  @socket&.disconnect
98
98
  @connected = false
99
99
  end
100
100
 
101
+ def wait_for_connection(timeout = 5)
102
+ start_time = Time.now
103
+ while !@connected && (Time.now - start_time) < timeout
104
+ sleep 0.1
105
+ end
106
+ @connected
107
+ end
108
+
101
109
  def connected?
102
110
  @connected
103
111
  end
@@ -109,8 +117,4 @@ class RealtimeX::Connection
109
117
  raise "Not connected to RealtimeX. Call connect() first."
110
118
  end
111
119
  end
112
-
113
- def debug_log(message)
114
- puts "[RealtimeX] #{message}" if @debug
115
- end
116
120
  end
@@ -1,3 +1,3 @@
1
1
  class RealtimeX
2
- VERSION = "1.0.4"
2
+ VERSION = "1.0.5"
3
3
  end
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: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - RealtimeX Team