add some feedback for the number of connected peers

This commit is contained in:
Jesse D. McDonald 2020-03-14 18:20:48 -05:00
parent bd8dcc6077
commit 7cbb9defbb
3 changed files with 27 additions and 0 deletions

View File

@ -207,6 +207,10 @@ button:disabled .silhouette {
cursor: default; cursor: default;
} }
#cb_peers {
color: #cccccc;
}
/*@media only screen and (max-width: 8in) {*/ /*@media only screen and (max-width: 8in) {*/
@media only screen and (max-aspect-ratio: 4/3) { @media only screen and (max-aspect-ratio: 4/3) {
#content { #content {

View File

@ -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.</p> and the joined piece from the capturing side moves to a new location from its original position as with any other capture.</p>
<p>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.</p> <p>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.</p>
</details> </details>
<p id="cb_peers"></p>
</div> </div>
</div> </div>

View File

@ -919,6 +919,28 @@ $(function (){
}); });
}, 15000); }, 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){ window.onpopstate = function(event){
var gameId = location.hash.replace(/^#\//, ''); var gameId = location.hash.replace(/^#\//, '');
if (gameId.length === 16) { if (gameId.length === 16) {