play fullscreen

This commit is contained in:
2025-12-12 16:00:06 +01:00
parent a7cf3c8a10
commit 0a92fd678f
3 changed files with 74 additions and 15 deletions
+21 -11
View File
@@ -5,16 +5,20 @@ import (
"net/http"
"os"
"path/filepath"
"teletype_softwares/domain"
"teletype_softwares/lib/template_utils"
"github.com/go-chi/chi/v5"
)
type PlayController struct{}
type PlayController struct {
softwareService domain.SoftwareServiceInterface
}
func NewPlayController() *PlayController {
return &PlayController{}
func NewPlayController(softwareService domain.SoftwareServiceInterface) *PlayController {
return &PlayController{
softwareService: softwareService,
}
}
func (c *PlayController) Play(w http.ResponseWriter, r *http.Request) {
@@ -24,19 +28,25 @@ func (c *PlayController) Play(w http.ResponseWriter, r *http.Request) {
return
}
software, err := c.softwareService.GetByNameWithReleases(name)
if err != nil {
if err == domain.ErrSoftwareNotFound {
http.Error(w, "Software not found", http.StatusNotFound)
return
}
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
tmpl, err := template_utils.GetTemplate("play_controller_play", "http/views/shared/layout.html", "http/views/play/play.html")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
data := struct {
Name string
}{
Name: name,
}
tmpl.Execute(w, data)
tmpl.Execute(w, map[string]interface{}{
"Software": software,
})
}
func (c *PlayController) ServeContent(w http.ResponseWriter, r *http.Request) {
+1 -1
View File
@@ -10,7 +10,7 @@ func StartHttpServer(domainInstance domain.Domain) {
NewSoftwareController(domainInstance.SoftwareService),
NewSoftwareUpdaterController(domainInstance.SoftwareUpdaterService),
NewDownloadController(domainInstance.DownloadService),
NewPlayController(),
NewPlayController(domainInstance.SoftwareService),
).Init()
http_utils.StartGenericHTTPServer(http_utils.StartGenericHTTPServerContext{
+52 -3
View File
@@ -1,10 +1,59 @@
{{define "content"}}
<h1 class="my-4">Play {{.Name}}</h1>
<h1 class="my-4">Play {{.Software.Title}}</h1>
<div class="ratio ratio-4x3" style="max-width: 640px; margin: 0 auto;">
<iframe id="gameFrame" src="/play/{{.Name}}/content/index.html" frameborder="0" allowfullscreen></iframe>
<iframe id="gameFrame" src="/play/{{.Software.Name}}/content/index.html" frameborder="0" allowfullscreen></iframe>
</div>
<p style="margin-top: 20px"><a href="/" class="btn btn-primary">Back to Softwares</a></p>
<div style="max-width: 640px; margin: 10px auto; text-align: center;">
<div class="btn-group" role="group" aria-label="Game controls">
<a href="/" class="btn btn-primary">Back to Softwares</a>
<button id="fullscreenButton" class="btn btn-secondary">Fullscreen</button>
</div>
</div>
<script>
document.getElementById('fullscreenButton').addEventListener('click', function() {
var iframe = document.getElementById('gameFrame');
if (iframe.requestFullscreen) {
iframe.requestFullscreen();
} else if (iframe.mozRequestFullScreen) { /* Firefox */
iframe.mozRequestFullScreen();
} else if (iframe.webkitRequestFullscreen) { /* Chrome, Safari and Opera */
iframe.webkitRequestFullscreen();
} else if (iframe.msRequestFullscreen) { /* IE/Edge */
iframe.msRequestFullscreen();
}
});
document.addEventListener('fullscreenchange', function() {
if (document.fullscreenElement) {
document.body.style.overflow = 'hidden';
} else {
document.body.style.overflow = '';
}
});
document.addEventListener('mozfullscreenchange', function() {
if (document.mozFullScreenElement) {
document.body.style.overflow = 'hidden';
} else {
document.body.style.overflow = '';
}
});
document.addEventListener('webkitfullscreenchange', function() {
if (document.webkitFullscreenElement) {
document.body.style.overflow = 'hidden';
} else {
document.body.style.overflow = '';
}
});
document.addEventListener('msfullscreenchange', function() {
if (document.msFullscreenElement) {
document.body.style.overflow = 'hidden';
} else {
document.body.style.overflow = '';
}
});
</script>
{{end}}