I want to connect to the GDAX websocket api with an in browser application built with react and webpack. I cannot use the offiicial gdax-node or gdax-toolkit api's because they are not compatible with webpack. I decided to try connecting to the websocket myself using socket.io, but the code below never establishes a connection. In the code below my "subscribing" log message after connect never appears. How do I get this code to connect or at least show an error message?
const io = require('socket.io-client');
var subscribe = {
"type": "subscribe",
"channels": [{"name": "ticker", "product_ids": ["BTC-EUR"]}]
};
function subscribeToTimer(cb) {
console.log('Opening socket');
var socket = io.connect('wss://ws-feed.gdax.com');
socket.on('connection', function(socket) {
console.log('Subscribing');
socket.on('disconnect', function(socket) {
console.log('Clinet disconnected.');
});
});
//socket.on('message', timestamp => cb(null, timestamp));
socket.on('message', data => { console.log(data); });
socket.on('error', data => { console.log(data); });
}
export { subscribeToTimer };