Comments
This commit is contained in:
parent
c124434429
commit
09336fa1e4
9 changed files with 32 additions and 33 deletions
|
@ -2,6 +2,12 @@ import {basicAuth, encodeBase64Url, topicShortUrl, topicUrlWs} from "./utils";
|
|||
|
||||
const retryBackoffSeconds = [5, 10, 15, 20, 30];
|
||||
|
||||
/**
|
||||
* A connection contains a single WebSocket connection for one topic. It handles its connection
|
||||
* status itself, including reconnect attempts and backoff.
|
||||
*
|
||||
* Incoming messages and state changes are forwarded via listeners.
|
||||
*/
|
||||
class Connection {
|
||||
constructor(connectionId, subscriptionId, baseUrl, topic, user, since, onNotification, onStateChanged) {
|
||||
this.connectionId = connectionId;
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
import Connection from "./Connection";
|
||||
import {sha256} from "./utils";
|
||||
|
||||
/**
|
||||
* The connection manager keeps track of active connections (WebSocket connections, see Connection).
|
||||
*
|
||||
* Its refresh() method reconciles state changes with the target state by closing/opening connections
|
||||
* as required. This is done pretty much exactly the same way as in the Android app.
|
||||
*/
|
||||
class ConnectionManager {
|
||||
constructor() {
|
||||
this.connections = new Map(); // ConnectionId -> Connection (hash, see below)
|
||||
|
|
|
@ -3,6 +3,10 @@ import prefs from "./Prefs";
|
|||
import subscriptionManager from "./SubscriptionManager";
|
||||
import logo from "../img/ntfy.png";
|
||||
|
||||
/**
|
||||
* The notifier is responsible for displaying desktop notifications. Note that not all modern browsers
|
||||
* support this; most importantly, all iOS browsers do not support window.Notification.
|
||||
*/
|
||||
class Notifier {
|
||||
async notify(subscriptionId, notification, onClickFallback) {
|
||||
if (!this.supported()) {
|
||||
|
|
|
@ -85,7 +85,7 @@ const SubscribePage = (props) => {
|
|||
const isExistingTopicUrl = existingTopicUrls.includes(topicUrl(baseUrl, topic));
|
||||
return validTopic(topic) && validUrl(baseUrl) && !isExistingTopicUrl;
|
||||
} else {
|
||||
const isExistingTopicUrl = existingTopicUrls.includes(topicUrl(window.location.origin, topic)); // FIXME
|
||||
const isExistingTopicUrl = existingTopicUrls.includes(topicUrl(window.location.origin, topic));
|
||||
return validTopic(topic) && !isExistingTopicUrl;
|
||||
}
|
||||
})();
|
||||
|
|
|
@ -66,6 +66,10 @@ export const useAutoSubscribe = (subscriptions, selected) => {
|
|||
}, [params, subscriptions, selected, hasRun]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Migrate the 'topics' item in localStorage to the subscriptionManager. This is only done once to migrate away
|
||||
* from the old web UI.
|
||||
*/
|
||||
export const useLocalStorageMigration = () => {
|
||||
const [hasRun, setHasRun] = useState(false);
|
||||
useEffect(() => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue