🚚 Rename to miniDb
This commit is contained in:
@@ -5,7 +5,7 @@ import { Action } from "../../interfaces/actions/Action";
|
|||||||
import { ActionType } from "../../enums/ActionType";
|
import { ActionType } from "../../enums/ActionType";
|
||||||
import { ChatClient } from "twitch-chat-client";
|
import { ChatClient } from "twitch-chat-client";
|
||||||
import { broadcast } from "../helpers/webServer";
|
import { broadcast } from "../helpers/webServer";
|
||||||
import { start } from "../helpers/scheduledActions";
|
import { start } from "../helpers/miniDb";
|
||||||
|
|
||||||
let chatClient: ChatClient;
|
let chatClient: ChatClient;
|
||||||
|
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
import { IncomingMessage, Server } from "http";
|
import { IncomingMessage, Server } from "http";
|
||||||
import { saveScheduledActions, scheduledActions } from "./scheduledActions";
|
import { saveScheduledActions, scheduledActions } from "./miniDb";
|
||||||
|
|
||||||
import { Action } from "../../interfaces/actions/Action";
|
import { Action } from "../../interfaces/actions/Action";
|
||||||
import { AddressInfo } from "net";
|
import { AddressInfo } from "net";
|
||||||
@@ -22,10 +22,7 @@ const wsServer = new WebSocket.Server({
|
|||||||
|
|
||||||
let server: Server;
|
let server: Server;
|
||||||
|
|
||||||
export {
|
export { listen, broadcast };
|
||||||
listen,
|
|
||||||
broadcast
|
|
||||||
};
|
|
||||||
|
|
||||||
wsServer.on("connection", onConnection);
|
wsServer.on("connection", onConnection);
|
||||||
|
|
||||||
@@ -74,9 +71,7 @@ function onConnection(socket: WebSocket, req: IncomingMessage) {
|
|||||||
|
|
||||||
// broadcast a message to all clients
|
// broadcast a message to all clients
|
||||||
function broadcast(msg: string, socket?: any) {
|
function broadcast(msg: string, socket?: any) {
|
||||||
const filteredSockets = socket
|
const filteredSockets = socket ? sockets.filter(s => s !== socket) : sockets;
|
||||||
? sockets.filter(s => s !== socket)
|
|
||||||
: sockets;
|
|
||||||
|
|
||||||
filteredSockets.forEach(s => s.send(msg));
|
filteredSockets.forEach(s => s.send(msg));
|
||||||
}
|
}
|
||||||
@@ -86,10 +81,7 @@ async function onMessage(msg: string) {
|
|||||||
const socket = this as WebSocket;
|
const socket = this as WebSocket;
|
||||||
const data = JSON.parse(msg);
|
const data = JSON.parse(msg);
|
||||||
|
|
||||||
if (
|
if (!data.actions || data.actions.length === 0) {
|
||||||
!data.actions ||
|
|
||||||
data.actions.length === 0
|
|
||||||
) {
|
|
||||||
broadcast(msg, socket);
|
broadcast(msg, socket);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user