Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

Commit

Permalink
Merge pull request #15 from phonegap/raghav/windows
Browse files Browse the repository at this point in the history
Initial commit to add support for windows universal platform
  • Loading branch information
macdonst committed Jul 7, 2015
2 parents b0830d5 + 3138ed1 commit 50d28cd
Showing 1 changed file with 58 additions and 9 deletions.
67 changes: 58 additions & 9 deletions src/windows8/PushPluginProxy.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,67 @@
// Copyright (c) Microsoft Open Technologies, Inc. Licensed under the MIT license.
var myApp = {};
var pushNotifications = Windows.Networking.PushNotifications;

var createNotificationJSON = function (e) {
var result = {};
var notificationPayload;

switch (e.notificationType) {
case pushNotifications.PushNotificationType.toast:
notificationPayload = e.toastNotification.content.getXml();
break;

case pushNotifications.PushNotificationType.tile:
notificationPayload = e.tileNotification.content.getXml();
break;

case pushNotifications.PushNotificationType.badge:
notificationPayload = e.badgeNotification.content.getXml();
break;

case pushNotifications.PushNotificationType.raw:
notificationPayload = e.rawNotification.content;
break;
}
result.message = "";
result.xmlContent = notificationPayload;
result.objectReference = e;
return result;
}

module.exports = {
register: function (success, fail, args) {
try {
var onNotificationReceived = window[args[0].ecb];
init: function (onSuccess, onFail, args) {

Windows.Networking.PushNotifications.PushNotificationChannelManager.createPushNotificationChannelForApplicationAsync().then(
var onNotificationReceived = function (e) {
var result = createNotificationJSON(e);
onSuccess(result, { keepCallback: true });
}

try {
pushNotifications.PushNotificationChannelManager.createPushNotificationChannelForApplicationAsync().done(
function (channel) {
var result = {};
result.registrationId = channel.uri;
myApp.channel = channel;
channel.addEventListener("pushnotificationreceived", onNotificationReceived);
success(channel);
}, fail);
myApp.notificationEvent = onNotificationReceived;
onSuccess(result, { keepCallback: true });
}, function (error) {
onFail(error);
});
} catch (ex) {
onFail(ex);
}
},
unregister: function (onSuccess, onFail, args) {
try {
myApp.channel.removeEventListener("pushnotificationreceived", myApp.notificationEvent);
myApp.channel.close();
onSuccess();
} catch(ex) {
fail(ex);
onFail(ex);
}
}
};
require("cordova/windows8/commandProxy").add("PushPlugin", module.exports);
require("cordova/exec/proxy").add("PushNotification", module.exports);


0 comments on commit 50d28cd

Please sign in to comment.