changed client example to not use socket.io
This commit is contained in:
@@ -1,17 +1,26 @@
|
|||||||
import { io } from 'socket.io-client';
|
import WebSocket from 'ws';
|
||||||
|
const ws = new WebSocket('ws://localhost:3000/ws');
|
||||||
|
|
||||||
const main = async () => {
|
ws.on('open', () => {
|
||||||
const socket = io('http://localhost:3000');
|
console.log('Connected to the server');
|
||||||
|
ws.send(JSON.stringify({ type: 'subscribe', channel: 'SOL-PERP' }));
|
||||||
socket.on('connect', () => {
|
});
|
||||||
socket.emit('subscribe', 'SOL-PERP');
|
|
||||||
});
|
ws.on('message', (data: WebSocket.Data) => {
|
||||||
|
try {
|
||||||
socket.on('SOL-PERP', (data: any) => {
|
const message = JSON.parse(data.toString());
|
||||||
console.log(data);
|
if (message.channel === 'SOL-PERP') {
|
||||||
});
|
console.log('Received data:', message.data);
|
||||||
};
|
}
|
||||||
|
} catch (e) {
|
||||||
main().then(() => {
|
console.error('Invalid message:', data);
|
||||||
console.log('running');
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ws.on('close', () => {
|
||||||
|
console.log('Disconnected from the server');
|
||||||
|
});
|
||||||
|
|
||||||
|
ws.on('error', (error: Error) => {
|
||||||
|
console.error('WebSocket error:', error);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user