Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .oxfmtrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"$schema": "./node_modules/oxfmt/configuration_schema.json",
"printWidth": 120,
"semi": false,
"singleQuote": true,
"bracketSameLine": false,
"trailingComma": "es5",
"singleAttributePerLine": true,
"sortPackageJson": false,
"ignorePatterns": [
"build",
"coverage",
"dist",
"node_modules"
]
}
33 changes: 33 additions & 0 deletions .oxlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"$schema": "./node_modules/oxlint/configuration_schema.json",
"plugins": ["typescript", "unicorn"],
"categories": {
"correctness": "error",
"suspicious": "warn"
},
"rules": {
"no-undef": "error",
"unicorn/no-null": "off",
"unicorn/filename-case": "off",
"unicorn/prefer-node-protocol": "off",
"unicorn/prefer-module": "off",
"typescript/no-explicit-any": "off",
"typescript/no-extraneous-class": "off"
},
"env": {
"builtin": true,
"node": true
},
"globals": {
"jest": true,
"describe": true,
"it": true,
"expect": true,
"beforeEach": true,
"afterEach": true,
"beforeAll": true,
"afterAll": true,
"test": true
},
"ignorePatterns": ["node_modules/**", "coverage/**", "dist/**"]
}
3 changes: 0 additions & 3 deletions .prettierignore

This file was deleted.

8 changes: 0 additions & 8 deletions .prettierrc.json

This file was deleted.

81 changes: 0 additions & 81 deletions eslint.config.mjs

This file was deleted.

31 changes: 13 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
},
"main": "dist/index.js",
"scripts": {
"ci": "yarn lint:tsc && yarn lint:eslint",
"lint": "yarn ci",
"lint:eslint": "eslint .",
"lint:eslint:fix": "eslint . --fix",
"lint:prettier": "prettier -c \"./src/**/*.{ts,js}\"",
"lint:prettier:fix": "prettier -w \"./src/**/*.{ts,js}\"",
"ci": "yarn lint:tsc && yarn lint:oxlint",
"lint": "[ \"$*\" = \"--fix\" ] && yarn lint:fix || yarn ci",
"lint:fix": "yarn lint:tsc && yarn lint:oxfmt:fix && yarn lint:oxlint:fix",
"lint:oxlint": "oxlint .",
"lint:oxlint:fix": "oxlint --fix .",
"lint:oxfmt": "oxfmt --check \"./src/**/*.{ts,js}\"",
"lint:oxfmt:fix": "oxfmt --write \"./src/**/*.{ts,js}\"",
"lint:tsc": "tsc --noEmit -p tsconfig.json --composite false",
"clean": "rimraf dist",
"build": "yarn clean && yarn lint && tsc && tsc-alias",
Expand All @@ -39,31 +40,25 @@
"reflect-metadata": "^0.2.2",
"typedi": "^0.10.0",
"winston": "^3.19.0",
"ws": "^8.19.0"
"ws": "^8.20.0"
},
"devDependencies": {
"@eslint/js": "^10.0.1",
"@stylistic/eslint-plugin": "^5.9.0",
"@types/cookies": "^0.9.2",
"@types/jest": "^30.0.0",
"@types/jsonwebtoken": "^9.0.10",
"@types/node": "^25.3.3",
"@types/node": "^24.12.0",
"@types/ws": "^8.18.1",
"eslint": "^10.0.2",
"eslint-config-prettier": "^10.1.8",
"eslint-plugin-prettier": "^5.5.5",
"eslint-plugin-unicorn": "^63.0.0",
"jest": "^30.2.0",
"jest": "^30.3.0",
"jest-junit": "^16.0.0",
"nodemon": "^3.1.14",
"prettier": "^3.8.1",
"oxfmt": "^0.42.0",
"oxlint": "^1.57.0",
"rimraf": "^6.1.3",
"ts-jest": "^29.4.6",
"ts-node": "^10.9.2",
"tsc-alias": "^1.8.16",
"tsconfig-paths": "^4.2.0",
"tslib": "^2.8.1",
"typescript": "^5.9.3",
"typescript-eslint": "^8.56.1"
"typescript": "^5.9.3"
}
}
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,4 @@ const init = async () => {
Container.get(WebsocketServer).init()
}

// eslint-disable-next-line unicorn/prefer-top-level-await
init().catch((error: Error) => console.error(error))
14 changes: 7 additions & 7 deletions src/model/user-connections.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import { Service } from 'typedi'
import { WebSocket } from 'ws'
import { UserWebSocket } from '@/model/user-web-socket'

@Service({ global: true })
export class UserConnections {
private readonly users: Map<string, Set<WebSocket>> = new Map<string, Set<WebSocket>>()
private readonly users: Map<string, Set<UserWebSocket>> = new Map<string, Set<UserWebSocket>>()

add(socket: WebSocket): void {
add(socket: UserWebSocket): void {
const userSockets = this.users.get(socket.ssoUserId)
if (userSockets && userSockets.add(socket)) {
return
}

this.users.set(socket.ssoUserId, new Set<WebSocket>().add(socket))
this.users.set(socket.ssoUserId, new Set<UserWebSocket>().add(socket))
}

remove(socket: WebSocket): void {
remove(socket: UserWebSocket): void {
this.users.get(socket.ssoUserId)?.delete(socket)
}

getAllForUser(ssoUserId: string): Set<WebSocket> {
return this.users.get(ssoUserId) ?? new Set<WebSocket>()
getAllForUser(ssoUserId: string): Set<UserWebSocket> {
return this.users.get(ssoUserId) ?? new Set<UserWebSocket>()
}
}
25 changes: 12 additions & 13 deletions src/server/websocket-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import { Inject, Service } from 'typedi'
import { UserConnections } from '@/model/user-connections'
import AppLogger from '@/logger/app-logger'
import { Config } from '@/config/config'

// todo, better types - remove as
import { UserWebSocket } from '@/model/user-web-socket'

@Service()
export class WebsocketServer {
Expand Down Expand Up @@ -52,10 +51,10 @@ export class WebsocketServer {
}

wss.handleUpgrade(request, socket, head, (ws) => {
const cws = ws as WebSocket.WebSocket
cws.ssoUserId = request.ssoUserId
userConnections.add(cws)
wss.emit('connection', cws, request)
const userWs = ws as UserWebSocket
userWs.ssoUserId = request.ssoUserId
userConnections.add(userWs)
wss.emit('connection', userWs, request)
})
})

Expand All @@ -66,19 +65,19 @@ export class WebsocketServer {
})

this.heartBeatInterval = setInterval(function ping() {
for (const ws of wss.clients) {
const cws = ws as WebSocket.WebSocket
if (cws.isAlive === false) {
userConnections.remove(cws)
for (const client of wss.clients) {
const ws = client as UserWebSocket
if (ws.isAlive === false) {
userConnections.remove(ws)
ws.terminate()

continue
}

cws.isAlive = false
cws.ping(null, false, (error) => {
ws.isAlive = false
ws.ping(null, false, (error) => {
if (error) {
userConnections.remove(cws)
userConnections.remove(ws)
ws.terminate()
}
})
Expand Down
8 changes: 0 additions & 8 deletions tsconfig.eslint.json

This file was deleted.

Loading
Loading