ruby-hyperloop / hyper-mesh

The project has moved to Hyperstack!! - Synchronization of active record models across multiple clients using Pusher, ActionCable, or Polling
https://hyperstack.org/
MIT License
22 stars 12 forks source link

HyperMesh.refresh_channels is broken for Pusher #25

Open adamcreekroad opened 7 years ago

adamcreekroad commented 7 years ago

I only found this while trying to debug why the client wasn't updating. I'm not sure where/when this breaks in use, but calling this stuff in the console breaks.

module HyperMesh
  def self.refresh_channels
    new_channels = pusher.channels[:channels].collect do |channel|
      channel.gsub(/^#{Regexp.quote(HyperMesh.channel)}/, '')
    end
  end
end

This breaks because pusher.channels[:channels] is a hash of String => Hash, so it breaks when it iterates on the value (which is a Hash).

Also the gsub doesn't account for the hyphen between the HyperMesh.channel name and the connection channel name.

Changing it to this seems to work.

module HyperMesh
  def self.refresh_channels
    pusher.channels[:channels].keys.map do |channel|
      channel.gsub(/^#{Regexp.quote(HyperMesh.channel)}-/, '')
    end
  end
end