This repository was archived by the owner on Oct 12, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +16
-5
lines changed
service-worker/worker/src Expand file tree Collapse file tree 2 files changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -64,12 +64,23 @@ export class PushImpl implements Plugin<PushImpl> {
6464 }
6565
6666 push ( data : any ) : void {
67- this . maybeShowNotification ( data ) ;
67+ let message : any ;
68+ try {
69+ message = JSON . parse ( data ) ;
70+ } catch ( e ) {
71+ // If the string can't be parsed, display it verbatim.
72+ message = {
73+ notification : {
74+ title : data ,
75+ } ,
76+ } ;
77+ }
78+ this . maybeShowNotification ( message ) ;
6879 if ( this . buffer !== null ) {
69- this . buffer . push ( data ) ;
80+ this . buffer . push ( message ) ;
7081 } else {
7182 this . streams . forEach ( id => {
72- this . worker . sendToStream ( id , data ) ;
83+ this . worker . sendToStream ( id , message ) ;
7384 } )
7485 }
7586 }
Original file line number Diff line number Diff line change @@ -280,10 +280,10 @@ export class Driver {
280280 }
281281
282282 Promise
283- // Wait for both initialization and the JSON data sent with the push message.
283+ // Wait for both initialization and the data sent with the push message.
284284 . all ( [
285285 this . init ,
286- event . data . json ( ) ,
286+ event . data . text ( ) ,
287287 ] )
288288 // Result of this.init is unimportant as long as it's resolved.
289289 . then ( results => results [ 1 ] )
You can’t perform that action at this time.
0 commit comments