- java.lang.Object
-
- com.zerodeplibs.webpush.PushSubscription
-
public class PushSubscription extends Object
This class represents a push subscription described in the Push API - W3C specification.
This class is used as if it was a simple "JavaBean" (this class doesn't implement
Serializableand therefore doesn't conform to the "JavaBean" standard strictly).Typically, each value of the fields of this class is set to the value of the corresponding field of a push subscription retrieved from a browser.
The following is a browser-side javascript example to get a JSON object of a push subscription.
// It is assumed that you have registered a service worker. const registration = await navigator.serviceWorker.ready; const subscription = await registration.pushManager.subscribe({ userVisibleOnly: true, applicationServerKey: serverPublicKey // your server's public key. }); // Sends the subscription to your server. await fetch('/subscribe', { method: 'POST', body: JSON.stringify(subscription), headers: { 'content-type': 'application/json' } });Instances of this class can be generated by utilizing a library that provides functionalities of JSON such as jackson.
Thread Safety:Instances of this class are mutable. So use them carefully if they are accessed from multiple threads.
- Author:
- Tomoki Sato
- See Also:
UserAgentMessageEncryptionKeyInfo
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPushSubscription.KeysThis class represents a 'keys' field for a push subscription.
-
Constructor Summary
Constructors Constructor Description PushSubscription()Creates a newPushSubscription.PushSubscription(PushSubscription another)Creates a newPushSubscription.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object o)Compares the given object with this object based on their properties.StringgetEndpoint()Gets the endpoint.LonggetExpirationTime()Gets the expiration time.PushSubscription.KeysgetKeys()Gets the keys.inthashCode()Returns the hash code value for this object based on its properties.voidsetEndpoint(String endpoint)Sets the endpoint.voidsetExpirationTime(Long expirationTime)Sets the expiration time.voidsetKeys(PushSubscription.Keys keys)Sets the keys.StringtoString()
-
-
-
Constructor Detail
-
PushSubscription
public PushSubscription()
Creates a newPushSubscription.
-
PushSubscription
public PushSubscription(PushSubscription another)
Creates a newPushSubscription. All the fields are deeply copied fromanother.- Parameters:
another- an object from which the fields are copied.
-
-
Method Detail
-
getEndpoint
public String getEndpoint()
Gets the endpoint.- Returns:
- the value of the endpoint.
-
setEndpoint
public void setEndpoint(String endpoint)
Sets the endpoint.- Parameters:
endpoint- the value of the endpoint.
-
getExpirationTime
public Long getExpirationTime()
Gets the expiration time.- Returns:
- the value of the expiration time.
-
setExpirationTime
public void setExpirationTime(Long expirationTime)
Sets the expiration time.- Parameters:
expirationTime- the value of the expiration time.
-
getKeys
public PushSubscription.Keys getKeys()
Gets the keys.- Returns:
- the value of the keys.
-
setKeys
public void setKeys(PushSubscription.Keys keys)
Sets the keys.- Parameters:
keys- the value of the keys.
-
equals
public boolean equals(Object o)
Compares the given object with this object based on their properties.
-
hashCode
public int hashCode()
Returns the hash code value for this object based on its properties.
-
-