mirror of
https://github.com/burrow-dev/burrow-client.git
synced 2026-11-18 17:37:50 -05:00
feat: theatre videos (client 1.3.2)
The game page could load nothing but its own server, so the theatre's YouTube video (staff's, for the room) and a player's own video link were blocked and showed black. It may now load the YouTube and Vimeo players' hosts, and the one sound or video file link the player put in the theatre's box, which the page passes on through the login page. Requests of the Flash plugin itself stay on the game's server. Not with onBeforeSendHeaders: in Electron 11 a listener there, even one that changes nothing, stops YouTube's player. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
2b70e10624
commit
1d12b7c238
5 files changed
+68
-2
No files matched your search
@@ -6,6 +6,7 @@ const sendWhitelist = new Set()
|
||||
.add("initialized")
|
||||
.add("fps")
|
||||
.add("openPage")
|
||||
.add("ownVideo")
|
||||
.add("presence")
|
||||
.add("printImage")
|
||||
.add("reloadGame")
|
||||
@@ -15,6 +16,7 @@ const sendWhitelist = new Set()
|
||||
const receiveWhitelist = new Set()
|
||||
.add("flashVarsReady")
|
||||
.add("hud")
|
||||
.add("ownVideoReady")
|
||||
.add("removed");
|
||||
|
||||
contextBridge.exposeInMainWorld(
|
||||
|
||||
@@ -1166,6 +1166,12 @@
|
||||
// main.js opens http and https addresses only
|
||||
window.client.openPage(String(event.args[0]));
|
||||
}
|
||||
else if (event.channel === "ownVideo") {
|
||||
// the player's own theatre video (the game page's link box): main.js
|
||||
// lets that one address load, then the page plays it.
|
||||
const link = String(event.args[0] || "");
|
||||
window.client.ownVideo(link).then(() => webview.send("ownVideoReady", link));
|
||||
}
|
||||
else if (event.channel === "presence") {
|
||||
// where the player is now (the game's AJClient.presenceRoom)
|
||||
showPresence(String(event.args[0] || ""));
|
||||
|
||||
+57
-1
@@ -220,6 +220,25 @@ ipcMain.handle("useServer", (event, serverUrl, gamePort, gameHost) => {
|
||||
// fetch from elsewhere (a picture named in a chat line once did) would hand
|
||||
// a stranger the player's address, or the plugin a stranger's file.
|
||||
const LOCAL_SCHEMES = ["file:", "devtools:", "chrome-devtools:", "chrome:", "data:", "blob:", "about:"];
|
||||
|
||||
// the theatre's video (the server's game page: the room's, played by staff,
|
||||
// and the player's own from its link box): the YouTube and Vimeo players
|
||||
// and what they load, measured in this Electron. a host here counts with
|
||||
// every host under it.
|
||||
const VIDEO_PLAYER_HOSTS = [
|
||||
"youtube-nocookie.com", "youtube.com", "ytimg.com", "ggpht.com", "googlevideo.com",
|
||||
"jnn-pa.googleapis.com", "gstatic.com", "www.google.com",
|
||||
"vimeo.com", "vimeocdn.com",
|
||||
];
|
||||
const videoPlayerHost = host => VIDEO_PLAYER_HOSTS.some(known => host === known || host.endsWith(`.${known}`));
|
||||
// the player's own sound or video file (the game page's link box): the one
|
||||
// address they typed, as the game page says it (ownVideo below), and where
|
||||
// it redirects. a <video>'s file is an "other" request in this Electron, as
|
||||
// is everything the Flash plugin asks for; those stay on the game's server
|
||||
// otherwise.
|
||||
let ownMedia = null;
|
||||
const ownMediaRequests = new Set(); // request ids of it, through redirects
|
||||
const withoutHash = url => url.href.replace(/#.*$/, "");
|
||||
const mayLoad = details => {
|
||||
let url;
|
||||
try {
|
||||
@@ -234,9 +253,42 @@ const mayLoad = details => {
|
||||
if (win && details.webContentsId === win.webContents.id) {
|
||||
return url.protocol === "http:" || url.protocol === "https:";
|
||||
}
|
||||
return gameOrigin !== null && url.origin === gameOrigin;
|
||||
if (gameOrigin !== null && url.origin === gameOrigin) {
|
||||
return true;
|
||||
}
|
||||
if (gameOrigin === null || (url.protocol !== "https:" && url.protocol !== "http:") || details.resourceType === "object") {
|
||||
return false;
|
||||
}
|
||||
if (details.resourceType === "other" || details.resourceType === "media") {
|
||||
if (ownMediaRequests.has(details.id) || (ownMedia !== null && withoutHash(url) === ownMedia)) {
|
||||
ownMediaRequests.add(details.id);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return url.protocol === "https:" && videoPlayerHost(url.hostname.toLowerCase());
|
||||
};
|
||||
|
||||
// the link the player put in the theatre's box, or "" when it stopped: from
|
||||
// the login page (index.html), which hears it from the game page. resolves
|
||||
// once requests for it may go.
|
||||
ipcMain.handle("ownVideo", (event, link) => {
|
||||
if (!win || event.sender !== win.webContents) {
|
||||
return false;
|
||||
}
|
||||
ownMedia = null;
|
||||
try {
|
||||
const url = new URL(String(link || ""));
|
||||
if (url.protocol === "https:" || url.protocol === "http:") {
|
||||
ownMedia = withoutHash(url);
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
// stopped, or not an address
|
||||
}
|
||||
return ownMedia !== null;
|
||||
});
|
||||
|
||||
// the server's /api only answers its own pages (it checks the Origin
|
||||
// header), and this client's page is a file. so the calls the page
|
||||
// needs are made from here, where a request carries no origin.
|
||||
@@ -494,6 +546,10 @@ app.on("web-contents-created", (event, contents) => {
|
||||
app.whenReady().then(() => {
|
||||
device.device(); // read now, so the first sign-in does not wait
|
||||
session.defaultSession.webRequest.onBeforeRequest((details, answer) => answer({cancel: !mayLoad(details)}));
|
||||
// only watching: in Electron 11 a listener that may change requests
|
||||
// (onBeforeSendHeaders, even one that changes nothing) stops YouTube's player.
|
||||
session.defaultSession.webRequest.onCompleted(details => ownMediaRequests.delete(details.id));
|
||||
session.defaultSession.webRequest.onErrorOccurred(details => ownMediaRequests.delete(details.id));
|
||||
session.fromPartition(CAPTCHA_PARTITION).webRequest.onBeforeRequest((details, answer) => {
|
||||
let url = null;
|
||||
try {
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "aj-private-client",
|
||||
"productName": "Burrow",
|
||||
"version": "1.3.1",
|
||||
"version": "1.3.2",
|
||||
"description": "The client for the Burrow private server",
|
||||
"main": "boot.js",
|
||||
"license": "UNLICENSED"
|
||||
|
||||
@@ -26,6 +26,8 @@ contextBridge.exposeInMainWorld("client", {
|
||||
showFile: file => ipcRenderer.send("showFile", file),
|
||||
toggleFullscreen: () => ipcRenderer.send("toggleFullscreen"),
|
||||
openPage: url => ipcRenderer.send("openPage", url),
|
||||
// the player's own theatre video file, which the game page may then load; "" when stopped.
|
||||
ownVideo: link => ipcRenderer.invoke("ownVideo", link),
|
||||
// Discord rich presence (discord.js): {appId, state, start, url}, or null.
|
||||
presence: info => ipcRenderer.send("presence", info),
|
||||
onFullscreen: listener => ipcRenderer.on("fullscreen", (event, on) => listener(on)),
|
||||
|
||||
Reference in new issue
Block a user