SSOT for compiled boot-js and base version of js/boot.js

This commit is contained in:
Shaka Chen 2022-08-03 18:48:22 +08:00
parent a70e84a062
commit b5c8e3a165
2 changed files with 8 additions and 129 deletions

View file

@ -113,6 +113,13 @@ script."
(defvar *long-poll-url* nil (defvar *long-poll-url* nil
"Dynamic variable indicating the url path used.") "Dynamic variable indicating the url path used.")
(defparameter *compiled-boot-js*
(with-open-file (stream (merge-pathnames #P"static-files/js/boot.js" (asdf:system-source-directory :clog)))
(let ((content (make-string (file-length stream))))
(read-sequence content stream)
content))
"A compiled version of current version of boot.js (private)")
;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;
;; generate-id ;; ;; generate-id ;;
;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;
@ -389,7 +396,7 @@ the contents sent to the brower."
(if (and (eq static-boot-js nil) (if (and (eq static-boot-js nil)
(equalp (getf env :path-info) "/js/boot.js")) (equalp (getf env :path-info) "/js/boot.js"))
`(200 (:content-type "text/javascript") `(200 (:content-type "text/javascript")
(,(compiled-boot-js))) (,*compiled-boot-js*))
(funcall app env)))) (funcall app env))))
(lambda (app) (lambda (app)
(lambda (env) (lambda (env)
@ -710,130 +717,3 @@ uses the jQuery CDN instead of the static js files."
</BODY> </BODY>
<noscript>Your browser must support JavaScript and be HTML 5 compilant to see this site.</noscript> <noscript>Your browser must support JavaScript and be HTML 5 compilant to see this site.</noscript>
</HTML>") </HTML>")
;;;;;;;;;;;;;;;;;;;;;;
;; compiled-boot-js ;;
;;;;;;;;;;;;;;;;;;;;;;
(defun compiled-boot-js ()
"Returns a compiled version of current version of boot.js (private)"
"
/*compiled version*/
var ws=null;
var adr; var adrc;
var clog={};
var pingerid;
var s = document.location.search;
var tokens;
var r = /[?&]?([^=]+)=([^&]*)/g;
clog['body']=document.body;
clog['head']=document.head;
clog['documentElement']=document.documentElement;
clog['window']=window;
clog['navigator']=navigator;
clog['document']=window.document;
clog['location']=window.location;
if (typeof clog_debug == 'undefined') {
clog_debug = false;
}
function Ping_ws() {
if (ws.readyState == 1) {
ws.send ('0');
}
}
function Shutdown_ws(event) {
if (ws != null) {
ws.onerror = null;
ws.onclose = null;
ws.close ();
ws = null;
}
clearInterval (pingerid);
if (clog['html_on_close'] != '') {
$(document.body).html(clog['html_on_close']);
}
}
function Setup_ws() {
ws.onmessage = function (event) {
try {
if (clog_debug == true) {
console.log ('eval data = ' + event.data);
}
eval (event.data);
} catch (e) {
console.error (e.message);
}
}
ws.onerror = function (event) {
console.log ('onerror: reconnect');
ws = null;
ws = new WebSocket (adr + '?r=' + clog['connection_id']);
ws.onopen = function (event) {
console.log ('onerror: reconnect successful');
Setup_ws();
}
ws.onclose = function (event) {
console.log ('onerror: reconnect failure');
Shutdown_ws(event);
}
}
ws.onclose = function (event) {
console.log ('onclose: reconnect');
ws = null;
ws = new WebSocket (adr + '?r=' + clog['connection_id']);
ws.onopen = function (event) {
console.log ('onclose: reconnect successful');
Setup_ws();
}
ws.onclose = function (event) {
console.log ('onclose: reconnect failure');
Shutdown_ws(event);
}
}
}
function Open_ws() {
if (location.protocol == 'https:') {
adr = 'wss://' + location.hostname;
} else {
adr = 'ws://' + location.hostname;
}
if (location.port != '') { adr = adr + ':' + location.port; }
adr = adr + '/clog';
if (clog['connection_id']) {
adrc = adr + '?r=' + clog['connection_id'];
} else { adrc = adr }
try {
console.log ('connecting to ' + adrc);
ws = new WebSocket (adrc);
} catch (e) {
console.log ('trying again, connecting to ' + adrc);
ws = new WebSocket (adrc);
}
if (ws != null) {
ws.onopen = function (event) {
console.log ('connection successful');
Setup_ws();
}
pingerid = setInterval (function () {Ping_ws ();}, 10000);
} else {
document.writeln ('If you are seeing this your browser or your connection to the internet is blocking websockets.');
}
}
$( document ).ready(function() {
if (ws == null) { Open_ws(); }
});
")

View file

@ -1,4 +1,3 @@
/*static version*/
var ws=null; var ws=null;
var adr; var adrc; var adr; var adrc;
var clog={}; var clog={};