Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ping removal #182

Merged
merged 2 commits into from
Mar 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 24 additions & 13 deletions static/js/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,12 @@ function recieveMessage(message) {

/**
* @param {string} data
* @param {boolean} log
*/
function websocketSend(data) {
console.log(data)
function websocketSend(data, log = true) {
if (log) {
console.log(data);
}
if (ws.readyState == ws.OPEN) {
ws.send(data);
} else {
Expand All @@ -325,8 +328,9 @@ function websocketSend(data) {
/**
* @param {string|any} msg
* @param {number} type
* @param {boolean} log
*/
function sendMessage(msg, type) {
function sendMessage(msg, type, log=true) {
if (typeof msg !== "string") {
msg = JSON.stringify(msg);
}
Expand All @@ -338,7 +342,7 @@ function sendMessage(msg, type) {
websocketSend(JSON.stringify({
Type: type,
Message: msg,
}));
}), log);
}


Expand Down Expand Up @@ -429,14 +433,14 @@ function processMessageKey(e) {
const n = filteredSuggestion[i];
if (n == currentSuggestion) {
newIdx = i;
if(keyCode == 40) {
if (keyCode == 40) {
newIdx = i + 1;
if (newIdx == filteredSuggestion.length) {
newIdx--;
}
} else if(keyCode == 38) {
newIdx = i-1;
if(newIdx < 0) {
} else if (keyCode == 38) {
newIdx = i - 1;
if (newIdx < 0) {
newIdx = 0;
}
}
Expand All @@ -456,9 +460,9 @@ function processMessageKey(e) {
let endsSpace = match[0].endsWith(" ");
let replaceVal = "";
if (currentSuggestionType == SuggestionType.Emote) {
replaceVal = ":"+currentSuggestion+":";
}else {
replaceVal = "@"+currentSuggestion;
replaceVal = ":" + currentSuggestion + ":";
} else {
replaceVal = "@" + currentSuggestion;
}

if (endsSpace) {
Expand All @@ -473,7 +477,7 @@ function processMessageKey(e) {
msg[0].selectionEnd = idx;

filteredSuggestion = [];
break;
break;
default:
return false;
}
Expand Down Expand Up @@ -613,7 +617,14 @@ function sendColor(color) {
function setupWebSocket() {
ws = new WebSocket(getWsUri());
ws.onmessage = (m) => recieveMessage(JSON.parse(m.data));
ws.onopen = () => console.log("Websocket Open");
ws.onopen = () => {
console.log("Websocket Open");
// Ngnix websocket timeouts at 60s
// http://nginx.org/en/docs/http/websocket.html
setInterval(() => {
sendMessage("", ClientDataType.CdPing, false);
}, 45000);
}
ws.onclose = () => {
closeChat();
setNotifyBox("The connection to the server has closed. Please refresh page to connect again.");
Expand Down