diff --git a/notify-term/WNSAuth.js b/notify-term/WNSAuth.js index e72f0ca..45a1a63 100644 --- a/notify-term/WNSAuth.js +++ b/notify-term/WNSAuth.js @@ -67,6 +67,13 @@ class WNSAuth extends EventEmitter var uuid = Rand.uuid(); _self.__send( ChannelUri, N, ( sender, e ) => { + + if( typeof( e ) == "string" ) + { + handler( _self, e ); + return; + } + if( e.statusCode == 200 ) { Model.Tokens.update( @@ -83,11 +90,8 @@ class WNSAuth extends EventEmitter } handler( _self, uuid ); } ); - return; } - handler( _self, e.statusCode + " Server Error: Unable to push message to channel" ); - } ); }; @@ -134,24 +138,32 @@ class WNSAuth extends EventEmitter return; } - var Request = new HttpRequest( ChannelUri, { - "Authorization": "Bearer " + AuthToken - , "X-WNS-RequestForStatus": "true" - , "X-WNS-Type": "wns/toast" - } ); - - if( !Request.Hostname.match( /.*\.notify\.windows\.com$/ ) ) + try { - handler( this, "Malicious hostname: " + Request.Hostname ); + var Request = new HttpRequest( ChannelUri, { + "Authorization": "Bearer " + AuthToken + , "X-WNS-RequestForStatus": "true" + , "X-WNS-Type": "wns/toast" + } ); + + if( !Request.Hostname.match( /.*\.notify\.windows\.com$/ ) ) + { + handler( this, "Malicious hostname: " + Request.Hostname ); + return; + } + + Request.PostData( NotisQ.Xml ); + Request.Headers[ "Content-Type" ] = "text/xml"; + + Request.addListener( "RequestComplete", handler ); + + Request.Send(); + } + catch( ex ) + { + handler( this, ex.message ); return; } - - Request.PostData( NotisQ.Xml ); - Request.Headers[ "Content-Type" ] = "text/xml"; - - Request.addListener( "RequestComplete", handler ); - - Request.Send(); } __authWNS() diff --git a/notify-term/app.js b/notify-term/app.js index d832b0f..ab83688 100644 --- a/notify-term/app.js +++ b/notify-term/app.js @@ -80,12 +80,13 @@ class App extends Base ProcessQueue() { - if( !this.RequestQueue.length ) return; + if(!( this.RequestQueue && this.RequestQueue.length )) + { + this.RequestQueue = []; + return; + } var Request = this.RequestQueue.shift(); - - Dragonfly.Info( "Processing Request: " + Request ); - this.OAuth.Deliver( Request ); } } diff --git a/notify-term/schema.js b/notify-term/schema.js index 137af18..f04e6fc 100644 --- a/notify-term/schema.js +++ b/notify-term/schema.js @@ -25,6 +25,10 @@ var R_Tokens = { type: Schema.Types.ObjectId, ref: "Tokens" }; var M_Tokens = new Schema({ name: { type: String, unique: true } , token: { type: String } + , date_created: { + type: Date + , default: Date.now + } });