Comparing version 1.0.6 to 1.1.0
@@ -1,3 +0,2 @@ | ||
var net = require('net'); | ||
var crypto = require('crypto'); | ||
var tls = require('tls'); | ||
var fs = require('fs'); | ||
@@ -20,4 +19,2 @@ var Buffer = require('buffer').Buffer; | ||
var Connection = function (optionArgs) { | ||
this.socket = new net.Stream(); | ||
this.credentials = crypto.createCredentials(); | ||
this.currentId = 0; | ||
@@ -28,2 +25,4 @@ this.cachedNotes = []; | ||
var hasKey = hasCert = false; | ||
var socketOptions = {}; | ||
var offlineCache = []; | ||
@@ -52,10 +51,9 @@ var options = { cert: 'cert.pem' /* Certificate file */ | ||
var startSocket = function () { | ||
self.socket.connect(options['port'], options['gateway']); | ||
self.socket = tls.connect(options['port'], options['gateway'], socketOptions); | ||
self.socket.pair.on('secure', function () { if(!self.socket.authorized) { throw self.socket.authorizationError } while(offlineCache.length) { self.socket.write(offlineCache.shift()); } }); | ||
self.socket.on('data', function(data) { handleTransmissionError(data); }); | ||
self.socket.once('end', function () { }); | ||
self.socket.once('close', function () { self.socket.removeAllListeners(); self.socket = undefined; }); | ||
} | ||
self.socket.on('connect', function() { self.socket.setSecure(self.credentials); }); | ||
self.socket.on('data', function(data) { handleTransmissionError(data); }); | ||
self.socket.on('error', function(data) {}); | ||
self.socket.on('end', function () { self.socket.end(); }); | ||
var connect = invoke_after(function() { startSocket(); }); | ||
@@ -67,3 +65,3 @@ | ||
} | ||
self.credentials.context.setCert(data.toString()); | ||
socketOptions['cert'] = data.toString(); | ||
hasCert = true; | ||
@@ -76,3 +74,3 @@ })); | ||
} | ||
self.credentials.context.setKey(data.toString()); | ||
socketOptions['key'] = data.toString(); | ||
hasKey = true; | ||
@@ -123,12 +121,7 @@ })); | ||
// If error occurs then slice array and resend all stored notes. | ||
if(self.socket.readyState != 'open') { | ||
if(self.socket.readyState == 'closed' && readyToConnect()) { | ||
if(self.socket === undefined || self.socket.readyState != 'open') { | ||
if((self.socket === undefined || self.socket.readyState == 'closed') && readyToConnect()) { | ||
startSocket(); | ||
} | ||
self.socket.on('connect', | ||
function() { | ||
self.socket.write(data); | ||
self.socket.removeListener('connect', arguments.callee); | ||
}); | ||
offlineCache.push(data); | ||
} | ||
@@ -250,7 +243,5 @@ else { | ||
var Feedback = function (optionArgs) { | ||
this.socket = new net.Stream(); | ||
this.credentials = crypto.createCredentials(); | ||
var self = this; | ||
var hasKey = hasCert = false; | ||
var socketOptions = {} | ||
@@ -285,11 +276,10 @@ var responsePacketLength = 38; | ||
this.startSocket = function () { | ||
self.socket.connect(options['port'], options['address']); | ||
self.startSocket = function () { | ||
self.socket = tls.connect(options['port'], options['address'], socketOptions); | ||
self.socket.pair.on('secure', function () { if(!self.socket.authorized) { throw self.socket.authorizationError } }); | ||
self.socket.on('data', function(data) { processData(data); }); | ||
self.socket.once('end', function () { }); | ||
self.socket.once('close', function () { self.socket.removeAllListeners(); self.socket = undefined; }); | ||
} | ||
self.socket.on('connect', function() { self.socket.setSecure(self.credentials); }); | ||
self.socket.on('data', function(data) { processData(data); }); | ||
self.socket.on('error', function(data) {}); | ||
self.socket.on('end', function () { self.socket.end(); }); | ||
var connect = invoke_after(function() { self.startSocket(); }); | ||
@@ -301,3 +291,3 @@ | ||
} | ||
self.credentials.context.setCert(data.toString()); | ||
socketOptions['cert'] = data.toString(); | ||
hasCert = true; | ||
@@ -310,3 +300,3 @@ })); | ||
} | ||
self.credentials.context.setKey(data.toString()); | ||
socketOptions['key'] = data.toString(); | ||
hasKey = true; | ||
@@ -360,3 +350,3 @@ })); | ||
Feedback.prototype.request = function () { | ||
if(this.socket.readyState == 'closed' && this.readyToConnect()) { | ||
if((this.socket === undefined || this.socket.readyState == 'closed') && this.readyToConnect()) { | ||
this.startSocket(); | ||
@@ -363,0 +353,0 @@ } |
{ | ||
"name": "apn", | ||
"description": "An interface to the Apple Push Notification service for Node.js", | ||
"version": "1.0.6", | ||
"version": "1.1.0", | ||
"author": "Andrew Naylor <argon@mkbot.net>", | ||
@@ -15,3 +15,3 @@ "contributors": [ | ||
}, | ||
"engines": { "node": ">= 0.2.0 <0.4.0" } | ||
"engines": { "node": ">= 0.4.0" } | ||
} |
@@ -129,8 +129,5 @@ #node-apn | ||
1.0.6: | ||
1.1.0: | ||
* Fixes issue #6 where a socket emitting an error could bring down the whole node instance as the exception is uncaught. | ||
1.0.5: | ||
* First shot at node-0.4.0 compatibility with new tls API. | ||
* Fixed a bug with parsing device token which could cause an out-of-bounds error. | ||
@@ -137,0 +134,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
25239
335
156