
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
SimplePusher is a HTML5 websocket powered realtime messaging tool used in Rails / Sintra project.
Add this line to your application's Gemfile:
gem 'simple_pusher'
And then execute:
$ bundle
Or install it yourself as:
$ gem install simple_pusher
Then start simple pusher server when rails app boot:
# config/initializers/simple_pusher.rb
EventMachine.next_tick do
SimplePusher.setup do |config|
config.port = 8088
end
SimplePusher.start
end
As initializer code config/initializers/simple_pusher.rb
show, your rails runtime environment must be in EventMachine run loop. Otherwise you start EventMachine run loop in a new thread.
Setup client js code.
Add //= require simple_pusher
to app/assets/javascripts/application.js
Add code to app/views/layouts/application.html.erb
<script type="text/javascript">
var simple_pusher = new SimplePusher("ws://<%= request.host %>:8088/");
simple_pusher.on('channel_name', function(message){
alert('got message:'+message);
});
</script>
Broadcast message via server side.
SimplePusher.publish('channel_name', "Time now #{Time.now.to_s(:db}")
Broadcast message via http POST.
curl -d 'channel=channel1&message=hello' http://localhost:3000/simple_pusher
Message callback at server side.
SimplePusher.on("ping") do
puts "I received ping request."
end
SimplePusher.on("ping") do
puts "I also received ping request."
end
# app.rb
require 'simple_pusher/sinatra_app'
EventMachine.next_tick do
SimplePusher.setup do |config|
config.port = 8088
end
SimplePusher.start
end
class MyApp < Sinatra::Base
use SimplePusher::SinatraApp # With this you just setup http post interface: curl -d 'channel=channel1&message=hello' http://localhost:3000/simple_pusher
end
Currently I have not implement directly require simple_pusher js from project. You can download simple_pusher.coffee
file from Github repository to your project for use.
It is possible to emulate WebSockets in older browsers using flash emulation. For example take a look at the web-socket-js project.
on
method message callback to client js.git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)FAQs
Unknown package
We found that simple_pusher demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.