1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- import { SearchService } from "../services/query.service"
- import _ = require("lodash")
- import { Subject, interval } from "rxjs";
- import * as WebSocket from 'ws';
- /* ---------------------- COMPLEX OPERATION ------------------------------ */
- // Check Heap size
- // const v8 = require('v8');
- // const heapStats = v8.getHeapStatistics();
- // const maxHeapSize = heapStats.heap_size_limit / (1024 * 1024); // Convert to MB
- // console.log(`Current maximum heap size: ${maxHeapSize.toFixed(2)} MB`);
- // Create new Subject to handle incoming data from remote subscription
- let payload: Subject<any> = new Subject()
- payload.subscribe((element) => {
- console.log(`Received message from server: ${element.appData.msgId}`);
- const used = process.memoryUsage().heapUsed / 1024 / 1024;
- console.log(`Heap used: ${used} MB`);
- })
- // Create a new WebSocket client
- const ws = new WebSocket('ws://localhost:8080');
- // Listen for the WebSocket connection to open
- ws.on('open', () => {
- console.log('Connected to WebSocket server');
- // Send a message to the server
- ws.send('Hello, server!');
- });
- // Listen for messages from the server
- ws.on('message', (message: string) => {
- let msgObj = JSON.parse(message)
- payload.next(msgObj)
- });
- // Listen for the WebSocket connection to close
- ws.on('close', () => {
- console.log('Disconnected from WebSocket server');
- });
|