From c2c3690f3f6eb0042052871e0cd0a7bdc2ad118e Mon Sep 17 00:00:00 2001 From: JefteCosta Date: Wed, 31 Jul 2024 08:29:32 -0300 Subject: [PATCH] feat(tools): criando novos tipos de ferrramento para o projeto --- src/index.ts | 7 +++---- src/interfaces/Utils.ts | 4 ++++ src/types/Utils.ts | 6 ++++++ src/utils/Tools.ts | 37 +++++++++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 src/interfaces/Utils.ts create mode 100644 src/types/Utils.ts create mode 100644 src/utils/Tools.ts diff --git a/src/index.ts b/src/index.ts index ca5bc0b..d045758 100644 --- a/src/index.ts +++ b/src/index.ts @@ -20,14 +20,13 @@ export interface OptionsData { error: (error: any) => void; }; } -export const authenticator = new Authenticator(); -export const sdpParser = new SDPParser(); -export const sipParser = new SIPParser(); + export function startServer(options: OptionsData) { const transactionManager = new TransactionManager(); - + + const sipParser = new SIPParser(); const callback = (m: any, remote: any) => { console.log('Processing message:', m); // ImplementaĆ§Ć£o do processamento da mensagem recebida diff --git a/src/interfaces/Utils.ts b/src/interfaces/Utils.ts new file mode 100644 index 0000000..7ac77c6 --- /dev/null +++ b/src/interfaces/Utils.ts @@ -0,0 +1,4 @@ + +export interface IError extends Error { + stack?: string; +} \ No newline at end of file diff --git a/src/types/Utils.ts b/src/types/Utils.ts new file mode 100644 index 0000000..f9a51b8 --- /dev/null +++ b/src/types/Utils.ts @@ -0,0 +1,6 @@ + +import { IError } from "#interfaces/Utils"; + +export type StringBase64 = Buffer; +export type Debug = (e: IError) => void; +export type ToBase64 = (s: StringBase64) => string; \ No newline at end of file diff --git a/src/utils/Tools.ts b/src/utils/Tools.ts new file mode 100644 index 0000000..efbe3c5 --- /dev/null +++ b/src/utils/Tools.ts @@ -0,0 +1,37 @@ +import * as util from 'util'; + +export interface IError extends Error { + stack?: string; +} +interface UtilsIdentityFn { + (arg: Array): Array; + } + +export type StringBase64 = Buffer; +export type Debug = (e: IError) => void; +export type ToBase64 = (s: StringBase64) => string; + +export const debug: Debug = (e: IError) => { + if (e.stack) { + util.debug(e + '\n' + e.stack); + } else { + util.debug(util.inspect(e)); + } +}; +export const toBase64: UtilsIdentityFn = (s: string[]) => { + switch(s.length % 3) { + case 1: + s += ' '; + break; + case 2: + s += ' '; + break; + default: + } + + return Buffer.from(s).toString('base64').replace(/\//g, '_').replace(/\+/g, '-'); + } + + function identity(arg: Type): Type { + return arg; + } \ No newline at end of file