TsgcWSAPIServer_WebPush › Olaylar › OnWebPushSubscription
Bir tarayıcı, PushManager.subscribe() çağrısından sonra Subscription uç noktasına POST yaptığında tetiklenir; sunucu tarafında kalıcı hâle getirmek için uç noktayı, p256dh anahtarını ve auth secret'ı alın.
property OnWebPushSubscription: TsgcWSWebPushSubscription;
// TsgcWSWebPushSubscription = procedure(Sender: TObject; aSubscription: TsgcHTTP_API_WebPush_PushSubscription; var ResponseCode: Integer) of object
—
Bileşen, yeni aboneliği zaten dahili Subscriptions listesinde depolar, böylece BroadcastNotification tarafından erişilebilir hale gelir. Gelen aboneliği kendi veritabanınıza kalıcı hale getirmek ve/veya sunucu tarafı doğrulaması (kimlik doğrulama, oran sınırlama, yinelenen tespiti) uygulamak için olayı kullanın. ResponseCode değerini tarayıcıya döndürülen HTTP durumuna ayarlayın — başarıda 200/201 döndürün veya reddetmek için bir 4xx (örneğin kullanıcı yetkili değilse 401).
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;