UNPKG

@amirmarmul/waba-common

Version:

![GitHub release](https://img.shields.io/github/v/release/amirmarmul/waba-common?style=flat-square)

35 lines (34 loc) 1.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Connection = void 0; const grpc_js_1 = require("@grpc/grpc-js"); const protobufjs_1 = require("protobufjs"); class Connection { static connection = null; static server = null; constructor() { Connection.connection = new protobufjs_1.Root(); const Event = new protobufjs_1.Type("Event").add(new protobufjs_1.Field("data", 1, "string")); const Listener = new protobufjs_1.Type("Listener").add(new protobufjs_1.Field("message", 1, "string")); Connection.connection.add(Event).add(Listener); if (!Connection.server) { Connection.server = new grpc_js_1.Server(); Connection.server.bindAsync(process.env.APP_GRPC, grpc_js_1.ServerCredentials.createInsecure(), () => { Connection.server.start(); }); } } static getConnection() { if (!Connection.connection) { new Connection(); } return Connection.connection; } static getServer() { if (!Connection.server) { new Connection(); } return Connection.server; } } exports.Connection = Connection;