Skip to content

Commit

Permalink
decompress only compressed string
Browse files Browse the repository at this point in the history
  • Loading branch information
shriramshankar committed Jul 20, 2017
1 parent 1a5da66 commit 69fedaa
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions realtime/redisSubscriber.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,31 @@ const unzipAsync = Promise.promisify(zlib.gunzip);
*/
module.exports = (io) => {
sub.on('message', (channel, mssgStr) => {
const mStr = Buffer.from(mssgStr, 'hex');
unzipAsync(mStr)
.then((_mssgStr) => {
try {
const mStr = Buffer.from(mssgStr, 'hex');
unzipAsync(mStr)
.then((_mssgStr) => {

// message object to be sent to the clients
const mssgObj = JSON.parse(_mssgStr);
const key = Object.keys(mssgObj)[0];

/*
* pass on the message received through the redis subscriber to the socket
* io emitter to send data to the browser clients.
*/
emitter(io, key, mssgObj);
});
} catch (err) {
// message object to be sent to the clients
const mssgObj = JSON.parse(_mssgStr);
const mssgObj = JSON.parse(mssgStr);
const key = Object.keys(mssgObj)[0];

/*
* pass on the message received through the redis subscriber to the socket
* io emitter to send data to the browser clients.
*/
emitter(io, key, mssgObj);
});
}
});
};

0 comments on commit 69fedaa

Please sign in to comment.