From 4138386fb355acb2d623e5a3544c528f929509c6 Mon Sep 17 00:00:00 2001 From: Kato Twofold Date: Sat, 4 Jun 2022 16:36:30 +0300 Subject: [PATCH] * Some code notes --- lib/socketmanager/socketmanager.go | 5 +++-- static/js/ws.js | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/socketmanager/socketmanager.go b/lib/socketmanager/socketmanager.go index 219ad37..f836ad2 100644 --- a/lib/socketmanager/socketmanager.go +++ b/lib/socketmanager/socketmanager.go @@ -11,10 +11,11 @@ import ( ) var wsUpgrader = websocket.Upgrader{ - ReadBufferSize: 1024, - WriteBufferSize: 1024, + ReadBufferSize: 1024, // TODO: Make it configurable via the .env file + WriteBufferSize: 1024, // TODO: Make it configurable via the .env file } +// TODO: Use generics so that we can take string messages, that'd be nice! type SocketMessage struct { EventType string `json:"eventType"` PadName string `json:"padName"` diff --git a/static/js/ws.js b/static/js/ws.js index f33ced3..cc9f75c 100644 --- a/static/js/ws.js +++ b/static/js/ws.js @@ -2,6 +2,9 @@ class PadSocket { ws = null; padName = null; + /** + * @deprecated + */ state = null; /** @@ -20,6 +23,7 @@ class PadSocket { // Connect to the websocket const ws = new WebSocket(connUrl); ws.onopen = () => { + // TODO: This is redundant, we could check the websocket status: ws.readyState == WebSocket.OPEN this.state = 'active'; } @@ -51,6 +55,7 @@ class PadSocket { }; } + // TODO: Compress the message, usually we will be sending the whole body of the pad from the client to the server or vice-versa. this.ws.send( JSON.stringify({ eventType, padName: this.padName, @@ -65,6 +70,7 @@ class PadSocket { } +// TODO: Test if this is actually necessary or the DOMContentLoaded event would suffice // wait for the whole window to load window.addEventListener(`load`, e => { window.socket = new PadSocket(padTitle);