Skip to content

Commit

Permalink
feat(tools): criando novos tipos de ferrramento para o projeto
Browse files Browse the repository at this point in the history
  • Loading branch information
JefteCosta committed Jul 31, 2024
1 parent 315c986 commit c2c3690
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/interfaces/Utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

export interface IError extends Error {
stack?: string;
}
6 changes: 6 additions & 0 deletions src/types/Utils.ts
Original file line number Diff line number Diff line change
@@ -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;
37 changes: 37 additions & 0 deletions src/utils/Tools.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import * as util from 'util';

export interface IError extends Error {
stack?: string;
}
interface UtilsIdentityFn<Type> {
(arg: Array<Type>): Array<Type>;
}

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<string> = (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<Type>(arg: Type): Type {
return arg;
}

0 comments on commit c2c3690

Please sign in to comment.