Fix some issues with websockets and encoding
This commit is contained in:
@@ -10,7 +10,7 @@ export class CenterSessionManager extends SessionManager {
|
||||
ManagedSessionClass: typeof Center = Center;
|
||||
sessionId: number = 0;
|
||||
sessions: Center[] = [];
|
||||
identifier: string = "center";
|
||||
identifier: string = "Client";
|
||||
readonly logger: Logger = new Logger("CenterSessionManager");
|
||||
|
||||
constructor() {
|
||||
|
@@ -10,7 +10,7 @@ export default class ClientSessionManager extends SessionManager {
|
||||
ManagedSessionClass: typeof Client = Client;
|
||||
sessionId: number = 0;
|
||||
sessions: Client[] = [];
|
||||
identifier: string = "client";
|
||||
identifier: string = "Client";
|
||||
readonly logger: Logger = new Logger("ClientSessionManager");
|
||||
|
||||
constructor() {
|
||||
|
@@ -2,15 +2,17 @@ import EventEmitter from "events";
|
||||
import {PDU, SerializedJob} from "../CommonObjects";
|
||||
|
||||
const smpp = require("smpp");
|
||||
|
||||
// TODO: Use pdu.data_coding for data coding
|
||||
// See available schemes here https://messaggio.com/industry-specifications-and-standards/smpp-data-coding-scheme/
|
||||
export class Job {
|
||||
static readonly STATE_CHANGED: string = "STATE_CHANGED";
|
||||
private eventEmitter: EventEmitter = new EventEmitter();
|
||||
|
||||
constructor(pdu: PDU, perSecond?: number, count?: number) {
|
||||
if (pdu.short_message && pdu.short_message.type === "Buffer") {
|
||||
pdu.short_message = String(pdu.short_message.data);
|
||||
pdu.short_message = Buffer.from(pdu.short_message.data, 'ascii').toString();
|
||||
}
|
||||
pdu.short_message = 'test123';
|
||||
this._pdu = pdu;
|
||||
this._perSecond = perSecond;
|
||||
this._count = count;
|
||||
|
@@ -131,22 +131,22 @@ export abstract class SmppSession {
|
||||
this.logger.log1(`Update WS: ${event}`);
|
||||
let message: {
|
||||
type: string,
|
||||
data?: string
|
||||
data?: any
|
||||
} = {
|
||||
type: event,
|
||||
};
|
||||
switch (event) {
|
||||
case this.EVENT.STATE_CHANGED:
|
||||
message.data = JSON.stringify(this.serialize());
|
||||
message.data = this.serialize();
|
||||
break;
|
||||
case this.EVENT.STATUS_CHANGED:
|
||||
message.data = JSON.stringify(this.status);
|
||||
message.data = this.status;
|
||||
break;
|
||||
case this.EVENT.ANY_PDU:
|
||||
message.data = JSON.stringify(args![0]);
|
||||
message.data = args![0];
|
||||
break;
|
||||
case this.EVENT.MESSAGE_SEND_COUNTER_UPDATE_EVENT:
|
||||
message.data = JSON.stringify(args![0]);
|
||||
message.data = args![0];
|
||||
break;
|
||||
}
|
||||
this.eventEmitter.emit(this.UPDATE_WS, message);
|
||||
|
@@ -19,6 +19,7 @@ export class ClientSet {
|
||||
this.sessionId = parseInt(data[1]);
|
||||
|
||||
this.logger = new Logger(`ClientSet-${this.type}-${this.sessionId}`);
|
||||
this.logger.log1(`Created client set for ${this.type} ${this.sessionId}`);
|
||||
|
||||
this.relevantSessionManager = sessionManagers.find(sm => sm.identifier === this.type);
|
||||
if (!this.relevantSessionManager) {
|
||||
@@ -45,7 +46,7 @@ export class ClientSet {
|
||||
add(ws: any): void {
|
||||
this.logger.log2(`Added client`);
|
||||
this.clients.push(ws);
|
||||
ws.on('close', this.eventOnClose.bind(this));
|
||||
ws.on('close', this.eventOnClose.bind(this, ws));
|
||||
}
|
||||
|
||||
eventOnClose(ws: any): void {
|
||||
@@ -54,11 +55,13 @@ export class ClientSet {
|
||||
}
|
||||
|
||||
notifyClients(message: string) {
|
||||
if (this.clients.length > 0) {
|
||||
this.logger.log2(`Notifying clients: ${message}`);
|
||||
this.clients.forEach((ws) => {
|
||||
ws.send(message);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private attachListener(session: SmppSession) {
|
||||
session.on(session.UPDATE_WS, (message: object) => this.notifyClients(JSON.stringify(message)));
|
||||
|
@@ -39,6 +39,7 @@ export class WSServer {
|
||||
let clientSet: ClientSet | undefined = this.clients.find((clientSet: ClientSet) => clientSet.identifier === message);
|
||||
if (!clientSet) {
|
||||
clientSet = new ClientSet(message, this.sessionManagers);
|
||||
this.clients.push(clientSet);
|
||||
}
|
||||
clientSet.add(ws);
|
||||
}
|
||||
|
Reference in New Issue
Block a user