cleanup
This commit is contained in:
@@ -0,0 +1,4 @@
|
|||||||
|
export function guardStringNotEmpty(data: any, cb: (data: string) => void): void {
|
||||||
|
if (typeof data != "string" || data != "") return;
|
||||||
|
cb(data);
|
||||||
|
}
|
||||||
+13
-11
@@ -1,7 +1,8 @@
|
|||||||
// TYPES
|
// TYPES
|
||||||
|
|
||||||
import { SubscriptionMap } from "./auxilary";
|
import { SubscriptionMap } from "./subscriptionMap";
|
||||||
import { WS } from "./index";
|
import { WS } from "./index";
|
||||||
|
import { guardStringNotEmpty } from "./utility";
|
||||||
|
|
||||||
// requests
|
// requests
|
||||||
export interface IncomingMessage {
|
export interface IncomingMessage {
|
||||||
@@ -38,16 +39,16 @@ export function forgetConnection(ws: WS): void {
|
|||||||
export function processMessage(ws: WS, messageString: string): void {
|
export function processMessage(ws: WS, messageString: string): void {
|
||||||
const messageObject: IncomingMessage = parseMessage(messageString);
|
const messageObject: IncomingMessage = parseMessage(messageString);
|
||||||
|
|
||||||
if (typeof messageObject.subscribeChannel == "string") {
|
guardStringNotEmpty(messageObject.subscribeChannel, (subscribeChannel) => {
|
||||||
trackSubscription(ws, messageObject.subscribeChannel);
|
trackSubscription(ws, subscribeChannel);
|
||||||
} else if (typeof messageObject.unsubscribeChannel == "string") {
|
});
|
||||||
removeSubscription(ws, messageObject.unsubscribeChannel);
|
guardStringNotEmpty(messageObject.unsubscribeChannel, (unsubscribeChannel) => {
|
||||||
} else if (
|
removeSubscription(ws, unsubscribeChannel);
|
||||||
typeof messageObject.messageChannel == "string" &&
|
});
|
||||||
typeof messageObject.messageBody == "string"
|
guardStringNotEmpty(messageObject.messageChannel == "string", (messageChannel) => {
|
||||||
) {
|
if (!messageObject.messageBody) return;
|
||||||
sendMessage(messageObject.messageChannel, messageObject.messageBody);
|
sendMessage(messageChannel, messageObject.messageBody);
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// MESSAGING
|
// MESSAGING
|
||||||
@@ -73,5 +74,6 @@ function confirmSubscription(ws: WS, channel: string): void {
|
|||||||
subscribed: subscriptions.getChannelList(ws)?.has(channel),
|
subscribed: subscriptions.getChannelList(ws)?.has(channel),
|
||||||
};
|
};
|
||||||
const messageString = stringifyMessage(messageObject);
|
const messageString = stringifyMessage(messageObject);
|
||||||
|
console.log(messageString);
|
||||||
ws.send(messageString);
|
ws.send(messageString);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user