* Some code notes

This commit is contained in:
Daniel Legt 2022-06-04 16:36:30 +03:00
parent cfe2c06dac
commit 4138386fb3
2 changed files with 9 additions and 2 deletions

View File

@ -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"`

View File

@ -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);