Implement zlib compression of ws messages

This commit is contained in:
David Majdandžić
2023-04-01 17:07:06 +02:00
parent af199c9449
commit f3917090f7
2 changed files with 4 additions and 2 deletions

View File

@@ -1,6 +1,7 @@
import Logger from "../Logger"; import Logger from "../Logger";
import {SessionManager} from "../SessionManager"; import {SessionManager} from "../SessionManager";
import {SmppSession} from "../SmppSession"; import {SmppSession} from "../SmppSession";
import ZlibCoder from "../ZlibCoder";
export class ClientSet { export class ClientSet {
identifier: string; identifier: string;
@@ -55,10 +56,11 @@ export class ClientSet {
} }
notifyClients(message: string) { notifyClients(message: string) {
let compressedMessage = ZlibCoder.compress(message);
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) => {
ws.send(message); ws.send(compressedMessage);
}); });
} }
} }

View File

@@ -2,7 +2,7 @@ const zlib = require("zlib");
export default class ZlibCoder { export default class ZlibCoder {
static compress(input: string): Buffer { static compress(input: string): Buffer {
return zlib.compress(input); return zlib.deflateSync(input).toString('base64');
} }
static decompress(input: Buffer): string { static decompress(input: Buffer): string {