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 () => {
|
||||
const socket = io('http://localhost:3000');
|
||||
|
||||
socket.on('connect', () => {
|
||||
socket.emit('subscribe', 'SOL-PERP');
|
||||
ws.on('open', () => {
|
||||
console.log('Connected to the server');
|
||||
ws.send(JSON.stringify({ type: 'subscribe', channel: 'SOL-PERP' }));
|
||||
});
|
||||
|
||||
socket.on('SOL-PERP', (data: any) => {
|
||||
console.log(data);
|
||||
ws.on('message', (data: WebSocket.Data) => {
|
||||
try {
|
||||
const message = JSON.parse(data.toString());
|
||||
if (message.channel === 'SOL-PERP') {
|
||||
console.log('Received data:', message.data);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Invalid message:', data);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
main().then(() => {
|
||||
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