From 7cbb9defbbcd09abb5ffd0eab3d55b070701fe2c Mon Sep 17 00:00:00 2001 From: Jesse McDonald Date: Sat, 14 Mar 2020 18:20:48 -0500 Subject: [PATCH] add some feedback for the number of connected peers --- css/chess.css | 4 ++++ index.html | 1 + js/chess.js | 22 ++++++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/css/chess.css b/css/chess.css index 4ef65d0..bff0420 100644 --- a/css/chess.css +++ b/css/chess.css @@ -207,6 +207,10 @@ button:disabled .silhouette { cursor: default; } +#cb_peers { + color: #cccccc; +} + /*@media only screen and (max-width: 8in) {*/ @media only screen and (max-aspect-ratio: 4/3) { #content { diff --git a/index.html b/index.html index 192bb13..6237678 100644 --- a/index.html +++ b/index.html @@ -217,6 +217,7 @@ and the joined piece from the capturing side moves to a new location from its original position as with any other capture.

Pawns are promoted when they reach the final row on the opposite side of the board, even if they were moved there by the other player as part of a joined pair.

+

diff --git a/js/chess.js b/js/chess.js index dec8dd5..601d837 100644 --- a/js/chess.js +++ b/js/chess.js @@ -919,6 +919,28 @@ $(function (){ }); }, 15000); + window.setInterval(function(){ + const peers = gun._.opt.peers; + var n_open = 0; + var n_total = 0; + for (const peerId in peers) { + ++n_total; + try { + const peer = peers[peerId]; + if (peer.constructor === RTCPeerConnection) { + if (peer.connectionState === 'connected') { + ++n_open; + } + } else if (peer.wire && peer.wire.constructor === WebSocket) { + if (peer.wire.readyState === peer.wire.OPEN) { + ++n_open; + } + } + } catch (err) {} + } + $('#cb_peers').text('Synchronizing with ' + n_open + (n_open === 1 ? ' peer' : ' peers') + ' (' + n_total + ' total).'); + }, 1000); + window.onpopstate = function(event){ var gameId = location.hash.replace(/^#\//, ''); if (gameId.length === 16) {