audio notification

master
const an teen 2021-12-31 14:40:16 -05:00
parent 13a9939030
commit 2cfa9d51ed
5 changed files with 35 additions and 5 deletions

View File

@ -8,5 +8,6 @@
<file>html/svg/message.svg</file>
<file>html/realtimechat.js</file>
<file>html/svg/airplane.svg</file>
<file>html/newmessage.mp3</file>
</qresource>
</RCC>

BIN
html/newmessage.mp3 100755

Binary file not shown.

View File

@ -4,14 +4,15 @@ let objCurrentServerStatus = document.getElementById("serverStatus");
let objOnlineCounter = document.getElementById("online");
let objOnlineList = document.getElementById("onlineList");
const HTML_SERVER_ONLINE_MARKER = "✅";
const HTML_SERVER_OFFLINE_MARKER = "❌";
let ajaxUrl = document.getElementById("ajaxPath").innerText;
let lastMessageId = document.getElementById("LMId").innerText;
let reqIsFailed = false;
let firstLoadingWithDisconnectedServer = false;
const ajaxUrl = document.getElementById("ajaxPath").innerText;
const audio = new Audio('/newmessage.mp3');
const HTML_SERVER_ONLINE_MARKER = "✅";
const HTML_SERVER_OFFLINE_MARKER = "❌";
function appendMessage(nick /* if == "***", then system message */, message)
{
let messageObject = document.createElement("div");
@ -26,7 +27,10 @@ function appendMessage(nick /* if == "***", then system message */, message)
nicknameContainer.innerText = "IRCaBot";
} else {
nicknameContainer.innerText = nick;
nicknameContainer.setAttribute("style", "color: #1b4af5")
nicknameContainer.setAttribute("style", "color: #1b4af5");
if (document.hidden) {
audio.play();
}
}
let textContainer = document.createElement("div");

View File

@ -197,6 +197,25 @@ void HttpServer::reader()
}
}
}
else if (urlPath == "/newmessage.mp3") {
QString eTag = global::getValue(request, "If-None-Match", global::eHttpHeader);
if (eTag == HTTP_ACTUAL_ETAG) {
if (socket->isOpen()) socket->write(HEADER_304.toUtf8());
}
else {
QFile mp3("://html/newmessage.mp3");
if (mp3.open(QIODevice::ReadOnly)) {
QByteArray file = mp3.readAll();
mp3.close();
QString header = HEADER_MP3;
replaceTag(header, "SIZE", QString::number(file.size()));
if (socket->isOpen()) {
socket->write(header.toUtf8());
if (not isHeadRequest) socket->write(file);
}
}
}
}
else if (urlPath == "/style.css") {
QString eTag = global::getValue(request, "If-None-Match", global::eHttpHeader);
if (eTag == HTTP_ACTUAL_ETAG) {

View File

@ -125,6 +125,12 @@ Content-Length: {{SIZE}}\r\n\r\n";
const QString HEADER_JSON = "\
HTTP/1.1 200 OK\r\n\
Content-Type: application/json; charset=utf-8\r\n\
Content-Length: {{SIZE}}\r\n\r\n";
const QString HEADER_MP3 = "\
HTTP/1.1 200 OK\r\n\
Content-Type: audio/mpeg;\r\n\
ETag: \""+HTTP_ACTUAL_ETAG+"\"\r\n\
Content-Length: {{SIZE}}\r\n\r\n";
const QString HEADER_304 = "HTTP/1.1 304 Not Modified\r\nContent-Length: 0\r\n\r\n";