Add a small silent when landing on variant page to allow newgame sound when unfocused
authorBenjamin Auder <benjamin.auder@somewhere>
Mon, 26 Nov 2018 11:57:04 +0000 (12:57 +0100)
committerBenjamin Auder <benjamin.auder@somewhere>
Mon, 26 Nov 2018 11:57:04 +0000 (12:57 +0100)
public/javascripts/components/game.js
public/sounds/silent.mp3 [new file with mode: 0644]

index 3f74fde..b0fde5e 100644 (file)
@@ -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 (file)
index 0000000..363822c
--- /dev/null
@@ -0,0 +1 @@
+#$# git-fat fd4df114c13626a6ca851752251e0d1a2deb9817                 4200