web-dave / angular-starter-v2

6 stars 3 forks source link

handle notification interactions #38

Open web-dave opened 7 years ago

web-dave commented 7 years ago
web-dave commented 7 years ago
touch src/ngsw/plugins/clickNotification.js
web-dave commented 7 years ago

clickNotification.js


export function ClickNotification () {
  return (worker) => new ClickNotificationImpl(worker);
}

export class ClickNotificationImpl {

  setup (ops) {}

  constructor (sw) {}

}
web-dave commented 7 years ago

basic.js

...
import { ClickNotification } from './plugins/clickNotification';
bootstrapServiceWorker({
  manifestUrl: 'ngsw-manifest.json',
  plugins: [
    StaticContentCache(),
    Dynamic([
      new FreshnessStrategy(),
      new PerformanceStrategy(),
    ]),
    ExternalContentCache(),
    RouteRedirection(),
    Push(),
    ClickNotification()
  ],
});
web-dave commented 7 years ago

clickNotification,js

  notificationclick(){
    self.addEventListener('notificationclick', function (event) {
      console.log('notificationclick: ', event);
    });
  }
web-dave commented 7 years ago

clickNotification,js

  notificationclose(){
    self.addEventListener('notificationclose', function (event) {
      console.log('notificationclose');
    });
  }
web-dave commented 7 years ago

clickNotification,js


  constructor(sw) {
    this.notificationclick();
    this.notificationclose();
  }
web-dave commented 7 years ago
npm run build-ngsw