diff --git a/html.qrc b/html.qrc index dd07166..c99dd34 100644 --- a/html.qrc +++ b/html.qrc @@ -8,5 +8,6 @@ html/svg/message.svg html/realtimechat.js html/svg/airplane.svg + html/newmessage.mp3 diff --git a/html/newmessage.mp3 b/html/newmessage.mp3 new file mode 100755 index 0000000..5fa431e Binary files /dev/null and b/html/newmessage.mp3 differ diff --git a/html/realtimechat.js b/html/realtimechat.js index 2c09a40..7dc984f 100644 --- a/html/realtimechat.js +++ b/html/realtimechat.js @@ -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"); diff --git a/httpserver.cpp b/httpserver.cpp index dd8ca1c..c66b2f1 100644 --- a/httpserver.cpp +++ b/httpserver.cpp @@ -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) { diff --git a/httpserver.h b/httpserver.h index 2cc6508..c4e8d55 100644 --- a/httpserver.h +++ b/httpserver.h @@ -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";