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
• 27,630 points
612 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,050 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
• 27,630 points
58 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
144 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,020 points
126 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
138 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
• 27,630 points
2,920 views
0 votes
1 answer
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,050 points
109 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,050 points
34 views