@hastehaul/common 2.0.27 → 2.0.29

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,7 +22,7 @@ export declare class RedisWrapper {
22
22
  * @param {string} host - The Redis server host address (default is "customer-redis-srv").
23
23
  * @param {number} port - The Redis server port number (default is 6379).
24
24
  */
25
- connect(host?: string, port?: number): void;
25
+ connect(host?: string, port?: number): Promise<void>;
26
26
  }
27
27
  /**
28
28
  * Singleton instance of the RedisWrapper class to provide a centralized Redis client connection.
@@ -1,4 +1,13 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
13
  };
@@ -34,12 +43,18 @@ class RedisWrapper {
34
43
  * @param {number} port - The Redis server port number (default is 6379).
35
44
  */
36
45
  connect(host, port) {
37
- this._redisClient = new ioredis_1.default({ host: host || this.host, port: port || this.port, maxRetriesPerRequest: null });
38
- this._redisClient.on("connect", function () {
39
- console.info("Redis Server Connected!");
40
- });
41
- this._redisClient.on("error", function (error) {
42
- console.error("Error in Redis", error);
46
+ return __awaiter(this, void 0, void 0, function* () {
47
+ return new Promise((resolve, reject) => {
48
+ this._redisClient = new ioredis_1.default({ host: host || this.host, port: port || this.port, maxRetriesPerRequest: null });
49
+ this._redisClient.on("connect", () => {
50
+ console.info("Redis Server Connected!");
51
+ resolve();
52
+ });
53
+ this._redisClient.on("error", (error) => {
54
+ console.error("Error in Redis", error);
55
+ reject(error);
56
+ });
57
+ });
43
58
  });
44
59
  }
45
60
  }
@@ -20,7 +20,7 @@ export declare class SocketWrapper {
20
20
  *
21
21
  * @param {http.Server} httpServer - The HTTP server instance to attach Socket.IO to.
22
22
  */
23
- connect(httpServer: http.Server, path?: string): void;
23
+ connect(httpServer: http.Server, path?: string): Promise<void>;
24
24
  }
25
25
  /**
26
26
  * Singleton instance of the SocketWrapper class to provide a centralized Socket.IO server connection.
@@ -1,4 +1,13 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.socketWrapper = exports.SocketWrapper = void 0;
4
13
  const socket_io_1 = require("socket.io");
@@ -25,15 +34,27 @@ class SocketWrapper {
25
34
  * @param {http.Server} httpServer - The HTTP server instance to attach Socket.IO to.
26
35
  */
27
36
  connect(httpServer, path) {
28
- this._io = new socket_io_1.Server(httpServer, {
29
- path: `/${path ? path + '/' : ''}socket/`,
30
- pingTimeout: 30000,
31
- pingInterval: 25000,
32
- cors: {
33
- origin: "*",
34
- methods: ["GET", "POST"],
35
- // credentials: true,
36
- },
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ return new Promise((resolve, reject) => {
39
+ this._io = new socket_io_1.Server(httpServer, {
40
+ path: `/${path ? path + '/' : ''}socket/`,
41
+ pingTimeout: 30000,
42
+ pingInterval: 25000,
43
+ cors: {
44
+ origin: "*",
45
+ methods: ["GET", "POST"],
46
+ // credentials: true,
47
+ },
48
+ });
49
+ this._io.on("connect", () => {
50
+ console.info("Socket.io Server Connected!");
51
+ resolve();
52
+ });
53
+ this._io.on("error", (error) => {
54
+ console.error("Error in Socket.io", error);
55
+ reject(error);
56
+ });
57
+ });
37
58
  });
38
59
  }
39
60
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hastehaul/common",
3
- "version": "2.0.27",
3
+ "version": "2.0.29",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",