{"id":19869706,"url":"https://github.com/sockjs/sockjs-ruby","last_synced_at":"2026-04-04T06:34:59.179Z","repository":{"id":66016842,"uuid":"2474893","full_name":"sockjs/sockjs-ruby","owner":"sockjs","description":"WebSocket emulation - Ruby server","archived":false,"fork":false,"pushed_at":"2012-07-20T15:14:51.000Z","size":1087,"stargazers_count":60,"open_issues_count":1,"forks_count":15,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-04-15T14:09:04.070Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://sockjs.org","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sockjs.png","metadata":{"files":{"readme":"README.textile","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-09-28T12:59:31.000Z","updated_at":"2022-09-18T00:08:35.000Z","dependencies_parsed_at":"2023-02-19T21:30:22.836Z","dependency_job_id":null,"html_url":"https://github.com/sockjs/sockjs-ruby","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sockjs%2Fsockjs-ruby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sockjs%2Fsockjs-ruby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sockjs%2Fsockjs-ruby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sockjs%2Fsockjs-ruby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sockjs","download_url":"https://codeload.github.com/sockjs/sockjs-ruby/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224305846,"owners_count":17289446,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-12T16:06:40.616Z","updated_at":"2026-04-04T06:34:59.146Z","avatar_url":"https://github.com/sockjs.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"h1. About\n\n_*Disclaimer:* This library is still work in progress._\n\nSockJS is WebSocket emulation library. It means that you use the WebSocket API, only instead of @WebSocket@ class you instantiate @SockJS@ class. I highly recommend to read \"SockJS: WebSocket emulation\":http://www.rabbitmq.com/blog/2011/09/13/sockjs-websocket-emulation on the RabbitMQ blog for more info.\n\nh2. Prerequisites\n\nEven though this library uses Rack interface, *Thin is required* as \"it supports asynchronous callback\":http://macournoyer.com/blog/2009/06/04/pusher-and-async-with-thin. For Websockets, we use \"faye-websocket\":http://blog.jcoglan.com/2011/11/28/announcing-faye-websocket-a-standards-compliant-websocket-library gem.\n\nh2. The Client-Side Part\n\nFor the client-side part you have to use JS library \"sockjs-client\":http://sockjs.github.com/sockjs-client which provides WebSocket-like API. Here's an example:\n\n\u003cpre\u003e\n\u003cscript src=\"http://cdn.sockjs.org/sockjs-0.2.1.min.js\"\u003e\u003c/script\u003e\n\n\u003cscript\u003e\n  var sock = new SockJS(\"http://mydomain.com/my_prefix\");\n\n  sock.onopen = function() {\n    console.log(\"open\");\n  };\n\n  sock.onmessage = function(e) {\n    console.log(\"message\", e.data);\n  };\n\n  sock.onclose = function() {\n    console.log(\"close\");\n  };\n\u003c/script\u003e\n\u003c/pre\u003e\n\nh2. The Server-Side Part\n\nNow in order to have someone to talk to, we need to run a server. That's exactly what is sockjs-ruby good for:\n\n\u003cpre\u003e\n#!/usr/bin/env ruby\n# encoding: utf-8\n\nrequire \"rack\"\nrequire \"rack/sockjs\"\nrequire \"eventmachine\"\n\n# Your custom app.\nclass MyHelloWorld\n  def call(env)\n    body = \"This is the app, not SockJS.\"\n    headers = {\n      \"Content-Type\" =\u003e \"text/plain; charset=UTF-8\",\n      \"Content-Length\" =\u003e body.bytesize.to_s\n    }\n\n    [200, headers, [body]]\n  end\nend\n\n\napp = Rack::Builder.new do\n  # Run one SockJS app on /echo.\n  use SockJS, \"/echo\" do |connection|\n    connection.subscribe do |session, message|\n      session.send(message)\n    end\n  end\n\n  # ... and the other one on /close.\n  use SockJS, \"/close\" do |connection|\n    connection.session_open do |session|\n      session.close(3000, \"Go away!\")\n    end\n  end\n\n  # This app will run on other URLs than /echo and /close,\n  # as these has already been assigned to SockJS.\n  run MyHelloWorld.new\nend\n\n\nEM.run do\n  thin = Rack::Handler.get(\"thin\")\n  thin.run(app.to_app, Port: 8081)\nend\n\u003c/pre\u003e\n\nFor more complex example check \"examples/sockjs_apps_for_sockjs_protocol_tests.rb\":https://github.com/sockjs/sockjs-ruby/blob/master/examples/sockjs_apps_for_sockjs_protocol_tests.rb\n\n\nh2. SockJS Family\n\n* \"SockJS-client\":https://github.com/sockjs/sockjs-client JavaScript client library.\n* \"SockJS-node\":https://github.com/sockjs/sockjs-node Node.js server.\n* \"SockJS-ruby\":https://github.com/sockjs/sockjs-ruby Ruby server.\n* \"SockJS-protocol\":https://github.com/sockjs/sockjs-protocol protocol tests and documentation.\n* \"SockJS-protocol spec\":http://sockjs.github.com/sockjs-protocol/sockjs-protocol-0.2.1.html\n\nh1. Development\n\nGet \"sockjs-protocol\":https://github.com/sockjs/sockjs-protocol (installation information are in its README) and run @./examples/sockjs_apps_for_sockjs_protocol_tests.rb@. Now you can run the tests against it, for instance:\n\n\u003cpre\u003e\n# Run all the tests.\n./venv/bin/python sockjs-protocol-0.2.1.py\n\n# Run all the tests defined in XhrStreaming.\n./venv/bin/python sockjs-protocol-0.2.1.py XhrStreaming\n\n# Run only XhrStreaming.test_transport test.\n./venv/bin/python sockjs-protocol-0.2.1.py XhrStreaming.test_transport\n\u003c/pre\u003e\n\nh1. Links\n\n* \"SockJS: WebSocket emulation\":http://www.rabbitmq.com/blog/2011/09/13/sockjs-websocket-emulation\n* \"SockJS: web messaging ain't easy\":http://www.rabbitmq.com/blog/2011/08/22/sockjs-web-messaging-aint-easy\n* \"PubSubHuddle Realtime Web talk\":http://www.rabbitmq.com/blog/2011/09/26/pubsubhuddle-realtime-web-talk\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsockjs%2Fsockjs-ruby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsockjs%2Fsockjs-ruby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsockjs%2Fsockjs-ruby/lists"}