Skip to content

Commit a8a6dfb

Browse files
committed
prevent multiple connections to same channel
1 parent 590ed1c commit a8a6dfb

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

ruby/hyper-operation/lib/hyper-operation/transport/client_drivers.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,19 @@ def self.open_channels
8484

8585
def self.add_connection(channel_name, id = nil)
8686
channel_string = "#{channel_name}#{'-'+id.to_s if id}"
87+
return if open_channels.include? channel_string
8788
open_channels << channel_string
8889
channel_string
8990
end
9091

9192
def self.connect_to(channel_name, id = nil)
9293
channel_string = add_connection(channel_name, id)
94+
return unless channel_string # already connected!
9395
if ClientDrivers.opts[:transport] == :pusher
9496
channel = "#{ClientDrivers.opts[:channel]}-#{channel_string}"
9597
%x{
9698
var channel = #{ClientDrivers.opts[:pusher_api]}.subscribe(#{channel.gsub('::', '==')});
97-
if (#{!@pusher_dispatcher_registered}) {
98-
console.log('registering dispatch for pusher')
99-
channel.bind('dispatch', #{ClientDrivers.opts[:dispatch]})
100-
}
99+
channel.bind('dispatch', #{ClientDrivers.opts[:dispatch]})
101100
channel.bind('pusher:subscription_succeeded', #{lambda {ClientDrivers.get_queued_data("connect-to-transport", channel_string)}})
102101
}
103102
@pusher_dispatcher_registered = true

0 commit comments

Comments
 (0)