television

a simple LAN/WLAN desktop public broadcasting service
Log | Files | Refs | README

commit ee2780583f31e49871e97f87bb4b5ea087d00049
Author: ugrnm <ultrageranium@bleu255.com>
Date:   Fri, 13 Sep 2024 14:58:12 +0200

proof of concept

Diffstat:
A.gitignore | 3+++
AREADME | 16++++++++++++++++
Ago.mod | 16++++++++++++++++
Atv.go | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
Awww/index.html | 13+++++++++++++
Awww/style.css | 3+++
Awww/tv.js | 12++++++++++++
7 files changed, 114 insertions(+), 0 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -0,0 +1,3 @@ +go.sum +www/tv.jpg +tv diff --git a/README b/README @@ -0,0 +1,16 @@ +television +========== + +A simple LAN/WLAN screen public broadcasting service. + + +build +----- + +blablabla + + +usage +----- + +blablabla diff --git a/go.mod b/go.mod @@ -0,0 +1,16 @@ +module television + +go 1.22 + +require ( + github.com/kbinani/screenshot v0.0.0-20240820160931-a8a2c5d0e191 + github.com/pixiv/go-libjpeg v0.0.0-20190822045933-3da21a74767d +) + +require ( + github.com/gen2brain/shm v0.1.0 // indirect + github.com/godbus/dbus/v5 v5.1.0 // indirect + github.com/jezek/xgb v1.1.1 // indirect + github.com/lxn/win v0.0.0-20210218163916-a377121e959e // indirect + golang.org/x/sys v0.24.0 // indirect +) diff --git a/tv.go b/tv.go @@ -0,0 +1,51 @@ +package main + +import ( + "os" + "log" + "time" + "net/http" + "github.com/kbinani/screenshot" + "github.com/pixiv/go-libjpeg/jpeg" +) + +func snap() { + + for { + + img, err := screenshot.CaptureDisplay(0) + if err != nil { + panic(err) + } + + fileName := "www/tv.jpg.tmp" + file, _ := os.Create(fileName) + defer file.Close() + + jpeg.Encode(file, img, &jpeg.EncoderOptions{ + Quality: 50, + OptimizeCoding: false, + ProgressiveMode: false, + DCTMethod: jpeg.DCTIFast}) + + os.Rename(fileName, "www/tv.jpg") + + log.Println("screenshot taken") + + time.Sleep(1000 * time.Millisecond) + + } +} + +func main() { + + go snap() + + log.Println("we're live!") + log.Println("ctrl-c for emergency shutdown") + + http.Handle("/", http.FileServer(http.Dir("www"))) + http.ListenAndServe(":8888", nil) + +} + diff --git a/www/index.html b/www/index.html @@ -0,0 +1,13 @@ +<!DOCTYPE html> +<html lang="en"> + <head> + <meta charset="UTF-8"> + <title>television</title> + <link rel="stylesheet" href="/style.css"> + <script src="/tv.js"></script> + </head> + <body> + <img id="television" src="/tv.jpg" alt="television"> + </body> +</html> + diff --git a/www/style.css b/www/style.css @@ -0,0 +1,3 @@ +img { + width: 100%; +} diff --git a/www/tv.js b/www/tv.js @@ -0,0 +1,12 @@ +// Fetch a new tv.jpg every second +// In theory, fetch() combined with a "no-store" cache directive should be +// enough, and it is fine on some browsers like chromium. However on firefox +// even though the file is effectly re-downloaded and not put in cache, +// the browser does not refresh the image. To force refresh it we have to +// update its src with bogus URL crap. Great. +// +setInterval(function(){ + fetch("/tv.jpg", { cache: "no-store", mode: "no-cors" }); + document.getElementById("television").src="/tv.jpg#" + Date.now(); +}, 1000); +