TsgcWSAPIServer_WebPush › Eventi › OnWebPushSubscription
Si attiva quando un browser esegue un POST all'endpoint Subscription dopo aver chiamato PushManager.subscribe(); ricevere l'endpoint, la chiave p256dh e il segreto auth da rendere persistenti lato server.
property OnWebPushSubscription: TsgcWSWebPushSubscription;
// TsgcWSWebPushSubscription = procedure(Sender: TObject; aSubscription: TsgcHTTP_API_WebPush_PushSubscription; var ResponseCode: Integer) of object
—
Il componente memorizza già la nuova sottoscrizione nell'elenco interno Subscriptions, rendendola raggiungibile da BroadcastNotification. Utilizzare l'evento per persistere la sottoscrizione in arrivo nel proprio database e/o applicare la validazione lato server (autenticazione, rate limiting, rilevamento dei duplicati). Impostare ResponseCode allo stato HTTP restituito al browser — restituire 200/201 in caso di successo o un 4xx per rifiutare (ad esempio 401 se l'utente non è autorizzato).
procedure TForm1.sgcWSAPIServer_WebPush1WebPushSubscription(Sender: TObject;
aSubscription: TsgcHTTP_API_WebPush_PushSubscription; var ResponseCode: Integer);
begin
SaveSubscriptionToDB(aSubscription.Endpoint,
aSubscription.PublicKey,
aSubscription.AuthSecret);
ResponseCode := 201;
end;