Skip to content

Commit

Permalink
feat(novas funcionalidades): criação de nova funcionalidade do tools
Browse files Browse the repository at this point in the history
  • Loading branch information
JefteCosta committed Aug 1, 2024
1 parent c2c3690 commit 664bddb
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Transport from '#services/Transport';

import TransactionManager from '#src/TransactionManager';
export interface OptionsData {

protocol: string;
port: number;
address: string;
publicAddress: string;
Expand Down
2 changes: 2 additions & 0 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Transport from '#services/Transport';
import TransactionManager from '#src/TransactionManager';

interface ServerOptions {
protocol: string;
port: number;
address: string;
publicAddress: string;
Expand All @@ -22,6 +23,7 @@ interface ServerOptions {

// Configuração inicial
const options: ServerOptions = {
protocol: 'udp',
port: 5060,
address: '0.0.0.0',
publicAddress: 'example.com',
Expand Down
13 changes: 7 additions & 6 deletions src/utils/Tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ import * as util from 'util';
export interface IError extends Error {
stack?: string;
}
interface UtilsIdentityFn<Type> {
(arg: Array<Type>): Array<Type>;
interface Lengthwise {
length: number;
}
interface ToolsFn<Type extends Lengthwise> {
(arg: Type): Type;
}

export type StringBase64 = Buffer;
Expand All @@ -18,7 +21,7 @@ export const debug: Debug = (e: IError) => {
util.debug(util.inspect(e));
}
};
export const toBase64: UtilsIdentityFn<string> = (s: string[]) => {
export const toBase64: ToolsFn<string> = (s: string):string => {
switch(s.length % 3) {
case 1:
s += ' ';
Expand All @@ -32,6 +35,4 @@ export const toBase64: UtilsIdentityFn<string> = (s: string[]) => {
return Buffer.from(s).toString('base64').replace(/\//g, '_').replace(/\+/g, '-');
}

function identity<Type>(arg: Type): Type {
return arg;
}

12 changes: 6 additions & 6 deletions test/teste.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { startServer } from "#src/index"

const options = {

protocol: 'udp',
port: 5060,
address: '0.0.0.0',
address: 'localhost',
publicAddress: 'example.com',
logger: {
recv: (msg: any, remote: any) => console.log('Received:', msg, remote),
send: (msg: any, target: any) => console.log('Sent:', msg, target),
error: (error: any) => console.error('Error:', error)
},
tls: {
key: '',
cert: ''
}
// tls: {
// key: '',
// cert: ''
// }
};

startServer(options);

0 comments on commit 664bddb

Please sign in to comment.