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;
|
||||
perSecond?: number;
|
||||
};
|
||||
export type WSMessage = {
|
||||
type: string;
|
||||
identifier: string;
|
||||
data?: any;
|
||||
};
|
||||
@@ -1,5 +1,5 @@
|
||||
import EventEmitter from "events";
|
||||
import {PDU} from "./CommonObjects";
|
||||
import {PDU, WSMessage} from "./CommonObjects";
|
||||
import Job from "./Job/Job";
|
||||
import Logger from "./Logger";
|
||||
import PduProcessor from "./PDUProcessor/PduProcessor";
|
||||
@@ -157,11 +157,9 @@ export default abstract class SmppSession {
|
||||
|
||||
updateWs(event: string, args?: any[]): void {
|
||||
this.logger.log1(`Update WS: ${event}`);
|
||||
let message: {
|
||||
type: string,
|
||||
data?: any
|
||||
} = {
|
||||
let message: WSMessage = {
|
||||
type: event,
|
||||
identifier: `${this.constructor.name}:${this.id.toString()}`
|
||||
};
|
||||
switch (event) {
|
||||
case this.EVENT.STATE_CHANGED:
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import {WSMessage} from "../CommonObjects";
|
||||
import Logger from "../Logger";
|
||||
import SessionManager from "../SessionManager";
|
||||
import SmppSession from "../SmppSession";
|
||||
@@ -55,8 +56,10 @@ export default class ClientSet {
|
||||
this.clients.splice(this.clients.indexOf(ws), 1);
|
||||
}
|
||||
|
||||
notifyClients(message: string) {
|
||||
let compressedMessage = ZlibCoder.compress(message);
|
||||
notifyClients(message: WSMessage) {
|
||||
if (message.identifier !== this.identifier) return;
|
||||
let textMessage: string = JSON.stringify(message);
|
||||
let compressedMessage = ZlibCoder.compress(textMessage);
|
||||
if (this.clients.length > 0) {
|
||||
this.logger.log2(`Notifying clients: ${message}`);
|
||||
this.clients.forEach((ws) => {
|
||||
@@ -66,6 +69,6 @@ export default class ClientSet {
|
||||
}
|
||||
|
||||
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