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

Room connection #10

Open
ricvillagrana opened this issue Nov 29, 2018 · 1 comment
Open

Room connection #10

ricvillagrana opened this issue Nov 29, 2018 · 1 comment
Labels

Comments

@ricvillagrana
Copy link

Is there a way to connect to a room? I successfully connected to a channel but I need to connect to a specified room. How to achieve this with es6-actioncable?

@eacaps
Copy link
Owner

eacaps commented Dec 3, 2018

Once you have subscribed to a channel you'll want to use the 'perform' or 'send' command on the subscription to do perform actions on that Subscription. See https://github.com/eacaps/es6-actioncable/blob/master/dist/actioncable/cable/Subscription.js

Here's a example of how it would look:

const subscription = WebSocket.getConsumer().subscriptions.create("MyChannel", {
      connected: function () {
        console.log('connected to mychannel');
      },
      received: function (data) {
        //do stuff with data
      }
    });
subscription.perform('follow', {id: 1234});

That will send a WS message that looks something like this:

{"command":"message","identifier":"{\"channel\":\"MyChannel\"}","data":"{\"action\":\"follow\",\"id\":1234}"}

And on the server it would call the follow method on MyChannel.rb

@eacaps eacaps added the question label Dec 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants