I have WebSocket Connection in Node which works fine. Now I want to use it in Angular with a rxjs websocket, but I have no idea how to solve the connection.
const WebSocket = require('ws');
const ws = new WebSocket('wss://example.com');
ws.on('open', function open() {
// on connection, send our authentication request
ws.send(JSON.stringify({action: 'auth', key: apiKey, secret: apiSecret}));
});
ws.on('close', function close() {
console.log('disconnected');
});
ws.on('message', function incoming(data) {
console.log(data)
var msg = JSON.parse(data);
if (msg.type === 'status' && msg.status === 'authenticated') {
// if we got authentication confirmation, send subscribe event to the server
ws.send(JSON.stringify({action: 'subscribe', buckets: ['exampleBucket']}));
}
});