UNPKG

9.61 kBMarkdownView Raw
1#mpns
2
3[![build status](https://secure.travis-ci.org/jeffwilcox/mpns.png)](http://travis-ci.org/jeffwilcox/mpns)
4
5Send toast and live tile updates to Windows Phones through the Microsoft Push Notification Service (MPNS). Intended for cloud applications powered by Node.js.
6
7## Installation
8
9Via [npm][]:
10
11 $ npm install mpns
12
13As a submodule of your Git project
14
15 $ git submodule add http://github.com/jeffwilcox/mpns.git mpns
16 $ git submodule update --init
17
18## Usage
19### Load in the module
20
21```javascript
22var mpns = require('mpns');
23```
24
25### Sending a toast
26To send a toast, simply call the `sendToast` method on mpns.
27
28```javascript
29var mpns = require('mpns');
30mpns.sendToast(pushUri, 'Bold Text', 'This is normal text');
31
32// Optional callback
33mpns.sendToast(pushUri, text1, text2, callback);
34```
35
36Each of the methods that send tile and toast notifications have two alternative parameter signatures:
37
38```
39send*(pushUri, [options], [callback])
40send*(pushUri, string1, string2, ..., [callback])
41```
42
43The ordering of the parameters in the non-object calling method assumes ordering as documented in the toast or tile-specific sections below.
44
45For toasts, the properties and ordering for them:
46
47* `text1` the text of the toast, this first text will appear bold on the phone
48* `text2` additional toast text, will appear in the normal font. It does not wrap.
49* `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
50
51### Sending a live tile update
52To send a tile update, call the `sendTile` method on mpns.
53
54It 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. To clear the value of a property, simply pass `null` as the value.
55
56The option names or ordering for parameters is:
57
58* `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.
59* `count` the number to appear in the tile
60* `title` the title of the tile
61* `backBackgroundImage` URI to the image to be on the flip side of the tile
62* `backTitle` optional title for the back tile
63* `backContent` optional content for the back tile (appears in a larger font size)
64* `id` optional ID for a secodary tile
65
66Some devices support an enhanced tile format called a "flip tile", which supports some additional parameters. This kind of tile can be sent using the `sendFlipTile` method, which supports *all of the above* parameters as well as:
67* `smallBackgroundImage` URI to the background image for the tile when it is shrunk to small size
68* `wideBackgroundImage` URI to the background image for the tile when it is expanded to wide size
69* `wideBackContent` content for the back tile (appears in a larger font size) when the tile is expanded to wide size
70* `wideBackBackgroundImage` URI to the image to be on the flip side of the tile when the tile is expanded to wide size
71
72Another format is called "iconic tile". This can be sent using `sendIconicTile` method with the following parameters:
73* `backgroundColor` hexadecimal color code in format ARGB
74* `count` the number that apper on the right of an icon
75* `title` the title of the tile
76* `iconImage` URI of the normal icon
77* `smallIconImage` URI of the icon for small tile
78* `wideContent1` top line of text shown in a wide tile
79* `wideContent2` second line of text
80* `wideContent3` third line of text
81
82### Sending a raw notification
83When creating the notification object, either provide the raw payload first, or as the `options.payload` property.
84
85```javascript
86var raw = new mpns.rawNotification('My Raw Payload', options);
87```
88
89Today the type on the request is set to UTF8 explicitly.
90
91### Using authenticated channels (MTLS)
92You may use authenticated channels for the push notifications. Further information can be found here:http://msdn.microsoft.com/en-us/library/windowsphone/develop/ff941099(v=vs.105).aspx
93
94Authenticated channels require a TLS client certificate for client authentication against the MPNS server.
95The TLS certificate is registered in your Microsoft Phone Development Dashboard.
96The CN of the certificate is used in the APP as Service Name in the HttpNotificationChannel constructor.
97
98To use authentication you must provide the client certificate (including the private key) to the options of the send* functions.
99The client certificate is used when the pushURI is a https URI.
100
101The following options from tls.connect() can be specified:
102
103* `pfx` Certificate, Private key and CA certificates to use for SSL. Default null.
104* `key` Private key to use for SSL. Default null.
105* `passphrase` A string of passphrase for the private key or pfx. Default null.
106* `cert` Public x509 certificate to use. Default null.
107* `ca` An authority certificate or array of authority certificates to check the remote host against.
108* `ciphers` A string describing the ciphers to use or exclude.
109* `rejectUnauthorized` If true, the server certificate is verified against the list of supplied CAs. An 'error' event is emitted if verification fails. Verification happens at the connection level, before the HTTP request is sent. Default true.
110
111```javascript
112var options = {
113 text1: 'Hello!',
114 text2: 'Great to see you today.'
115 cert: fs.readFileSync('mycert.pem'),
116 key: fs.readFileSync('mycertkey.pem')
117 };
118
119mpns.sendToast(httpspushUri, options, callback);
120```
121
122### HTTP proxy support
123
124If the options passed into a tile or push call include a `proxy` value, the proxy server information will be used. The string value should be the URI to the proxy, including host, for example: `{ proxy: 'http://yourproxy:8080'}`.
125
126### Results object information
127A results object is passed back through the callback and has important information from MPNS.
128
129- `deviceConnectionStatus`: The device status as reported by the service.
130- `notificationStatus`: The status of your provided notification.
131- `subscriptionStatus`: The status of the subscription URI.
132
133The object will also contain all the key fields for your toast or live tile update, plus the pushType. This makes it easy to store this information in a history log somewhere in the ether.
134
135### Handling Errors
136It is very important as a consumer that you store appropriate actionable data about failed push notification attempts. As a result, the callback's first parameter (err) is set to the standard results object as well as a few additional fields depending on the returned status code from the server.
137
138Remember to take action on that information in order to be a good MPNS citizen. These values may be set in the error object and of interest to you:
139
140- `minutesToDelay`: If this is present, it is the suggested minimum amount of time that you should wait until making another request to the same subscription URI. For HTTP 412s, for example, the minimum time is one hour and so the returned value defaults to 61.
141- `shouldDeleteChannel`: If this is set to `true`, the channel is gone according to MPNS. Delete it from your channel/subscription database and never look back.
142- `innerError`: If an error is captured while trying to make the HTTP request, this will be set to that error callback instance.
143
144### A note about different Windows Phone versions
145This module permits sending toasts and tiles supported only on specific versions of Windows Phone. If you use those features on a version where they are unsupported, unfortunately notifications may not be received, or will error out the subscription.
146
147Take care when registering your subscription channels with your cloud service to include the application platform version of the app (7.1 for Mango apps). To rock, maybe also grab the OS version and deployed app version. That information can be helpful when supporting customers.
148
149Here is a list of features that are only supported in given versions of Windows Phone:
150* For Windows Phone 7.0
151 * Do not use the `param` or other fields as indicated below and it should work OK.
152* Only supported in Windows Phone 7.5+ (Mango/WP 7.1 OS)
153 * Including the `param` field when sending a push
154 * Including the `id` parameter when sending a tile
155* Only supported in Windows Phone 7.8+ (including Windows Phone 8)
156 * Sending "flip" tiles
157
158## Credits
159
160NPM module written and maintained by [Jeff Wilcox] with contributions from:
161
162- Jeff Wilcox : https://github.com/jeffwilcox
163- Shawn Burke : https://github.com/shawnburke
164- Jeremie Pelletier : https://github.com/ddude
165- Yavor Georgiev: https://github.com/yavorg
166- Stephan Eckbauer: https://github.com/ste99
167
168## License
169
170Copyright Jeff Wilcox
171
172Licensed under the Apache License, Version 2.0 (the "License");
173you may not use this file except in compliance with the License.
174You may obtain a copy of the License at
175
176 http://www.apache.org/licenses/LICENSE-2.0
177
178Unless required by applicable law or agreed to in writing, software
179distributed under the License is distributed on an "AS IS" BASIS,
180WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
181See the License for the specific language governing permissions and
182limitations under the License.
183
184[Jeff Wilcox]: http://www.jeff.wilcox.name
185[npm]: http://github.com/isaacs/npm
186
187## Changelog
188
189The changelog has moved over time.
190
191* 1.2.8 and newer: The GitHub releases feature provides this information at https://github.com/jeffwilcox/mpns/releases
192* 0-1.2.8: Available in the [CHANGELOG.md](https://github.com/jeffwilcox/mpns/blob/master/CHANGELOG.md) markdown file
193