сокеты nestjs подключены и отключены
У меня проблема с сокетами с Nestjs, каждую секунду он пишет подключено и отключено, искал несколько одинаковых вопросов в Stackoverflow, а также на уроках Youtube, но не помог .. буду рад, если кто-то поможет ..
это журнал
[Nest] 12036 - 04/02/2021, 9:18:03 PM [AppGateWay] lient disconnected jRscMMVD0squB05iAABX
[Nest] 12036 - 04/02/2021, 9:18:03 PM [AppGateWay] lient connecter fIlNEX9iuFZczryIAABt
[Nest] 12036 - 04/02/2021, 9:18:03 PM [AppGateWay] lient connecter uZNRYlyQ-MbAawJMAABu
[Nest] 12036 - 04/02/2021, 9:18:06 PM [AppGateWay] lient disconnected DPvlifohhyihQCWsAABY
[Nest] 12036 - 04/02/2021, 9:18:06 PM [AppGateWay] lient connecter k3uyxN-fc3GrGsdDAABv
[Nest] 12036 - 04/02/2021, 9:18:07 PM [AppGateWay] lient disconnected x8fuIwTgLKcOrZzvAABZ
[Nest] 12036 - 04/02/2021, 9:18:07 PM [AppGateWay] lient connecter Y2KR6mRUf70lidA_AABw
[Nest] 12036 - 04/02/2021, 9:18:08 PM [AppGateWay] lient disconnected 1SIGUFCZthvnkLBoAABa
[Nest] 12036 - 04/02/2021, 9:18:08 PM [AppGateWay] lient disconnected Zy9txh5pIosNNxHTAABb
[Nest] 12036 - 04/02/2021, 9:18:08 PM [AppGateWay] lient connecter LB4h3oOjP0aKjjcBAABx
[Nest] 12036 - 04/02/2021, 9:18:08 PM [AppGateWay] lient connecter VDoVyVgXE9zQWrkGAABy
[Nest] 12036 - 04/02/2021, 9:18:11 PM [AppGateWay] lient disconnected DGk_RFIFQFw-h25DAABc
package.json
{
"name": "nestjs-task-management",
"version": "0.0.1",
"description": "",
"author": "",
"private": true,
"license": "UNLICENSED",
"scripts": {
"prebuild": "rimraf dist",
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "ts-node -r tsconfig-paths/register src/main.ts",
"start:dev": "nodemon",
"start:debug": "nodemon --config nodemon-debug.json",
"start:prod": "node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"dependencies": {
"@nestjs/common": "^7.0.0",
"@nestjs/core": "^7.0.0",
"@nestjs/jwt": "^7.1.0",
"@nestjs/passport": "^7.1.0",
"@nestjs/platform-express": "^7.3.1",
"@nestjs/platform-socket.io": "^15.6.15",
"@nestjs/serve-static": "^2.1.4",
"@nestjs/typeorm": "^7.1.0",
"@nestjs/websockets": "^7.6.15",
"@types/sharp": "^0.27.1",
"class-transformer": "^0.2.3",
"class-validator": "^0.12.2",
"config": "^3.3.1",
"g": "^2.0.1",
"global": "^4.4.0",
"multer": "^1.4.2",
"nodemon": "^2.0.3",
"passport": "^0.4.1",
"passport-jwt": "^4.0.0",
"pg": "^8.2.1",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^6.5.4",
"sharp": "^0.26.2",
"typeorm": "^0.2.25"
},
"devDependencies": {
"@nestjs/cli": "^7.0.0",
"@nestjs/schematics": "^7.0.0",
"@nestjs/swagger": "^4.6.0",
"@nestjs/testing": "^7.0.0",
"@types/express": "^4.17.7",
"@types/jest": "25.1.4",
"@types/node": "^13.9.1",
"@types/socket.io": "^2.1.13",
"@types/supertest": "^2.0.8",
"@typescript-eslint/eslint-plugin": "^2.23.0",
"@typescript-eslint/parser": "^2.23.0",
"bcrypt": "^5.0.0",
"cross-env": "^7.0.2",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.10.0",
"eslint-plugin-import": "^2.20.1",
"jest": "^25.1.0",
"prettier": "^1.19.1",
"supertest": "^4.0.2",
"swagger-ui-express": "^4.1.4",
"ts-jest": "25.2.1",
"ts-loader": "^6.2.1",
"ts-node": "^8.6.2",
"tsconfig-paths": "^3.9.0",
"typescript": "^3.8.3"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}
app.gateway.ts
import { Socket,Server } from 'socket.io';
import { Logger } from '@nestjs/common';
import { SubscribeMessage, WebSocketGateway, OnGatewayInit, OnGatewayConnection } from '@nestjs/websockets';
@WebSocketGateway()
export class AppGateway implements OnGatewayInit, OnGatewayConnection, OnGatewayConnection{
private logger: Logger = new Logger("AppGateWay");
afterInit(server: Server){
this.logger.log('Initialized')
}
handleConnection(client: Socket){
this.logger.log(`lient connecter ${client.id}`)
}
handleDisconnect(client: Socket){
this.logger.log(`lient disconnected ${client.id}`)
}
@SubscribeMessage('message')
handleMessage(client: any, payload: any): string {
return 'Hello world!';
}
}
Слишком много пробовала, но безрезультатно .... может кто знает, что делать? может быть проблема с версиями, как с другими людьми, но с какой библиотекой или с какой версией ...: |
1 ответ
export class AppGateway implements OnGatewayInit, OnGatewayConnection, OnGatewayConnection{
Вы набралиOnGatewayConnection
дважды вместоOnGatewayConnection, OnGatewayDisconnect