[BUG] Error on creating Socket namespace
See original GitHub issueHi, guys!
I’m trying to just connect the @tsed/socketio
into my project, but when I try follow the documentation to use socket my namespace, as a service, inside a controller it’s throwing the following error.
[2021-04-05T18:26:19.605] [INFO ] [TSED] - Call hook $beforeListen
[2021-04-05T18:26:19.618] [INFO ] [TSED] - Listen server on http://0.0.0.0:8083
[2021-04-05T18:26:19.619] [INFO ] [TSED] - Call hook $afterListen
[2021-04-05T18:26:19.622] [ERROR] [TSED] - TypeError: Cannot read property 'set' of undefined
at NotificationService.set (C:\project\node_modules\@tsed\core\src\domain\Store.ts:110:15)
at SocketHandlersBuilder.build (C:\project\node_modules\@tsed\socketio\src\class\SocketHandlersBuilder.ts:47:20)
at SocketIOService.addSocketProvider (C:\project\node_modules\@tsed\socketio\src\services\SocketIOService.ts:61:95)
at C:\project\node_modules\@tsed\socketio\src\SocketIOModule.ts:46:76
at Array.forEach (<anonymous>)
at SocketIOModule.$afterListen (C:\project\node_modules\@tsed\socketio\src\SocketIOModule.ts:46:33)
at Map.emit (C:\project\node_modules\@tsed\di\src\class\LocalsContainer.ts:15:34)
at PlatformExpress.callHook (C:\project\node_modules\@tsed\common\src\platform\builder\PlatformBuilder.ts:227:22)
at PlatformExpress.listen (C:\project\node_modules\@tsed\common\src\platform\builder\PlatformBuilder.ts:192:16)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at bootstrap (C:\project\src\/index.ts:11:5)
Does Somebody know how can I fix this?
Information
- Version: 6.36.0
package.json file
{
...
"dependencies": {
"@tsed/ajv": "^6.36.0",
"@tsed/cli": "^2.12.0",
"@tsed/common": "^6.36.0",
"@tsed/core": "^6.36.0",
"@tsed/di": "^6.36.0",
"@tsed/exceptions": "^6.36.0",
"@tsed/json-mapper": "^6.36.0",
"@tsed/passport": "^6.36.0",
"@tsed/platform-express": "^6.36.0",
"@tsed/schema": "^6.36.0",
"@tsed/socketio": "^6.36.0",
"@tsed/swagger": "^6.36.0",
"@tsed/typeorm": "^6.36.0",
"ajv": "^7.2.4",
"bcrypt": "^5.0.1",
"body-parser": "^1.19.0",
"compression": "^1.7.4",
"cookie-parser": "^1.4.5",
"cors": "^2.8.5",
"cross-env": "^7.0.3",
"express": "^4.17.1",
"http": "^0.0.1-security",
"jsonwebtoken": "^8.5.1",
"method-override": "^3.0.0",
"passport": "^0.4.1",
"passport-jwt": "^4.0.0",
"passport-local": "^1.0.0",
"socket.io": "^4.0.1",
"sqlite3": "^5.0.2",
"typeorm": "^0.2.31"
},
"devDependencies": {
"@tsed/cli-plugin-eslint": "2.12.0",
"@tsed/cli-plugin-jest": "2.12.0",
"@tsed/cli-plugin-passport": "2.12.0",
"@tsed/cli-plugin-typeorm": "2.12.0",
"@types/bcrypt": "^3.0.0",
"@types/compression": "^1.7.0",
"@types/cookie-parser": "^1.4.2",
"@types/cors": "^2.8.10",
"@types/express": "^4.17.11",
"@types/jest": "^26.0.22",
"@types/method-override": "^0.0.31",
"@types/multer": "^1.4.5",
"@types/node": "^14.14.36",
"@types/passport": "^1.0.6",
"@types/passport-jwt": "^3.0.5",
"@types/passport-local": "^1.0.33",
"@types/socket.io": "^2.1.13",
"@types/supertest": "^2.0.10",
"@typescript-eslint/eslint-plugin": "^4.19.0",
"@typescript-eslint/parser": "^4.19.0",
"babel-plugin-transform-typescript-metadata": "^0.3.2",
"concurrently": "^6.0.0",
"nodemon": "^2.0.7",
"ts-node": "^9.1.1",
"tsconfig-paths": "^3.9.0",
"typescript": "^4.2.3"
},
"tsed": {
"packageManager": "yarn",
"convention": "default"
}
}
Code
Server.ts
import '@tsed/ajv';
import { $log, PlatformApplication } from '@tsed/common';
import { Env } from '@tsed/core';
import { Configuration, Inject } from '@tsed/di';
import '@tsed/passport';
import '@tsed/platform-express'; // /!\ keep this import
import '@tsed/socketio';
import '@tsed/swagger';
import '@tsed/typeorm';
import bodyParser from 'body-parser';
import compress from 'compression';
import cookieParser from 'cookie-parser';
import cors from 'cors';
import methodOverride from 'method-override';
import typeormConfig from '../ormconfig.json';
import { IndexController } from './controllers/pages/IndexController';
export const rootDir = __dirname;
export const isProduction = process.env.NODE_ENV === Env.PROD;
if (isProduction) {
$log.appenders.set('stdout', {
type: 'stdout',
levels: ['info', 'debug'],
layout: {
type: 'json',
},
});
$log.appenders.set('stderr', {
levels: ['trace', 'fatal', 'error', 'warn'],
type: 'stderr',
layout: {
type: 'json',
},
});
}
@Configuration({
rootDir,
acceptMimes: ['application/json'],
httpPort: process.env.PORT || 8083,
httpsPort: false, // CHANGE
logger: {
disableRoutesSummary: isProduction,
},
mount: {
'/rest': [`${rootDir}/controllers/**/*.ts`],
'/': [IndexController],
},
componentsScan: [
`${rootDir}/protocols/*.ts`, // scan protocols directory
],
passport: {},
swagger: [
{
path: '/v2/docs',
specVersion: '2.0',
},
{
path: '/v3/docs',
specVersion: '3.0.1',
},
],
views: {
root: `${rootDir}/../views`,
viewEngine: 'ejs',
},
typeorm: [typeormConfig as any],
exclude: ['**/*.spec.ts'],
})
export class Server {
@Inject()
app: PlatformApplication;
@Configuration()
settings: Configuration;
$beforeRoutesInit(): void {
this.app
.use(cors())
.use(cookieParser())
.use(compress({}))
.use(methodOverride())
.use(bodyParser.json())
.use(
bodyParser.urlencoded({
extended: true,
}),
);
}
}
NotificationService.ts
import { Nsp, SocketService } from '@tsed/socketio';
@SocketService('/my-namespace')
export class NotificationService {
@Nsp nsp: Nsp;
helloAll() {
this.nsp.emit('hi', 'everyone!');
}
}
NotificarionController.ts
import { Controller, Get } from '@tsed/common';
import { NotificationService } from '../services/sockets/NotificationService';
@Controller('/')
export class NotificationController {
constructor(private notificationService: NotificationService) {
}
@Get('/allo')
allo() {
this.notificationService.helloAll();
return 'is sent';
}
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:6
Top Results From Across the Web
Socket.io custom namespace clients do not receive an ...
My problem is the following. Authentication is provided as namespace middleware that if it fails, it calls the next callback of socket ......
Read more >Invalid namespace for socket v2 connecting to server v3
After upgrading the server to v3.1.0 and using the allowEIO3: true option the client socket v2.2.0 cannot connect to the indicated namespace ...
Read more >unix(7) - Linux manual page
Abstract sockets automatically disappear when all open references to the socket are closed. The abstract socket namespace is a nonportable Linux extension.
Read more >AAA-LPS-0005 error when testing an LDAP or Active ...
Symptom 1: An LDAP ™ or Active Directory ™ namespace verification fails with this message: AAA-LPS-0005 Unable to communicate with legacy ...
Read more >Windows Sockets Error Codes (Winsock2.h) - Win32 apps
A socket operation encountered a dead host. Networking activity on the local host has not been initiated.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
🎉 This issue has been resolved in version 6.39.1 🎉
The release is available on:
v6.39.1
Your semantic-release bot 📦🚀
🎉 This issue has been resolved in version 6.44.0 🎉
The release is available on:
v6.44.0
Your semantic-release bot 📦🚀