Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic Setup of Action Cable #5744

Merged
merged 14 commits into from
Jun 27, 2019
Merged

Basic Setup of Action Cable #5744

merged 14 commits into from
Jun 27, 2019

Conversation

namangupta01
Copy link
Member

Fixes #5743

@namangupta01
Copy link
Member Author

@jywarren Here's the setup of the Action Cable. Have a look at it.

@namangupta01
Copy link
Member Author

namangupta01 commented May 19, 2019

After deploying this we can test this out.
Open public lab website in two different browser or computers and in one of the computer type App.room.speak('any_message') in the console and this message will appear in all the browser console of all the computers. This way we can check this out.

@namangupta01
Copy link
Member Author

After merging of this we can work further on this.

@plotsbot
Copy link
Collaborator

plotsbot commented May 19, 2019

2 Warnings
⚠️ It looks like you merged from master in this pull request. Please rebase to get rid of the merge commits – you may want to rewind the master branch and rebase instead of merging in from master, which can cause problems when accepting new code!
⚠️ There was an error with Danger bot’s Junit parsing: No JUnit file was found at output.xml
2 Messages
📖 @namangupta01 Thank you for your pull request! I’m here to help with some tips and recommendations. Please take a look at the list provided and help us review and accept your contribution! And don’t be discouraged if you see errors – we’re here to help.
📖 #
Screenshots 📸 (click to expand)

Learn about automated screenshots

Generated by 🚫 Danger

@namangupta01
Copy link
Member Author

@jywarren @gautamig54 @gauravano Please review! Thanks

@jywarren
Copy link
Member

I think rebasing this could pass tests, since we resolved some big test issues!

@namangupta01 namangupta01 force-pushed the actioncable_basic_setup branch from efd2fbf to d382520 Compare May 25, 2019 16:53
@namangupta01
Copy link
Member Author

Rebased let's hope it passes!

@namangupta01
Copy link
Member Author

@jywarren Tests has passed! I think we can ignore the codeclimate?

@namangupta01
Copy link
Member Author

@jywarren, @gautamig54 Have a look.

@namangupta01
Copy link
Member Author

Can anyone review ? Its pending from a long time.
Thanks

@namangupta01
Copy link
Member Author

@publiclab/reviewers

Copy link
Member

@jywarren jywarren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! I had a few questions, suggestions, etc! Also, once we resolve them, would you like to test this out on unstable to see how it does in a production environment?

Thanks @namangupta01 this is exciting!!!!

@@ -0,0 +1,13 @@
App.room = App.cable.subscriptions.create "RoomChannel",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @namangupta01 this is great, and I have nothing against CoffeeScript but do you think we should try to standardize so there's not a mix of coffeescript/javascript in the project? I'm open to suggestions but just thinking about newcomers and how much they have to learn to be able to work on this file... what do you think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! I will change it to javascript. 👍

# Called when the subscription has been terminated by the server

received: (data) ->
console.log("Response: " + data["message"]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this affect all users, or is it turned "on" for just some?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I said in the other comment. Room channel will be connected to all the sessions.

@@ -0,0 +1,13 @@
class RoomChannel < ApplicationCable::Channel
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What will correspond to a "room"? Are we aiming for notifications of comments to start with? Is each node a "room" and comments are messages in the room? Maybe we should make a "NodeChannel" instead, what do you think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There will be multiple channels for multiple features, but I was thinking of making a room_channel which will be connected to all the users irrespective, in the case we want to use it in the future to send some notifications to all the users even they are logged in or not.
And I am going to make a differnt channel for a different feature, for example, node_channel, like_channel etc.
What do you say?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are your thoughts about this @jywarren ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, my apologies for missing this!!! Yes, this sounds good; can you add this as a comment at the top of this file, just so there's some context?

@namangupta01
Copy link
Member Author

Hi @jywarren, if you can just take out one minute and have a look at it and pass it. I will complete it super soon. Just waiting for your suggestion on my comment. Thanks

@namangupta01
Copy link
Member Author

Hi! Please read my comments and let me know what do you think? I am hoping to merge this as soon as possible.

@jywarren
Copy link
Member

Thanks Naman. Again, apologies for the slow response.

@namangupta01
Copy link
Member Author

@jywarren, I have done the suggested changes. And while testing on unstable I am getting error Error during WebSocket handshake: Unexpected response code: 404. I guess this is a NGINX error. Can you setup the NGINX with the configuration on the link https://stackoverflow.com/a/51048929. Thanks a lot.

@namangupta01
Copy link
Member Author

@jywarren How to see the configuration in https://jenkins.laboratoriopublico.org. Sorry, I checked but I didn't find any configuration.

@icarito
Copy link
Member

icarito commented Jun 21, 2019

Hi I just adjusted our unstable nginx config in accordance to the stackoverflow answer you posted! Please let me know if this works or we can tweak it!

server {                                                                                        
    listen 80;                                                                                  
    return 301 https://$server_name$request_uri;                                                
    server_name unstable.publiclab.org;                                                         
}                                                                                               
                                                                                                
server {                                                                                        
                                                                                                
#    listen 80;                                                                                 
    listen 443 ssl;                                                                             
                                                                                                
    server_name unstable.publiclab.org;                                                         
    error_page 502 https://jenkins.laboratoriopublico.org/job/Plots-Unstable/lastBuild/console; 
                                                                                                
    ssl_certificate      /etc/letsencrypt/live/unstable.publiclab.org/fullchain.pem;            
##    ssl_dhparam /etc/ssl/private/dhparams.pem;                                                
    ssl_certificate_key  /etc/letsencrypt/live/unstable.publiclab.org/privkey.pem;              
                                                                                                
    ssl on;                                                                                     
    ssl_session_cache  builtin:1000  shared:SSL:10m;                                            
    ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;                                                       
    ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;                       
    ssl_prefer_server_ciphers on;                                                               
                                                                                                
    location /api {                                                                             
        root /srv/plots_unstable/plots2/public/;                                                
        proxy_redirect off;                                                                     
        proxy_buffering off;                                                                    
        try_files $uri @plots_api;                                                              
    }                                                                                           
                                                                                                
    location @plots_api {                                                                       
      add_header              Access-Control-Allow-Origin *;                                    
      proxy_set_header        Host $host;                                                       
      proxy_set_header        X-Real-IP $remote_addr;                                           
      proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;                       
      proxy_set_header        X-Forwarded-Proto $scheme;                                        
                                                                                                
      proxy_pass          http://localhost:5001;                                                
                                                                                                
      proxy_redirect off;                                                                       
      proxy_buffering off;                                                                      
    }                                                                                           
    location / {                                                                                
        root /srv/plots_unstable/plots2/public/;                                                
        proxy_redirect off;                                                                     
        proxy_buffering off;                                                                    
        try_files $uri @plots;                                                                  
    }                                                                                           
                                                                                                
    location /cable {                                                                           
        proxy_pass          http://localhost:5001;                                              
        proxy_http_version 1.1;                                                                 
        proxy_set_header Upgrade websocket;                                                     
        proxy_set_header Connection Upgrade;                                                    
    }                                                                                           
                                                                                                
    location @plots {                                                                           
      proxy_set_header        Host $host;                                                       
      proxy_set_header        X-Real-IP $remote_addr;                                           
      proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;                       
      proxy_set_header        X-Forwarded-Proto $scheme;                                        
                                                                                                
      proxy_pass          http://localhost:5001;                                                
                                                                                                
      proxy_redirect off;                                                                       
      proxy_buffering off;                                                                      
    }                                                                                           
  }                                                                                             

@namangupta01
Copy link
Member Author

Hi @icarito, thanks for changing the conf. I also tried on my local with this configuration. This is working. But this is not working in unstable. Have you restarted the nginx?

@namangupta01
Copy link
Member Author

It's working after restarting nginx.

@icarito
Copy link
Member

icarito commented Jun 22, 2019

I "reloaded config" but didn't restart. I'll restart now in case it helps.

@namangupta01
Copy link
Member Author

I made some changes to config/production.rb. And finally, it worked and live on unstable.
@jywarren You can check this out on unstable by typing App.room.speak("hey") in the console and it will appear on all the sessions connected to unstable. You can test this out by opening the browser in a different tab, window or even computer.

And I guess this is now good to merge.
Thanks.

@jywarren
Copy link
Member

jywarren commented Jun 22, 2019 via email

@namangupta01
Copy link
Member Author

Yeah! This is what I was hoping to do in the next part.

@jywarren
Copy link
Member

jywarren commented Jun 22, 2019 via email

@namangupta01
Copy link
Member Author

Sure! I am doing that. I have to add and destroy cookies while logging in and logout.

@namangupta01 namangupta01 force-pushed the actioncable_basic_setup branch from 55691b2 to ccde4f3 Compare June 25, 2019 15:03
@namangupta01
Copy link
Member Author

@jywarren Please have a look. I have added cookie while loading the page so that the websocket connection is able to find the user and can use role of the user.

@namangupta01
Copy link
Member Author

Good to merge? What do you say?

Copy link
Member

@grvsachdeva grvsachdeva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!!


cookies.signed["user_token"] = nil
if @current_user
cookies.signed["user_token"] = @current_user.persistence_token
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, so does this update the cookie on any usage of current_user, or when exactly? Thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once this is answered, I think we are good to merge, yes!!!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I am using current_user cookie to let the WebSocket while connecting to know that from which user the WebSocket is connecting so that we can do role-based functionality.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because session is not available in ActionCable channels so while loading page we check for current_user and when we are checking for current_user we set the cookie so that the websocket can let the action cable know which user it is.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jywarren Does this helps?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, just want to know, when logging out, will the cookie then be flushed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add any test for this, perhaps a system test? We can do it in follow-up, but I'd like to protect this with some tests.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that current_user function will be called when we log out and the browser redirect it to any page. But it good to specifically set the cookie while logging out.
Doing it.
Thanks!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And regarding System Test, yes we can do this in the follow up pr.

Copy link
Member Author

@namangupta01 namangupta01 Jun 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it is not needed to set the cookie to nil because while logging out we change the persistence token of the user.

current_user&.reset_persistence_token!

What do you say? I guess it is not needed. Let me know what do you think?

@jywarren
Copy link
Member

jywarren commented Jun 27, 2019 via email

@namangupta01
Copy link
Member Author

namangupta01 commented Jun 27, 2019 via email

@jywarren jywarren merged commit 61684ae into master Jun 27, 2019
@jywarren
Copy link
Member

Ok great! Please test out on stable too!

sagarpreet-chadha pushed a commit that referenced this pull request Jun 29, 2019
* Added room channel

* Basic Setup Of Action Cable

* Basic Implementation of Testing Channel Completed

* Minor Change

* Minor Change

* Minor Change

* Added room channel code in js and removed code in coffeescript

* Added ActionCable Config Url and Action Cable Allowed Request Origin

* Added ActionCable Config Url and Action Cable Allowed Request Origin

* Added ActionCable Config Url and Action Cable Allowed Request Origin

* Added Cookie for identifying user in websocket connection

* Minor Changes
enviro3 pushed a commit to enviro3/plots2 that referenced this pull request Aug 15, 2019
* Added room channel

* Basic Setup Of Action Cable

* Basic Implementation of Testing Channel Completed

* Minor Change

* Minor Change

* Minor Change

* Added room channel code in js and removed code in coffeescript

* Added ActionCable Config Url and Action Cable Allowed Request Origin

* Added ActionCable Config Url and Action Cable Allowed Request Origin

* Added ActionCable Config Url and Action Cable Allowed Request Origin

* Added Cookie for identifying user in websocket connection

* Minor Changes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Basic Implementation and setup of Action Cable into Plots2
5 participants