Skip to content

Commit 4ab82f7

Browse files
committed
update TS, fix typings
1 parent 3903eae commit 4ab82f7

File tree

5 files changed

+20
-12
lines changed

5 files changed

+20
-12
lines changed

TypescriptServer/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
"ws": "^8.13.0"
2727
},
2828
"devDependencies": {
29-
"@types/node": "^18.15.11",
29+
"@types/node": "^25.0.3",
3030
"@types/semver": "^7.3.13",
3131
"@types/ws": "^8.5.4",
32-
"typescript": "^5.0.3"
32+
"typescript": "^5.9.3"
3333
},
3434
"imports": {
3535
"#root/*": "./out/*.js",

TypescriptServer/src/concepts/chat.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import Client from "#concepts/client";
22
import Account, { IProfile } from "#schemas/profile";
33

4-
import { ObjectId } from "mongoose";
4+
import { Document, ObjectId } from "mongoose";
55

6-
import ChatLog, { IChatLog, IMessage } from "#schemas/chat";
6+
import ChatLog, { IChatLog, IMessage, TChatLogDocument } from "#schemas/chat";
77
import { getRandomId } from "#util/random_id";
88

99
export { IChatLog, IMessage };
@@ -42,7 +42,7 @@ export interface SerializedChat {
4242
}
4343

4444
export class Chat {
45-
chatlog: IChatLog;
45+
chatlog: TChatLogDocument;
4646

4747
online_members: Client[] = [];
4848
get messages(): IMessage[] {
@@ -59,7 +59,7 @@ export class Chat {
5959
return this.chatlog.members;
6060
}
6161

62-
constructor(chatlog: IChatLog) {
62+
constructor(chatlog: TChatLogDocument) {
6363
this.chatlog = chatlog;
6464
}
6565

TypescriptServer/src/concepts/client.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,13 +315,15 @@ export default class Client extends SendStuff implements IClient {
315315

316316
this.socket = new_client.socket;
317317
this.socket_type = new_client.socket_type;
318-
319-
this.socket.removeAllListeners();
320318

321-
if (this.socket_type === 'tcp')
319+
if (this.socket_type === 'tcp') {
320+
(this.socket as TCPSocket).removeAllListeners();
322321
this.bindTCP(this.socket);
323-
else
322+
}
323+
else {
324+
(this.socket as WebSocket).removeAllListeners();
324325
this.bindWS(this.socket);
326+
}
325327

326328
// delete self from the list
327329
let idx = global.clients.indexOf(new_client);

TypescriptServer/src/schemas/chat.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,19 @@ const messageSchema = new Schema<IMessage>({
3131
content: String
3232
}, { _id: false });
3333

34-
export interface IChatLog extends Document {
34+
export interface IChatLog {//extends Document {
3535
_id: string,
3636
type: ChatType,
3737
private: boolean,
3838
messages: IMessage[],
3939
members: ObjectId[]
4040
}
4141

42+
export type TChatLogDocument = IChatLog & Document<string, {}, IChatLog>;
43+
4244
// you can edit this schema!
4345
const chatSchema = new Schema<IChatLog>({
44-
_id: { type: String, unique: true, index: true },
46+
_id: { type: String, default: '' },
4547

4648
private: { type: Boolean, default: false },
4749
type: { type: String, default: 'group' },

TypescriptServer/src/server.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ const server = createServer(function(socket) {
6464

6565
// When data arrived
6666
socket.on('data', function(data) {
67+
// ensure it's a buffer
68+
if (typeof data === 'string')
69+
return;
70+
6771
// create artificial_delay
6872
if (delayReceive.enabled) {
6973
setTimeout(function() {

0 commit comments

Comments
 (0)