Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 38ab4703ea | |||
| 554af7752e |
@@ -0,0 +1,38 @@
|
|||||||
|
{
|
||||||
|
"@git.zone/cli": {
|
||||||
|
"projectType": "npm",
|
||||||
|
"module": {
|
||||||
|
"githost": "code.foss.global",
|
||||||
|
"gitscope": "push.rocks",
|
||||||
|
"gitrepo": "smartsocket",
|
||||||
|
"description": "Provides easy and secure websocket communication mechanisms, including server and client implementation, function call routing, connection management, and tagging.",
|
||||||
|
"npmPackagename": "@push.rocks/smartsocket",
|
||||||
|
"license": "MIT",
|
||||||
|
"projectDomain": "push.rocks"
|
||||||
|
},
|
||||||
|
"release": {
|
||||||
|
"registries": [
|
||||||
|
"https://verdaccio.lossless.digital",
|
||||||
|
"https://registry.npmjs.org"
|
||||||
|
],
|
||||||
|
"accessLevel": "public"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"@git.zone/tsdoc": {
|
||||||
|
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
||||||
|
},
|
||||||
|
"@git.zone/tsbundle": {
|
||||||
|
"bundles": [
|
||||||
|
{
|
||||||
|
"from": "./ts/index.ts",
|
||||||
|
"to": "./dist_bundle/bundle.js",
|
||||||
|
"outputMode": "bundle",
|
||||||
|
"bundler": "esbuild"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"@ship.zone/szci": {
|
||||||
|
"npmGlobalTools": [],
|
||||||
|
"npmRegistryUrl": "registry.npmjs.org"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,14 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 2026-04-30 - 4.0.1 - fix(build)
|
||||||
|
tighten TypeScript compatibility and update project build configuration
|
||||||
|
|
||||||
|
- enable stricter null and implicit-any-safe typing across client, connection, request, and server classes
|
||||||
|
- add runtime guards for missing socket connections and missing function request ids
|
||||||
|
- update build and release configuration for tsbuild/tsbundle and npm publishing metadata
|
||||||
|
- refresh dependency versions and include smart config and license files in published package
|
||||||
|
- strengthen reconnect and tagging tests with explicit existence checks
|
||||||
|
|
||||||
## 2025-12-04 - 4.0.0 - BREAKING CHANGE(socketconnection)
|
## 2025-12-04 - 4.0.0 - BREAKING CHANGE(socketconnection)
|
||||||
Stricter typings, smartserve hooks, connection fixes, and tag API change
|
Stricter typings, smartserve hooks, connection fixes, and tag API change
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2026 Task Venture Capital GmbH
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
+14
-7
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"gitzone": {
|
"@git.zone/cli": {
|
||||||
"projectType": "npm",
|
"projectType": "npm",
|
||||||
"module": {
|
"module": {
|
||||||
"githost": "code.foss.global",
|
"githost": "code.foss.global",
|
||||||
@@ -21,13 +21,20 @@
|
|||||||
"function routing",
|
"function routing",
|
||||||
"secure"
|
"secure"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"release": {
|
||||||
|
"registries": [
|
||||||
|
"https://verdaccio.lossless.digital",
|
||||||
|
"https://registry.npmjs.org"
|
||||||
|
],
|
||||||
|
"accessLevel": "public"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"npmci": {
|
"@git.zone/tsdoc": {
|
||||||
"npmGlobalTools": [],
|
|
||||||
"npmAccessLevel": "public"
|
|
||||||
},
|
|
||||||
"tsdoc": {
|
|
||||||
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
||||||
|
},
|
||||||
|
"@ship.zone/szci": {
|
||||||
|
"npmGlobalTools": [],
|
||||||
|
"npmRegistryUrl": "registry.npmjs.org"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-15
@@ -1,13 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "@push.rocks/smartsocket",
|
"name": "@push.rocks/smartsocket",
|
||||||
"version": "4.0.0",
|
"version": "4.0.1",
|
||||||
"description": "Provides easy and secure websocket communication mechanisms, including server and client implementation, function call routing, connection management, and tagging.",
|
"description": "Provides easy and secure websocket communication mechanisms, including server and client implementation, function call routing, connection management, and tagging.",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist_ts/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/ --verbose)",
|
"test": "(tstest test/ --verbose)",
|
||||||
"build": "(tsbuild --web --allowimplicitany && tsbundle --from ./ts/index.ts --to dist_bundle/bundle.js)",
|
"build": "tsbuild --web && tsbundle",
|
||||||
"buildDocs": "tsdoc"
|
"buildDocs": "tsdoc"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
@@ -17,30 +17,30 @@
|
|||||||
"author": "Task Venture Capital GmbH",
|
"author": "Task Venture Capital GmbH",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://community.foss.global/"
|
"url": "https://code.foss.global/push.rocks/smartsocket/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://code.foss.global/push.rocks/smartsocket",
|
"homepage": "https://code.foss.global/push.rocks/smartsocket",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@api.global/typedrequest-interfaces": "^3.0.19",
|
"@api.global/typedrequest-interfaces": "^3.0.19",
|
||||||
"@push.rocks/isohash": "^2.0.1",
|
"@push.rocks/isohash": "^2.0.1",
|
||||||
"@push.rocks/isounique": "^1.0.5",
|
"@push.rocks/isounique": "^1.0.5",
|
||||||
"@push.rocks/lik": "^6.2.2",
|
"@push.rocks/lik": "^6.4.1",
|
||||||
"@push.rocks/smartdelay": "^3.0.5",
|
"@push.rocks/smartdelay": "^3.0.5",
|
||||||
"@push.rocks/smartenv": "^6.0.0",
|
"@push.rocks/smartenv": "^6.0.0",
|
||||||
"@push.rocks/smartjson": "^5.2.0",
|
"@push.rocks/smartjson": "^6.0.1",
|
||||||
"@push.rocks/smartlog": "^3.1.10",
|
"@push.rocks/smartlog": "^3.2.2",
|
||||||
"@push.rocks/smartpromise": "^4.2.3",
|
"@push.rocks/smartpromise": "^4.2.3",
|
||||||
"@push.rocks/smartrx": "^3.0.10",
|
"@push.rocks/smartrx": "^3.0.10",
|
||||||
"@push.rocks/smarttime": "^4.1.1",
|
"@push.rocks/smarttime": "^4.2.3",
|
||||||
"ws": "^8.18.3"
|
"ws": "^8.20.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@git.zone/tsbuild": "^3.1.2",
|
"@git.zone/tsbuild": "^4.4.0",
|
||||||
"@git.zone/tsbundle": "^2.6.3",
|
"@git.zone/tsbundle": "^2.10.1",
|
||||||
"@git.zone/tsrun": "^2.0.0",
|
"@git.zone/tsrun": "^2.0.3",
|
||||||
"@git.zone/tstest": "^3.1.3",
|
"@git.zone/tstest": "^3.6.3",
|
||||||
"@push.rocks/smartserve": "^1.1.2",
|
"@push.rocks/smartserve": "^2.0.4",
|
||||||
"@types/node": "^24.10.1",
|
"@types/node": "^25.6.0",
|
||||||
"@types/ws": "^8.18.1"
|
"@types/ws": "^8.18.1"
|
||||||
},
|
},
|
||||||
"private": false,
|
"private": false,
|
||||||
@@ -53,6 +53,8 @@
|
|||||||
"dist_ts_web/**/*",
|
"dist_ts_web/**/*",
|
||||||
"assets/**/*",
|
"assets/**/*",
|
||||||
"cli.js",
|
"cli.js",
|
||||||
|
".smartconfig.json",
|
||||||
|
"license",
|
||||||
"npmextra.json",
|
"npmextra.json",
|
||||||
"readme.md"
|
"readme.md"
|
||||||
],
|
],
|
||||||
@@ -71,5 +73,6 @@
|
|||||||
"function routing",
|
"function routing",
|
||||||
"secure",
|
"secure",
|
||||||
"rpc"
|
"rpc"
|
||||||
]
|
],
|
||||||
|
"packageManager": "pnpm@10.28.2"
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+2228
-1917
File diff suppressed because it is too large
Load Diff
@@ -81,6 +81,9 @@ tap.test('should be able to tag a connection from client', async (tools) => {
|
|||||||
return true;
|
return true;
|
||||||
})
|
})
|
||||||
.getTagById('awesome');
|
.getTagById('awesome');
|
||||||
|
if (!tagOnServerSide) {
|
||||||
|
throw new Error('Expected server-side tag awesome to exist');
|
||||||
|
}
|
||||||
expect(tagOnServerSide.payload).toEqual('yes');
|
expect(tagOnServerSide.payload).toEqual('yes');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -93,7 +96,13 @@ tap.test('should be able to tag a connection from server', async (tools) => {
|
|||||||
id: 'awesome2',
|
id: 'awesome2',
|
||||||
payload: 'absolutely',
|
payload: 'absolutely',
|
||||||
});
|
});
|
||||||
|
if (!testSmartsocketClient.socketConnection) {
|
||||||
|
throw new Error('Expected client socket connection to exist');
|
||||||
|
}
|
||||||
const tagOnClientSide = await testSmartsocketClient.socketConnection.getTagById('awesome2');
|
const tagOnClientSide = await testSmartsocketClient.socketConnection.getTagById('awesome2');
|
||||||
|
if (!tagOnClientSide) {
|
||||||
|
throw new Error('Expected client-side tag awesome2 to exist');
|
||||||
|
}
|
||||||
expect(tagOnClientSide.payload).toEqual('absolutely');
|
expect(tagOnClientSide.payload).toEqual('absolutely');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -142,6 +151,9 @@ tap.test('should be able to locate a connection tag after reconnect', async (too
|
|||||||
return true;
|
return true;
|
||||||
})
|
})
|
||||||
.getTagById('awesome');
|
.getTagById('awesome');
|
||||||
|
if (!tagOnServerSide) {
|
||||||
|
throw new Error('Expected server-side tag awesome to exist after reconnect');
|
||||||
|
}
|
||||||
expect(tagOnServerSide.payload).toEqual('yes');
|
expect(tagOnServerSide.payload).toEqual('yes');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -81,6 +81,9 @@ tap.test('should be able to tag a connection from client', async (tools) => {
|
|||||||
return true;
|
return true;
|
||||||
})
|
})
|
||||||
.getTagById('awesome');
|
.getTagById('awesome');
|
||||||
|
if (!tagOnServerSide) {
|
||||||
|
throw new Error('Expected server-side tag awesome to exist');
|
||||||
|
}
|
||||||
expect(tagOnServerSide.payload).toEqual('yes');
|
expect(tagOnServerSide.payload).toEqual('yes');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -93,7 +96,13 @@ tap.test('should be able to tag a connection from server', async (tools) => {
|
|||||||
id: 'awesome2',
|
id: 'awesome2',
|
||||||
payload: 'absolutely',
|
payload: 'absolutely',
|
||||||
});
|
});
|
||||||
|
if (!testSmartsocketClient.socketConnection) {
|
||||||
|
throw new Error('Expected client socket connection to exist');
|
||||||
|
}
|
||||||
const tagOnClientSide = await testSmartsocketClient.socketConnection.getTagById('awesome2');
|
const tagOnClientSide = await testSmartsocketClient.socketConnection.getTagById('awesome2');
|
||||||
|
if (!tagOnClientSide) {
|
||||||
|
throw new Error('Expected client-side tag awesome2 to exist');
|
||||||
|
}
|
||||||
expect(tagOnClientSide.payload).toEqual('absolutely');
|
expect(tagOnClientSide.payload).toEqual('absolutely');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -135,6 +144,9 @@ tap.test('should be able to locate a connection tag after reconnect', async (too
|
|||||||
return true;
|
return true;
|
||||||
})
|
})
|
||||||
.getTagById('awesome');
|
.getTagById('awesome');
|
||||||
|
if (!tagOnServerSide) {
|
||||||
|
throw new Error('Expected server-side tag awesome to exist after reconnect');
|
||||||
|
}
|
||||||
expect(tagOnServerSide.payload).toEqual('yes');
|
expect(tagOnServerSide.payload).toEqual('yes');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@push.rocks/smartsocket',
|
name: '@push.rocks/smartsocket',
|
||||||
version: '4.0.0',
|
version: '4.0.1',
|
||||||
description: 'Provides easy and secure websocket communication mechanisms, including server and client implementation, function call routing, connection management, and tagging.'
|
description: 'Provides easy and secure websocket communication mechanisms, including server and client implementation, function call routing, connection management, and tagging.'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,10 +28,10 @@ export class SmartsocketClient {
|
|||||||
public shortId = plugins.isounique.uni();
|
public shortId = plugins.isounique.uni();
|
||||||
|
|
||||||
// the shortId of the remote we connect to
|
// the shortId of the remote we connect to
|
||||||
public remoteShortId: string = null;
|
public remoteShortId: string | null = null;
|
||||||
|
|
||||||
public alias: string;
|
public alias: string;
|
||||||
public socketConnection: SocketConnection;
|
public socketConnection?: SocketConnection;
|
||||||
public serverUrl: string;
|
public serverUrl: string;
|
||||||
public serverPort: number;
|
public serverPort: number;
|
||||||
public autoReconnect: boolean;
|
public autoReconnect: boolean;
|
||||||
@@ -50,7 +50,7 @@ export class SmartsocketClient {
|
|||||||
|
|
||||||
// tagStore
|
// tagStore
|
||||||
private tagStore: { [key: string]: interfaces.ITag } = {};
|
private tagStore: { [key: string]: interfaces.ITag } = {};
|
||||||
private tagStoreSubscription: plugins.smartrx.rxjs.Subscription;
|
private tagStoreSubscription?: plugins.smartrx.rxjs.Subscription;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* adds a tag to a connection
|
* adds a tag to a connection
|
||||||
@@ -86,7 +86,7 @@ export class SmartsocketClient {
|
|||||||
this.alias = optionsArg.alias;
|
this.alias = optionsArg.alias;
|
||||||
this.serverUrl = optionsArg.url;
|
this.serverUrl = optionsArg.url;
|
||||||
this.serverPort = optionsArg.port;
|
this.serverPort = optionsArg.port;
|
||||||
this.autoReconnect = optionsArg.autoReconnect;
|
this.autoReconnect = optionsArg.autoReconnect ?? false;
|
||||||
this.maxRetries = optionsArg.maxRetries ?? 100; // Default to 100 retries
|
this.maxRetries = optionsArg.maxRetries ?? 100; // Default to 100 retries
|
||||||
this.initialBackoffDelay = optionsArg.initialBackoffDelay ?? 1000; // Default to 1 second
|
this.initialBackoffDelay = optionsArg.initialBackoffDelay ?? 1000; // Default to 1 second
|
||||||
this.maxBackoffDelay = optionsArg.maxBackoffDelay ?? 60000; // Default to 1 minute
|
this.maxBackoffDelay = optionsArg.maxBackoffDelay ?? 60000; // Default to 1 minute
|
||||||
@@ -148,6 +148,7 @@ export class SmartsocketClient {
|
|||||||
smartsocketHost: this,
|
smartsocketHost: this,
|
||||||
socket: socket as any,
|
socket: socket as any,
|
||||||
});
|
});
|
||||||
|
const socketConnection = this.socketConnection;
|
||||||
|
|
||||||
// Increment attempt ID to invalidate any pending timers from previous attempts
|
// Increment attempt ID to invalidate any pending timers from previous attempts
|
||||||
this.connectionAttemptId++;
|
this.connectionAttemptId++;
|
||||||
@@ -183,7 +184,7 @@ export class SmartsocketClient {
|
|||||||
this.remoteShortId = authRequestPayload.serverAlias;
|
this.remoteShortId = authRequestPayload.serverAlias;
|
||||||
|
|
||||||
// Send authentication data
|
// Send authentication data
|
||||||
this.socketConnection.sendMessage({
|
socketConnection.sendMessage({
|
||||||
type: 'auth',
|
type: 'auth',
|
||||||
payload: { alias: this.alias },
|
payload: { alias: this.alias },
|
||||||
});
|
});
|
||||||
@@ -193,7 +194,7 @@ export class SmartsocketClient {
|
|||||||
const authResponse = message.payload as interfaces.IAuthResponsePayload;
|
const authResponse = message.payload as interfaces.IAuthResponsePayload;
|
||||||
if (authResponse.success) {
|
if (authResponse.success) {
|
||||||
logger.log('info', 'client is authenticated');
|
logger.log('info', 'client is authenticated');
|
||||||
this.socketConnection.authenticated = true;
|
socketConnection.authenticated = true;
|
||||||
} else {
|
} else {
|
||||||
logger.log('warn', `authentication failed: ${authResponse.error}`);
|
logger.log('warn', `authentication failed: ${authResponse.error}`);
|
||||||
await this.disconnect();
|
await this.disconnect();
|
||||||
@@ -202,15 +203,15 @@ export class SmartsocketClient {
|
|||||||
|
|
||||||
case 'serverReady':
|
case 'serverReady':
|
||||||
// Set up function request listening
|
// Set up function request listening
|
||||||
await this.socketConnection.listenToFunctionRequests();
|
await socketConnection.listenToFunctionRequests();
|
||||||
|
|
||||||
// Handle retagging
|
// Handle retagging
|
||||||
const oldTagStore = this.tagStore;
|
const oldTagStore = this.tagStore;
|
||||||
this.tagStoreSubscription?.unsubscribe();
|
this.tagStoreSubscription?.unsubscribe();
|
||||||
for (const keyArg of Object.keys(this.tagStore)) {
|
for (const keyArg of Object.keys(this.tagStore)) {
|
||||||
this.socketConnection.addTag(this.tagStore[keyArg]);
|
socketConnection.addTag(this.tagStore[keyArg]);
|
||||||
}
|
}
|
||||||
this.tagStoreSubscription = this.socketConnection.tagStoreObservable.subscribe(
|
this.tagStoreSubscription = socketConnection.tagStoreObservable.subscribe(
|
||||||
(tagStoreArg) => {
|
(tagStoreArg) => {
|
||||||
this.tagStore = tagStoreArg;
|
this.tagStore = tagStoreArg;
|
||||||
}
|
}
|
||||||
@@ -226,7 +227,7 @@ export class SmartsocketClient {
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
// Other messages are handled by SocketConnection
|
// Other messages are handled by SocketConnection
|
||||||
this.socketConnection.handleMessage(message);
|
socketConnection.handleMessage(message);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -341,6 +342,9 @@ export class SmartsocketClient {
|
|||||||
functionNameArg: T['method'],
|
functionNameArg: T['method'],
|
||||||
dataArg: T['request']
|
dataArg: T['request']
|
||||||
): Promise<T['response']> {
|
): Promise<T['response']> {
|
||||||
|
if (!this.socketConnection) {
|
||||||
|
throw new Error('Cannot call server without an active socket connection');
|
||||||
|
}
|
||||||
const socketRequest = new SocketRequest<T>(this, {
|
const socketRequest = new SocketRequest<T>(this, {
|
||||||
side: 'requesting',
|
side: 'requesting',
|
||||||
originSocketConnection: this.socketConnection,
|
originSocketConnection: this.socketConnection,
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export type TSocketConnectionSide = 'server' | 'client';
|
|||||||
* interface for constructor of class SocketConnection
|
* interface for constructor of class SocketConnection
|
||||||
*/
|
*/
|
||||||
export interface ISocketConnectionConstructorOptions {
|
export interface ISocketConnectionConstructorOptions {
|
||||||
alias: string;
|
alias?: string;
|
||||||
authenticated: boolean;
|
authenticated: boolean;
|
||||||
side: TSocketConnectionSide;
|
side: TSocketConnectionSide;
|
||||||
smartsocketHost: Smartsocket | SmartsocketClient;
|
smartsocketHost: Smartsocket | SmartsocketClient;
|
||||||
@@ -43,7 +43,7 @@ export let allSocketConnections = new plugins.lik.ObjectMap<SocketConnection>();
|
|||||||
* class SocketConnection represents a websocket connection
|
* class SocketConnection represents a websocket connection
|
||||||
*/
|
*/
|
||||||
export class SocketConnection {
|
export class SocketConnection {
|
||||||
public alias: string;
|
public alias?: string;
|
||||||
public side: TSocketConnectionSide;
|
public side: TSocketConnectionSide;
|
||||||
public authenticated: boolean = false;
|
public authenticated: boolean = false;
|
||||||
public smartsocketRef: Smartsocket | SmartsocketClient;
|
public smartsocketRef: Smartsocket | SmartsocketClient;
|
||||||
@@ -97,6 +97,10 @@ export class SocketConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private handleFunctionCall(messageData: interfaces.ISocketMessage<interfaces.IFunctionCallPayload>): void {
|
private handleFunctionCall(messageData: interfaces.ISocketMessage<interfaces.IFunctionCallPayload>): void {
|
||||||
|
if (!messageData.id) {
|
||||||
|
logger.log('warn', 'received function call without request id');
|
||||||
|
return;
|
||||||
|
}
|
||||||
const requestData: ISocketRequestDataObject<any> = {
|
const requestData: ISocketRequestDataObject<any> = {
|
||||||
funcCallData: {
|
funcCallData: {
|
||||||
funcName: messageData.payload.funcName,
|
funcName: messageData.payload.funcName,
|
||||||
@@ -124,6 +128,10 @@ export class SocketConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private handleFunctionResponse(messageData: interfaces.ISocketMessage<interfaces.IFunctionCallPayload>): void {
|
private handleFunctionResponse(messageData: interfaces.ISocketMessage<interfaces.IFunctionCallPayload>): void {
|
||||||
|
if (!messageData.id) {
|
||||||
|
logger.log('warn', 'received function response without request id');
|
||||||
|
return;
|
||||||
|
}
|
||||||
const responseData: ISocketRequestDataObject<any> = {
|
const responseData: ISocketRequestDataObject<any> = {
|
||||||
funcCallData: {
|
funcCallData: {
|
||||||
funcName: messageData.payload.funcName,
|
funcName: messageData.payload.funcName,
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ export interface ISocketRequestConstructorOptions<
|
|||||||
side: TSocketRequestSide;
|
side: TSocketRequestSide;
|
||||||
originSocketConnection: SocketConnection;
|
originSocketConnection: SocketConnection;
|
||||||
shortId: string;
|
shortId: string;
|
||||||
funcCallData?: ISocketFunctionCallDataRequest<T>;
|
funcCallData: ISocketFunctionCallDataRequest<T>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ import { logger } from './smartsocket.logging.js';
|
|||||||
*/
|
*/
|
||||||
export class SocketServer {
|
export class SocketServer {
|
||||||
private smartsocket: Smartsocket;
|
private smartsocket: Smartsocket;
|
||||||
private httpServer: pluginsTyped.http.Server | pluginsTyped.https.Server;
|
private httpServer: pluginsTyped.http.Server | pluginsTyped.https.Server | null = null;
|
||||||
private wsServer: pluginsTyped.ws.WebSocketServer;
|
private wsServer: pluginsTyped.ws.WebSocketServer | null = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* whether httpServer is standalone (created by us)
|
* whether httpServer is standalone (created by us)
|
||||||
@@ -38,17 +38,19 @@ export class SocketServer {
|
|||||||
const httpModule = await this.smartsocket.smartenv.getSafeNodeModule('http');
|
const httpModule = await this.smartsocket.smartenv.getSafeNodeModule('http');
|
||||||
const wsModule = await this.smartsocket.smartenv.getSafeNodeModule('ws');
|
const wsModule = await this.smartsocket.smartenv.getSafeNodeModule('ws');
|
||||||
|
|
||||||
this.httpServer = httpModule.createServer();
|
const httpServer = httpModule.createServer();
|
||||||
|
this.httpServer = httpServer;
|
||||||
this.standaloneServer = true;
|
this.standaloneServer = true;
|
||||||
|
|
||||||
// Create WebSocket server attached to HTTP server
|
// Create WebSocket server attached to HTTP server
|
||||||
this.wsServer = new wsModule.WebSocketServer({ server: this.httpServer });
|
const wsServer = new wsModule.WebSocketServer({ server: httpServer });
|
||||||
|
this.wsServer = wsServer;
|
||||||
|
|
||||||
this.wsServer.on('connection', (ws: pluginsTyped.ws.WebSocket) => {
|
wsServer.on('connection', (ws: pluginsTyped.ws.WebSocket) => {
|
||||||
this.smartsocket.handleNewConnection(ws);
|
this.smartsocket.handleNewConnection(ws);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.httpServer.listen(this.smartsocket.options.port, () => {
|
httpServer.listen(this.smartsocket.options.port, () => {
|
||||||
logger.log(
|
logger.log(
|
||||||
'success',
|
'success',
|
||||||
`Server started in standalone mode on port ${this.smartsocket.options.port}`
|
`Server started in standalone mode on port ${this.smartsocket.options.port}`
|
||||||
|
|||||||
+4
-4
@@ -5,10 +5,10 @@
|
|||||||
"target": "ES2022",
|
"target": "ES2022",
|
||||||
"module": "NodeNext",
|
"module": "NodeNext",
|
||||||
"moduleResolution": "NodeNext",
|
"moduleResolution": "NodeNext",
|
||||||
|
"noImplicitAny": true,
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"verbatimModuleSyntax": true
|
"verbatimModuleSyntax": true,
|
||||||
|
"types": ["node"]
|
||||||
},
|
},
|
||||||
"exclude": [
|
"exclude": ["dist_*/**/*.d.ts"]
|
||||||
"dist_*/**/*.d.ts"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user