This repository has been archived by the owner on Sep 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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 #15 from phonegap/raghav/windows
Initial commit to add support for windows universal platform
- Loading branch information
Showing
1 changed file
with
58 additions
and
9 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
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); | ||
|
||
|