-
Notifications
You must be signed in to change notification settings - Fork 49
Support for Browser Push in the Java SDK #99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mpodwysocki
wants to merge
9
commits into
main
Choose a base branch
from
v0.5
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
eadbe0c
Updating to 0.4
mpodwysocki f36a77e
Updatng to v0.5
mpodwysocki 72a16d1
Merge branch 'main' of https://github.com/Azure/azure-notificationhub…
mpodwysocki 1a41ce5
Fixing parsing bug
mpodwysocki e659eec
Updating type safety
mpodwysocki 708fd81
Cleaning up based upon comments
mpodwysocki 4beb441
Updating typings
mpodwysocki 724d477
Merge branch 'main' of https://github.com/Azure/azure-notificationhub…
mpodwysocki f11a861
Fixing telemetry
mpodwysocki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
NotificationHubs/src/com/windowsazure/messaging/BrowserCredential.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| //---------------------------------------------------------------- | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| //---------------------------------------------------------------- | ||
|
|
||
| package com.windowsazure.messaging; | ||
|
|
||
| import java.util.AbstractMap; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * This class represents Browser Push PNS credentials for Azure Notification Hubs. | ||
| */ | ||
| public final class BrowserCredential extends PnsCredential { | ||
| private String subject; | ||
| private String vapidPublicKey; | ||
| private String vapidPrivateKey; | ||
|
|
||
| /** | ||
| * Creates a new BrowserCredential with default values. | ||
| */ | ||
| public BrowserCredential() { | ||
| } | ||
|
|
||
| /** | ||
| * Creates a BrowserCredential with subject, VAPID public key and private key. | ||
| * @param subject The subject in mailto: or http:// form. | ||
| * @param vapidPublicKey The VAPID public key. | ||
| * @param vapidPrivateKey The VAPID private key. | ||
| */ | ||
| public BrowserCredential(String subject, String vapidPublicKey, String vapidPrivateKey) { | ||
| this.subject = subject; | ||
| this.vapidPublicKey = vapidPublicKey; | ||
| this.vapidPrivateKey = vapidPrivateKey; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the browser credential subject. | ||
| * @return The browser credential subject. | ||
| */ | ||
| public String getSubject() { return subject; } | ||
|
|
||
| /** | ||
| * Sets the browser credential subject. | ||
| * @param value The new browser credential subject to set. | ||
| */ | ||
| public void setSubject(String value) { subject = value; } | ||
|
|
||
| /** | ||
| * Gets the browser credential VAPID public key. | ||
| * @return The browser credential VAPID public key. | ||
| */ | ||
| public String getVapidPublicKey() { return vapidPublicKey; } | ||
|
|
||
| /** | ||
| * Sets the browser credential VAPID public key. | ||
| * @param value The browser credential VAPID public key to set. | ||
| */ | ||
| public void setVapidPublicKey(String value) { vapidPublicKey = value; } | ||
|
|
||
| /** | ||
| * Gets the browser credential VAPID private key. | ||
| * @return The browser credential VAPID private key. | ||
| */ | ||
| public String getVapidPrivateKey() { return vapidPrivateKey; } | ||
|
|
||
| /** | ||
| * Sets the browser credential VAPID private key. | ||
| * @param value The browser credential VAPID private key to set. | ||
| */ | ||
| public void setVapidPrivateKey(String value) { vapidPrivateKey = value; } | ||
|
|
||
| @Override | ||
| public List<AbstractMap.SimpleEntry<String, String>> getProperties() { | ||
| ArrayList<AbstractMap.SimpleEntry<String, String>> result = new ArrayList<>(); | ||
| result.add(new AbstractMap.SimpleEntry<>("Subject", subject)); | ||
| result.add(new AbstractMap.SimpleEntry<>("VapidPublicKey", vapidPublicKey)); | ||
| result.add(new AbstractMap.SimpleEntry<>("VapidPrivateKey", vapidPrivateKey)); | ||
| return result; | ||
| } | ||
|
|
||
| @Override | ||
| public String getRootTagName() { | ||
| return "BrowserCredential"; | ||
| } | ||
| } |
61 changes: 61 additions & 0 deletions
61
NotificationHubs/src/com/windowsazure/messaging/BrowserInstallation.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| package com.windowsazure.messaging; | ||
|
|
||
| /** | ||
| * This class represents an installation for browser push. | ||
| */ | ||
| public class BrowserInstallation extends BaseInstallation { | ||
| private BrowserPushChannel pushChannel; | ||
|
|
||
| /** | ||
| * Creates a new instance of the BrowserInstallation class. | ||
| * | ||
| * @param installationId The ID for the installation. | ||
| */ | ||
| public BrowserInstallation(String installationId) { | ||
| this(installationId, (String[]) null); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a new instance of the BrowserInstallation class. | ||
| * | ||
| * @param installationId The ID for the installation. | ||
| * @param tags The tags for the installation. | ||
| */ | ||
| public BrowserInstallation(String installationId, String... tags) { | ||
| this(installationId, null, tags); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a new instance of the Installation class. | ||
| * | ||
| * @param installationId The ID for the installation. | ||
| */ | ||
| public BrowserInstallation(String installationId, BrowserPushChannel pushChannel) { | ||
| this(installationId, pushChannel, (String[]) null); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a new instance of the Installation class. | ||
| * @param installationId The ID for the installation. | ||
| * @param pushChannel The device specific push channel for the installation. | ||
| * @param tags The tags for the installation. | ||
| */ | ||
| public BrowserInstallation(String installationId, BrowserPushChannel pushChannel, String... tags) { | ||
| super(installationId, NotificationPlatform.Browser, tags); | ||
| this.pushChannel = pushChannel; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the PNS specific push channel for the installation. | ||
| * | ||
| * @return The PNS specific push channel for the installation. | ||
| */ | ||
| public BrowserPushChannel getPushChannel() { return pushChannel; } | ||
|
|
||
| /** | ||
| * Sets the PNS specific push channel for the installation. | ||
| * | ||
| * @param value The PNS specific push channel for the installation | ||
| */ | ||
| public void setPushChannel(BrowserPushChannel value) { pushChannel = value; } | ||
| } |
4 changes: 4 additions & 0 deletions
4
NotificationHubs/src/com/windowsazure/messaging/BrowserNotification.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| package com.windowsazure.messaging; | ||
|
|
||
| public class BrowserNotification extends Notification { | ||
| } |
84 changes: 84 additions & 0 deletions
84
NotificationHubs/src/com/windowsazure/messaging/BrowserPushChannel.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| package com.windowsazure.messaging; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| /** | ||
| * This class represents | ||
| */ | ||
| public class BrowserPushChannel { | ||
| private String endpoint; | ||
| private String p256dh; | ||
| private String auth; | ||
|
|
||
| /** | ||
| * Creates a new instance of the BrowserPushChannel class. | ||
| */ | ||
| public BrowserPushChannel() { | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * Creates a new instance of the BrowserPushChannel class. | ||
| * @param endpoint The browser PNS endpoint URL. | ||
| * @param p256dh The P256DH key from the browser registration. | ||
| * @param auth The auth secret from the browser registration. | ||
| */ | ||
| public BrowserPushChannel( | ||
| String endpoint, | ||
| String p256dh, | ||
| String auth | ||
| ) { | ||
| this.endpoint = endpoint; | ||
| this.p256dh = p256dh; | ||
| this.auth = auth; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the browser PNS endpoint URL. | ||
| * @return The browser PNS endpoint URL. | ||
| */ | ||
| public String getEndpoint() { return endpoint; } | ||
|
|
||
| /** | ||
| * Sets the browser PNS endpoint URL. | ||
| * @param value The browser PNS endpoint URL. | ||
| */ | ||
| public void setEndpoint(String value) { endpoint = value; } | ||
|
|
||
| /** | ||
| * Gets the browser subscription p256dh key. | ||
| * @return The browser subscription p256dh key. | ||
| */ | ||
| public String getP256dh() { return p256dh; } | ||
|
|
||
| /** | ||
| * Sets the browser subscription p256dh key. | ||
| * @param value The browser subscription p256dh key. | ||
| */ | ||
| public void setP256dh(String value) { p256dh = value; } | ||
|
|
||
| /** | ||
| * Gets the browser subscription auth secret. | ||
| * @return The browser subscription auth secret. | ||
| */ | ||
| public String getAuth() { return auth; } | ||
|
|
||
| /** | ||
| * Sets the browser subscription auth secret. | ||
| * @param value The browser subscription auth secret. | ||
| */ | ||
| public void setAuth(String value) { auth = value; } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (o == null || getClass() != o.getClass()) return false; | ||
| BrowserPushChannel that = (BrowserPushChannel) o; | ||
| return Objects.equals(getEndpoint(), that.getEndpoint()) && Objects.equals(getP256dh(), that.getP256dh()) && Objects.equals(getAuth(), that.getAuth()); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(getEndpoint(), getP256dh(), getAuth()); | ||
| } | ||
| } |
126 changes: 126 additions & 0 deletions
126
NotificationHubs/src/com/windowsazure/messaging/BrowserRegistration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| //---------------------------------------------------------------- | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| //---------------------------------------------------------------- | ||
|
|
||
| package com.windowsazure.messaging; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| /** | ||
| * This class represents a Browser Push device registration. | ||
| */ | ||
| public class BrowserRegistration extends Registration { | ||
| private static final String BROWSER_NATIVE_REGISTRATION1 = "<?xml version=\"1.0\" encoding=\"utf-8\"?><entry xmlns=\"http://www.w3.org/2005/Atom\"><content type=\"application/xml\"><BrowserRegistrationDescription xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://schemas.microsoft.com/netservices/2010/10/servicebus/connect\">"; | ||
| private static final String BROWSER_NATIVE_REGISTRATION2 = "<Endpoint>"; | ||
| private static final String BROWSER_NATIVE_REGISTRATION3 = "</Endpoint><P256DH>"; | ||
| private static final String BROWSER_NATIVE_REGISTRATION4 = "</P256DH><Auth>"; | ||
| private static final String BROWSER_NATIVE_REGISTRATION5 = "</Auth></BrowserRegistrationDescription></content></entry>"; | ||
|
|
||
| protected String endpoint; | ||
| protected String p256dh; | ||
| protected String auth; | ||
|
|
||
| /** | ||
| * Creates a new instance of the BrowserRegistration class. | ||
| */ | ||
| public BrowserRegistration() { | ||
| super(); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a new instance of the BrowserRegistration class with endpoint, p256dh and auth secret. | ||
| * @param endpoint The browser PNS endpoint URL. | ||
| * @param p256dh The P256DH key from the browser registration. | ||
| * @param auth The auth secret from the browser registration. | ||
| */ | ||
| public BrowserRegistration(String endpoint, String p256dh, String auth) { | ||
| super(); | ||
| this.endpoint = endpoint; | ||
| this.p256dh = p256dh; | ||
| this.auth = auth; | ||
| } | ||
|
|
||
| /** | ||
| * Creates a new instance of the BrowserRegistration class with endpoint, p256dh and auth secret. | ||
| * @param registrationId The Azure Notification Hubs registration ID. | ||
| * @param endpoint The browser PNS endpoint URL. | ||
| * @param p256dh The P256DH key from the browser registration. | ||
| * @param auth The auth secret from the browser registration. | ||
| */ | ||
| public BrowserRegistration(String registrationId, String endpoint, String p256dh, String auth) { | ||
| super(registrationId); | ||
| this.endpoint = endpoint; | ||
| this.p256dh = p256dh; | ||
| this.auth = auth; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the browser PNS endpoint URL. | ||
| * @return The browser PNS endpoint URL. | ||
| */ | ||
| public String getEndpoint() { return endpoint; } | ||
|
|
||
| /** | ||
| * Sets the browser PNS endpoint URL. | ||
| * @param value The browser PNS endpoint URL. | ||
| */ | ||
| public void setEndpoint(String value) { endpoint = value; } | ||
|
|
||
| /** | ||
| * Gets the browser subscription p256dh key. | ||
| * @return The browser subscription p256dh key. | ||
| */ | ||
| public String getP256dh() { return p256dh; } | ||
|
|
||
| /** | ||
| * Sets the browser subscription p256dh key. | ||
| * @param value The browser subscription p256dh key. | ||
| */ | ||
| public void setP256dh(String value) { p256dh = value; } | ||
|
|
||
| /** | ||
| * Gets the browser subscription auth secret. | ||
| * @return The browser subscription auth secret. | ||
| */ | ||
| public String getAuth() { return auth; } | ||
|
|
||
| /** | ||
| * Sets the browser subscription auth secret. | ||
| * @param value The browser subscription auth secret. | ||
| */ | ||
| public void setAuth(String value) { auth = value; } | ||
|
|
||
| /** | ||
| * Gets the PNS handle for getting devices by channel. | ||
| * @return The PNS handle for getting devices by channel. | ||
| */ | ||
| @Override | ||
| public String getPnsHandle() { return endpoint; } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (o == null || getClass() != o.getClass()) return false; | ||
| if (!super.equals(o)) return false; | ||
| BrowserRegistration that = (BrowserRegistration) o; | ||
| return Objects.equals(getEndpoint(), that.getEndpoint()) && Objects.equals(getP256dh(), that.getP256dh()) && Objects.equals(getAuth(), that.getAuth()); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(super.hashCode(), getEndpoint(), getP256dh(), getAuth()); | ||
| } | ||
|
|
||
| @Override | ||
| public String getXml() { | ||
| return BROWSER_NATIVE_REGISTRATION1 + | ||
| getTagsXml() + | ||
| BROWSER_NATIVE_REGISTRATION2 + | ||
| endpoint + | ||
| BROWSER_NATIVE_REGISTRATION3 + | ||
| p256dh + | ||
| BROWSER_NATIVE_REGISTRATION4 + | ||
| auth + | ||
| BROWSER_NATIVE_REGISTRATION5; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.