add some feedback for the number of connected peers
This commit is contained in:
parent
bd8dcc6077
commit
7cbb9defbb
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
<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>
|
||||
<p id="cb_peers"></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
22
js/chess.js
22
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) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue