Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
c2052f16a8 | |||
ff7cdc908c | |||
f3d41b8719 | |||
f9f0fc45e2 | |||
da6b7724b8 | |||
be7ca29e4b | |||
f401d78c4b | |||
6ceec0201f | |||
16ce4e09a9 | |||
2868ab686d | |||
5dab36382f | |||
02a32eb8c7 |
42
package-lock.json
generated
42
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartuniverse",
|
"name": "@pushrocks/smartuniverse",
|
||||||
"version": "1.0.74",
|
"version": "1.0.80",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@ -305,20 +305,23 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@pushrocks/smartrx": {
|
"@pushrocks/smartrx": {
|
||||||
"version": "2.0.3",
|
"version": "2.0.5",
|
||||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartrx/-/smartrx-2.0.3.tgz",
|
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartrx/-/smartrx-2.0.5.tgz",
|
||||||
"integrity": "sha512-OWxagu+CBdPaq76AIg91hJyrNhDTlEpesj01ooWCeVIaLY3G7yvFkqHsEKNOwPUG1LzCWmjq1l1dHQx9p2vJ9A==",
|
"integrity": "sha512-BOlIJmnCO8pxqu9f18D9UV5rIsyrmKeK/mWNMiAe/NH2OTeRPNLpgmhZBkXSKNVD8tSsD8aazs4BcACgYOg1FQ==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@pushrocks/lik": "^3.0.2",
|
"@pushrocks/lik": "^3.0.11",
|
||||||
"@pushrocks/smartevent": "^2.0.3",
|
"@pushrocks/smartevent": "^2.0.3",
|
||||||
"@pushrocks/smartpromise": "^2.0.5",
|
"@pushrocks/smartpromise": "^3.0.2",
|
||||||
"rxjs": "^6.3.3"
|
"rxjs": "^6.5.3"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartpromise": {
|
"rxjs": {
|
||||||
"version": "2.0.5",
|
"version": "6.5.3",
|
||||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartpromise/-/smartpromise-2.0.5.tgz",
|
"resolved": "https://verdaccio.lossless.one/rxjs/-/rxjs-6.5.3.tgz",
|
||||||
"integrity": "sha512-9j/chLtIiNkR0MDw7Mpxg9slxAVvAQwUZuiaPYX5KpHdKxQaHLI1VZ8IN0vPhwlfgNO4i4vGXV0wB8BvSDj03g=="
|
"integrity": "sha512-wuYsAYYFdWTAnAaPoKGNhfpWwKZbJW+HgAJ+mImp+Epl7BG8oNWBCTyRM8gba9k4lk8BgWdoYm21Mo/RYhhbgA==",
|
||||||
|
"requires": {
|
||||||
|
"tslib": "^1.9.0"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -2382,6 +2385,7 @@
|
|||||||
"version": "6.4.0",
|
"version": "6.4.0",
|
||||||
"resolved": "https://verdaccio.lossless.one/rxjs/-/rxjs-6.4.0.tgz",
|
"resolved": "https://verdaccio.lossless.one/rxjs/-/rxjs-6.4.0.tgz",
|
||||||
"integrity": "sha512-Z9Yfa11F6B9Sg/BK9MnqnQ+aQYicPLtilXBp2yUtDt2JRCE0h26d33EnfO3ZxoNxG0T92OUucP3Ct7cpfkdFfw==",
|
"integrity": "sha512-Z9Yfa11F6B9Sg/BK9MnqnQ+aQYicPLtilXBp2yUtDt2JRCE0h26d33EnfO3ZxoNxG0T92OUucP3Ct7cpfkdFfw==",
|
||||||
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"tslib": "^1.9.0"
|
"tslib": "^1.9.0"
|
||||||
}
|
}
|
||||||
@ -2769,16 +2773,16 @@
|
|||||||
"integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ=="
|
"integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ=="
|
||||||
},
|
},
|
||||||
"tslint": {
|
"tslint": {
|
||||||
"version": "5.19.0",
|
"version": "5.20.0",
|
||||||
"resolved": "https://registry.npmjs.org/tslint/-/tslint-5.19.0.tgz",
|
"resolved": "https://verdaccio.lossless.one/tslint/-/tslint-5.20.0.tgz",
|
||||||
"integrity": "sha512-1LwwtBxfRJZnUvoS9c0uj8XQtAnyhWr9KlNvDIdB+oXyT+VpsOAaEhEgKi1HrZ8rq0ki/AAnbGSv4KM6/AfVZw==",
|
"integrity": "sha512-2vqIvkMHbnx8acMogAERQ/IuINOq6DFqgF8/VDvhEkBqQh/x6SP0Y+OHnKth9/ZcHQSroOZwUQSN18v8KKF0/g==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"@babel/code-frame": "^7.0.0",
|
"@babel/code-frame": "^7.0.0",
|
||||||
"builtin-modules": "^1.1.1",
|
"builtin-modules": "^1.1.1",
|
||||||
"chalk": "^2.3.0",
|
"chalk": "^2.3.0",
|
||||||
"commander": "^2.12.1",
|
"commander": "^2.12.1",
|
||||||
"diff": "^3.2.0",
|
"diff": "^4.0.1",
|
||||||
"glob": "^7.1.1",
|
"glob": "^7.1.1",
|
||||||
"js-yaml": "^3.13.1",
|
"js-yaml": "^3.13.1",
|
||||||
"minimatch": "^3.0.4",
|
"minimatch": "^3.0.4",
|
||||||
@ -2787,14 +2791,6 @@
|
|||||||
"semver": "^5.3.0",
|
"semver": "^5.3.0",
|
||||||
"tslib": "^1.8.0",
|
"tslib": "^1.8.0",
|
||||||
"tsutils": "^2.29.0"
|
"tsutils": "^2.29.0"
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"diff": {
|
|
||||||
"version": "3.5.0",
|
|
||||||
"resolved": "https://verdaccio.lossless.one/diff/-/diff-3.5.0.tgz",
|
|
||||||
"integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==",
|
|
||||||
"dev": true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"tslint-config-prettier": {
|
"tslint-config-prettier": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartuniverse",
|
"name": "@pushrocks/smartuniverse",
|
||||||
"version": "1.0.74",
|
"version": "1.0.80",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "messaging service for your micro services",
|
"description": "messaging service for your micro services",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
@ -18,13 +18,14 @@
|
|||||||
"@gitzone/tstest": "^1.0.24",
|
"@gitzone/tstest": "^1.0.24",
|
||||||
"@pushrocks/tapbundle": "^3.0.13",
|
"@pushrocks/tapbundle": "^3.0.13",
|
||||||
"@types/node": "^12.7.4",
|
"@types/node": "^12.7.4",
|
||||||
"tslint": "^5.19.0",
|
"tslint": "^5.20.0",
|
||||||
"tslint-config-prettier": "^1.18.0"
|
"tslint-config-prettier": "^1.18.0"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"rxjs": "*"
|
"rxjs": "*"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@apiglobal/typedrequest-interfaces": "^1.0.7",
|
||||||
"@pushrocks/lik": "^3.0.11",
|
"@pushrocks/lik": "^3.0.11",
|
||||||
"@pushrocks/smartdelay": "^2.0.3",
|
"@pushrocks/smartdelay": "^2.0.3",
|
||||||
"@pushrocks/smartexpress": "^3.0.40",
|
"@pushrocks/smartexpress": "^3.0.40",
|
||||||
@ -33,7 +34,7 @@
|
|||||||
"@pushrocks/smartlog": "^2.0.19",
|
"@pushrocks/smartlog": "^2.0.19",
|
||||||
"@pushrocks/smartpromise": "^3.0.2",
|
"@pushrocks/smartpromise": "^3.0.2",
|
||||||
"@pushrocks/smartrequest": "^1.1.27",
|
"@pushrocks/smartrequest": "^1.1.27",
|
||||||
"@pushrocks/smartrx": "^2.0.3",
|
"@pushrocks/smartrx": "^2.0.5",
|
||||||
"@pushrocks/smartsocket": "^1.1.49",
|
"@pushrocks/smartsocket": "^1.1.49",
|
||||||
"@pushrocks/smarttime": "^3.0.12",
|
"@pushrocks/smarttime": "^3.0.12",
|
||||||
"@pushrocks/smartunique": "^3.0.1"
|
"@pushrocks/smartunique": "^3.0.1"
|
||||||
|
15
test/test.ts
15
test/test.ts
@ -69,9 +69,22 @@ tap.test('a second client should be able to subscibe', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
testClientUniverse2.addChannel(testChannelData.channelName, testChannelData.channelPass);
|
testClientUniverse2.addChannel(testChannelData.channelName, testChannelData.channelPass);
|
||||||
|
await testClientUniverse2.start();
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should receive a message correctly', async () => {});
|
tap.test('should receive a message correctly', async (tools) => {
|
||||||
|
const done = tools.defer();
|
||||||
|
const testChannel = testClientUniverse.getChannel(testChannelData.channelName);
|
||||||
|
const testChannel2 = testClientUniverse2.getChannel(testChannelData.channelName);
|
||||||
|
const subscription = testChannel2.subscribe(messageArg => {
|
||||||
|
console.log('Yay##########');
|
||||||
|
done.resolve();
|
||||||
|
});
|
||||||
|
await testChannel.sendMessage({
|
||||||
|
messageText: 'hellothere'
|
||||||
|
});
|
||||||
|
await done.promise;
|
||||||
|
});
|
||||||
|
|
||||||
tap.test('should disconnect the client correctly', async () => {
|
tap.test('should disconnect the client correctly', async () => {
|
||||||
await testClientUniverse.stop();
|
await testClientUniverse.stop();
|
||||||
|
@ -9,4 +9,8 @@ export * from './smartuniverse.classes.universecache';
|
|||||||
export * from './smartuniverse.classes.universechannel';
|
export * from './smartuniverse.classes.universechannel';
|
||||||
export * from './smartuniverse.classes.universemessage';
|
export * from './smartuniverse.classes.universemessage';
|
||||||
|
|
||||||
|
// Reaction Response
|
||||||
|
export * from './smartuniverse.classes.reactionrequest';
|
||||||
|
export * from './smartuniverse.classes.reactionresponse';
|
||||||
|
|
||||||
export * from './interfaces';
|
export * from './interfaces';
|
||||||
|
@ -7,7 +7,7 @@ export interface ISocketRequest_SubscribeChannel {
|
|||||||
passphrase: string;
|
passphrase: string;
|
||||||
};
|
};
|
||||||
response: {
|
response: {
|
||||||
subscriptionStatus: 'subscribed' | 'unsubscribed'
|
subscriptionStatus: 'subscribed' | 'unsubscribed';
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -15,6 +15,6 @@ export interface ISocketRequest_ProcessMessage {
|
|||||||
method: 'processMessage';
|
method: 'processMessage';
|
||||||
request: interfaces.IUniverseMessage;
|
request: interfaces.IUniverseMessage;
|
||||||
response: {
|
response: {
|
||||||
messageStatus: 'ok' | 'channel not found'
|
messageStatus: 'ok' | 'channel not found';
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,3 @@
|
|||||||
export type IServerCallActions =
|
|
||||||
| 'channelSubscription'
|
|
||||||
| 'processMessage'
|
|
||||||
| 'channelUnsubscribe'
|
|
||||||
| 'terminateConnection';
|
|
||||||
|
|
||||||
|
|
||||||
export interface IServerUnsubscribeActionPayload {
|
export interface IServerUnsubscribeActionPayload {
|
||||||
name: string;
|
name: string;
|
||||||
}
|
}
|
||||||
|
@ -147,7 +147,7 @@ export class ClientUniverse {
|
|||||||
await this.smartsocketClient.connect();
|
await this.smartsocketClient.connect();
|
||||||
plugins.smartlog.defaultLogger.log('info', 'universe client connected successfully');
|
plugins.smartlog.defaultLogger.log('info', 'universe client connected successfully');
|
||||||
await this.clientUniverseCache.channelMap.forEach(async clientUniverseChannelArg => {
|
await this.clientUniverseCache.channelMap.forEach(async clientUniverseChannelArg => {
|
||||||
await clientUniverseChannelArg.subscribe();
|
await clientUniverseChannelArg.populateSubscriptionToServer();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,34 +53,33 @@ export class ClientUniverseChannel implements interfaces.IUniverseChannel {
|
|||||||
* subscribes to a channel
|
* subscribes to a channel
|
||||||
* tells the universe about this instances interest into a channel
|
* tells the universe about this instances interest into a channel
|
||||||
*/
|
*/
|
||||||
public async subscribe(observerArg?: plugins.smartrx.rxjs.Observer<any>) {
|
public subscribe(observingFunctionArg: (messageArg: ClientUniverseMessage) => void) {
|
||||||
|
|
||||||
|
return this.subject.subscribe(
|
||||||
|
messageArg => {
|
||||||
|
observingFunctionArg(messageArg);
|
||||||
|
},
|
||||||
|
error => console.log(error)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async populateSubscriptionToServer() {
|
||||||
// lets make sure the channel is connected
|
// lets make sure the channel is connected
|
||||||
if (this.status === 'unsubscribed') {
|
if (this.status === 'unsubscribed') {
|
||||||
const response = await this.clientUniverseRef.smartsocketClient.serverCall<interfaces.ISocketRequest_SubscribeChannel>(
|
const response = await this.clientUniverseRef.smartsocketClient.serverCall<
|
||||||
'subscribeChannel',
|
interfaces.ISocketRequest_SubscribeChannel
|
||||||
{
|
>('subscribeChannel', {
|
||||||
name: this.name,
|
name: this.name,
|
||||||
passphrase: this.passphrase
|
passphrase: this.passphrase
|
||||||
}
|
});
|
||||||
);
|
|
||||||
this.status = response.subscriptionStatus;
|
this.status = response.subscriptionStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (observerArg) {
|
|
||||||
return this.subject.subscribe(observerArg);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async emitMessageLocally(messageArg: ClientUniverseMessage) {
|
public async emitMessageLocally(messageArg: ClientUniverseMessage) {
|
||||||
this.subject.next(messageArg);
|
this.subject.next(messageArg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public askForReaction(reactionRequest: ReactionRequest): ReactionResponse {
|
|
||||||
const reactionResponse = new ReactionResponse();
|
|
||||||
return reactionResponse;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sends a message towards the server
|
* sends a message towards the server
|
||||||
* @param messageArg
|
* @param messageArg
|
||||||
|
@ -1,5 +1,24 @@
|
|||||||
import * as plugins from './smartuniverse.plugins';
|
import * as plugins from './smartuniverse.plugins';
|
||||||
|
|
||||||
export class ReactionRequest {
|
export interface IReactionRequestConstructorOptions<T extends plugins.typedrequestInterfaces.ITypedRequest> {
|
||||||
|
method: T['method'];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ICombinatorPayload<T extends plugins.typedrequestInterfaces.ITypedRequest> {
|
||||||
|
/**
|
||||||
|
* needed for tying responses to requests
|
||||||
|
*/
|
||||||
|
id: string;
|
||||||
|
typedRequestPayload: T;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class ReactionRequest<T extends plugins.typedrequestInterfaces.ITypedRequest> {
|
||||||
|
public method: T['method'];
|
||||||
|
|
||||||
|
constructor(optionsArg: IReactionRequestConstructorOptions<T>) {
|
||||||
|
this.method = optionsArg.method;
|
||||||
|
}
|
||||||
|
|
||||||
|
public fireRequest(channelArg) {}
|
||||||
|
}
|
||||||
|
@ -1,3 +1,31 @@
|
|||||||
import * as plugins from './smartuniverse.plugins';
|
import * as plugins from './smartuniverse.plugins';
|
||||||
|
|
||||||
export class ReactionResponse {}
|
import { ICombinatorPayload } from './smartuniverse.classes.reactionrequest';
|
||||||
|
import { UniverseChannel } from './smartuniverse.classes.universechannel';
|
||||||
|
import { ClientUniverseChannel } from './smartuniverse.classes.clientuniversechannel';
|
||||||
|
import { UniverseMessage } from './smartuniverse.classes.universemessage';
|
||||||
|
import { ClientUniverseMessage } from './smartuniverse.classes.clientuniversemessage';
|
||||||
|
|
||||||
|
export interface IReactionResponseConstructorOptions<T extends plugins.typedrequestInterfaces.ITypedRequest> {
|
||||||
|
method: T['method'];
|
||||||
|
channels: Array<UniverseChannel | ClientUniverseChannel>;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export class ReactionResponse<T extends plugins.typedrequestInterfaces.ITypedRequest> {
|
||||||
|
public method: T['method'];
|
||||||
|
public channels = new plugins.lik.Objectmap<UniverseChannel | ClientUniverseChannel>();
|
||||||
|
|
||||||
|
constructor(optionsArg: IReactionResponseConstructorOptions<T>) {
|
||||||
|
this.channels.addArray(optionsArg.channels);
|
||||||
|
for (const channel of this.channels.getArray()) {
|
||||||
|
channel.subscribe(messageArg => {
|
||||||
|
this.processMessageForReaction(messageArg);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private processMessageForReaction(messageArg: UniverseMessage | ClientUniverseMessage) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -62,6 +62,16 @@ export class Universe {
|
|||||||
*/
|
*/
|
||||||
public addChannel(nameArg: string, passphraseArg: string) {
|
public addChannel(nameArg: string, passphraseArg: string) {
|
||||||
const newChannel = UniverseChannel.createChannel(this, nameArg, passphraseArg);
|
const newChannel = UniverseChannel.createChannel(this, nameArg, passphraseArg);
|
||||||
|
return newChannel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns a channel
|
||||||
|
*/
|
||||||
|
public getChannelByName(channelNameArg: string) {
|
||||||
|
return this.universeCache.channelMap.find(channelArg => {
|
||||||
|
return channelArg.name === channelNameArg;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -95,13 +105,12 @@ export class Universe {
|
|||||||
// add the role to smartsocket
|
// add the role to smartsocket
|
||||||
this.smartsocket.addSocketRoles([ClientRole]);
|
this.smartsocket.addSocketRoles([ClientRole]);
|
||||||
|
|
||||||
const socketFunctionSubscription = new plugins.smartsocket.SocketFunction<interfaces.ISocketRequest_SubscribeChannel>({
|
const socketFunctionSubscription = new plugins.smartsocket.SocketFunction<
|
||||||
|
interfaces.ISocketRequest_SubscribeChannel
|
||||||
|
>({
|
||||||
allowedRoles: [ClientRole], // there is only one client role, Authentication happens on another level
|
allowedRoles: [ClientRole], // there is only one client role, Authentication happens on another level
|
||||||
funcName: 'subscribeChannel',
|
funcName: 'subscribeChannel',
|
||||||
funcDef: async (
|
funcDef: async (dataArg, socketConnectionArg) => {
|
||||||
dataArg,
|
|
||||||
socketConnectionArg
|
|
||||||
) => {
|
|
||||||
const universeConnection = new UniverseConnection({
|
const universeConnection = new UniverseConnection({
|
||||||
socketConnection: socketConnectionArg,
|
socketConnection: socketConnectionArg,
|
||||||
authenticationRequests: [dataArg]
|
authenticationRequests: [dataArg]
|
||||||
|
@ -59,7 +59,7 @@ export class UniverseCache {
|
|||||||
UniverseChannel.authorizeAMessageForAChannel(this, messageArg);
|
UniverseChannel.authorizeAMessageForAChannel(this, messageArg);
|
||||||
this.messageMap.add(messageArg);
|
this.messageMap.add(messageArg);
|
||||||
messageArg.universeChannelList.forEach(universeChannel => {
|
messageArg.universeChannelList.forEach(universeChannel => {
|
||||||
universeChannel.pushToClients(messageArg);
|
universeChannel.push(messageArg);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,6 +85,7 @@ export class UniverseChannel {
|
|||||||
*/
|
*/
|
||||||
public name: string;
|
public name: string;
|
||||||
public universeRef: Universe;
|
public universeRef: Universe;
|
||||||
|
private subject = new plugins.smartrx.rxjs.Subject<UniverseMessage>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the passphrase for the channel
|
* the passphrase for the channel
|
||||||
@ -113,9 +114,10 @@ export class UniverseChannel {
|
|||||||
* pushes a message to clients
|
* pushes a message to clients
|
||||||
* @param messageArg
|
* @param messageArg
|
||||||
*/
|
*/
|
||||||
public async pushToClients(messageArg: UniverseMessage) {
|
public async push(messageArg: UniverseMessage) {
|
||||||
|
this.subject.next(messageArg);
|
||||||
const universeConnectionsWithChannelAccess: UniverseConnection[] = [];
|
const universeConnectionsWithChannelAccess: UniverseConnection[] = [];
|
||||||
this.universeRef.universeCache.connectionMap.forEach(async socketConnection => {
|
await this.universeRef.universeCache.connectionMap.forEach(async socketConnection => {
|
||||||
if (socketConnection.authenticatedChannels.includes(this)) {
|
if (socketConnection.authenticatedChannels.includes(this)) {
|
||||||
universeConnectionsWithChannelAccess.push(socketConnection);
|
universeConnectionsWithChannelAccess.push(socketConnection);
|
||||||
}
|
}
|
||||||
@ -139,4 +141,30 @@ export class UniverseChannel {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// functions to interact with a channel locally
|
||||||
|
public subscribe(observingFunctionArg: (messageArg: UniverseMessage) => void) {
|
||||||
|
return this.subject.subscribe(
|
||||||
|
messageArg => {
|
||||||
|
observingFunctionArg(messageArg);
|
||||||
|
},
|
||||||
|
error => console.log(error)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ export class UniverseConnection {
|
|||||||
universeConnection
|
universeConnection
|
||||||
);
|
);
|
||||||
universeRef.universeCache.connectionMap.add(universeConnection);
|
universeRef.universeCache.connectionMap.add(universeConnection);
|
||||||
|
console.log('hi')
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3,6 +3,13 @@ import * as path from 'path';
|
|||||||
|
|
||||||
export { path };
|
export { path };
|
||||||
|
|
||||||
|
// apiglobal scope
|
||||||
|
import * as typedrequestInterfaces from '@apiglobal/typedrequest-interfaces';
|
||||||
|
|
||||||
|
export {
|
||||||
|
typedrequestInterfaces
|
||||||
|
};
|
||||||
|
|
||||||
// pushrocks scope
|
// pushrocks scope
|
||||||
import * as lik from '@pushrocks/lik';
|
import * as lik from '@pushrocks/lik';
|
||||||
import * as smarthash from '@pushrocks/smarthash';
|
import * as smarthash from '@pushrocks/smarthash';
|
||||||
|
Reference in New Issue
Block a user