ts-game-decorators 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -43,6 +43,12 @@ import { SocketService, OnEvent, OnDisconnect, AuthenSocket } from 'express-sock
43
43
 
44
44
  @SocketService()
45
45
  export class GameSocketService {
46
+
47
+ private io: Server;
48
+ constructor(io: Server) {
49
+ this.io = io;
50
+ }
51
+
46
52
  @OnEvent('startGame')
47
53
  @AuthenSocket()
48
54
  start(socket, data) {
@@ -58,7 +58,14 @@ function registerSocketServices(io, ...serviceClasses) {
58
58
  serviceClasses.forEach(ServiceClass => {
59
59
  if (!Reflect.getMetadata(SOCKET_SERVICE_META, ServiceClass))
60
60
  return;
61
- const instance = new ServiceClass();
61
+ // Nếu class nhận io ở constructor thì truyền vào
62
+ let instance;
63
+ try {
64
+ instance = new ServiceClass(io);
65
+ }
66
+ catch (_a) {
67
+ instance = new ServiceClass();
68
+ }
62
69
  const events = Reflect.getMetadata(SOCKET_EVENTS_META, ServiceClass) || [];
63
70
  const classAuthen = Reflect.getMetadata(SOCKET_AUTHEN_META, ServiceClass);
64
71
  const methodAuthenArr = Reflect.getMetadata(SOCKET_AUTHEN_META, ServiceClass) || [];
@@ -52,10 +52,6 @@ const authSocketToken = (socket, next) => {
52
52
  }
53
53
  catch (error) {
54
54
  console.error('❌ Socket authentication error:', error);
55
- // Temporarily allow connection even with invalid token for debugging
56
- console.log('⚠️ Invalid token, but allowing connection for debugging');
57
- socket.userId = 'anonymous';
58
- next();
59
55
  }
60
56
  };
61
57
  exports.authSocketToken = authSocketToken;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-game-decorators",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Express & Socket.IO decorators for auto routing and event handling. using for backend game development.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",