websocket 节点模块中的套接字网关提供和错误

anauzrmj  于 2023-03-08  发布在  其他
关注(0)|答案(1)|浏览(157)

我想在我的项目中使用WebSocket做一个简单的网关。当我想做它的时候,我遇到了一个NestJs的问题。
enter image description here

import { 
    SubscribeMessage, 
    WebSocketGateway, 
    WebSocketServer, 
    OnGatewayDisconnect,
    ConnectedSocket,
} from '@nestjs/websockets';
import { Server } from 'socket.io';

@WebSocketGateway()
export class ChatGateway { //implements OnGatewayDisconnect {

    constructor() {}

    @WebSocketServer() server : Server;

}

enter image description here

import { Module } from '@nestjs/common';
import { ChatService } from './chat.service';
import { ChatGateway } from './chat.gateway';

@Module({
  providers: [
            ChatService,
            ChatGateway
        ]
})
export class ChatModule {}

我得到了这个错误:
enter image description here

/Users/mlecherb/transcendance-1/backend/node_modules/@nestjs/websockets/gateway-metadata-explorer.js:13
            .getAllMethodNames(instancePrototype)
             ^
TypeError: this.metadataScanner.getAllMethodNames is not a function
    at GatewayMetadataExplorer.explore (/Users/mlecherb/transcendance-1/backend/node_modules/@nestjs/websockets/gateway-metadata-explorer.js:13:14)
    at WebSocketsController.subscribeToServerEvents (/Users/mlecherb/transcendance-1/backend/node_modules/@nestjs/websockets/web-sockets-controller.js:33:61)
    at WebSocketsController.connectGatewayToServer (/Users/mlecherb/transcendance-1/backend/node_modules/@nestjs/websockets/web-sockets-controller.js:30:14)
    at SocketModule.connectGatewayToServer (/Users/mlecherb/transcendance-1/backend/node_modules/@nestjs/websockets/socket-module.js:47:35)
    at /Users/mlecherb/transcendance-1/backend/node_modules/@nestjs/websockets/socket-module.js:36:38
    at IteratorWithOperators.forEach (/Users/mlecherb/transcendance-1/backend/node_modules/iterare/src/iterate.ts:202:13)
    at SocketModule.connectAllGateways (/Users/mlecherb/transcendance-1/backend/node_modules/@nestjs/websockets/socket-module.js:36:14)
    at /Users/mlecherb/transcendance-1/backend/node_modules/@nestjs/websockets/socket-module.js:31:61
    at ModulesContainer.forEach (<anonymous>)
    at SocketModule.register (/Users/mlecherb/transcendance-1/backend/node_modules/@nestjs/websockets/socket-module.js:31:17)

有谁知道吗?
谢谢
我已经尽力使它尽可能短,我已经下载了所有必要的软件包.

t9aqgxwy

t9aqgxwy1#

尝试使用此版本“@nestjs/platform-socket.io“:“9.2.1”,“@nestjs/网络套接字”:“第9.2.1条”,

相关问题