Warning: session_start(): open(/var/lib/php/sessions/sess_jmqkdlmcdkdm8jue2k24ilvir7, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
// defines:
// variable ws (the websocket)
// variable wsReady (boolean)
// variable wsVerbose (boolean)
// wsSend(msg) (send a message when websocket is ready)
// wsOnMessage(function(event) {...}) (react to messages)
// wsOnOpen(function() {}) (react to opening of websocket)
sclass HInitWebSocket {
S wsVar = "ws";
S readyMsg = "WebSocket ready!";
bool handleEvals = true; // automatically handle {"eval":"jsCode();"}
bool wsVerbose;
S headStuff aka get() {
ret hreconnectingWebSockets() + hscript(js());
}
LS dependencies() {
ret ll(hjssnippet(hreconnectingWebSockets_snippetID(), "data-comment" := "ReconnectingWebSocket"));
}
S js() {
ret replaceDollarVars2([[
var wsReady = false;
var wsInitialMsgs = [];
var wsMsgListeners = [];
var wsOpenListeners = [];
var wsVerbose = $wsVerbose;
var wsURL = ((window.location.protocol === "https:") ? "wss://" : "ws://") + window.location.host
+ window.location.pathname + window.location.search;
var ]] + wsVar + [[ = new ReconnectingWebSocket(wsURL);
]] + wsVar + [[.onopen = function(event) {
wsReady = true;
console.log(]] + jsQuote(readyMsg + " ") + [[+ wsURL);
wsOpenListeners.forEach(function(f) { f(); });
ws.onmessage = function(event) {
wsMsgListeners.forEach(function(listener) {
listener(event);
});
};
wsInitialMsgs.forEach(function(msg) {
if (wsVerbose) console.log("Sending initial msg: " + msg);
ws.send(msg);
});
wsInitialMsgs = [];
};
// send it now if ws is open already or when ws was opened
function wsSend(msg) {
if (wsReady) {
if (wsVerbose) console.log("Sending msg: " + msg);
ws.send(msg);
} else
wsInitialMsgs.push(msg);
}
function wsOnOpen(f) {
wsOpenListeners.push(f);
}
function wsOnMessage(f) {
wsMsgListeners.push(f);
}
]], +wsVerbose) + (!handleEvals ? "" : "wsOnMessage(" + js_evalOnWebSocketMessage() + ");\n";
}
}