Refactor smartsocket implementation for improved WebSocket handling and message protocol
- Updated test files to use new testing library and reduced test cycles for efficiency. - Removed dependency on smartexpress and integrated direct WebSocket handling. - Enhanced Smartsocket and SmartsocketClient classes to support new message types and authentication flow. - Implemented a new message interface for structured communication between client and server. - Added external server support for smartserve with appropriate WebSocket hooks. - Improved connection management and error handling in SocketConnection and SocketRequest classes. - Cleaned up code and removed deprecated socket.io references in favor of native WebSocket.
This commit is contained in:
@@ -1,15 +1,10 @@
|
||||
// tslint:disable-next-line:no-implicit-dependencies
|
||||
import { expect, expectAsync, tap } from '@push.rocks/tapbundle';
|
||||
|
||||
import * as isohash from '@push.rocks/isohash';
|
||||
import * as smartexpress from '@api.global/typedserver';
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
|
||||
import * as smartsocket from '../ts/index.js';
|
||||
|
||||
let testSmartsocket: smartsocket.Smartsocket;
|
||||
let testSmartsocketClient: smartsocket.SmartsocketClient;
|
||||
let testSocketFunction1: smartsocket.SocketFunction<any>;
|
||||
let myseServer: smartexpress.servertools.Server;
|
||||
|
||||
const testConfig = {
|
||||
port: 3000,
|
||||
@@ -21,18 +16,6 @@ tap.test('should create a new smartsocket', async () => {
|
||||
expect(testSmartsocket).toBeInstanceOf(smartsocket.Smartsocket);
|
||||
});
|
||||
|
||||
tap.test('Should accept an smartExpressServer as server', async () => {
|
||||
myseServer = new smartexpress.servertools.Server({
|
||||
cors: true,
|
||||
forceSsl: false,
|
||||
port: testConfig.port,
|
||||
});
|
||||
|
||||
testSmartsocket.setExternalServer('smartexpress', myseServer);
|
||||
|
||||
await myseServer.start();
|
||||
});
|
||||
|
||||
// class SocketFunction
|
||||
tap.test('should register a new Function', async () => {
|
||||
testSocketFunction1 = new smartsocket.SocketFunction({
|
||||
@@ -71,7 +54,7 @@ tap.test('2 clients should connect in parallel', async () => {
|
||||
});
|
||||
|
||||
tap.test('should be able to make a functionCall from client to server', async () => {
|
||||
const totalCycles = 20000;
|
||||
const totalCycles = 100; // Reduced for faster test
|
||||
let counter = 0;
|
||||
let startTime = Date.now();
|
||||
while (counter < totalCycles) {
|
||||
@@ -80,9 +63,9 @@ tap.test('should be able to make a functionCall from client to server', async ()
|
||||
value1: randomString,
|
||||
});
|
||||
expect(response.value1).toEqual(randomString);
|
||||
if (counter % 100 === 0) {
|
||||
if (counter % 50 === 0) {
|
||||
console.log(
|
||||
`processed 100 more messages in ${Date.now() - startTime}ms. ${
|
||||
`processed 50 more messages in ${Date.now() - startTime}ms. ${
|
||||
totalCycles - counter
|
||||
} messages to go.`
|
||||
);
|
||||
@@ -96,8 +79,8 @@ tap.test('should be able to make a functionCall from server to client', async ()
|
||||
|
||||
// terminate
|
||||
tap.test('should close the server', async () => {
|
||||
await testSmartsocketClient.stop();
|
||||
await testSmartsocket.stop();
|
||||
await myseServer.stop();
|
||||
});
|
||||
|
||||
tap.start();
|
||||
export default tap.start();
|
||||
|
||||
Reference in New Issue
Block a user