Enable client connecting
This commit is contained in:
@@ -103,14 +103,16 @@ export class Client implements SmppSession {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.session.bind_transceiver({
|
this.session.bind_transceiver({
|
||||||
system_id: this.username, password: this.password,
|
system_id: this._username, password: this._password,
|
||||||
}, this.eventBindReply.bind(this));
|
}, this.eventBindReply.bind(this));
|
||||||
});
|
});
|
||||||
return this.bindPromise;
|
return this.bindPromise;
|
||||||
}
|
}
|
||||||
|
|
||||||
connectAndBind(): Promise<void> {
|
connectAndBind(): Promise<void> {
|
||||||
return this.connect().then(this.bind.bind(this));
|
return this.connect().then(this.bind.bind(this), (error) => {
|
||||||
|
this.logger.log1(`Client-${this.id} connectAndBind failed: ${error}`);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
serialize(): string {
|
serialize(): string {
|
||||||
@@ -160,10 +162,10 @@ export class Client implements SmppSession {
|
|||||||
this.eventEmitter.emit(Client.ClientEvents.ANY_PDU, pdu);
|
this.eventEmitter.emit(Client.ClientEvents.ANY_PDU, pdu);
|
||||||
}
|
}
|
||||||
|
|
||||||
private eventSessionError(): void {
|
private eventSessionError(pdu: any): void {
|
||||||
this.logger.log1(`Client-${this.id} error on ${this._url}`);
|
this.logger.log1(`Client-${this.id} error on ${this._url}`);
|
||||||
this.setStatus(ClientStatus.NOT_CONNECTED);
|
this.setStatus(ClientStatus.NOT_CONNECTED);
|
||||||
this.rejectPromises();
|
this.rejectPromises(pdu);
|
||||||
}
|
}
|
||||||
|
|
||||||
private eventSessionClose(): void {
|
private eventSessionClose(): void {
|
||||||
@@ -183,17 +185,17 @@ export class Client implements SmppSession {
|
|||||||
this.logger.log1(`Client-${this.id} bind failed to ${this.url}`);
|
this.logger.log1(`Client-${this.id} bind failed to ${this.url}`);
|
||||||
this.setStatus(ClientStatus.CONNECTED);
|
this.setStatus(ClientStatus.CONNECTED);
|
||||||
if (this.bindPromise) {
|
if (this.bindPromise) {
|
||||||
this.bindPromise.reject();
|
this.bindPromise.reject(pdu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private rejectPromises(): void {
|
private rejectPromises(err?: any): void {
|
||||||
if (this.connectPromise) {
|
if (this.connectPromise) {
|
||||||
this.connectPromise.reject();
|
this.connectPromise.reject(err);
|
||||||
}
|
}
|
||||||
if (this.bindPromise) {
|
if (this.bindPromise) {
|
||||||
this.bindPromise.reject();
|
this.bindPromise.reject(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
35
src/main.ts
35
src/main.ts
@@ -22,44 +22,11 @@ const MESSAGE_SEND_UPDATE_DELAY: number = Number(process.env.MESSAGE_SEND_UPDATE
|
|||||||
// TODO: Add support for encodings
|
// TODO: Add support for encodings
|
||||||
// TODO: Implement some sort of metrics on frontend by counting the pdus
|
// TODO: Implement some sort of metrics on frontend by counting the pdus
|
||||||
|
|
||||||
[
|
|
||||||
'debug',
|
|
||||||
'log',
|
|
||||||
'warn',
|
|
||||||
'error'
|
|
||||||
].forEach((methodName: string) => {
|
|
||||||
// @ts-ignore
|
|
||||||
const originalLoggingMethod: object = console[methodName];
|
|
||||||
// @ts-ignore
|
|
||||||
console[methodName] = (firstArgument, ...otherArguments) => {
|
|
||||||
// @ts-ignore
|
|
||||||
const originalPrepareStackTrace = Error.prepareStackTrace;
|
|
||||||
// @ts-ignore
|
|
||||||
Error.prepareStackTrace = (_, stack) => stack;
|
|
||||||
// @ts-ignore
|
|
||||||
const callee = new Error().stack[2];
|
|
||||||
// @ts-ignore
|
|
||||||
Error.prepareStackTrace = originalPrepareStackTrace;
|
|
||||||
// @ts-ignore
|
|
||||||
const relativeFileName = path.relative(process.cwd(), callee.getFileName());
|
|
||||||
// @ts-ignore
|
|
||||||
const prefix = `${relativeFileName}:${callee.getLineNumber()}:`;
|
|
||||||
// @ts-ignore
|
|
||||||
if (typeof firstArgument === 'string') {
|
|
||||||
// @ts-ignore
|
|
||||||
originalLoggingMethod(prefix + ' ' + firstArgument, ...otherArguments);
|
|
||||||
} else {
|
|
||||||
// @ts-ignore
|
|
||||||
originalLoggingMethod(prefix, firstArgument, ...otherArguments);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
let logger = new Logger("main");
|
let logger = new Logger("main");
|
||||||
|
|
||||||
import {Client} from "./client";
|
import {Client} from "./client";
|
||||||
|
|
||||||
let client: Client = new Client(0, "smpp://localhost:7001", "test", "test");
|
let client: Client = new Client(0, "smpp://localhost:7000", "test", "test");
|
||||||
client.connectAndBind().then(() => {
|
client.connectAndBind().then(() => {
|
||||||
console.log("POGGIES");
|
console.log("POGGIES");
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user