diff --git a/lib/apn.js b/lib/apn.js index 67fae601..7cf99e4a 100644 --- a/lib/apn.js +++ b/lib/apn.js @@ -4,6 +4,19 @@ var sys = require('sys'); var fs = require('fs'); var Buffer = require('buffer').Buffer; +var Errors = { + 'noErrorsEncountered': 0 + , 'processingError': 1 + , 'missingDeviceToken': 2 + , 'missingTopic': 3 + , 'missingPayload': 4 + , 'invalidTokenSize': 5 + , 'invalidTopicSize': 6 + , 'invalidPayloadSize': 7 + , 'invalidToken': 8 + , 'none': 255 +} + var Connection = function (optionArgs) { this.socket = new net.Stream(); this.credentials = crypto.createCredentials(); @@ -62,7 +75,12 @@ var Connection = function (optionArgs) { var messageLength = Buffer.byteLength(message); var pos = 0; - // Check notification length here. Return non-zero as error + if(token === undefined) { + return Errors['missingDeviceToken']; + } + if(messageLength > 255) { + return Errors['invalidPayloadSize']; + } note._uid = this.currentId++; @@ -344,4 +362,5 @@ function invoke_after(callback) { exports.connection = Connection; exports.notification = Notification; exports.device = Device; -exports.feedback = Feedback; \ No newline at end of file +exports.feedback = Feedback; +exports.error = Errors; \ No newline at end of file