2021-10-23 01:26:01 +00:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html lang="en">
|
|
|
|
<head>
|
|
|
|
<title>ntfy.sh</title>
|
|
|
|
<style>
|
2021-10-24 02:49:50 +00:00
|
|
|
body { font-size: 1.2em; line-height: 130%; }
|
2021-10-24 01:29:45 +00:00
|
|
|
#error { color: darkred; font-style: italic; }
|
2021-10-24 02:49:50 +00:00
|
|
|
#main { max-width: 900px; margin: 0 auto 50px auto; }
|
2021-10-23 01:26:01 +00:00
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
<body>
|
2021-10-24 01:29:45 +00:00
|
|
|
<div id="main">
|
2021-10-24 02:49:50 +00:00
|
|
|
<h1>ntfy.sh - simple HTTP-based pub-sub</h1>
|
2021-10-24 01:29:45 +00:00
|
|
|
<p>
|
2021-10-24 02:49:50 +00:00
|
|
|
<b>ntfy</b> (pronounce: <i>notify</i>) is a simple <b>HTTP-based pub-sub notification service and tool</b>.
|
|
|
|
It allows you to send <b>desktop notifications via scripts</b>, entirely <b>without signup or cost</b>.
|
2021-10-24 03:30:10 +00:00
|
|
|
It's also <a href="https://github.com/binwiederhier/ntfy">open source</a> if you want to run your own.
|
2021-10-24 01:29:45 +00:00
|
|
|
</p>
|
2021-10-24 02:49:50 +00:00
|
|
|
<p id="error"></p>
|
2021-10-23 01:26:01 +00:00
|
|
|
|
2021-10-24 02:49:50 +00:00
|
|
|
<h2>Subscribe to a topic</h2>
|
2021-10-24 01:29:45 +00:00
|
|
|
<p>
|
2021-10-24 02:49:50 +00:00
|
|
|
Topics are created on the fly by subscribing to them. You can create and subscribe to a topic either in this web UI, or in
|
|
|
|
your own app by subscribing to an <a href="https://developer.mozilla.org/en-US/docs/Web/API/EventSource">EventSource</a>,
|
|
|
|
a JSON feed, or raw feed.
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
Because there is no sign-up, <b>the topic is essentially a password</b>, so pick something that's not easily guessable.
|
2021-10-24 01:29:45 +00:00
|
|
|
</p>
|
2021-10-23 01:26:01 +00:00
|
|
|
|
2021-10-24 02:49:50 +00:00
|
|
|
<h3>Subscribe via web</h3>
|
|
|
|
<p>
|
|
|
|
If you subscribe to a topic via this web UI in the field below, messages published to any subscribed topic
|
2021-10-24 03:30:10 +00:00
|
|
|
will show up as <b>desktop notification</b>.
|
2021-10-24 02:49:50 +00:00
|
|
|
</p>
|
2021-10-24 01:29:45 +00:00
|
|
|
<form id="subscribeForm">
|
|
|
|
<p>
|
2021-10-24 02:49:50 +00:00
|
|
|
<label for="topicField">Topic ID:</label>
|
2021-10-24 03:30:10 +00:00
|
|
|
<input type="text" id="topicField" placeholder="Letters, numbers, _ and -" pattern="[-_A-Za-z]{1,64}" autofocus />
|
2021-10-24 01:29:45 +00:00
|
|
|
<input type="submit" id="subscribeButton" value="Subscribe topic" />
|
|
|
|
</p>
|
|
|
|
</form>
|
2021-10-24 02:49:50 +00:00
|
|
|
<p id="topicsHeader">Subscribed topics:</p>
|
2021-10-24 01:29:45 +00:00
|
|
|
<ul id="topicsList"></ul>
|
|
|
|
|
2021-10-24 02:49:50 +00:00
|
|
|
<h3>Subscribe via your app, or via the CLI</h3>
|
|
|
|
<tt>
|
|
|
|
curl -s ntfy.sh/mytopic/raw # one message per line (\n are replaced with a space)<br/>
|
|
|
|
curl -s ntfy.sh/mytopic/json # one JSON message per line<br/>
|
|
|
|
curl -s ntfy.sh/mytopic/sse # server-sent events (SSE) stream
|
|
|
|
</tt>
|
|
|
|
|
|
|
|
<h3>Publishing messages</h3>
|
|
|
|
<p>
|
|
|
|
Publishing messages can be done via PUT or POST using. Here's an example using <tt>curl</tt>:
|
|
|
|
</p>
|
|
|
|
<tt>
|
|
|
|
curl -d "long process is done" ntfy.sh/mytopic
|
|
|
|
</tt>
|
|
|
|
<p>
|
|
|
|
Messages published to a non-existing topic or a topic without subscribers will not be delivered later.
|
|
|
|
There is (currently) no buffering of any kind. If you're not listening, the message won't be delivered.
|
|
|
|
</p>
|
2021-10-24 01:29:45 +00:00
|
|
|
</div>
|
2021-10-23 01:26:01 +00:00
|
|
|
|
2021-10-23 17:21:33 +00:00
|
|
|
<script type="text/javascript">
|
|
|
|
let topics = {};
|
2021-10-23 01:26:01 +00:00
|
|
|
|
2021-10-24 01:29:45 +00:00
|
|
|
const topicsHeader = document.getElementById("topicsHeader");
|
2021-10-23 17:21:33 +00:00
|
|
|
const topicsList = document.getElementById("topicsList");
|
2021-10-24 01:29:45 +00:00
|
|
|
const topicField = document.getElementById("topicField");
|
2021-10-23 17:21:33 +00:00
|
|
|
const subscribeButton = document.getElementById("subscribeButton");
|
|
|
|
const subscribeForm = document.getElementById("subscribeForm");
|
|
|
|
const errorField = document.getElementById("error");
|
|
|
|
|
2021-10-23 19:22:17 +00:00
|
|
|
const subscribe = (topic) => {
|
2021-10-23 17:21:33 +00:00
|
|
|
if (Notification.permission !== "granted") {
|
2021-10-23 19:22:17 +00:00
|
|
|
Notification.requestPermission().then((permission) => {
|
2021-10-23 17:21:33 +00:00
|
|
|
if (permission === "granted") {
|
2021-10-23 19:22:17 +00:00
|
|
|
subscribeInternal(topic, 0);
|
2021-10-24 01:29:45 +00:00
|
|
|
} else {
|
|
|
|
showNotificationDeniedError();
|
2021-10-23 17:21:33 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
2021-10-23 19:22:17 +00:00
|
|
|
subscribeInternal(topic, 0);
|
2021-10-23 01:26:01 +00:00
|
|
|
}
|
2021-10-23 17:21:33 +00:00
|
|
|
};
|
2021-10-23 01:26:01 +00:00
|
|
|
|
2021-10-23 19:22:17 +00:00
|
|
|
const subscribeInternal = (topic, delaySec) => {
|
|
|
|
setTimeout(() => {
|
|
|
|
// Render list entry
|
|
|
|
let topicEntry = document.getElementById(`topic-${topic}`);
|
|
|
|
if (!topicEntry) {
|
|
|
|
topicEntry = document.createElement('li');
|
|
|
|
topicEntry.id = `topic-${topic}`;
|
|
|
|
topicEntry.innerHTML = `${topic} <button onclick="unsubscribe('${topic}')">Unsubscribe</button>`;
|
|
|
|
topicsList.appendChild(topicEntry);
|
|
|
|
}
|
2021-10-24 01:29:45 +00:00
|
|
|
topicsHeader.style.display = '';
|
2021-10-23 19:22:17 +00:00
|
|
|
|
|
|
|
// Open event source
|
|
|
|
let eventSource = new EventSource(`${topic}/sse`);
|
|
|
|
eventSource.onopen = () => {
|
|
|
|
topicEntry.innerHTML = `${topic} <button onclick="unsubscribe('${topic}')">Unsubscribe</button>`;
|
|
|
|
delaySec = 0; // Reset on successful connection
|
|
|
|
};
|
|
|
|
eventSource.onerror = (e) => {
|
|
|
|
const newDelaySec = (delaySec + 5 <= 30) ? delaySec + 5 : 30;
|
|
|
|
topicEntry.innerHTML = `${topic} <i>(Reconnecting in ${newDelaySec}s ...)</i> <button onclick="unsubscribe('${topic}')">Unsubscribe</button>`;
|
|
|
|
eventSource.close()
|
|
|
|
subscribeInternal(topic, newDelaySec);
|
|
|
|
};
|
|
|
|
eventSource.onmessage = (e) => {
|
|
|
|
const event = JSON.parse(e.data);
|
|
|
|
new Notification(event.message);
|
|
|
|
};
|
|
|
|
topics[topic] = eventSource;
|
|
|
|
localStorage.setItem('topics', JSON.stringify(Object.keys(topics)));
|
|
|
|
}, delaySec * 1000);
|
2021-10-23 17:21:33 +00:00
|
|
|
};
|
2021-10-23 01:26:01 +00:00
|
|
|
|
2021-10-23 19:22:17 +00:00
|
|
|
const unsubscribe = (topic) => {
|
2021-10-23 17:21:33 +00:00
|
|
|
topics[topic].close();
|
2021-10-23 19:22:17 +00:00
|
|
|
delete topics[topic];
|
|
|
|
localStorage.setItem('topics', JSON.stringify(Object.keys(topics)));
|
2021-10-23 17:21:33 +00:00
|
|
|
document.getElementById(`topic-${topic}`).remove();
|
2021-10-24 01:29:45 +00:00
|
|
|
if (Object.keys(topics).length === 0) {
|
|
|
|
topicsHeader.style.display = 'none';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const showError = (msg) => {
|
|
|
|
errorField.innerHTML = msg;
|
|
|
|
topicField.disabled = true;
|
|
|
|
subscribeButton.disabled = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
const showBrowserIncompatibleError = () => {
|
|
|
|
showError("Your browser is not compatible to use the web-based desktop notifications.");
|
|
|
|
};
|
|
|
|
|
|
|
|
const showNotificationDeniedError = () => {
|
|
|
|
showError("You have blocked desktop notifications for this website. Please unblock them and refresh to use the web-based desktop notifications.");
|
2021-10-23 17:21:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
subscribeForm.onsubmit = function () {
|
|
|
|
if (!topicField.value) {
|
|
|
|
return false;
|
2021-10-23 01:26:01 +00:00
|
|
|
}
|
2021-10-23 17:21:33 +00:00
|
|
|
subscribe(topicField.value);
|
2021-10-23 19:22:17 +00:00
|
|
|
topicField.value = "";
|
2021-10-23 17:21:33 +00:00
|
|
|
return false;
|
2021-10-23 01:26:01 +00:00
|
|
|
};
|
2021-10-23 17:21:33 +00:00
|
|
|
|
2021-10-23 19:22:17 +00:00
|
|
|
// Disable Web UI if notifications of EventSource are not available
|
2021-10-23 17:21:33 +00:00
|
|
|
if (!window["Notification"] || !window["EventSource"]) {
|
2021-10-24 01:29:45 +00:00
|
|
|
showBrowserIncompatibleError();
|
2021-10-23 17:21:33 +00:00
|
|
|
} else if (Notification.permission === "denied") {
|
2021-10-24 01:29:45 +00:00
|
|
|
showNotificationDeniedError();
|
2021-10-23 17:21:33 +00:00
|
|
|
}
|
2021-10-23 19:22:17 +00:00
|
|
|
|
|
|
|
// Reset UI
|
|
|
|
topicField.value = "";
|
|
|
|
|
|
|
|
// Restore topics
|
|
|
|
const storedTopics = localStorage.getItem('topics');
|
2021-10-24 01:29:45 +00:00
|
|
|
if (storedTopics && Notification.permission === "granted") {
|
|
|
|
const storedTopicsArray = JSON.parse(storedTopics)
|
|
|
|
storedTopicsArray.forEach((topic) => { subscribeInternal(topic, 0); });
|
|
|
|
if (storedTopicsArray.length === 0) {
|
|
|
|
topicsHeader.style.display = 'none';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
topicsHeader.style.display = 'none';
|
2021-10-23 19:22:17 +00:00
|
|
|
}
|
2021-10-23 01:26:01 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|