Javascript Websocket subscribe to channel

0 votes

I am trying to subscribe to channel using native WebSocket in vanilla javascript. I have the following code: 

let ws = new WebSocket('wss://ws-feed.gdax.com');

var params = {
   "type": "subscribe",
   "channels": [{"name": "ticker", "product_ids": ["BTC-USD"]}]
}

ws.onmessage = function(msg) {
    console.log(msg);
}

I am trying to connect to this channel but I am not able to do so

Aug 28, 2018 in Blockchain by digger
• 26,740 points
4,213 views

1 answer to this question.

0 votes

This is how you can do it

let ws = new WebSocket('ws://localhost:4000/cable');

ws.onopen = function(){
  //Subscribe to the channel
  ws.send(JSON.stringify({"command": "subscribe","identifier":"{\"channel\":\"ArticlesChannel\"}"}))
}    

ws.onmessage = function(msg) {
    console.log(JSON.parse(msg.data).message);
}
answered Aug 28, 2018 by slayer
• 29,350 points

Related Questions In Blockchain

0 votes
1 answer

GDAX Heartbeat Channel: Failed to subscribe error

You to include "product_ids" : ["BTC-GBP"] as a field ...READ MORE

answered Sep 7, 2018 in Blockchain by digger
• 26,740 points
927 views
0 votes
1 answer

How to store picture(s) in a hyperledger blockchain channel

You can hold images as encrypted characters ...READ MORE

answered Jun 16, 2018 in Blockchain by charlie_brown
• 7,720 points
1,131 views
0 votes
1 answer
0 votes
1 answer

Unable to request channel creation using Rest Api

I'd recommend taking a look at the ordering ...READ MORE

answered Jul 16, 2018 in Blockchain by Perry
• 17,100 points
673 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,663 views
+1 vote
3 answers

Removing double quotes from a string from JSON response in PHP

Just remove the json_encode call, and it should work: $resp ...READ MORE

answered Sep 12, 2018 in Blockchain by digger
• 26,740 points
43,812 views
0 votes
1 answer

How do I add multiple recipients for transactions via Blockchain API?

Convert the recipes into JSON objects. x = ...READ MORE

answered Jul 6, 2018 in Blockchain by Perry
• 17,100 points
673 views
0 votes
1 answer

Javascript mBTC to BTC conversion not working

At the beginning of bitcoinConversion() you have: if (currentUnit != ...READ MORE

answered Sep 5, 2018 in Blockchain by slayer
• 29,350 points
841 views
0 votes
1 answer

Basic pusher connection to cryptsy using javascript

Try this <script src="//js.pusher.com/2.2/pusher.min.js" type="text/javascript"></script> <script type="text/javascript"> var pusher = ...READ MORE

answered Sep 11, 2018 in Blockchain by slayer
• 29,350 points
397 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP