Fix issue where wsmessages were broadscast instead of sent to their respective client
This commit is contained in:
@@ -30,3 +30,8 @@ export type SerializedJob = {
|
|||||||
count?: number;
|
count?: number;
|
||||||
perSecond?: number;
|
perSecond?: number;
|
||||||
};
|
};
|
||||||
|
export type WSMessage = {
|
||||||
|
type: string;
|
||||||
|
identifier: string;
|
||||||
|
data?: any;
|
||||||
|
};
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import EventEmitter from "events";
|
import EventEmitter from "events";
|
||||||
import {PDU} from "./CommonObjects";
|
import {PDU, WSMessage} from "./CommonObjects";
|
||||||
import Job from "./Job/Job";
|
import Job from "./Job/Job";
|
||||||
import Logger from "./Logger";
|
import Logger from "./Logger";
|
||||||
import PduProcessor from "./PDUProcessor/PduProcessor";
|
import PduProcessor from "./PDUProcessor/PduProcessor";
|
||||||
@@ -157,11 +157,9 @@ export default abstract class SmppSession {
|
|||||||
|
|
||||||
updateWs(event: string, args?: any[]): void {
|
updateWs(event: string, args?: any[]): void {
|
||||||
this.logger.log1(`Update WS: ${event}`);
|
this.logger.log1(`Update WS: ${event}`);
|
||||||
let message: {
|
let message: WSMessage = {
|
||||||
type: string,
|
|
||||||
data?: any
|
|
||||||
} = {
|
|
||||||
type: event,
|
type: event,
|
||||||
|
identifier: `${this.constructor.name}:${this.id.toString()}`
|
||||||
};
|
};
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case this.EVENT.STATE_CHANGED:
|
case this.EVENT.STATE_CHANGED:
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import {WSMessage} from "../CommonObjects";
|
||||||
import Logger from "../Logger";
|
import Logger from "../Logger";
|
||||||
import SessionManager from "../SessionManager";
|
import SessionManager from "../SessionManager";
|
||||||
import SmppSession from "../SmppSession";
|
import SmppSession from "../SmppSession";
|
||||||
@@ -55,8 +56,10 @@ export default class ClientSet {
|
|||||||
this.clients.splice(this.clients.indexOf(ws), 1);
|
this.clients.splice(this.clients.indexOf(ws), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
notifyClients(message: string) {
|
notifyClients(message: WSMessage) {
|
||||||
let compressedMessage = ZlibCoder.compress(message);
|
if (message.identifier !== this.identifier) return;
|
||||||
|
let textMessage: string = JSON.stringify(message);
|
||||||
|
let compressedMessage = ZlibCoder.compress(textMessage);
|
||||||
if (this.clients.length > 0) {
|
if (this.clients.length > 0) {
|
||||||
this.logger.log2(`Notifying clients: ${message}`);
|
this.logger.log2(`Notifying clients: ${message}`);
|
||||||
this.clients.forEach((ws) => {
|
this.clients.forEach((ws) => {
|
||||||
@@ -66,6 +69,6 @@ export default class ClientSet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private attachListener(session: SmppSession) {
|
private attachListener(session: SmppSession) {
|
||||||
session.on(session.UPDATE_WS, (message: object) => this.notifyClients(JSON.stringify(message)));
|
session.on(session.UPDATE_WS, (message: WSMessage) => this.notifyClients(message));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user