mirror of
https://github.com/burrow-dev/burrow-client.git
synced 2026-11-18 17:37:50 -05:00
Compare commits
2
Commits
1d12b7c238
...
17347462cc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
17347462cc | ||
|
|
66f0c80430 |
No files matched your search
@@ -6,6 +6,7 @@ const sendWhitelist = new Set()
|
||||
.add("initialized")
|
||||
.add("fps")
|
||||
.add("openPage")
|
||||
.add("browser")
|
||||
.add("ownVideo")
|
||||
.add("presence")
|
||||
.add("printImage")
|
||||
@@ -17,6 +18,8 @@ const receiveWhitelist = new Set()
|
||||
.add("flashVarsReady")
|
||||
.add("hud")
|
||||
.add("ownVideoReady")
|
||||
.add("browserSupported")
|
||||
.add("browserState")
|
||||
.add("removed");
|
||||
|
||||
contextBridge.exposeInMainWorld(
|
||||
|
||||
+121
-1
@@ -259,6 +259,12 @@
|
||||
width: min(100vw, calc((100vh - var(--bar-height)) * 900 / 550));
|
||||
height: min(calc(100vh - var(--bar-height)), calc(100vw * 550 / 900));
|
||||
}
|
||||
/* the theatre's browser, over the theatre screen (theatreBrowser below) */
|
||||
#theatre-browser-view {
|
||||
position: absolute;
|
||||
z-index: 1;
|
||||
background: #fff;
|
||||
}
|
||||
#loading {
|
||||
position: absolute;
|
||||
top: 0; right: 0; bottom: 0; left: 0;
|
||||
@@ -364,7 +370,7 @@
|
||||
</label>
|
||||
<label class="check"><input id="new-remember" type="checkbox"> Remember me</label>
|
||||
<label class="check agree"><input id="new-agreed" type="checkbox">
|
||||
<span>I am 13 or older, and old enough in my country to agree to this myself. I agree to the <a href="#" id="terms-signup">Terms of Service</a> and the <a href="#" id="privacy-signup">Privacy Policy</a>.</span></label>
|
||||
<span>I am 16 or older, and old enough in my country to agree to this myself. I agree to the <a href="#" id="terms-signup">Terms of Service</a> and the <a href="#" id="privacy-signup">Privacy Policy</a>.</span></label>
|
||||
<button id="sign-up" class="main" type="submit">Create account</button>
|
||||
</div>
|
||||
<p id="signup-status" class="status" role="status"></p>
|
||||
@@ -1077,6 +1083,7 @@
|
||||
webview.remove();
|
||||
webview = null;
|
||||
}
|
||||
theatreBrowser.close();
|
||||
session = null;
|
||||
$("game").hidden = true;
|
||||
$("login").hidden = false;
|
||||
@@ -1121,12 +1128,117 @@
|
||||
$("hud").textContent = "HUD";
|
||||
};
|
||||
|
||||
// the theatre's browser (experimental; the server's admin turns it on
|
||||
// for its game page): the game page (the server's game.html) says where the
|
||||
// theatre screen is and what to show, and a webview of its own is laid
|
||||
// over it here, in a session that keeps nothing (main.js). nothing of
|
||||
// it goes to the server, and it sees nothing of the game.
|
||||
const theatreBrowser = (() => {
|
||||
let view = null;
|
||||
let ready = false; // a webview answers nothing before its first dom-ready
|
||||
const webAddress = text => {
|
||||
try {
|
||||
const url = new URL(String(text));
|
||||
return url.protocol === "https:" || url.protocol === "http:" ? url.href : null;
|
||||
}
|
||||
catch (err) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
const tell = () => {
|
||||
if (view && ready && webview) {
|
||||
let url = "";
|
||||
try {
|
||||
url = view.getURL();
|
||||
}
|
||||
catch (err) {
|
||||
// not attached yet
|
||||
}
|
||||
webview.send("browserState", {url, back: view.canGoBack(), forward: view.canGoForward(), loading: view.isLoading()});
|
||||
}
|
||||
};
|
||||
const close = () => {
|
||||
if (view) {
|
||||
view.remove();
|
||||
view = null;
|
||||
ready = false;
|
||||
}
|
||||
};
|
||||
const open = url => {
|
||||
if (view && ready) {
|
||||
view.loadURL(url);
|
||||
return;
|
||||
}
|
||||
if (view) {
|
||||
view.src = url;
|
||||
return;
|
||||
}
|
||||
view = document.createElement("webview");
|
||||
view.id = "theatre-browser-view";
|
||||
view.setAttribute("partition", "aj-browser");
|
||||
view.src = url;
|
||||
view.style.visibility = "hidden";
|
||||
view.addEventListener("dom-ready", () => {
|
||||
ready = true;
|
||||
tell();
|
||||
});
|
||||
for (const name of ["did-navigate", "did-navigate-in-page", "did-start-loading", "did-stop-loading", "did-fail-load"]) {
|
||||
view.addEventListener(name, tell);
|
||||
}
|
||||
$("stage").append(view);
|
||||
};
|
||||
// where: {x, y, w, h} in the game page's pixels, `clip` its CSS
|
||||
// clip-path (what the game draws over it cut out), `shown`.
|
||||
const place = where => {
|
||||
if (!view || !webview || !where) {
|
||||
return;
|
||||
}
|
||||
const game = webview.getBoundingClientRect();
|
||||
const stage = $("stage").getBoundingClientRect();
|
||||
const number = value => (Number.isFinite(Number(value)) ? Number(value) : 0);
|
||||
view.style.left = `${game.left - stage.left + number(where.x)}px`;
|
||||
view.style.top = `${game.top - stage.top + number(where.y)}px`;
|
||||
view.style.width = `${Math.max(0, number(where.w))}px`;
|
||||
view.style.height = `${Math.max(0, number(where.h))}px`;
|
||||
view.style.clipPath = typeof where.clip === "string" && /^(?:none|polygon\(evenodd,[0-9a-z%.,\s]*\))$/.test(where.clip) ? where.clip : "none";
|
||||
view.style.visibility = where.shown === true ? "visible" : "hidden";
|
||||
};
|
||||
return {
|
||||
close,
|
||||
// one message from the game page: {action, url?, where?}
|
||||
handle(message) {
|
||||
if (!message || typeof message !== "object") {
|
||||
return;
|
||||
}
|
||||
const url = webAddress(message.url);
|
||||
if (message.action === "go" && url) {
|
||||
open(url);
|
||||
}
|
||||
else if (message.action === "close") {
|
||||
close();
|
||||
}
|
||||
else if (view && ready && message.action === "back" && view.canGoBack()) {
|
||||
view.goBack();
|
||||
}
|
||||
else if (view && ready && message.action === "forward" && view.canGoForward()) {
|
||||
view.goForward();
|
||||
}
|
||||
else if (view && ready && message.action === "reload") {
|
||||
view.reload();
|
||||
}
|
||||
place(message.where);
|
||||
tell();
|
||||
},
|
||||
};
|
||||
})();
|
||||
|
||||
const openGame = () => {
|
||||
// A reload keeps the sound as it was; a login starts as the setting says.
|
||||
const muted = webview ? isMuted() : fieldValue("start-muted");
|
||||
if (webview) {
|
||||
webview.remove();
|
||||
}
|
||||
theatreBrowser.close();
|
||||
// A fresh webview each time: the page and the plugin start clean.
|
||||
webview = document.createElement("webview");
|
||||
webview.setAttribute("plugins", "");
|
||||
@@ -1135,6 +1247,8 @@
|
||||
webview.addEventListener("dom-ready", () => {
|
||||
setMuted(muted);
|
||||
webview.send("flashVarsReady", session.flashVars);
|
||||
// this client can show the theatre's browser; the server says whether it is offered
|
||||
webview.send("browserSupported", true);
|
||||
}, {once: true});
|
||||
webview.addEventListener("did-fail-load", event => {
|
||||
if (event.isMainFrame) {
|
||||
@@ -1166,6 +1280,12 @@
|
||||
// main.js opens http and https addresses only
|
||||
window.client.openPage(String(event.args[0]));
|
||||
}
|
||||
else if (event.channel === "browser") {
|
||||
// not inside this handler: Electron 11 takes the whole window
|
||||
// down when a webview is made while another's message is handled.
|
||||
const message = event.args[0];
|
||||
setTimeout(() => theatreBrowser.handle(message), 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.
|
||||
|
||||
+64
-2
@@ -76,6 +76,21 @@ const SANDBOXED = !app.commandLine.hasSwitch("aj-no-renderer-sandbox");
|
||||
// the main process's own calls to a server get a session to themselves, so
|
||||
// that the rule below about what pages may load does not apply to them.
|
||||
const API_PARTITION = "aj-api";
|
||||
// the theatre's browser (experimental, index.html): a webview of its own
|
||||
// over the theatre screen, in a session of its own that is kept in memory
|
||||
// only, so nothing it visits stays and none of it reaches the game.
|
||||
const BROWSER_PARTITION = "aj-browser";
|
||||
let browserSession = null;
|
||||
const isBrowser = contents => browserSession !== null && contents.session === browserSession;
|
||||
const webAddress = text => {
|
||||
try {
|
||||
const url = new URL(String(text));
|
||||
return url.protocol === "https:" || url.protocol === "http:";
|
||||
}
|
||||
catch (err) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
// two copies cannot share one HTTP cache: the second to start moves the
|
||||
// first one's cache aside, and the first then gets broken game files out of
|
||||
@@ -493,16 +508,38 @@ ipcMain.on("toggleFullscreen", () => {
|
||||
|
||||
app.on("web-contents-created", (event, contents) => {
|
||||
// the game page is a guest: it gets our preload and nothing more.
|
||||
contents.on("will-attach-webview", (attachEvent, webPreferences) => {
|
||||
webPreferences.preload = GAME_PRELOAD;
|
||||
contents.on("will-attach-webview", (attachEvent, webPreferences, params) => {
|
||||
webPreferences.nodeIntegration = false;
|
||||
webPreferences.contextIsolation = true;
|
||||
// the theatre's browser: a web page like any, with nothing of ours.
|
||||
if (params.partition === BROWSER_PARTITION) {
|
||||
delete webPreferences.preload;
|
||||
delete webPreferences.preloadURL;
|
||||
webPreferences.sandbox = true;
|
||||
webPreferences.plugins = false;
|
||||
webPreferences.webviewTag = false;
|
||||
if (!webAddress(params.src)) {
|
||||
params.src = "about:blank";
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (params.partition) {
|
||||
attachEvent.preventDefault();
|
||||
return;
|
||||
}
|
||||
webPreferences.preload = GAME_PRELOAD;
|
||||
webPreferences.backgroundThrottling = false;
|
||||
webPreferences.sandbox = SANDBOXED;
|
||||
});
|
||||
// the login page stays the login page, and the game page stays on its
|
||||
// server: a page that arrived any other way would inherit what these have.
|
||||
contents.on("will-navigate", (navigateEvent, url) => {
|
||||
if (isBrowser(contents)) {
|
||||
if (!webAddress(url)) {
|
||||
navigateEvent.preventDefault();
|
||||
}
|
||||
return;
|
||||
}
|
||||
let origin = null;
|
||||
try {
|
||||
origin = new URL(url).origin;
|
||||
@@ -516,6 +553,13 @@ app.on("web-contents-created", (event, contents) => {
|
||||
});
|
||||
contents.on("new-window", (windowEvent, url) => {
|
||||
windowEvent.preventDefault();
|
||||
// the theatre's browser opens a new window's page in itself
|
||||
if (isBrowser(contents)) {
|
||||
if (webAddress(url)) {
|
||||
contents.loadURL(url);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (/^https?:\/\//.test(url)) {
|
||||
shell.openExternal(url);
|
||||
}
|
||||
@@ -550,6 +594,24 @@ app.whenReady().then(() => {
|
||||
// (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));
|
||||
// the theatre's browser: the web, and nothing of this computer's; no
|
||||
// camera, microphone, notifications or the like, and no downloads. it says
|
||||
// it is plain Chrome, which sites know, not this client.
|
||||
browserSession = session.fromPartition(BROWSER_PARTITION);
|
||||
browserSession.setUserAgent(browserSession.getUserAgent().replace(/ (?:Electron|Burrow|aj-private-client)\/\S+/gi, ""));
|
||||
browserSession.setPermissionRequestHandler((contents, permission, answer) => answer(false));
|
||||
browserSession.setPermissionCheckHandler(() => false);
|
||||
browserSession.on("will-download", downloadEvent => downloadEvent.preventDefault());
|
||||
browserSession.webRequest.onBeforeRequest((details, answer) => {
|
||||
let url = null;
|
||||
try {
|
||||
url = new URL(details.url);
|
||||
}
|
||||
catch (err) {
|
||||
// not an address: refused.
|
||||
}
|
||||
answer({cancel: !url || !["https:", "http:", "data:", "blob:", "about:"].includes(url.protocol)});
|
||||
});
|
||||
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.2",
|
||||
"version": "1.3.3",
|
||||
"description": "The client for the Burrow private server",
|
||||
"main": "boot.js",
|
||||
"license": "UNLICENSED"
|
||||
|
||||
Reference in new issue
Block a user