aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--main/app/sprinkles/core/assets/SiteAssets/php/Chatserver/src/ChatProcessor.php22
-rw-r--r--main/app/sprinkles/core/templates/pages/partials/chat.js.twig33
-rw-r--r--startserver.sh1
3 files changed, 49 insertions, 7 deletions
diff --git a/main/app/sprinkles/core/assets/SiteAssets/php/Chatserver/src/ChatProcessor.php b/main/app/sprinkles/core/assets/SiteAssets/php/Chatserver/src/ChatProcessor.php
index 603bc01..ab306b6 100644
--- a/main/app/sprinkles/core/assets/SiteAssets/php/Chatserver/src/ChatProcessor.php
+++ b/main/app/sprinkles/core/assets/SiteAssets/php/Chatserver/src/ChatProcessor.php
@@ -73,6 +73,7 @@ class ChatProcessor implements MessageComponentInterface
if ($channel == $target) {
$MessageObject = new \stdClass();
$MessageObject->ServerMessage = false;
+ $MessageObject->GroupName = $channel;
$MessageObject->Username = $this->connectedUsersNames[$conn->resourceId];
$MessageObject->Message = htmlspecialchars($data->Message);
if ($id === $conn->resourceId) {
@@ -85,6 +86,27 @@ class ChatProcessor implements MessageComponentInterface
}
}
}
+ case "TypingState":
+ if (isset($this->subscriptions[$conn->resourceId])) {
+ $target = $this->subscriptions[$conn->resourceId];
+ foreach ($this->subscriptions as $id => $channel) {
+ if ($channel == $target) {
+ $MessageObject = new \stdClass();
+ $MessageObject->ServerMessage = true;
+ $MessageObject->ServerMessageType = "TypingState";
+ $MessageObject->GroupName = $channel;
+ $MessageObject->Username = $this->connectedUsersNames[$conn->resourceId];
+ $MessageObject->State = htmlspecialchars($data->State);
+ if ($id === $conn->resourceId) {
+ $MessageObject->WasHimself = true;
+ } else {
+ $MessageObject->WasHimself = false;
+ }
+ $MessageJson = json_encode($MessageObject, true);
+ $this->users[$id]->send($MessageJson);
+ }
+ }
+ }
}
}
diff --git a/main/app/sprinkles/core/templates/pages/partials/chat.js.twig b/main/app/sprinkles/core/templates/pages/partials/chat.js.twig
index 6c4c673..ed30475 100644
--- a/main/app/sprinkles/core/templates/pages/partials/chat.js.twig
+++ b/main/app/sprinkles/core/templates/pages/partials/chat.js.twig
@@ -84,20 +84,33 @@ function InitializeChatServer() {
}
} else if (MessageObject.ServerMessage === true) {
if (MessageObject.ServerMessageType === "GroupJoin") {
- if (MessageObject.WasHimself === false) {
- var Message = "{{ translate("CHAT_MESSAGES.USER_GROUP_JOIN", {user: "ConvertTranslatedMessageWithUsername"}) }}".replace("ConvertTranslatedMessageWithUsername", MessageObject.Username);
- } else if (MessageObject.WasHimself === true) {
+ if (MessageObject.WasHimself === true) {
ChatMessages.empty();
var Message = "{{ translate("CHAT_MESSAGES.YOU_GROUP_JOIN", {group: "ConvertTranslatedMessageWithGroupName"}) }}".replace("ConvertTranslatedMessageWithGroupName", '"' + MessageObject.GroupName + '"');
+ } else if (MessageObject.WasHimself === false) {
+ var Message = "{{ translate("CHAT_MESSAGES.USER_GROUP_JOIN", {user: "ConvertTranslatedMessageWithUsername"}) }}".replace("ConvertTranslatedMessageWithUsername", MessageObject.Username);
}
ChatMessages.append("<div class='ServerChatMessage'>" + Message + "</span>.</div><br><br>");
} else if (MessageObject.ServerMessageType === "UserDisconnect") {
var TranslatedDisconnectMessage = "{{ translate("CHAT_MESSAGES.USER_DISCONNECT", {user: "ConvertTranslatedMessageWithUsername"}) }}".replace("ConvertTranslatedMessageWithUsername", MessageObject.Username);
ChatMessages.append("<div class='ServerChatMessage'>" + TranslatedDisconnectMessage + ".</div><br><br>");
+ } else if (MessageObject.ServerMessageType === "TypingState") {
+ if (MessageObject.State === true) {
+ if (MessageObject.WasHimself === true) {
+ console.log("[SERVER REPORT] YOU STARTED TYPING");
+ } else if (MessageObject.WasHimself === false) {
+ console.log("[SERVER REPORT] " + MessageObject.Username + " STARTED TYPING");
+ }
+ } else if (MessageObject.State === false) {
+ if (MessageObject.WasHimself === true) {
+ console.log("[SERVER REPORT] YOU STOPPED TYPING");
+ } else if (MessageObject.WasHimself === false) {
+ console.log("[SERVER REPORT] " + MessageObject.Username + " STOPPED TYPING");
+ }
+ }
}
}
ChatMessages.animate({scrollTop: document.querySelector("#ChatMessages").scrollHeight}, "slow");
- //window.scrollTo(0,document.querySelector("#ChatMessages").scrollHeight);
};
SubscribeTextInput.keyup(function (e) {
@@ -115,12 +128,18 @@ function InitializeChatServer() {
ChatTypeTimeout = setTimeout(sendStopTyping, 2500);
function sendStartTyping() {
- if (IsTyping !== true) sendTypingState(true);
+ if (IsTyping !== true) {
+ console.log("[TYPE LOGGER] USER STARTED TYPING");
+ sendTypingState(true);
+ }
IsTyping = true;
}
function sendStopTyping() {
- if (IsTyping !== false) sendTypingState(false);
+ if (IsTyping !== false) {
+ console.log("[TYPE LOGGER] USER STOPPED TYPING");
+ sendTypingState(false);
+ }
IsTyping = false;
}
@@ -143,7 +162,7 @@ function InitializeChatServer() {
}
function sendTypingState(state) {
- ChatSocket.send(JSON.stringify({ClientMessageType: "TypingState", Message: state}));
+ ChatSocket.send(JSON.stringify({ClientMessageType: "TypingState", State: state}));
}
};
}
diff --git a/startserver.sh b/startserver.sh
index f5f9ae0..d4a1938 100644
--- a/startserver.sh
+++ b/startserver.sh
@@ -1,2 +1,3 @@
+#!/usr/bin/env bash
cd main/app/sprinkles/core/assets/SiteAssets/php/Chatserver/bin/
nohup php WebChatServer.php &