Test button
This commit is contained in:
parent
d6a7c3f5b0
commit
1ab0282101
1 changed files with 11 additions and 4 deletions
|
@ -94,7 +94,7 @@
|
||||||
if (!topicEntry) {
|
if (!topicEntry) {
|
||||||
topicEntry = document.createElement('li');
|
topicEntry = document.createElement('li');
|
||||||
topicEntry.id = `topic-${topic}`;
|
topicEntry.id = `topic-${topic}`;
|
||||||
topicEntry.innerHTML = `${topic} <button onclick="unsubscribe('${topic}')">Unsubscribe</button>`;
|
topicEntry.innerHTML = `${topic} <button onclick="test('${topic}')">Test</button> <button onclick="unsubscribe('${topic}')">Unsubscribe</button>`;
|
||||||
topicsList.appendChild(topicEntry);
|
topicsList.appendChild(topicEntry);
|
||||||
}
|
}
|
||||||
topicsHeader.style.display = '';
|
topicsHeader.style.display = '';
|
||||||
|
@ -102,12 +102,12 @@
|
||||||
// Open event source
|
// Open event source
|
||||||
let eventSource = new EventSource(`${topic}/sse`);
|
let eventSource = new EventSource(`${topic}/sse`);
|
||||||
eventSource.onopen = () => {
|
eventSource.onopen = () => {
|
||||||
topicEntry.innerHTML = `${topic} <button onclick="unsubscribe('${topic}')">Unsubscribe</button>`;
|
topicEntry.innerHTML = `${topic} <button onclick="test('${topic}')">Test</button> <button onclick="unsubscribe('${topic}')">Unsubscribe</button>`;
|
||||||
delaySec = 0; // Reset on successful connection
|
delaySec = 0; // Reset on successful connection
|
||||||
};
|
};
|
||||||
eventSource.onerror = (e) => {
|
eventSource.onerror = (e) => {
|
||||||
const newDelaySec = (delaySec + 5 <= 30) ? delaySec + 5 : 30;
|
const newDelaySec = (delaySec + 5 <= 15) ? delaySec + 5 : 15;
|
||||||
topicEntry.innerHTML = `${topic} <i>(Reconnecting in ${newDelaySec}s ...)</i> <button onclick="unsubscribe('${topic}')">Unsubscribe</button>`;
|
topicEntry.innerHTML = `${topic} <i>(Reconnecting in ${newDelaySec}s ...)</i> <button disabled="disabled">Test</button> <button onclick="unsubscribe('${topic}')">Unsubscribe</button>`;
|
||||||
eventSource.close()
|
eventSource.close()
|
||||||
subscribeInternal(topic, newDelaySec);
|
subscribeInternal(topic, newDelaySec);
|
||||||
};
|
};
|
||||||
|
@ -130,6 +130,13 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const test = (topic) => {
|
||||||
|
fetch(`/${topic}`, {
|
||||||
|
method: 'PUT',
|
||||||
|
body: `This is a test notification for topic ${topic}!`
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
const showError = (msg) => {
|
const showError = (msg) => {
|
||||||
errorField.innerHTML = msg;
|
errorField.innerHTML = msg;
|
||||||
topicField.disabled = true;
|
topicField.disabled = true;
|
||||||
|
|
Loading…
Reference in a new issue