fix(core): update
This commit is contained in:
parent
7998d79b13
commit
051aba3299
@ -50,9 +50,8 @@ tap.test('should get a observable correctly', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should send a message correctly', async () => {
|
tap.test('should send a message correctly', async () => {
|
||||||
await testClientUniverse.sendMessage({
|
await (await testClientUniverse.getChannel(testChannelData.channelName)).sendMessage({
|
||||||
messageText: 'hello',
|
messageText: 'hello'
|
||||||
targetChannelName: testChannelData.channelName
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -2,9 +2,11 @@ export interface IMessageCreator {
|
|||||||
messageText: string;
|
messageText: string;
|
||||||
payload?: string | number | any;
|
payload?: string | number | any;
|
||||||
payloadStringType?: 'Buffer' | 'string' | 'object';
|
payloadStringType?: 'Buffer' | 'string' | 'object';
|
||||||
targetChannelName: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
export interface IUniverseMessage extends IMessageCreator {
|
export interface IUniverseMessage extends IMessageCreator {
|
||||||
id: string;
|
id: string;
|
||||||
/**
|
/**
|
||||||
@ -12,4 +14,5 @@ export interface IUniverseMessage extends IMessageCreator {
|
|||||||
*/
|
*/
|
||||||
timestamp: number;
|
timestamp: number;
|
||||||
passphrase: string;
|
passphrase: string;
|
||||||
|
targetChannelName: string;
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ export class ClientUniverse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// lets create the channel
|
// lets create the channel
|
||||||
ClientUniverseChannel.createClientUniverseChannel(this, channelNameArg, passphraseArg);
|
await ClientUniverseChannel.createClientUniverseChannel(this, channelNameArg, passphraseArg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -68,21 +68,6 @@ export class ClientUniverse {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* sends a message towards the server
|
|
||||||
* @param messageArg
|
|
||||||
*/
|
|
||||||
public async sendMessage(messageArg: interfaces.IMessageCreator) {
|
|
||||||
await this.checkConnection();
|
|
||||||
const universeMessageToSend: interfaces.IUniverseMessage = {
|
|
||||||
id: plugins.smartunique.shortId(),
|
|
||||||
timestamp: Date.now(),
|
|
||||||
passphrase: (await this.getChannel(messageArg.targetChannelName)).passphrase,
|
|
||||||
...messageArg
|
|
||||||
};
|
|
||||||
await this.smartsocketClient.serverCall('processMessage', universeMessageToSend);
|
|
||||||
}
|
|
||||||
|
|
||||||
public close() {
|
public close() {
|
||||||
this.smartsocketClient.disconnect();
|
this.smartsocketClient.disconnect();
|
||||||
}
|
}
|
||||||
@ -91,7 +76,7 @@ export class ClientUniverse {
|
|||||||
* checks the connection towards a universe server
|
* checks the connection towards a universe server
|
||||||
* since password validation is done through other means, a connection should always be possible
|
* since password validation is done through other means, a connection should always be possible
|
||||||
*/
|
*/
|
||||||
private async checkConnection(): Promise<void> {
|
public async checkConnection(): Promise<void> {
|
||||||
if (!this.smartsocketClient && !this.observableIntake) {
|
if (!this.smartsocketClient && !this.observableIntake) {
|
||||||
const parsedURL = url.parse(this.options.serverAddress);
|
const parsedURL = url.parse(this.options.serverAddress);
|
||||||
const socketConfig: plugins.smartsocket.ISmartsocketClientOptions = {
|
const socketConfig: plugins.smartsocket.ISmartsocketClientOptions = {
|
||||||
|
@ -37,10 +37,10 @@ export class ClientUniverseChannel implements interfaces.IUniverseChannel {
|
|||||||
public passphrase: string;
|
public passphrase: string;
|
||||||
|
|
||||||
// refs
|
// refs
|
||||||
public clientUniverse: ClientUniverse;
|
public clientUniverseRef: ClientUniverse;
|
||||||
|
|
||||||
constructor(clientUniverseArg: ClientUniverse, nameArg: string, passphraseArg: string) {
|
constructor(clientUniverseArg: ClientUniverse, nameArg: string, passphraseArg: string) {
|
||||||
this.clientUniverse = clientUniverseArg;
|
this.clientUniverseRef = clientUniverseArg;
|
||||||
this.name = nameArg;
|
this.name = nameArg;
|
||||||
this.passphrase = passphraseArg;
|
this.passphrase = passphraseArg;
|
||||||
}
|
}
|
||||||
@ -55,6 +55,24 @@ export class ClientUniverseChannel implements interfaces.IUniverseChannel {
|
|||||||
name: this.name,
|
name: this.name,
|
||||||
passphrase: this.passphrase
|
passphrase: this.passphrase
|
||||||
};
|
};
|
||||||
this.clientUniverse.smartsocketClient.serverCall(serverCallActionName, serverCallActionPayload);
|
await this.clientUniverseRef.smartsocketClient.serverCall(serverCallActionName, serverCallActionPayload);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sends a message towards the server
|
||||||
|
* @param messageArg
|
||||||
|
*/
|
||||||
|
public async sendMessage(messageArg: interfaces.IMessageCreator) {
|
||||||
|
await this.clientUniverseRef.checkConnection();
|
||||||
|
const universeMessageToSend: interfaces.IUniverseMessage = {
|
||||||
|
id: plugins.smartunique.shortId(),
|
||||||
|
timestamp: Date.now(),
|
||||||
|
passphrase: this.passphrase,
|
||||||
|
targetChannelName: this.name,
|
||||||
|
messageText: messageArg.messageText,
|
||||||
|
payload: messageArg.payload,
|
||||||
|
payloadStringType: messageArg.payloadStringType
|
||||||
|
};
|
||||||
|
await this.clientUniverseRef.smartsocketClient.serverCall('processMessage', universeMessageToSend);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -124,16 +124,9 @@ export class Universe {
|
|||||||
if (universeConnection) {
|
if (universeConnection) {
|
||||||
console.log('found UniverseConnection for socket');
|
console.log('found UniverseConnection for socket');
|
||||||
} else {
|
} else {
|
||||||
console.log('universe client not yet present');
|
return {
|
||||||
console.log('creating one now as send only');
|
error: 'You need to authenticate for a channel'
|
||||||
const universeConnectionInstance = new UniverseConnection({
|
};
|
||||||
socketConnection: socketConnectionArg,
|
|
||||||
authenticationRequests: []
|
|
||||||
});
|
|
||||||
await UniverseConnection.addConnectionToCache(
|
|
||||||
this.universeCache,
|
|
||||||
universeConnectionInstance
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
const unauthenticatedMessage = UniverseMessage.createMessageFromPayload(dataArg);
|
const unauthenticatedMessage = UniverseMessage.createMessageFromPayload(dataArg);
|
||||||
const foundChannel = await UniverseChannel.authorizeAMessageForAChannel(
|
const foundChannel = await UniverseChannel.authorizeAMessageForAChannel(
|
||||||
|
@ -23,6 +23,7 @@ export class UniverseConnection {
|
|||||||
universeConnection = await UniverseConnection.authenticateAuthenticationRequests(
|
universeConnection = await UniverseConnection.authenticateAuthenticationRequests(
|
||||||
universeConnection
|
universeConnection
|
||||||
);
|
);
|
||||||
|
universeCache.connectionMap.add(universeConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user