Skip to content

Commit

Permalink
Allow empty data field in custom ping msg
Browse files Browse the repository at this point in the history
  • Loading branch information
Spiss, Lukas committed Dec 5, 2018
1 parent df6981c commit 042ce32
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/sse-channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ function parseMessage(msg, jsonEncode) {
}

var data = msg.data || '';
if (jsonEncode) {
if (jsonEncode && msg.data !== null && typeof msg.data !== 'undefined') {
data = JSON.stringify(data);
}

Expand Down
6 changes: 3 additions & 3 deletions test/sse-channel.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,17 +437,17 @@ describe('sse-channel', function() {
it('sends custom automatic ping', function(done) {
var interval = 25;
var message = {
data: '',
data: null,
event: 'KEEP-ALIVE',
id: 'id'
id: 1
};
initServer({ pingInterval: interval, keepAliveMessage: message });

var opts = url.parse(host + path);
opts.headers = { Accept: 'text/event-stream' };

var initialMessage = ':ok\n\n';
var parsedKeepAliveMessage = 'event: KEEP-ALIVE\nid: id\ndata: ""\n\n\n';
var parsedKeepAliveMessage = 'event: KEEP-ALIVE\nid: 1\ndata: \n\n\n';

var req = http.request(opts, function(res) {
var buf = '';
Expand Down

0 comments on commit 042ce32

Please sign in to comment.