fix(core): update
This commit is contained in:
parent
6e2e2768e2
commit
2f51e10fc4
@ -3,7 +3,7 @@ import * as plugins from './typedsocket.plugins';
|
||||
const publicRoleName = 'publicRoleName';
|
||||
const publicRolePass = 'publicRolePass';
|
||||
|
||||
export type TTypedSocketSide = 'server' | 'client';
|
||||
export type TTypedSocketSide = 'server' | 'client';
|
||||
|
||||
export class TypedSocket {
|
||||
// STATIC
|
||||
@ -11,7 +11,7 @@ export class TypedSocket {
|
||||
* creates a typedsocket server
|
||||
* note: this will fail in browser environments as server libs are not bundled.
|
||||
*/
|
||||
public static async createServer(
|
||||
public static async createServer (
|
||||
typedrouterArg: plugins.typedrequest.TypedRouter,
|
||||
smartexpressServerArg?: any
|
||||
): Promise<TypedSocket> {
|
||||
@ -22,7 +22,7 @@ export class TypedSocket {
|
||||
if (smartexpressServerArg) {
|
||||
smartsocketServer.setExternalServer('smartexpress', smartexpressServerArg);
|
||||
}
|
||||
|
||||
|
||||
smartsocketServer.socketFunctions.add(
|
||||
new plugins.smartsocket.SocketFunction({
|
||||
funcName: 'processMessage',
|
||||
@ -34,7 +34,7 @@ export class TypedSocket {
|
||||
const typedsocket = new TypedSocket(
|
||||
'server',
|
||||
typedrouterArg,
|
||||
async <T extends plugins.typedrequestInterfaces.ITypedRequest>(
|
||||
async <T extends plugins.typedrequestInterfaces.ITypedRequest> (
|
||||
dataArg: T,
|
||||
targetConnectionArg?: plugins.smartsocket.SocketConnection
|
||||
): Promise<T> => {
|
||||
@ -43,7 +43,7 @@ export class TypedSocket {
|
||||
console.log(
|
||||
'Since no targetConnection was supplied and there is only one active one present, choosing that one automatically'
|
||||
);
|
||||
targetConnectionArg = smartsocketServer.socketConnections.getArray()[0];
|
||||
targetConnectionArg = smartsocketServer.socketConnections.getArray()[ 0 ];
|
||||
} else {
|
||||
throw new Error('you need to specify the wanted targetConnection. Currently no target is selectable automatically.');
|
||||
}
|
||||
@ -62,7 +62,7 @@ export class TypedSocket {
|
||||
return typedsocket;
|
||||
}
|
||||
|
||||
public static async createClient(
|
||||
public static async createClient (
|
||||
typedrouterArg: plugins.typedrequest.TypedRouter,
|
||||
serverUrlArg: string,
|
||||
aliasArg = 'clientArg'
|
||||
@ -89,7 +89,7 @@ export class TypedSocket {
|
||||
const typedsocket = new TypedSocket(
|
||||
'client',
|
||||
typedrouterArg,
|
||||
async <T extends plugins.typedrequestInterfaces.ITypedRequest>(dataArg: T): Promise<T> => {
|
||||
async <T extends plugins.typedrequestInterfaces.ITypedRequest> (dataArg: T): Promise<T> => {
|
||||
const response: T = (smartsocketClient.serverCall('processMessage', dataArg) as any) as T;
|
||||
return response;
|
||||
},
|
||||
@ -122,7 +122,7 @@ export class TypedSocket {
|
||||
this.socketServerOrClient = socketServerOrClientArg;
|
||||
}
|
||||
|
||||
public addTag(keyArg: string, payloadArg: any) {
|
||||
public addTag (keyArg: string, payloadArg: any) {
|
||||
if (this.side === 'client' && this.socketServerOrClient instanceof plugins.smartsocket.SmartsocketClient) {
|
||||
this.socketServerOrClient.socketConnection.addTag({
|
||||
id: keyArg,
|
||||
@ -133,8 +133,8 @@ export class TypedSocket {
|
||||
}
|
||||
}
|
||||
|
||||
public createTypedRequest<T extends plugins.typedrequestInterfaces.ITypedRequest>(
|
||||
methodName: T['method'],
|
||||
public createTypedRequest<T extends plugins.typedrequestInterfaces.ITypedRequest> (
|
||||
methodName: T[ 'method' ],
|
||||
targetConnection?: plugins.smartsocket.SocketConnection
|
||||
): plugins.typedrequest.TypedRequest<T> {
|
||||
const typedrequest = new plugins.typedrequest.TypedRequest<T>(
|
||||
@ -154,7 +154,7 @@ export class TypedSocket {
|
||||
* @param asyncFindFuncArg
|
||||
* @returns
|
||||
*/
|
||||
public async findAllTargetConnections(
|
||||
public async findAllTargetConnections (
|
||||
asyncFindFuncArg: (connectionArg: plugins.smartsocket.SocketConnection) => Promise<boolean>
|
||||
) {
|
||||
if (this.socketServerOrClient instanceof plugins.smartsocket.Smartsocket) {
|
||||
@ -175,31 +175,31 @@ export class TypedSocket {
|
||||
* @param asyncFindFuncArg
|
||||
* @returns
|
||||
*/
|
||||
public async findTargetConnection(
|
||||
public async findTargetConnection (
|
||||
asyncFindFuncArg: (connectionArg: plugins.smartsocket.SocketConnection) => Promise<boolean>
|
||||
) {
|
||||
const allMatching = await this.findAllTargetConnections(asyncFindFuncArg);
|
||||
return allMatching[0];
|
||||
return allMatching[ 0 ];
|
||||
}
|
||||
|
||||
public async findAllTargetConnectionsByTag(keyArg: string, payloadArg?: any) {
|
||||
public async findAllTargetConnectionsByTag (keyArg: string, payloadArg?: any) {
|
||||
return this.findAllTargetConnections(async socketConnectionArg => {
|
||||
let result: boolean;
|
||||
if (!payloadArg) {
|
||||
result = !!(await socketConnectionArg.getTagById(keyArg));
|
||||
} else {
|
||||
result = !!(await socketConnectionArg.getTagById(keyArg)) === payloadArg;
|
||||
result = !!((await socketConnectionArg.getTagById(keyArg)).payload === payloadArg);
|
||||
}
|
||||
return result;
|
||||
})
|
||||
}
|
||||
|
||||
public async findTargetConnectionByTag(keyArg: string, payloadArg?: any) {
|
||||
public async findTargetConnectionByTag (keyArg: string, payloadArg?: any) {
|
||||
const allResults = await this.findAllTargetConnectionsByTag(keyArg, payloadArg)
|
||||
return allResults[0];
|
||||
return allResults[ 0 ];
|
||||
}
|
||||
|
||||
public async stop() {
|
||||
public async stop () {
|
||||
await this.socketServerOrClient.stop()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user