lib/synchromesh/synchromesh.rb in hyper-mesh-0.5.2 vs lib/synchromesh/synchromesh.rb in hyper-mesh-0.5.3

- old
+ new

@@ -87,21 +87,21 @@ channel.gsub(/^#{Regexp.quote(HyperMesh.channel)}/,'') end end def self.send(channel, data) - if on_console? + if !on_server? send_to_server(channel, data) elsif transport == :pusher pusher.trigger("#{HyperMesh.channel}-#{data[1][:channel]}", *data) elsif transport == :action_cable ActionCable.server.broadcast("synchromesh-#{channel}", message: data[0], data: data[1]) end end - def self.on_console? - defined?(Rails::Console) + def self.on_server? + Rails.const_defined? 'Server' end def self.send_to_server(channel, data) salt = SecureRandom.hex authorization = HyperMesh.authorization(salt, channel, data[1][:broadcast_id]) @@ -143,10 +143,10 @@ ) end def self.after_commit(operation, model) InternalPolicy.regulate_broadcast(model) do |data| - if HyperMesh.on_console? && Connection.root_path + if !HyperMesh.on_server? && Connection.root_path HyperMesh.send_to_server(data[:channel], [operation, data]) else Connection.send_to_channel(data[:channel], [operation, data]) end end