fix(core): update

This commit is contained in:
2023-07-25 11:33:13 +02:00
parent b5fcefa93b
commit 4ccbc004db
33 changed files with 5028 additions and 11607 deletions
+29 -39
View File
@@ -1,16 +1,15 @@
import * as plugins from './smartuniverse.plugins';
import * as pluginsTyped from './smartuniverse.pluginstyped';
import * as plugins from './smartuniverse.plugins.js';
import * as pluginsTyped from './smartuniverse.pluginstyped.js';
import { Handler, Route, Server } from '@pushrocks/smartexpress';
import { UniverseCache, UniverseChannel, UniverseMessage } from './';
import { UniverseCache, UniverseChannel, UniverseMessage } from './index.js';
import * as interfaces from './interfaces';
import { UniverseConnection } from './smartuniverse.classes.universeconnection';
import { logger } from './smartuniverse.logging';
import * as interfaces from './interfaces/index.js';
import { UniverseConnection } from './smartuniverse.classes.universeconnection.js';
import { logger } from './smartuniverse.logging.js';
export interface ISmartUniverseConstructorOptions {
messageExpiryInMilliseconds: number;
externalServer?: pluginsTyped.smartexpress.Server;
externalServer?: pluginsTyped.typedserver.servertools.Server;
}
/**
@@ -26,7 +25,7 @@ export class Universe {
/**
* the smartexpress server used
*/
private smartexpressServer: pluginsTyped.smartexpress.Server;
private server: pluginsTyped.typedserver.servertools.Server;
/**
* the smartsocket used
@@ -69,7 +68,7 @@ export class Universe {
* returns a channel
*/
public getChannel(channelNameArg: string) {
return this.universeCache.channelMap.find((channelArg) => {
return this.universeCache.channelMap.findSync((channelArg) => {
return channelArg.name === channelNameArg;
});
}
@@ -86,44 +85,35 @@ export class Universe {
// add websocket upgrade
this.smartsocket = new plugins.smartsocket.Smartsocket({
port: portArg
alias: 'smartuniverse',
port: portArg,
});
// lets create the base smartexpress server
if (this.options.externalServer) {
console.log('Universe is using externally supplied server');
this.smartsocket.setExternalServer('smartexpress' ,this.options.externalServer);
this.smartsocket.setExternalServer('smartexpress', this.options.externalServer);
}
// add a role for the clients
const ClientRole = new plugins.smartsocket.SocketRole({
name: 'UniverseClient',
passwordHash: await plugins.isohash.sha256FromString('UniverseClient'), // authentication happens on another level
});
// add the role to smartsocket
this.smartsocket.addSocketRoles([ClientRole]);
const socketFunctionSubscription =
new plugins.smartsocket.SocketFunction<interfaces.ISocketRequest_SubscribeChannel>({
funcName: 'subscribeChannel',
funcDef: async (dataArg, socketConnectionArg) => {
const universeConnection = new UniverseConnection({
universe: this,
socketConnection: socketConnectionArg,
authenticationRequests: [dataArg],
});
await UniverseConnection.addConnectionToCache(this, universeConnection);
return {
subscriptionStatus: 'subscribed',
};
},
});
const socketFunctionSubscription = new plugins.smartsocket.SocketFunction<
interfaces.ISocketRequest_SubscribeChannel
>({
allowedRoles: [ClientRole], // there is only one client role, Authentication happens on another level
funcName: 'subscribeChannel',
funcDef: async (dataArg, socketConnectionArg) => {
const universeConnection = new UniverseConnection({
universe: this,
socketConnection: socketConnectionArg,
authenticationRequests: [dataArg],
});
await UniverseConnection.addConnectionToCache(this, universeConnection);
return {
subscriptionStatus: 'subscribed',
};
},
});
const socketFunctionProcessMessage = new plugins.smartsocket.SocketFunction<any>({ // TODO proper ITypedRequest here instead of any
allowedRoles: [ClientRole], // there is only one client role, Authentication happens on another level
const socketFunctionProcessMessage = new plugins.smartsocket.SocketFunction<any>({
// TODO proper ITypedRequest here instead of any
funcName: 'processMessage',
funcDef: async (messageDataArg: interfaces.IUniverseMessage, socketConnectionArg) => {
const universeConnection = UniverseConnection.findUniverseConnectionBySocketConnection(