Implement zlib compression of ws messages
This commit is contained in:
@@ -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);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -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 {
|
||||||
|
Reference in New Issue
Block a user