@hastehaul/common 3.12.0 → 4.0.0

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.
@@ -1,8 +1,8 @@
1
1
  import { EventEmitter } from 'events';
2
- declare class SingletonEventEmitter {
3
- private _instance?;
4
- get instance(): EventEmitter;
5
- init(): void;
2
+ declare class SingletonEventEmitter extends EventEmitter {
3
+ private static _instance;
4
+ private constructor();
5
+ static get instance(): SingletonEventEmitter;
6
6
  }
7
7
  export declare const emitterWrapper: SingletonEventEmitter;
8
8
  export {};
@@ -2,14 +2,16 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.emitterWrapper = void 0;
4
4
  const events_1 = require("events");
5
- class SingletonEventEmitter {
6
- get instance() {
7
- if (!this._instance)
8
- throw new Error("Can not access EVENT EMITTER client before connecting");
9
- return this._instance;
5
+ class SingletonEventEmitter extends events_1.EventEmitter {
6
+ constructor() {
7
+ super();
10
8
  }
11
- init() {
12
- this._instance = new events_1.EventEmitter();
9
+ static get instance() {
10
+ if (!this._instance) {
11
+ this._instance = new SingletonEventEmitter();
12
+ }
13
+ return this._instance;
13
14
  }
14
15
  }
15
- exports.emitterWrapper = new SingletonEventEmitter();
16
+ // Export the singleton instance
17
+ exports.emitterWrapper = SingletonEventEmitter.instance;
@@ -1,5 +1,5 @@
1
1
  import http from "http";
2
- import { Server } from 'socket.io';
2
+ import { Server, ServerOptions } from 'socket.io';
3
3
  /**
4
4
  * A wrapper class for the Socket.IO server to manage connections and provide a centralized server instance.
5
5
  */
@@ -19,7 +19,7 @@ export declare class SocketWrapper {
19
19
  *
20
20
  * @param {http.Server} httpServer - The HTTP server instance to attach Socket.IO to.
21
21
  */
22
- connect(httpServer: http.Server, path?: string, adapter?: any): Promise<void>;
22
+ connect(httpServer: http.Server, opts?: Partial<ServerOptions>): Promise<void>;
23
23
  }
24
24
  /**
25
25
  * Singleton instance of the SocketWrapper class to provide a centralized Socket.IO server connection.
@@ -33,20 +33,10 @@ class SocketWrapper {
33
33
  *
34
34
  * @param {http.Server} httpServer - The HTTP server instance to attach Socket.IO to.
35
35
  */
36
- connect(httpServer, path, adapter) {
36
+ connect(httpServer, opts) {
37
37
  return __awaiter(this, void 0, void 0, function* () {
38
38
  return new Promise((resolve, reject) => {
39
- this._io = new socket_io_1.Server(httpServer, {
40
- adapter: adapter,
41
- path: `/${path ? path + '/' : ''}socket/`,
42
- pingTimeout: 30000,
43
- pingInterval: 25000,
44
- cors: {
45
- origin: "*",
46
- methods: ["GET", "POST"],
47
- // credentials: true,
48
- },
49
- });
39
+ this._io = new socket_io_1.Server(httpServer, opts);
50
40
  resolve();
51
41
  });
52
42
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hastehaul/common",
3
- "version": "3.12.0",
3
+ "version": "4.0.0",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",