almost lost this
This commit is contained in:
parent
b90139bd7f
commit
d4a4efa983
21
.vscode/launch.json
vendored
Normal file
21
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "pwa-node",
|
||||
"request": "launch",
|
||||
"name": "Launch Program",
|
||||
"skipFiles": [
|
||||
"<node_internals>/**"
|
||||
],
|
||||
"program": "${workspaceFolder}\\index.js",
|
||||
"preLaunchTask": "tsc: build - tsconfig.json",
|
||||
"outFiles": [
|
||||
"${workspaceFolder}/build/**/*.js"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
100
build/Channel.js
100
build/Channel.js
@ -24,7 +24,7 @@ var Channel = /** @class */ (function (_super) {
|
||||
function Channel(server, _id, set, p, crownX, crownY) {
|
||||
var _this = _super.call(this) || this;
|
||||
_this.server = server;
|
||||
_this.connectedClients = new Map();
|
||||
_this.connectedClients = [_id];
|
||||
server.channels.set(_this._id, _this);
|
||||
_this._id = _id;
|
||||
_this.settings = new ChannelSettings(set);
|
||||
@ -42,22 +42,11 @@ var Channel = /** @class */ (function (_super) {
|
||||
_this.bindEventListeners();
|
||||
return _this;
|
||||
}
|
||||
Channel.updateSubscribers = function () {
|
||||
this.subscribers.forEach(function (cl, participantId, map) {
|
||||
var list = [];
|
||||
cl.server.channels.forEach(function (channel, channelId, map) {
|
||||
list.push(channel.getChannelProperties());
|
||||
});
|
||||
console.log(list);
|
||||
cl.sendArray([{
|
||||
m: 'ls',
|
||||
c: true,
|
||||
u: list
|
||||
}]);
|
||||
});
|
||||
Channel.prototype.getClient = function (_id) {
|
||||
return this.server.findClientBy_ID(_id);
|
||||
};
|
||||
Channel.prototype.tick = function () {
|
||||
if (this.connectedClients.size <= 0) {
|
||||
if (this.connectedClients.length <= 0) {
|
||||
this.server.destroyChannel(this._id);
|
||||
}
|
||||
};
|
||||
@ -70,7 +59,7 @@ var Channel = /** @class */ (function (_super) {
|
||||
settings: this.settings,
|
||||
_id: this._id,
|
||||
id: this._id,
|
||||
count: this.connectedClients.size,
|
||||
count: this.connectedClients.length,
|
||||
crown: this.crown ? this.crown : undefined
|
||||
};
|
||||
};
|
||||
@ -78,33 +67,45 @@ var Channel = /** @class */ (function (_super) {
|
||||
this.applyQuota(cl);
|
||||
if (this.hasClient(cl)) {
|
||||
// this.connectedClients.set(cl.getOwnParticipant()._id, cl);
|
||||
cl.participantID = this.connectedClients.get(cl.getOwnParticipant()._id).participantID;
|
||||
// cl.participantID = this.server.findClientBy_ID(cl.getOwnParticipant()._id).participantID;
|
||||
}
|
||||
else {
|
||||
this.connectedClients.set(cl.getOwnParticipant()._id, cl);
|
||||
this.connectedClients.push(cl.getOwnParticipant()._id);
|
||||
}
|
||||
this.sendChannelMessageAll();
|
||||
cl.sendChatHistory(this.chatHistory);
|
||||
};
|
||||
Channel.prototype.removeClient = function (cl) {
|
||||
this.connectedClients["delete"](cl.getOwnParticipant()._id);
|
||||
// this.connectedClients.delete(cl.getOwnParticipant()._id);
|
||||
// this.sendChannelMessageAll();
|
||||
this.connectedClients.splice(this.connectedClients.indexOf(cl.getOwnParticipant()._id), 1);
|
||||
this.sendByeMessageAll(cl.participantID);
|
||||
};
|
||||
Channel.prototype.hasClient = function (cl) {
|
||||
var p1 = cl.getOwnParticipant();
|
||||
var entries = this.connectedClients.entries();
|
||||
// let p1 = cl.getOwnParticipant();
|
||||
// let entries = this.connectedClients.entries();
|
||||
// for (let c of entries.next().value) {
|
||||
// let p2 = c.getOwnParticipant();
|
||||
// if (p1._id == p2._id) {
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
this.connectedClients.forEach(function (cl, _id, map) {
|
||||
if (cl.user._id == _id) {
|
||||
// this.connectedClients.forEach(_id => {
|
||||
// // if (cl.user._id == _id) {
|
||||
// // return true;
|
||||
// // }
|
||||
// let cl = this.server.findClientBy_ID(_id);
|
||||
// if (cl.getOwnParticipant()._id == _id) {
|
||||
// return true;
|
||||
// }
|
||||
// });
|
||||
for (var _i = 0, _a = this.connectedClients; _i < _a.length; _i++) {
|
||||
var _id = _a[_i];
|
||||
var cl_1 = this.server.findClientBy_ID(_id);
|
||||
if (cl_1.getOwnParticipant()._id == _id) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
return false;
|
||||
};
|
||||
Channel.prototype.sendChat = function (p, clmsg) {
|
||||
@ -131,11 +132,19 @@ var Channel = /** @class */ (function (_super) {
|
||||
n: clmsg.n,
|
||||
p: p.id
|
||||
};
|
||||
this.connectedClients.forEach(function (cl, _id, map) {
|
||||
// this.connectedClients.forEach(_id => {
|
||||
// let cl = this.server.findClientBy_ID(_id);
|
||||
// if (cl.getOwnParticipant().id !== p.id) {
|
||||
// cl.sendArray([msg]);
|
||||
// }
|
||||
// });
|
||||
for (var _b = 0, _c = this.connectedClients; _b < _c.length; _b++) {
|
||||
var _id = _c[_b];
|
||||
var cl = this.server.findClientBy_ID(_id);
|
||||
if (cl.getOwnParticipant().id !== p.id) {
|
||||
cl.sendArray([msg]);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
Channel.prototype.sendCursorPosition = function (p, x, y) {
|
||||
var msg = {
|
||||
@ -148,9 +157,10 @@ var Channel = /** @class */ (function (_super) {
|
||||
};
|
||||
Channel.prototype.sendChannelMessageAll = function () {
|
||||
var _this = this;
|
||||
// console.log(this.server.channels);
|
||||
this.connectedClients.forEach(function (cl, _id, map) {
|
||||
console.log('sendChannelMessageAllL ' + cl.participantID);
|
||||
this.connectedClients.forEach(function (_id) {
|
||||
console.log(_id);
|
||||
var cl = _this.server.findClientBy_ID(_id);
|
||||
console.log('sendChannelMessageAll ' + cl.participantID);
|
||||
cl.sendChannelMessage(_this);
|
||||
});
|
||||
};
|
||||
@ -174,30 +184,48 @@ var Channel = /** @class */ (function (_super) {
|
||||
// for (let cl of this.connectedClients) {
|
||||
// cl.sendArray(arr);
|
||||
// }
|
||||
this.connectedClients.forEach(function (cl, _id, map) {
|
||||
// this.connectedClients.forEach(_id => {
|
||||
// let cl = this.server.findClientBy_ID(_id);
|
||||
// cl.sendArray(arr);
|
||||
// });
|
||||
for (var _i = 0, _a = this.connectedClients; _i < _a.length; _i++) {
|
||||
var _id = _a[_i];
|
||||
var cl = this.server.findClientBy_ID(_id);
|
||||
cl.sendArray(arr);
|
||||
});
|
||||
}
|
||||
};
|
||||
Channel.prototype.sendUserUpdate = function (user, x, y) {
|
||||
// for (let cl of this.connectedClients) {
|
||||
// cl.sendParticipantMessage(user, {x: x, y: y});
|
||||
// }
|
||||
this.connectedClients.forEach(function (cl, _id, map) {
|
||||
// this.connectedClients.forEach(_id => {
|
||||
// let cl = this.server.findClientBy_ID(_id);
|
||||
// cl.sendParticipantMessage(user, {x: x, y: y});
|
||||
// });
|
||||
for (var _i = 0, _a = this.connectedClients; _i < _a.length; _i++) {
|
||||
var _id = _a[_i];
|
||||
var cl = this.server.findClientBy_ID(_id);
|
||||
cl.sendParticipantMessage(user, { x: x, y: y });
|
||||
});
|
||||
}
|
||||
};
|
||||
Channel.prototype.getParticipantList = function () {
|
||||
// console.log('getting participant list');
|
||||
var ppl = [];
|
||||
this.connectedClients.forEach(function (cl, _id, map) {
|
||||
for (var _i = 0, _a = this.connectedClients; _i < _a.length; _i++) {
|
||||
var _id = _a[_i];
|
||||
var cl = this.server.findClientBy_ID(_id);
|
||||
if (!cl.getOwnParticipant())
|
||||
return;
|
||||
ppl.push(cl.getOwnParticipant());
|
||||
});
|
||||
}
|
||||
// this.connectedClients.forEach(_id => {
|
||||
// let cl = this.server.findClientBy_ID(_id);
|
||||
// if (!cl.getOwnParticipant()) return;
|
||||
// ppl.push(cl.getOwnParticipant());
|
||||
// });
|
||||
// console.log('ppl: ', ppl);
|
||||
return ppl;
|
||||
};
|
||||
Channel.subscribers = new Map();
|
||||
return Channel;
|
||||
}(stream_1.EventEmitter));
|
||||
exports.Channel = Channel;
|
||||
|
@ -382,7 +382,7 @@ var Client = /** @class */ (function (_super) {
|
||||
ch: {
|
||||
settings: ch.settings,
|
||||
_id: ch._id,
|
||||
count: ch.connectedClients.size,
|
||||
count: ch.connectedClients.length,
|
||||
crown: ch.crown
|
||||
},
|
||||
ppl: ppl,
|
||||
@ -392,10 +392,8 @@ var Client = /** @class */ (function (_super) {
|
||||
this.sendArray([msg]);
|
||||
};
|
||||
Client.prototype.subscribeToChannelList = function () {
|
||||
Channel_1.Channel.subscribers.set(this.participantID, this);
|
||||
};
|
||||
Client.prototype.unsubscribeFromChannelList = function () {
|
||||
Channel_1.Channel.subscribers["delete"](this.participantID);
|
||||
};
|
||||
Client.prototype.sendParticipantMessage = function (p, cursor) {
|
||||
var msg = {
|
||||
|
@ -216,7 +216,8 @@ var Database = /** @class */ (function () {
|
||||
m: new RateLimit_1.RateLimit(1000 / 20),
|
||||
ch: new RateLimit_1.RateLimit(1000),
|
||||
chset: new RateLimit_1.RateLimit(1500),
|
||||
t: new RateLimit_1.RateLimit(20)
|
||||
t: new RateLimit_1.RateLimit(20),
|
||||
a: new RateLimit_1.RateLimitChain(4, 6000)
|
||||
};
|
||||
};
|
||||
Database.client = new mongodb_1.MongoClient(MPP_MONGO_URI);
|
||||
|
@ -8,21 +8,29 @@ var WebSocketServer = /** @class */ (function () {
|
||||
function WebSocketServer(server) {
|
||||
this.server = server;
|
||||
this.canConnect = false;
|
||||
this.delayTime = 10000;
|
||||
this.delayTime = 5000;
|
||||
this.wss = new WebSocket.Server({
|
||||
noServer: true
|
||||
});
|
||||
this.bindEventListeners();
|
||||
this.startCount();
|
||||
this.startDelayed();
|
||||
}
|
||||
WebSocketServer.prototype.startCount = function () {
|
||||
WebSocketServer.prototype.startDelayed = function () {
|
||||
var _this = this;
|
||||
setTimeout(function () {
|
||||
_this.canConnect = true;
|
||||
_this.start();
|
||||
}, this.delayTime);
|
||||
};
|
||||
WebSocketServer.prototype.start = function () {
|
||||
this.canConnect = true;
|
||||
};
|
||||
WebSocketServer.prototype.handleUpgrade = function (req, socket, head) {
|
||||
var _this = this;
|
||||
// if (!this.canConnect) {
|
||||
// socket.end(() => {
|
||||
// socket.destroy();
|
||||
// });
|
||||
// }
|
||||
this.wss.handleUpgrade(req, socket, head, function (ws, req) {
|
||||
if (!_this.canConnect) {
|
||||
ws.close();
|
||||
|
123
src/Channel.ts
123
src/Channel.ts
@ -6,31 +6,33 @@ import { RateLimitChain } from "./RateLimit";
|
||||
import { Server } from "./Server";
|
||||
|
||||
class Channel extends EventEmitter { // TODO channel
|
||||
static subscribers = new Map<string, Client>();
|
||||
// static subscribers = new Map<string, string>();
|
||||
|
||||
static updateSubscribers() {
|
||||
this.subscribers.forEach((cl, participantId, map) => {
|
||||
let list = [];
|
||||
// static updateSubscribers(server) {
|
||||
// this.subscribers.forEach((_id, participantId, map) => {
|
||||
// let list = [];
|
||||
|
||||
cl.server.channels.forEach((channel, channelId, map) => {
|
||||
list.push(channel.getChannelProperties());
|
||||
});
|
||||
// let cl = server.findClientBy_ID(_id);
|
||||
|
||||
console.log(list);
|
||||
// cl.server.channels.forEach((channel, channelId, map) => {
|
||||
// list.push(channel.getChannelProperties());
|
||||
// });
|
||||
|
||||
// console.log(list);
|
||||
|
||||
cl.sendArray([{
|
||||
m: 'ls',
|
||||
c: true,
|
||||
u: list
|
||||
}]);
|
||||
// cl.sendArray([{
|
||||
// m: 'ls',
|
||||
// c: true,
|
||||
// u: list
|
||||
// }]);
|
||||
|
||||
});
|
||||
}
|
||||
// });
|
||||
// }
|
||||
|
||||
server: Server;
|
||||
_id: string;
|
||||
settings: ChannelSettings;
|
||||
connectedClients: Map<string, Client>;
|
||||
connectedClients: string[];
|
||||
crown?: Crown;
|
||||
chatHistory: any[];
|
||||
|
||||
@ -38,7 +40,7 @@ class Channel extends EventEmitter { // TODO channel
|
||||
super();
|
||||
|
||||
this.server = server;
|
||||
this.connectedClients = new Map();
|
||||
this.connectedClients = [_id];
|
||||
server.channels.set(this._id, this);
|
||||
|
||||
this._id = _id;
|
||||
@ -59,8 +61,12 @@ class Channel extends EventEmitter { // TODO channel
|
||||
this.bindEventListeners();
|
||||
}
|
||||
|
||||
getClient(_id) {
|
||||
return this.server.findClientBy_ID(_id);
|
||||
}
|
||||
|
||||
tick() {
|
||||
if (this.connectedClients.size <= 0) {
|
||||
if (this.connectedClients.length <= 0) {
|
||||
this.server.destroyChannel(this._id);
|
||||
}
|
||||
}
|
||||
@ -76,7 +82,7 @@ class Channel extends EventEmitter { // TODO channel
|
||||
settings: this.settings,
|
||||
_id: this._id,
|
||||
id: this._id,
|
||||
count: this.connectedClients.size,
|
||||
count: this.connectedClients.length,
|
||||
crown: this.crown ? this.crown : undefined
|
||||
}
|
||||
}
|
||||
@ -86,9 +92,9 @@ class Channel extends EventEmitter { // TODO channel
|
||||
|
||||
if (this.hasClient(cl)) {
|
||||
// this.connectedClients.set(cl.getOwnParticipant()._id, cl);
|
||||
cl.participantID = this.connectedClients.get(cl.getOwnParticipant()._id).participantID;
|
||||
// cl.participantID = this.server.findClientBy_ID(cl.getOwnParticipant()._id).participantID;
|
||||
} else {
|
||||
this.connectedClients.set(cl.getOwnParticipant()._id, cl);
|
||||
this.connectedClients.push(cl.getOwnParticipant()._id);
|
||||
}
|
||||
|
||||
this.sendChannelMessageAll();
|
||||
@ -96,14 +102,15 @@ class Channel extends EventEmitter { // TODO channel
|
||||
}
|
||||
|
||||
removeClient(cl: Client) {
|
||||
this.connectedClients.delete(cl.getOwnParticipant()._id);
|
||||
// this.connectedClients.delete(cl.getOwnParticipant()._id);
|
||||
// this.sendChannelMessageAll();
|
||||
this.connectedClients.splice(this.connectedClients.indexOf(cl.getOwnParticipant()._id), 1);
|
||||
this.sendByeMessageAll(cl.participantID);
|
||||
}
|
||||
|
||||
hasClient(cl: Client): boolean {
|
||||
let p1 = cl.getOwnParticipant();
|
||||
let entries = this.connectedClients.entries();
|
||||
// let p1 = cl.getOwnParticipant();
|
||||
// let entries = this.connectedClients.entries();
|
||||
// for (let c of entries.next().value) {
|
||||
// let p2 = c.getOwnParticipant();
|
||||
// if (p1._id == p2._id) {
|
||||
@ -111,11 +118,23 @@ class Channel extends EventEmitter { // TODO channel
|
||||
// }
|
||||
// }
|
||||
|
||||
this.connectedClients.forEach((cl, _id, map) => {
|
||||
if (cl.user._id == _id) {
|
||||
// this.connectedClients.forEach(_id => {
|
||||
// // if (cl.user._id == _id) {
|
||||
// // return true;
|
||||
// // }
|
||||
|
||||
// let cl = this.server.findClientBy_ID(_id);
|
||||
// if (cl.getOwnParticipant()._id == _id) {
|
||||
// return true;
|
||||
// }
|
||||
// });
|
||||
|
||||
for (let _id of this.connectedClients) {
|
||||
let cl = this.server.findClientBy_ID(_id);
|
||||
if (cl.getOwnParticipant()._id == _id) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -150,11 +169,19 @@ class Channel extends EventEmitter { // TODO channel
|
||||
p: p.id
|
||||
}
|
||||
|
||||
this.connectedClients.forEach((cl, _id, map) => {
|
||||
// this.connectedClients.forEach(_id => {
|
||||
// let cl = this.server.findClientBy_ID(_id);
|
||||
// if (cl.getOwnParticipant().id !== p.id) {
|
||||
// cl.sendArray([msg]);
|
||||
// }
|
||||
// });
|
||||
|
||||
for (let _id of this.connectedClients) {
|
||||
let cl = this.server.findClientBy_ID(_id);
|
||||
if (cl.getOwnParticipant().id !== p.id) {
|
||||
cl.sendArray([msg]);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
sendCursorPosition(p: User | PublicUser, x: number, y: number): void {
|
||||
@ -169,9 +196,10 @@ class Channel extends EventEmitter { // TODO channel
|
||||
}
|
||||
|
||||
sendChannelMessageAll() {
|
||||
// console.log(this.server.channels);
|
||||
this.connectedClients.forEach((cl, _id, map) => {
|
||||
console.log('sendChannelMessageAllL ' + cl.participantID);
|
||||
this.connectedClients.forEach(_id => {
|
||||
console.log(_id);
|
||||
let cl = this.server.findClientBy_ID(_id);
|
||||
console.log('sendChannelMessageAll ' + cl.participantID);
|
||||
cl.sendChannelMessage(this);
|
||||
})
|
||||
}
|
||||
@ -200,9 +228,15 @@ class Channel extends EventEmitter { // TODO channel
|
||||
// cl.sendArray(arr);
|
||||
// }
|
||||
|
||||
this.connectedClients.forEach((cl, _id, map) => {
|
||||
// this.connectedClients.forEach(_id => {
|
||||
// let cl = this.server.findClientBy_ID(_id);
|
||||
// cl.sendArray(arr);
|
||||
// });
|
||||
|
||||
for (let _id of this.connectedClients) {
|
||||
let cl = this.server.findClientBy_ID(_id);
|
||||
cl.sendArray(arr);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
sendUserUpdate(user: User | PublicUser, x?: number, y?: number) {
|
||||
@ -210,19 +244,32 @@ class Channel extends EventEmitter { // TODO channel
|
||||
// cl.sendParticipantMessage(user, {x: x, y: y});
|
||||
// }
|
||||
|
||||
this.connectedClients.forEach((cl, _id, map) => {
|
||||
// this.connectedClients.forEach(_id => {
|
||||
// let cl = this.server.findClientBy_ID(_id);
|
||||
// cl.sendParticipantMessage(user, {x: x, y: y});
|
||||
// });
|
||||
|
||||
for (let _id of this.connectedClients) {
|
||||
let cl = this.server.findClientBy_ID(_id);
|
||||
cl.sendParticipantMessage(user, {x: x, y: y});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
getParticipantList() {
|
||||
// console.log('getting participant list');
|
||||
let ppl = [];
|
||||
|
||||
this.connectedClients.forEach((cl, _id, map) => {
|
||||
for (let _id of this.connectedClients) {
|
||||
let cl = this.server.findClientBy_ID(_id);
|
||||
if (!cl.getOwnParticipant()) return;
|
||||
ppl.push(cl.getOwnParticipant());
|
||||
});
|
||||
}
|
||||
|
||||
// this.connectedClients.forEach(_id => {
|
||||
// let cl = this.server.findClientBy_ID(_id);
|
||||
// if (!cl.getOwnParticipant()) return;
|
||||
// ppl.push(cl.getOwnParticipant());
|
||||
// });
|
||||
|
||||
// console.log('ppl: ', ppl);
|
||||
|
||||
|
@ -217,7 +217,7 @@ class Client extends EventEmitter {
|
||||
}
|
||||
|
||||
getOwnParticipant(): PublicUser { //* finished
|
||||
let u = this.getOwnParticipant();
|
||||
let u = this.user;
|
||||
// remember to 'clean' the user object
|
||||
delete u.flags;
|
||||
u.id = this.participantID;
|
||||
@ -339,7 +339,7 @@ class Client extends EventEmitter {
|
||||
ch: {
|
||||
settings: ch.settings,
|
||||
_id: ch._id,
|
||||
count: ch.connectedClients.size,
|
||||
count: ch.connectedClients.length,
|
||||
crown: ch.crown
|
||||
},
|
||||
ppl: ppl,
|
||||
@ -352,11 +352,11 @@ class Client extends EventEmitter {
|
||||
}
|
||||
|
||||
subscribeToChannelList() { // TODO channel listing and subscribing
|
||||
Channel.subscribers.set(this.participantID, this);
|
||||
|
||||
}
|
||||
|
||||
unsubscribeFromChannelList() { // TODO channel listing and subscribing
|
||||
Channel.subscribers.delete(this.participantID);
|
||||
|
||||
}
|
||||
|
||||
sendParticipantMessage(p, cursor) {
|
||||
@ -385,6 +385,7 @@ class ClientRateLimits {
|
||||
chset: RateLimit;
|
||||
nq: RateLimitChain;
|
||||
t: RateLimit;
|
||||
a: RateLimitChain;
|
||||
|
||||
constructor () {
|
||||
let data = Database.getDefaultClientRateLimits();
|
||||
|
@ -154,7 +154,8 @@ class Database {
|
||||
m: new RateLimit(1000 / 20),
|
||||
ch: new RateLimit(1000),
|
||||
chset: new RateLimit(1500),
|
||||
t: new RateLimit(20)
|
||||
t: new RateLimit(20),
|
||||
a: new RateLimitChain(4, 6000)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ class Server extends EventEmitter {
|
||||
webServer: WebServer;
|
||||
wsServer: WebSocketServer;
|
||||
channels: Map<string, Channel>;
|
||||
clients: Map<string, Client>;
|
||||
clients: Map<string, Client>; //! urgent - this should be the ONLY place to reference clients
|
||||
|
||||
constructor () {
|
||||
super();
|
||||
|
@ -15,23 +15,32 @@ class WebSocketServer {
|
||||
constructor (server: Server) {
|
||||
this.server = server;
|
||||
this.canConnect = false;
|
||||
this.delayTime = 10000;
|
||||
this.delayTime = 5000;
|
||||
|
||||
this.wss = new WebSocket.Server({
|
||||
noServer: true
|
||||
});
|
||||
|
||||
this.bindEventListeners();
|
||||
this.startCount();
|
||||
this.startDelayed();
|
||||
}
|
||||
|
||||
startCount() {
|
||||
startDelayed() {
|
||||
setTimeout(() => {
|
||||
this.canConnect = true;
|
||||
this.start();
|
||||
}, this.delayTime);
|
||||
}
|
||||
|
||||
start() {
|
||||
this.canConnect = true;
|
||||
}
|
||||
|
||||
handleUpgrade(req: IncomingMessage, socket: Duplex, head: Buffer) {
|
||||
// if (!this.canConnect) {
|
||||
// socket.end(() => {
|
||||
// socket.destroy();
|
||||
// });
|
||||
// }
|
||||
this.wss.handleUpgrade(req, (socket as Socket), head, (ws, req) => {
|
||||
if (!this.canConnect) {
|
||||
ws.close();
|
||||
|
Loading…
x
Reference in New Issue
Block a user