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

Commit

Permalink
Merge branch 'browser'
Browse files Browse the repository at this point in the history
  • Loading branch information
surajpindoria committed Jul 21, 2016
2 parents 4bea2a7 + e8e0fe4 commit a2ad8da
Show file tree
Hide file tree
Showing 9 changed files with 396 additions and 1 deletion.
9 changes: 9 additions & 0 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ Attribute | Type | Default | Description
`android.forceShow` | `boolean` | `false` | Optional. Controls the behavior of the notification when app is in foreground. If `true` and app is in foreground, it will show a notification in the notification drawer, the same way as when the app is in background (and `on('notification')` callback will be called *only when the user clicks the notification*). When `false` and app is in foreground, the `on('notification')` callback will be called immediately.
`android.topics` | `array` | `[]` | Optional. If the array contains one or more strings each string will be used to subscribe to a GcmPubSub topic.

#### Browser

Attribute | Type | Default | Description
--------- | ---- | ------- | -----------
`browser.pushServiceURL` | `string` | `http://push.api.phongeap.com/v1/push` | Optional. URL for the push server you want to use.

#### iOS

All iOS boolean options can also be specified as `string`
Expand Down Expand Up @@ -93,6 +99,9 @@ var push = PushNotification.init({
android: {
senderID: "12345679"
},
browser: {
pushServiceURL: 'https://yourPushServer.com/push'
},
ios: {
alert: "true",
badge: true,
Expand Down
3 changes: 3 additions & 0 deletions docs/EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ var push = PushNotification.init({
android: {
senderID: "12345679"
},
browser: {
pushServiceURL: 'https://yourPushServer.com/push'
},
ios: {
alert: "true",
badge: "true",
Expand Down
14 changes: 14 additions & 0 deletions docs/INSTALLATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
- [minSdkVersion === 14](#minsdkversion--14)
- [Multidex](#multidex)
- [More than one library with package name 'com.google.android.gms'](#more-than-one-library-with-package-name-comgoogleandroidgms)
- [Browser details](#browser-details)
- [Browser quirks](#browser-quirks)
- [Browser Support](#browser-support)
- [iOS details](#ios-details)
- [XCode](#xcode)
- [Bitcode](#bitcode)
Expand Down Expand Up @@ -175,6 +178,17 @@ Alternatively, switch to another plugin that provides the same functionality but
[https://github.com/danwilson/google-analytics-plugin](https://github.com/danwilson/google-analytics-plugin)
[https://github.com/cmackay/google-analytics-plugin](https://github.com/cmackay/google-analytics-plugin)

## Browser details

### Browser quirks

For the time being push support on the browser will only work using the PhoneGap push server.

### Browser Support

Chrome 49+
Firefox 46+

## iOS details

### XCode
Expand Down
8 changes: 7 additions & 1 deletion docs/PAYLOAD.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ var push = PushNotification.init({
"android": {
"senderID": "12345679"
},
browser: {
pushServiceURL: 'https://yourPushServer.com/push'
},
"ios": {
"alert": "true",
"badge": "true",
Expand All @@ -95,6 +98,9 @@ var push = PushNotification.init({
"icon": "phonegap",
"iconColor": "blue"
},
browser: {
pushServiceURL: 'https://yourPushServer.com/push'
},
"ios": {
"alert": "true",
"badge": "true",
Expand Down Expand Up @@ -1007,7 +1013,7 @@ app.accept = function(data) {
console.log('accept callback finished');
}, function() {
console.log('accept callback failed');
}, data.additionalData.notId);
}, data.additionalData.notId);
};
```

Expand Down
1 change: 1 addition & 0 deletions docs/PLATFORM_SUPPORT.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

- Cordova CLI (3.6.3 or newer)
- Android (`cordova-android` 4.0.0 or higher)
- Browser
- iOS (`cordova-ios` 4.1.0 or higher)
- Windows Universal (not Windows Phone 8)
7 changes: 7 additions & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@
<source-file src="src/android/com/adobe/phonegap/push/PermissionUtils.java" target-dir="src/com/adobe/phonegap/push/"/>
<source-file src="src/android/com/adobe/phonegap/push/BackgroundActionButtonHandler.java" target-dir="src/com/adobe/phonegap/push/"/>
</platform>
<platform name="browser">
<js-module src="www/browser/push.js" name="BrowserPush">
<clobbers target="PushNotification" />
</js-module>
<asset src="src/browser/ServiceWorker.js" target="ServiceWorker.js" />
<asset src="src/browser/manifest.json" target="manifest.json" />
</platform>
<platform name="ios">
<config-file target="config.xml" parent="/*">
<feature name="PushNotification">
Expand Down
41 changes: 41 additions & 0 deletions src/browser/ServiceWorker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
var messageChannel;

self.addEventListener('install', function(event) {
self.skipWaiting();
});

self.addEventListener('push', function(event) {
// parse incoming message
var obj = {};
if (event.data) {
obj = event.data.json();
}

// Need to figure out a way to make these configurable
var title = obj.title || 'Default title';
var body = obj.body || 'This is the default body';
var icon = 'https://avatars1.githubusercontent.com/u/60365?v=3&s=200';
var tag = 'simple-push-demo-notification-tag';

event.waitUntil(
self.registration.showNotification(title, {
body: body,
icon: icon,
tag: tag
})
);

var pushData = {
title: title,
message: body,
count: 1,
sound: 'default',
additionalData: {}
};
messageChannel.ports[0].postMessage(pushData);

});

self.addEventListener('message', function(event) {
messageChannel = event;
});
4 changes: 4 additions & 0 deletions src/browser/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "Push Demo",
"gcm_sender_id": "85075801930"
}
Loading

0 comments on commit a2ad8da

Please sign in to comment.