Comparing version 1.0.4 to 1.1.0
@@ -1,2 +0,2 @@ | ||
// Copyright 2011 Jeff Wilcox | ||
// Copyright Jeff Wilcox | ||
// | ||
@@ -205,9 +205,44 @@ // Licensed under the Apache License, Version 2.0 (the "License"); | ||
var propertiesOfInterest = [ | ||
'pushType', | ||
exports.sendTile = function () { | ||
send('tile', tileProperties, LiveTile, arguments); | ||
} | ||
exports.sendToast = function () { | ||
send('toast', toastProperties, Toast, arguments); | ||
} | ||
exports.sendRawNotification = function () { | ||
send('raw', 'payload', RawNotification, arguments); | ||
} | ||
function send(type, typeProperties, objectType, args) { | ||
var pushUri = Array.prototype.shift.apply(args); | ||
var params = []; | ||
if (typeof args[0] === 'object') { | ||
var payload = Array.prototype.shift.apply(args); | ||
copyOfInterest(payload, params, typeProperties); | ||
} | ||
else { | ||
// assume parameters are provided as atomic, string arguments of the function call | ||
var i = 0; | ||
while ((typeof args[0] === 'string' || typeof args[0] === 'number') && i < typeProperties.length) { | ||
var item = Array.prototype.shift.apply(args); | ||
var key = typeProperties[i++]; | ||
params[key] = item; | ||
} | ||
} | ||
var callback = args[0]; | ||
var instance = new objectType(params); | ||
instance.send(pushUri, callback); | ||
} | ||
var toastProperties = [ | ||
'text1', | ||
'text2', | ||
'param', | ||
'param' | ||
]; | ||
var tileProperties = [ | ||
'backgroundImage', | ||
@@ -218,9 +253,10 @@ 'count', | ||
'backTitle', | ||
'backContent', | ||
'payload' | ||
'backContent' | ||
]; | ||
var propertiesOfInterest = toastProperties.concat(tileProperties); | ||
propertiesOfInterest.push('payload', 'pushType'); | ||
exports.liveTile = LiveTile; | ||
exports.toast = Toast; | ||
exports.rawNotification = RawNotification; |
{ | ||
"name": "mpns", | ||
"description": "A Node.js interface to the Microsoft Push Notification Service (MPNS) for Windows Phone.", | ||
"version": "1.0.4", | ||
"version": "1.1.0", | ||
"author": "Jeff Wilcox <jeffwilcox+github@gmail.com>", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
@@ -9,3 +9,3 @@ #mpns | ||
$ npm install mspn | ||
$ npm install mpns | ||
@@ -20,34 +20,62 @@ As a submodule of your Git project | ||
var mpns = require('mpns'); | ||
```javascript | ||
var mpns = require('mpns'); | ||
``` | ||
### Create a new notification | ||
You can create a new notification object (either of type live tile or toast). | ||
### Sending a toast | ||
To send a toast, simply call the `sendToast` method on mpns. | ||
Property names for the notification object directly correlate to the names used in the MPNS XML payload as documented on MSDN. Properties can either be set directly on the object (such as toast.text1) or by passing the values in as options to the constructor. | ||
```javascript | ||
var mpns = require('mpns'); | ||
mpns.sendToast(pushUri, 'Bold Text', 'This is normal text'); | ||
options = { text1: 'Hello!' | ||
, text2: 'Great to see you today.' | ||
}; | ||
// Optional callback | ||
mpns.sendToast(pushUri, text1, text2, callback); | ||
``` | ||
var toast = new mpns.toast(options); | ||
Each of the methods that send tile and toast notifications have two alternative parameter signatures: | ||
### Sending a notification | ||
To send a notification simply call the `send` method on the object. The first parameter is the HTTP URI to the MPNS endpoint of the client you'd like to send the notification to. You may provide an optional callback function as well. | ||
``` | ||
send*(pushUri, [options], [callback]) | ||
send*(pushUri, string1, string2, ..., [callback]) | ||
``` | ||
toast.send('http://sn1.notify.live.net/throttledthirdparty/01.00/YOUR_ENDPOINT_HERE'); | ||
The ordering of the parameters in the non-object calling method assumes ordering as documented in the toast or tile-specific sections below. | ||
You can also use the other syntax. Let's send a live tile update! | ||
For toasts, the properties and ordering for them: | ||
var toast = new mpns.liveTile(); | ||
toast.title: 'My App'; | ||
toast.backgroundUri: 'http://sample.com/image.png'; | ||
toast.send('http://sn1.notify.live.net/throttledthirdparty/01.00/YOUR_ENDPOINT_HERE', function(err,res) { | ||
if (err) console.dir(err); | ||
else console.dir(res); | ||
}); | ||
* `text1` the text of the toast, this first text will appear bold on the phone | ||
* `text2` additional toast text, will appear in the normal font. It does not wrap. | ||
* `param` optional URI parameter within your application specifying the XAML page to open within the app, along with any query string parameters for the page's context | ||
### Sending a live tile update | ||
To send a tile update, call the `sendTile` method on mpns. | ||
It is recommended that you use the options syntax for this call as it is possible for the live tile update to include just one component in the update, say the tile count, and not update other properties. | ||
The option names or ordering for parameters is: | ||
* `backgroundImage` URI to the background image for the tile. Beware that the URI may be restricted to the whitelisted domain names that you provided in your application. | ||
* `count` the number to appear in the tile | ||
* `title` the title of the tile | ||
* `backBackgroundImage` URI to the image to be on the flip side of the tile | ||
* `backTitle` optional title for the back tile | ||
* `backContent` optional content for the back tile (appears in a larger font size) | ||
### Create a new notification object | ||
You can create a new notification object (either of type live tile or toast). This is the original style for this module but it is now recommended that you use the shorter `send*` syntax on the mpns object itself. This aligns with the WNS module for Windows in its simplicity. | ||
Property names for the notification object directly correlate to the names used in the MPNS XML payload as documented on MSDN. Properties can either be set directly on the object (such as toast.text1) or by passing the values in as options to the constructor. | ||
```javascript | ||
options = { text1: 'Hello!', text2: 'Great to see you today.' }; | ||
var toast = new mpns.toast(options); | ||
``` | ||
### Sending a raw notification | ||
When creating the notification object, either provide the raw payload first, or as the `options.payload` property. | ||
var raw = new mpns.rawNotification('My Raw Payload', options); | ||
```javascript | ||
var raw = new mpns.rawNotification('My Raw Payload', options); | ||
``` | ||
@@ -108,2 +136,6 @@ Today the type on the request is set to UTF8 explicitly. | ||
1.1.0: | ||
* Adds `sendText` and `sendTile` methods more consistent with the WNS module, removing the need to create a new object, only to then call send on it with a push URI. | ||
1.0.4: | ||
@@ -110,0 +142,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
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
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
220
158
16049
4
1