first pass at custom route/popup definitions

This commit is contained in:
a. fox 2023-04-04 15:00:20 -04:00
parent 9dea24f102
commit 4c8fb93f48
3 changed files with 48 additions and 2 deletions

View File

@ -30,13 +30,14 @@
"owncast" "util"))
(:file "extensions" :depends-on ("owncast" "services" "commands"
"util" "config" "web" "handlers"
"conditions"))
"conditions" "routes"))
(:file "web" :depends-on ("util" "commands" "handlers"
"services"))
(:file "owncast" :depends-on ("util" "config"))
(:file "services" :depends-on ("util" "conditions"))
(:file "handlers" :depends-on ("util" "conditions"))
(:file "commands" :depends-on ("util" "owncast"))
(:file "routes" :depends-on ("util" "web"))
(:file "util" :depends-on ("conditions"))
(:file "conditions")
(:file "config"))))

View File

@ -35,5 +35,6 @@
(defpackage ida-bot.extension
(:use :cl :ida-bot.util :ida-bot.commands
:ida-bot.actions :ida-bot.config
:ida-bot.services :ida-bot.handler))
:ida-bot.services :ida-bot.handler
:ida-bot.routes))
(in-package :ida-bot.extension)

44
src/routes.lisp Normal file
View File

@ -0,0 +1,44 @@
(defpackage ida-bot.routes
(:use :cl :cl-markup :caveman2 :parenscript)
(:import-from :ida-bot.web :*web*)
(:export :define-media-popup))
(in-package :ida-bot.routes)
;; maybe add in a timeout option?
(defmacro define-media-popup (route media-path)
"defines a new ROUTE that will display a video at MEDIA-PATH, when the trigger-function is called
returns TRIGGER-FUNCTION
ROUTE is the web route that the video will be played at
VIDEO-PATH is the web route to the video file - should be located in the bot's *static-directory* (defaults to ./static/)"
(let ((trigger-var (gensym)))
`(let ((,trigger-var))
(declare (ignorable ,trigger-var))
(prog1
(lambda ()
(unless ,trigger-var
(setf ,trigger-var t)))
(defroute (*web* ,route :method :GET) ()
(prog1 (html5
(:head
(:meta :http-equiv "refresh" :content (if ,trigger-var "-1" "1"))
(:script :type "text/javascript"
(raw "
function hidePopup () {
var element = document.getElementById(\"popup\");
element.style = \"display:none;\";
window.location.reload();
}
function displayPopup () {
var element = document.getElementById(\"popup\");
element.style = \"display:block\";
element.play();
}")))
(:body :onload (if ,trigger-var "displayPopup();" "")
(:video :id "popup" :style "display:none;" :preload "auto" :onended "hidePopup();"
(:source :src ,media-path))))
(when ,trigger-var (setf ,trigger-var nil))))))))