fix(types,client,server): improve type safety and harden client/server message handling

This commit is contained in:
2026-05-01 11:22:06 +00:00
parent 496fd9a81a
commit 3ac4c2e708
22 changed files with 9276 additions and 3895 deletions
@@ -69,8 +69,12 @@ export class ClientUniverseChannel implements interfaces.IUniverseChannel {
public async populateSubscriptionToServer() {
// lets make sure the channel is connected
if (this.status === 'unsubscribed') {
const smartsocketClient = this.clientUniverseRef.smartsocketClient;
if (!smartsocketClient) {
throw new Error('Cannot subscribe channel before the smartuniverse client is connected.');
}
const response =
await this.clientUniverseRef.smartsocketClient.serverCall<interfaces.ISocketRequest_SubscribeChannel>(
await smartsocketClient.serverCall<interfaces.ISocketRequest_SubscribeChannel>(
'subscribeChannel',
{
name: this.name,
@@ -91,6 +95,10 @@ export class ClientUniverseChannel implements interfaces.IUniverseChannel {
*/
public async postMessage(messageArg: interfaces.IMessageCreator) {
await this.clientUniverseRef.start(); // its ok to call this multiple times
const smartsocketClient = this.clientUniverseRef.smartsocketClient;
if (!smartsocketClient) {
throw new Error('Cannot post message before the smartuniverse client is connected.');
}
const universeMessageToSend: interfaces.IUniverseMessage = {
id: plugins.isounique.uni(),
timestamp: Date.now(),
@@ -99,7 +107,7 @@ export class ClientUniverseChannel implements interfaces.IUniverseChannel {
messageText: messageArg.messageText,
payload: messageArg.payload,
};
await this.clientUniverseRef.smartsocketClient.serverCall(
await smartsocketClient.serverCall<interfaces.ISocketRequest_ProcessMessage>(
'processMessage',
universeMessageToSend
);