![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Rack-based WebSocket server
Create sample rack config file, and inside build app basing on Rack::WebSocket::Application.
require 'rack/websocket'
class MyApp < Rack::WebSocket::Application
end
map '/' do
run MyApp.new
end
After that just run Rack config from Rack server:
thin -R config.ru start
Done.
Rack::WebSocket::Application make following methods available:
Called once after server is started. This is place for application configuration so each instance variables from here will be available in whole application.
Example:
class MyApp < Rack::WebSocket::Application
def initialize(options = {})
super
@myvar = 4
end
end
It is important to include 'super' in initialize function, so application will be properly configured.
Please notice that in some servers, when 'initialize' is called, EventMachine reactor is not running yet. If you would like to configure EventMachine-based software, then you need to put it inside 'EM.next_tick' block, so this function will be called in first cycle of reactor.
Example:
class MyWebSocket < Rack::WebSocket::Application
def initialize
EM.next_tick { @redis = EM::Hiredis.connect }
end
end
Called after client is connected. Rack env of client is passed as attribute.
Example:
class MyApp < Rack::WebSocket::Application
def on_open(env)
puts "Clien connected"
end
end
Called after client is disconnected. Rack env of client is passed as attribute.
Example:
class MyApp < Rack::WebSocket::Application
def on_close(env)
puts "Clien disconnected"
end
end
Called after server receive message. Rack env of client is passed as attribute.
Example:
class MyApp < Rack::WebSocket::Application
def on_message(env, msg)
puts "Received message: " + msg
end
end
Called after server catch error. Variable passed is instance of Ruby Exception class.
Example:
class MyApp < Rack::WebSocket::Application
def on_error(env, error)
puts "Error occured: " + error.message
end
end
Sends data do client.
Example:
class MyApp < Rack::WebSocket::Application
def on_open(env)
send_data "Hello to you!"
end
end
Closes connection.
Example:
class MyApp < Rack::WebSocket::Application
def on_open(env)
close_websocket if env['REQUEST_PATH'] != '/websocket'
end
end
Options passed to app on initialize.
Example:
# In config.ru
map '/' do
run MyApp.new :some => :variable
end
# In application instance
@options # => { :some => :variable }
Currently we support drafts -75 and -76 form old(hixie) numeration and all drafts from -00 to -13 from current(ietf-hybi) numeration. Please note that ietf-hybi-13 is currently proposed as final standard.
Currently we are supporting following servers:
Just use :backend => { :debug => true } option when initializing your app.
Thin v1.2.8 have --ssl option - just use that! :)
Check Thin config - any option supported by Thin(like demonizing, SSL etc.) is supported by WebSocket-Rack.
Author: Bernard Potocki <bernard.potocki@imanel.org>
Released under MIT license.
FAQs
Unknown package
We found that websocket-rack 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
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.