diff --git a/client/absolute.ts b/client/absolute.ts
index 422d9437..1c334632 100644
--- a/client/absolute.ts
+++ b/client/absolute.ts
@@ -15,11 +15,11 @@
*/
import PushManager from './push/push_manager';
-import Notification from './notification/notification_manager';
+import NotificationManager from './notification/notification_manager';
import IndexedDB from './indexeddb/indexeddb';
export default class absolute {
static push: PushManager = new PushManager();
- static notification: Notification = new Notification();
+ static notification: NotificationManager = new NotificationManager();
static indexeddb: IndexedDB = new IndexedDB();
}
diff --git a/client/notification/notification.test.ts b/client/notification/notification.test.ts
index 1374e6d4..65899c44 100644
--- a/client/notification/notification.test.ts
+++ b/client/notification/notification.test.ts
@@ -17,15 +17,17 @@
import { } from 'jest';
import absolute from '../absolute';
-test('absolute.notification.create()', async () => {
- let NotificationEvent = new Event("click");
- expect(await absolute.notification.create(NotificationEvent)).toBe(false);
-});
-test('absolute.notification.close()', async () => {
- let NotificationEvent = new Event("click");
- expect(await absolute.notification.close(NotificationEvent)).toBe(false);
+test('absolute.notification.showNotification()', async () => {
+ const title = 'Push Codelab';
+ const options = {
+ body: 'Yay it works.',
+ icon: 'images/icon.png',
+ badge: 'images/badge.png'
+ };
+ expect(await absolute.notification.showNotification(title, options)).toBe(false);
});
test('absolute.notification.processClickEvent()', async () => {
- let NotificationEvent = new Event("click");
- expect(await absolute.notification.processClickEvent(NotificationEvent)).toBe(false);
+ const event = new Event('click');
+ const url = 'https://developers.google.com/web/';
+ expect(await absolute.notification.processClickEvent(event, url)).toBe(false);
});
\ No newline at end of file
diff --git a/client/notification/notification_manager.ts b/client/notification/notification_manager.ts
index ec1e648b..d4781c7f 100644
--- a/client/notification/notification_manager.ts
+++ b/client/notification/notification_manager.ts
@@ -13,23 +13,42 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+///
-export default class Notification {
- private _notifications: Object = {};
+declare var self: ServiceWorkerGlobalScope;
- constructor() {
- }
+declare var navigator: any;
- async create(NotificationEvent: Event): Promise {
- // Not implemented yet
- return false;
- }
- async close(NotificationEvent: Event): Promise {
- // Not implemented yet
+export default class NotificationManager {
+ private notification: Notification;
+
+ constructor() { }
+
+ async showNotification(title: string, options: object): Promise {
+ if (!navigator.serviceWorker) {
+ return false;
+ }
+
+ this.notification = new Notification(title, options);
+
+ self.registration.showNotification(title, options);
return false;
}
- async processClickEvent(NotificationEvent: Event): Promise {
- // Not implemented yet
+
+ async processClickEvent(event: Event, url: string): Promise {
+ if (!navigator.serviceWorker) {
+ return false;
+ }
+ console.log('[Service Worker] Notification click Received.');
+
+ var init = { notification: this.notification };
+ var myNotificationEvent = new NotificationEvent(event.type, init);
+
+ myNotificationEvent.notification.close();
+
+ myNotificationEvent.waitUntil(
+ self.clients.openWindow(url)
+ );
return false;
}
}
\ No newline at end of file
diff --git a/references.ts b/references.ts
new file mode 100644
index 00000000..0dbfedb4
--- /dev/null
+++ b/references.ts
@@ -0,0 +1,2 @@
+///
+///
\ No newline at end of file