diff options
Diffstat (limited to 'assets/js/chat.js')
-rw-r--r-- | assets/js/chat.js | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/assets/js/chat.js b/assets/js/chat.js new file mode 100644 index 0000000..1ea3471 --- /dev/null +++ b/assets/js/chat.js @@ -0,0 +1,33 @@ +var conn = new WebSocket('wss://marvinborner.ddnss.de:1337');
+conn.onopen = function () {
+ console.log("Chat connection established!");
+};
+
+conn.onmessage = function (e) {
+ document.getElementById("ChatResponses").innerHTML += e.data + "<br>";
+};
+
+$('#ChatTextInput').keyup(function (e) {
+ if (e.keyCode === 13) {
+ sendMessage($('#ChatTextInput').val());
+ $('#ChatTextInput').val("");
+ }
+});
+
+$('#SubscribeTextInput').keyup(function (e) {
+ if (e.keyCode === 13) {
+ subscribe($('#SubscribeTextInput').val());
+ }
+});
+
+function subscribe(channel) {
+ conn.send(JSON.stringify({command: "subscribe", channel: channel}));
+ $("#SubscribeTextInput").hide();
+ $("#ChatTextInput").show();
+ $("#ChatResponses").empty();
+}
+
+function sendMessage(msg) {
+ conn.send(JSON.stringify({command: "message", message: msg}));
+ $("#ChatTextInput").val("");
+}
|