-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a display which shows an arbitrary web page (closes #140).
- Loading branch information
Showing
8 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
Copyright 2024 Team 254. All Rights Reserved. | ||
Author: [email protected] (Patrick Fairbank) | ||
*/ | ||
|
||
html { | ||
overflow: hidden; | ||
} | ||
body { | ||
margin: 0; | ||
background-color: #000; | ||
} | ||
#webpageFrame { | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
width: 100%; | ||
height: 100%; | ||
border: none; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright 2024 Team 254. All Rights Reserved. | ||
// Author: [email protected] (Patrick Fairbank) | ||
// | ||
// Client-side logic for the web page display. | ||
|
||
var websocket; | ||
|
||
$(function() { | ||
// Read the configuration for this display from the URL query string. | ||
var urlParams = new URLSearchParams(window.location.search); | ||
console.log(urlParams.get("url")); | ||
$("#webpageFrame").attr("src", urlParams.get("url")); | ||
|
||
// Set up the websocket back to the server. | ||
websocket = new CheesyWebsocket("/displays/webpage/websocket", { | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{{/* | ||
Copyright 2024 Team 254. All Rights Reserved. | ||
Author: [email protected] (Patrick Fairbank) | ||
|
||
Display to show an arbitrary web page. | ||
*/}} | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Web Page Display - {{.EventSettings.Name}} - Cheesy Arena </title> | ||
<link rel="shortcut icon" href="/static/img/favicon.ico"> | ||
<link rel="stylesheet" href="/static/css/webpage_display.css" /> | ||
</head> | ||
<body> | ||
<iframe id="webpageFrame"></iframe> | ||
<script src="/static/js/lib/jquery.min.js"></script> | ||
<script src="/static/js/lib/jquery.json-2.4.min.js"></script> | ||
<script src="/static/js/lib/jquery.websocket-0.0.1.js"></script> | ||
<script src="/static/js/cheesy-websocket.js"></script> | ||
<script src="/static/js/webpage_display.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright 2024 Team 254. All Rights Reserved. | ||
// Author: [email protected] (Patrick Fairbank) | ||
// | ||
// Web routes for a display to show an arbitrary web page. | ||
|
||
package web | ||
|
||
import ( | ||
"github.com/Team254/cheesy-arena/model" | ||
"github.com/Team254/cheesy-arena/websocket" | ||
"net/http" | ||
) | ||
|
||
// Renders the web page view. | ||
func (web *Web) webpageDisplayHandler(w http.ResponseWriter, r *http.Request) { | ||
if !web.enforceDisplayConfiguration(w, r, map[string]string{"url": "https://www.team254.com"}) { | ||
return | ||
} | ||
|
||
template, err := web.parseFiles("templates/webpage_display.html") | ||
if err != nil { | ||
handleWebErr(w, err) | ||
return | ||
} | ||
data := struct { | ||
*model.EventSettings | ||
}{web.arena.EventSettings} | ||
err = template.ExecuteTemplate(w, "webpage_display.html", data) | ||
if err != nil { | ||
handleWebErr(w, err) | ||
return | ||
} | ||
} | ||
|
||
// The websocket endpoint for sending configuration commands to the display. | ||
func (web *Web) webpageDisplayWebsocketHandler(w http.ResponseWriter, r *http.Request) { | ||
display, err := web.registerDisplay(r) | ||
if err != nil { | ||
handleWebErr(w, err) | ||
return | ||
} | ||
defer web.arena.MarkDisplayDisconnected(display.DisplayConfiguration.Id) | ||
|
||
ws, err := websocket.NewWebsocket(w, r) | ||
if err != nil { | ||
handleWebErr(w, err) | ||
return | ||
} | ||
defer ws.Close() | ||
|
||
// Subscribe the websocket to the notifiers whose messages will be passed on to the client. | ||
ws.HandleNotifiers(display.Notifier, web.arena.ReloadDisplaysNotifier) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2024 Team 254. All Rights Reserved. | ||
// Author: [email protected] (Patrick Fairbank) | ||
|
||
package web | ||
|
||
import ( | ||
"github.com/Team254/cheesy-arena/websocket" | ||
gorillawebsocket "github.com/gorilla/websocket" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestWebpageDisplay(t *testing.T) { | ||
web := setupTestWeb(t) | ||
|
||
recorder := web.getHttpResponse("/displays/webpage?displayId=1&url=https://www.team254.com") | ||
assert.Equal(t, 200, recorder.Code) | ||
assert.Contains(t, recorder.Body.String(), "Web Page Display - Untitled Event - Cheesy Arena") | ||
} | ||
|
||
func TestWebpageDisplayWebsocket(t *testing.T) { | ||
web := setupTestWeb(t) | ||
|
||
server, wsUrl := web.startTestServer() | ||
defer server.Close() | ||
conn, _, err := gorillawebsocket.DefaultDialer.Dial(wsUrl+"/displays/webpage/websocket?displayId=123", nil) | ||
assert.Nil(t, err) | ||
defer conn.Close() | ||
ws := websocket.NewTestWebsocket(conn) | ||
|
||
// Should get a few status updates right after connection. | ||
readWebsocketType(t, ws, "displayConfiguration") | ||
} |