Last active
January 2, 2016 04:19
-
-
Save stephenlb/8249445 to your computer and use it in GitHub Desktop.
Calculating a PubNub Message Payload Size. This is necessary to prevent yourself from getting a "Message Too Large" gateway response.
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
(function(){ | |
// Calculating a PubNub Message Payload Size. | |
function calculate_payload_size( channel, message ) { | |
return encodeURIComponent( channel + JSON.stringify(message) ).length + 97; | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Calculating a PubNub Message Payload Size
You'll want to calculate your message size before sending to PubNub in order to prevent
"Message Too Large"
Gateway Responses. Normally this isn't necessary if you generally cap your message size below 500 bytes, but if you want to approach the absolute limit, here is the solution:Calculation Usage Example