fix(core): update

This commit is contained in:
2019-09-10 09:56:32 +02:00
parent b258979b5a
commit 02a32eb8c7
5 changed files with 49 additions and 30 deletions

View File

@ -1,5 +1,5 @@
import * as plugins from './smartuniverse.plugins';
export class ReactionRequest {
}

View File

@ -59,7 +59,7 @@ export class UniverseCache {
UniverseChannel.authorizeAMessageForAChannel(this, messageArg);
this.messageMap.add(messageArg);
messageArg.universeChannelList.forEach(universeChannel => {
universeChannel.pushToClients(messageArg);
universeChannel.push(messageArg);
});
}

View File

@ -85,6 +85,7 @@ export class UniverseChannel {
*/
public name: string;
public universeRef: Universe;
private subject = new plugins.smartrx.rxjs.Subject<UniverseMessage>();
/**
* the passphrase for the channel
@ -113,7 +114,8 @@ export class UniverseChannel {
* pushes a message to clients
* @param messageArg
*/
public async pushToClients(messageArg: UniverseMessage) {
public async push(messageArg: UniverseMessage) {
this.subject.next(messageArg);
const universeConnectionsWithChannelAccess: UniverseConnection[] = [];
this.universeRef.universeCache.connectionMap.forEach(async socketConnection => {
if (socketConnection.authenticatedChannels.includes(this)) {
@ -139,4 +141,25 @@ export class UniverseChannel {
);
}
}
// functions to interact with a channel locally
public async subscribe(observer: plugins.smartrx.rxjs.Observer<any>) {
return this.subject.subscribe(observer);
}
/**
* sends a message to the channel
*/
public async sendMessage(messageDescriptor: interfaces.IMessageCreator) {
const messageToSend = new UniverseMessage({
id: plugins.smartunique.shortId(),
messageText: messageDescriptor.messageText,
payload: messageDescriptor.payload,
payloadStringType: messageDescriptor.payloadStringType,
targetChannelName: this.name,
passphrase: this.passphrase,
timestamp: Date.now()
});
this.push(messageToSend);
}
}