From 92ff5bae505d05010e0f1be7fc00577f3ab076f1 Mon Sep 17 00:00:00 2001
From: Benjamin Auder <benjamin.auder@somewhere>
Date: Mon, 26 Nov 2018 12:57:04 +0100
Subject: [PATCH] Add a small silent when landing on variant page to allow
 newgame sound when unfocused

---
 public/javascripts/components/game.js | 10 ++++++++--
 public/sounds/silent.mp3              |  1 +
 2 files changed, 9 insertions(+), 2 deletions(-)
 create mode 100644 public/sounds/silent.mp3

diff --git a/public/javascripts/components/game.js b/public/javascripts/components/game.js
index 3f74fde9..b0fde5eb 100644
--- a/public/javascripts/components/game.js
+++ b/public/javascripts/components/game.js
@@ -393,6 +393,11 @@ Vue.component('my-game', {
 			? localStorage.getItem("myid")
 			// random enough (TODO: function)
 			: (Date.now().toString(36) + Math.random().toString(36).substr(2, 7)).toUpperCase();
+		if (!continuation)
+		{
+			// HACK: play a small silent sound to allow "new game" sound later if tab not focused
+			new Audio("/sounds/silent.mp3").play().then(() => {}).catch(err => {});
+		}
 		this.conn = new WebSocket(url + "/?sid=" + this.myid + "&page=" + variant);
 		const socketOpenListener = () => {
 			if (continuation)
@@ -734,8 +739,9 @@ Vue.component('my-game', {
 			let rectStart = startSquare.getBoundingClientRect();
 			let rectEnd = endSquare.getBoundingClientRect();
 			let translation = {x:rectEnd.x-rectStart.x, y:rectEnd.y-rectStart.y};
-			let movingPiece = document.querySelector("#" + this.getSquareId(move.start) + " > img.piece");
-			// HACK for animation (otherwise with positive translate, image slides "under background"...)
+			let movingPiece =
+				document.querySelector("#" + this.getSquareId(move.start) + " > img.piece");
+			// HACK for animation (with positive translate, image slides "under background"...)
 			// Possible improvement: just alter squares on the piece's way...
 			squares = document.getElementsByClassName("board");
 			for (let i=0; i<squares.length; i++)
diff --git a/public/sounds/silent.mp3 b/public/sounds/silent.mp3
new file mode 100644
index 00000000..363822c0
--- /dev/null
+++ b/public/sounds/silent.mp3
@@ -0,0 +1 @@
+#$# git-fat fd4df114c13626a6ca851752251e0d1a2deb9817                 4200
-- 
2.44.0