
Security News
New Website “Is It Really FOSS?” Tracks Transparency in Open Source Distribution Models
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
Very simple but functional websocket server for Rack async application.
Intended to use with Falcon web server or other web server based on.
Add this line to your application's Gemfile:
gem 'async_cable'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install async_cable
# config.ru
require_relative 'lib/main_cable'
app = RackBuilder.new do
use Rack::Session::Cookie, key: 'test.app', secret: ENV['RACK_SECRET']
map '/cable' do
run AsyncCable::Server.new(connection_class: MainCable)
end
end
run app
# lib/main_cable.rb
class ChatCable < AsyncCable::Connection
identified_as :main
attr_reader :current_user
def on_open
@current_user = User.find_by id: request.session['user_id']
reject_unauthorized if current_user.nil?
stream_for request.params['room_name']
logger.info { "User##{current_user.id} has joined to #{channel_name}/#{stream_name}." }
self.class.broadcast(stream_name, message: "#{current_user.username} has joined.")
transmit(message: "Welcome #{current_user.username}.")
end
def on_data(data)
self.class.broadcast(stream_name, message: data[:message].to_s, by_who: current_user.username)
end
def on_close
return if identifier.nil?
logger.info { "User##{current_user.id} has left #{channel_name}/#{stream_name}." }
self.class.broadcast(stream_name, message: "#{current_user.username} has left.")
end
end
example of JS code for connecting with websocket server
var socket = new WebSocket("ws://localhost:9292/cable");
socket.onopen = function(_event) {
console.log("WebSocket connected");
};
socket.onerror = function(error) {
console.log("WebSocket error", error);
};
socket.onclose = function(event) {
console.log("WebSocket closed", event.wasClean, event.code, event.reason);
};
socket.onmessage = function(event) {
console.log("WebSocket data received", JSON.parse(event.data));
};
var transmit = function (data) {
socket.send( JSON.generate(data) );
};
var close = function (code, reason) {
socket.close(code || 1000, reason);
};
gem_push=false rake release
gem push pkg/async_cable-X.Y.Z.gem
will use Semver from version 1.0.0
Bug reports and pull requests are welcome on GitHub at https://github.com/senid231/async_cable. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the AsyncCable project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.
FAQs
Unknown package
We found that async_cable 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.
Security News
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
Security News
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.