-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow message and presencemessage to work without data
- Loading branch information
Simon Woolf
committed
May 11, 2015
1 parent
c1c7606
commit 440f4ec
Showing
3 changed files
with
10 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,11 +24,11 @@ var Message = (function() { | |
encoding: this.encoding | ||
}; | ||
|
||
/* encode to base64 if we're returning real JSON; | ||
/* encode data to base64 if present and we're returning real JSON; | ||
* although msgpack calls toJSON(), we know it is a stringify() | ||
* call if it has a non-empty arguments list */ | ||
var data = this.data; | ||
if(arguments.length > 0 && BufferUtils.isBuffer(data)) { | ||
if(data && arguments.length > 0 && BufferUtils.isBuffer(data)) { | ||
var encoding = this.encoding; | ||
result.encoding = encoding ? (encoding + '/base64') : 'base64'; | ||
data = BufferUtils.base64Encode(data); | ||
|
@@ -78,10 +78,12 @@ var Message = (function() { | |
}; | ||
|
||
Message.encode = function(msg, options) { | ||
var data = msg.data, encoding; | ||
if(typeof(data) != 'string' && !BufferUtils.isBuffer(data)) { | ||
msg.data = JSON.stringify(data); | ||
msg.encoding = (encoding = msg.encoding) ? (encoding + '/json') : 'json'; | ||
if(msg.data){ | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
SimonWoolf
Member
|
||
var data = msg.data, encoding; | ||
if(typeof(data) != 'string' && !BufferUtils.isBuffer(data)) { | ||
msg.data = JSON.stringify(data); | ||
msg.encoding = (encoding = msg.encoding) ? (encoding + '/json') : 'json'; | ||
} | ||
} | ||
if(options != null && options.encrypted) | ||
Message.encrypt(msg, options); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Why read
msg.data
here and then read it again on the next line?Don't we just need to add a
data &&
to the followingif
?Edit: actually that won't work either, because
''
is falsy but we want to send''
.