Web: Login: fixed types of ws
This commit is contained in:
parent
16af62e19b
commit
fb403556fc
@ -10,6 +10,7 @@ import { getAssets } from "./lib/helpers";
|
|||||||
import { renderToString } from "react-dom/server";
|
import { renderToString } from "react-dom/server";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import App from "../client/App";
|
import App from "../client/App";
|
||||||
|
import { Server } from "ws";
|
||||||
|
|
||||||
let port: number = 5011;
|
let port: number = 5011;
|
||||||
|
|
||||||
@ -73,7 +74,8 @@ if (IS_DEVELOPMENT) {
|
|||||||
waitTimeout = setTimeout(() => {
|
waitTimeout = setTimeout(() => {
|
||||||
fsWait = false;
|
fsWait = false;
|
||||||
clearTimeout(waitTimeout);
|
clearTimeout(waitTimeout);
|
||||||
wss.broadcast("reload");
|
|
||||||
|
wss.broadcast && wss.broadcast("reload");
|
||||||
}, 100);
|
}, 100);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1,30 +1,36 @@
|
|||||||
const WebSocket = require("ws");
|
import { RawData, WebSocketServer, Server } from "ws";
|
||||||
const pkg = require("../../../package.json");
|
import pkg from "../../../package.json";
|
||||||
const { socketPath } = pkg;
|
const { socketPath } = pkg;
|
||||||
|
|
||||||
module.exports = (expressServer) => {
|
interface WSS extends Server {
|
||||||
const wss = new WebSocket.Server({
|
broadcast?: (message: RawData | string) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default (expressServer: any) => {
|
||||||
|
const wss: WSS = new WebSocketServer({
|
||||||
noServer: true,
|
noServer: true,
|
||||||
path: socketPath,
|
path: socketPath,
|
||||||
});
|
});
|
||||||
|
|
||||||
expressServer.on("upgrade", (request, socket, head) => {
|
const broadcast = (message: RawData | string): void => {
|
||||||
|
wss.clients.forEach(function each(client) {
|
||||||
|
client.send(message);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
expressServer.on("upgrade", (request: any, socket: any, head: any) => {
|
||||||
wss.handleUpgrade(request, socket, head, (websocket) => {
|
wss.handleUpgrade(request, socket, head, (websocket) => {
|
||||||
wss.emit("connection", websocket, request);
|
wss.emit("connection", websocket, request);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
wss.on("connection", function connection(ws) {
|
wss.on("connection", (ws) => {
|
||||||
ws.on("message", function (message) {
|
ws.on("message", (message) => {
|
||||||
wss.broadcast(message);
|
broadcast(message);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
wss.broadcast = function broadcast(msg) {
|
wss.broadcast = broadcast;
|
||||||
wss.clients.forEach(function each(client) {
|
|
||||||
client.send(msg);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
return wss;
|
return wss;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user