Git Product home page Git Product logo

ruby-websockets-chat-demo's Introduction

Ruby WebSockets Chat Demo

Deploy

This is a simple application that serves tasty WebSockets to your users with faye-websocket, Puma, and Sinatra.

Check out the live demo or read the docs.

Setup

To install all the dependencies, run:

bundle install

Next the app requires some env vars for configuration. A sample .env.sample is provided for running the app locally. You can copy .env.sample to .env which foreman will pick up.

Using foreman we can boot the application.

$ foreman start

You can now visit http://localhost:5000 to see the application.

ruby-websockets-chat-demo's People

Contributors

hone avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

ruby-websockets-chat-demo's Issues

BAD URI

/usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/uri/common.rb:176:in `split': bad URI(is not URI?):  (URI::InvalidURIError)                                    
        from /usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/uri/common.rb:211:in `parse'                                                                      
        from /usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/uri/common.rb:747:in `parse'                                                                      
        from /root/ruby-websockets-chat-demo/middlewares/chat_backend.rb:15:in `initialize'                                                                    
        from /usr/local/rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/builder.rb:86:in `new'                                                                    
        from /usr/local/rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/builder.rb:86:in `block in use'                                                           
        from /usr/local/rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/builder.rb:134:in `[]'                                                                    
        from /usr/local/rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/builder.rb:134:in `block in to_app'                                                       
        from /usr/local/rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/builder.rb:134:in `each'                                                                  
        from /usr/local/rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/builder.rb:134:in `inject'                                                                
        from /usr/local/rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/builder.rb:134:in `to_app'                                                                
        from config.ru:8:in `<main>'                                                                                                                           
        from /usr/local/rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/builder.rb:49:in `eval'                                                                   
        from /usr/local/rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/builder.rb:49:in `new_from_string'                                                        
        from /usr/local/rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/builder.rb:40:in `parse_file'                                                             
        from /usr/local/rvm/gems/ruby-2.1.2/gems/puma-2.6.0/lib/puma/configuration.rb:93:in `app'                                                              
        from /usr/local/rvm/gems/ruby-2.1.2/gems/puma-2.6.0/lib/puma/runner.rb:105:in `load_and_bind'                                                          
        from /usr/local/rvm/gems/ruby-2.1.2/gems/puma-2.6.0/lib/puma/single.rb:73:in `run'                                                                     
        from /usr/local/rvm/gems/ruby-2.1.2/gems/puma-2.6.0/lib/puma/cli.rb:442:in `run'                                                                       
        from /usr/local/rvm/gems/ruby-2.1.2/gems/puma-2.6.0/bin/puma:10:in `<top (required)>'                                                                  
        from /usr/local/rvm/gems/ruby-2.1.2/bin/puma:23:in `load'                                                                                              
        from /usr/local/rvm/gems/ruby-2.1.2/bin/puma:23:in `<main>'                                                                                            
        from /usr/local/rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `eval'                                                                             
        from /usr/local/rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `<main>'                                               

Any fix?

foreman run web fails

Chriss-MacBook-Pro:ruby-websockets-chat-demo chrisallick$ foreman run web
/Users/chrisallick/.rvm/gems/ruby-2.0.0-p451/gems/puma-2.6.0/lib/puma/cli.rb:272:in parse_options': missing argument: -p (OptionParser::MissingArgument) from /Users/chrisallick/.rvm/gems/ruby-2.0.0-p451/gems/puma-2.6.0/lib/puma/cli.rb:418:inrun'
from /Users/chrisallick/.rvm/gems/ruby-2.0.0-p451/gems/puma-2.6.0/bin/puma:10:in <top (required)>' from /Users/chrisallick/.rvm/gems/ruby-2.0.0-p451/bin/puma:23:inload'
from /Users/chrisallick/.rvm/gems/ruby-2.0.0-p451/bin/puma:23:in <main>' from /Users/chrisallick/.rvm/gems/ruby-2.0.0-p451/bin/ruby_executable_hooks:15:ineval'
from /Users/chrisallick/.rvm/gems/ruby-2.0.0-p451/bin/ruby_executable_hooks:15:in `

'

Heroku now defaulting to SSL and app breaks if pushed there

I just used the "Deploy to Heroku" button to try it out on Heroku. It deployed fine and client access to the URL provided the expected screen. However, nothing worked from there.

I noticed that the client URL was using HTTPS. From my other Heroku apps, I understand that Heroku is now enabling HTTPS as the default. The app doesn't seem ready for that.

I then attempted client access by changing the protocol to HTTP and everything worked fine.

bad URI error

Hi, I get the following when running foreman start. Any ideas?

18:44:28 web.1  | started with pid 18702
18:44:29 web.1  | Puma starting in single mode...
18:44:29 web.1  | * Version 2.6.0, codename: Pantsuit Party
18:44:29 web.1  | * Min threads: 0, max threads: 16
18:44:29 web.1  | * Environment: development
18:44:29 web.1  | ! Unable to load application
18:44:29 web.1  | /usr/local/var/rbenv/versions/2.1.2/lib/ruby/2.1.0/uri/common.rb:176:in `split': bad URI(is not URI?):  (URI::InvalidURIError)
18:44:29 web.1  |   from /usr/local/var/rbenv/versions/2.1.2/lib/ruby/2.1.0/uri/common.rb:211:in `parse'
18:44:29 web.1  |   from /usr/local/var/rbenv/versions/2.1.2/lib/ruby/2.1.0/uri/common.rb:747:in `parse'
18:44:29 web.1  |   from /Users/vdolbilov/Dev/ruby-websockets-chat-demo/middlewares/chat_backend.rb:15:in `initialize'
18:44:29 web.1  |   from /usr/local/var/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rack-1.5.2/lib/rack/builder.rb:86:in `new'
18:44:29 web.1  |   from /usr/local/var/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rack-1.5.2/lib/rack/builder.rb:86:in `block in use'
18:44:29 web.1  |   from /usr/local/var/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rack-1.5.2/lib/rack/builder.rb:134:in `[]'
18:44:29 web.1  |   from /usr/local/var/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rack-1.5.2/lib/rack/builder.rb:134:in `block in to_app'
18:44:29 web.1  |   from /usr/local/var/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rack-1.5.2/lib/rack/builder.rb:134:in `each'
18:44:29 web.1  |   from /usr/local/var/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rack-1.5.2/lib/rack/builder.rb:134:in `inject'
18:44:29 web.1  |   from /usr/local/var/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rack-1.5.2/lib/rack/builder.rb:134:in `to_app'
18:44:29 web.1  |   from config.ru:8:in `<main>'
18:44:29 web.1  |   from /usr/local/var/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rack-1.5.2/lib/rack/builder.rb:49:in `eval'
18:44:29 web.1  |   from /usr/local/var/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rack-1.5.2/lib/rack/builder.rb:49:in `new_from_string'
18:44:29 web.1  |   from /usr/local/var/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rack-1.5.2/lib/rack/builder.rb:40:in `parse_file'
18:44:29 web.1  |   from /usr/local/var/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/puma-2.6.0/lib/puma/configuration.rb:93:in `app'
18:44:29 web.1  |   from /usr/local/var/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/puma-2.6.0/lib/puma/runner.rb:105:in `load_and_bind'
18:44:29 web.1  |   from /usr/local/var/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/puma-2.6.0/lib/puma/single.rb:73:in `run'
18:44:29 web.1  |   from /usr/local/var/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/puma-2.6.0/lib/puma/cli.rb:442:in `run'
18:44:29 web.1  |   from /usr/local/var/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/puma-2.6.0/bin/puma:10:in `<top (required)>'
18:44:29 web.1  |   from /usr/local/var/rbenv/versions/2.1.2/bin/puma:23:in `load'
18:44:29 web.1  |   from /usr/local/var/rbenv/versions/2.1.2/bin/puma:23:in `<main>'
18:44:29 web.1  | exited with code 1
18:44:29 system | sending SIGTERM to all processes

Problem Integrating with Rails

I checked out the tutorial for Sinatra here: https://devcenter.heroku.com/articles/ruby-websockets
and I was able to get Websockets working for heroku deployment with sinatra.

Near the bottom of the tutorial, they mentioned switching to rails was trivial. I followed their suggestion, as well as making other modifications to my rails file to get things working.

So I'm not sure what I'm doing wrong, if the switching is "trivial", then perhaps anyone can make a new repository with rails embedded instead?

Example breaks if run under Puma in "clustered mode"

My puma config looked like this:

workers 3
thread 0,16
preload_app!

Specifying workers puts puma in clustered mode, and broke my slightly modified version of the middleware presented in this example.

I verified that the messages are being published properly to the redis pubsub channel, and that the redis subscription inside of the thread does receive the messages and fires the on.message block, but the ws client in the browser never gets the message.

This is due to @clients being an empty array inside the thread (for a reason that is escaping me), meaning that the block passed to @clients.each is never executed, so the message dies there.

Accessing @clients outside of that thread does return all of the open ws connections properly.

Removing the workers 3 line fixes the issue, but I figured I would report it, in case someone else runs into this themselves.

I am running this on MRI 2.0-p247, FWIW.

Cheers, and thanks for the demo app and the new labs feature enabling websockets on the heroku platform. Very excited to incorporate realtime elements into my current project without having to rely on a 3rd party service.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.