forked from blackberry/BES10-Cascades
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request blackberry#5 from bthornton32/master
Added JavaScript server sample
- Loading branch information
Showing
4 changed files
with
146 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# ServerNotify Server Samples | ||
There are 2 options here. The standard C# implementation and a JavaScript implementation for those that do not use .NET. | ||
|
||
*Note: The JavaScript version is very bare-bones and meant to be a manual push. | ||
|
||
The sample code for this application is Open Source under the [Apache 2.0 License](http://www.apache.org/licenses/LICENSE-2.0.html). | ||
|
||
**Author(s)** | ||
|
||
* [Brent Thornton](http://www.twitter.com/brentthornton32) | ||
* [John Mutter](http://www.twitter.com/muttejo) | ||
|
||
|
||
## Bug Reporting and Feature Requests | ||
|
||
If you find a bug in a Sample, or have an enhancement request, simply file an Issue for the Sample. | ||
|
||
## Disclaimer | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# ServerNotify Server JavaScript Implementation | ||
|
||
*Note: The JavaScript version is very bare-bones and meant to be a manual push. | ||
|
||
The sample code for this application is Open Source under the [Apache 2.0 License](http://www.apache.org/licenses/LICENSE-2.0.html). | ||
|
||
**Author(s)** | ||
|
||
* [Brent Thornton](http://www.twitter.com/brentthornton32) | ||
|
||
## How To Use | ||
|
||
1. Enter the Destination Email or PIN of the device you are pushing to. | ||
2. Enter the BES address that the user is on. | ||
3. Enter the BES MDS-CS Push Listen port. Usually 8080. | ||
4. Click Do Push. | ||
|
||
## Options for Push Payload | ||
|
||
The push payload is separated into 4 segments (delimeted by |). The first is the priority (see Priority section below for explaination). The second is the Title of the push. The third is the Description. Finally the forth is a url (ie. could be a url of the server you are alerting on). | ||
|
||
**Priority** | ||
|
||
Priority can be set to 0, 1, or 2. | ||
|
||
0 - No notification. Will only show up in the push list if the application is open. | ||
|
||
1 - Notification in the hub (if app isn't in foreground). Will show up in the push list if the application is closed or open in foreground. | ||
|
||
2 - Will popup a dialog alerting the user of the push. Will show up in the application push list. | ||
|
||
## Bug Reporting and Feature Requests | ||
|
||
If you find a bug in a Sample, or have an enhancement request, simply file an Issue for the Sample. | ||
|
||
## Disclaimer | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<!-- | ||
Copyright 2012 Research In Motion Limited. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Push Server Test</title> | ||
|
||
<script type="text/javascript"> | ||
window.addEventListener('load', init); | ||
function init(){ | ||
//if parameters are passed in url insert them | ||
document.getElementById("email").value = getParameterByName('email'); | ||
document.getElementById("bes").value = getParameterByName('bes'); | ||
document.getElementById("mdsPort").value = getParameterByName('mdsPort'); | ||
document.getElementById("appPort").value = getParameterByName('appPort'); | ||
} | ||
|
||
function doPost(){ | ||
var xmlhttp = new XMLHttpRequest(); | ||
|
||
var bes = document.getElementById("bes").value; | ||
var mdsPort = document.getElementById("mdsPort").value; | ||
var email = document.getElementById("email").value; | ||
var appPort = document.getElementById("appPort").value; | ||
var content = document.getElementById("content").value; | ||
|
||
xmlhttp.open("POST", "http://" + bes + ":" + mdsPort + "/push?DESTINATION=" + email + "&PORT=" + appPort + "&REQUESTURI=/", true); | ||
xmlhttp.onreadystatechange=function() { | ||
if (xmlhttp.readyState==4) { | ||
document.getElementById("result").innerHTML = "Success"; | ||
} | ||
} | ||
|
||
xmlhttp.setRequestHeader("Content-Type", "text/plain"); | ||
xmlhttp.send(content); | ||
} | ||
|
||
function getParameterByName(name) { | ||
var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search); | ||
return match && decodeURIComponent(match[1].replace(/\+/g, ' ')); | ||
} | ||
</script> | ||
|
||
</head> | ||
<body> | ||
Destination Email/PIN: <br /> | ||
<input id="email" type="text" size="50" /> | ||
<br /> | ||
BES Address: <br /> | ||
<input id="bes" type="text" size="50" /> | ||
<br /> | ||
MDS-CS Listen Port: <br /> | ||
<input id="mdsPort" type="text" /> | ||
<br /> | ||
Application Listen Port: <br /> | ||
<input id="appPort" type="text" value="bb_server_notify" /> | ||
<br /> | ||
Push Payload: <br /> | ||
<textarea id="content" rows="8" cols="50" >2|Sample Data|More stuff ...|http://www.developer.blackberry.com</textarea> | ||
|
||
<br /> | ||
<input type="button" onclick="doPost();" value="Do Push"/> | ||
<div id="result"></div> | ||
|
||
|
||
|
||
</body> | ||
</html> | ||
|