Skip to content

Commit

Permalink
Merge pull request blackberry#5 from bthornton32/master
Browse files Browse the repository at this point in the history
Added JavaScript server sample
  • Loading branch information
bthornton32 committed Jun 14, 2013
2 parents e6348f0 + b532546 commit 8d99cfa
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 2 deletions.
7 changes: 5 additions & 2 deletions ServerNotify/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ The sample code for this application is Open Source under the [Apache 2.0 Licens

1. You will need a BlackBerry 10 smartphone to test.
2. You with need a BlackBerry Device Service Server or access to one.
3. A .NET web server to run the monitoring.
3. A .NET web server to run the monitoring (optional).

*Note: If you don't use .NET on the backend you can use any server side technology that can make an HTTP POST. You create the POST in a similar manner to the C# example provided.

## Initial Client Setup

Expand All @@ -45,7 +47,8 @@ The sample code for this application is Open Source under the [Apache 2.0 Licens

## Deployment

Usually you can pass the signed bar file to your BES administrator and have them
Usually you can pass the signed bar file to your BES administrator and have them:

1. Add it to the BDS.
2. Add it to a software configuration.
3. Apply the software configuration to the user account you are testing with.
Expand Down
20 changes: 20 additions & 0 deletions ServerNotify/server/README.md
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.
38 changes: 38 additions & 0 deletions ServerNotify/server/dotNetAlternative/README.md
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.
83 changes: 83 additions & 0 deletions ServerNotify/server/dotNetAlternative/index.html
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>

0 comments on commit 8d99cfa

Please sign in to comment.